-
Notifications
You must be signed in to change notification settings - Fork 29
/
decorators.go
38 lines (31 loc) · 1.33 KB
/
decorators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package ante
import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
entitykeeper "github.com/ixofoundation/ixo-blockchain/v3/x/entity/keeper"
entitytypes "github.com/ixofoundation/ixo-blockchain/v3/x/entity/types"
)
type BlockNftContractTransferForEntityDecorator struct {
entityKeeper entitykeeper.Keeper
}
func NewBlockNftContractTransferForEntityDecorator(entityKeeper entitykeeper.Keeper) BlockNftContractTransferForEntityDecorator {
return BlockNftContractTransferForEntityDecorator{
entityKeeper: entityKeeper,
}
}
// if MsgExecuteContract is for nft module contract then block direct MsgExecuteContract as must be done through entity module
func (dec BlockNftContractTransferForEntityDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
wasmMsg, ok := msg.(*wasmtypes.MsgExecuteContract)
if !ok {
continue
}
var params entitytypes.Params
dec.entityKeeper.ParamSpace.GetParamSetIfExists(ctx, ¶ms)
if wasmMsg.Contract == params.NftContractAddress {
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "cannot execute contract set as the entity nft contract address")
}
}
return next(ctx, tx, simulate)
}