Skip to content

Commit

Permalink
Merge pull request #34 from initia-labs/fix/nft-transfer
Browse files Browse the repository at this point in the history
fix: add move middleware for nft-transfer
  • Loading branch information
beer-1 authored Dec 13, 2023
2 parents 4f16b82 + 9ed4b35 commit 70af2d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
36 changes: 18 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ type InitiaApp struct {
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
Expand Down Expand Up @@ -547,18 +545,13 @@ func NewInitiaApp(

var transferStack porttypes.IBCModule
{
routerMiddleware := &router.IBCMiddleware{}
moveMiddleware := &moveibcmiddleware.IBCMiddleware{}
feeMiddleware := &ibcfee.IBCMiddleware{}
permMiddleware := &ibcperm.IBCMiddleware{}

// Create Transfer Keepers
transferKeeper := ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
// ics4wrapper: transfer -> router
routerMiddleware,
app.RouterKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
Expand All @@ -568,9 +561,6 @@ func NewInitiaApp(
app.TransferKeeper = &transferKeeper
transferIBCModule := ibctransfer.NewIBCModule(*app.TransferKeeper)

// channel -> perm -> ibcfee -> move -> router -> transfer
transferStack = permMiddleware

// setup package forward module for multi-hop forwarding
app.RouterKeeper = routerkeeper.NewKeeper(
appCodec, keys[routertypes.StoreKey],
Expand All @@ -580,9 +570,9 @@ func NewInitiaApp(
app.DistrKeeper,
app.BankKeeper,
// ics4wrapper: transfer -> router -> fee
feeMiddleware,
app.IBCFeeKeeper,
)
*routerMiddleware = router.NewIBCMiddleware(
routerMiddleware := router.NewIBCMiddleware(
// receive: router -> transfer
transferIBCModule,
app.RouterKeeper,
Expand All @@ -592,7 +582,7 @@ func NewInitiaApp(
)

// create move middleware for transfer
*moveMiddleware = moveibcmiddleware.NewIBCMiddleware(
moveMiddleware := moveibcmiddleware.NewIBCMiddleware(
// receive: move -> router -> transfer
routerMiddleware,
// ics4wrapper: not used
Expand All @@ -601,15 +591,15 @@ func NewInitiaApp(
)

// create ibcfee middleware for transfer
*feeMiddleware = ibcfee.NewIBCMiddleware(
feeMiddleware := ibcfee.NewIBCMiddleware(
// receive: fee -> move -> router -> transfer
moveMiddleware,
// ics4wrapper: transfer -> router -> fee -> channel
*app.IBCFeeKeeper,
)

// create perm middleware for transfer
*permMiddleware = ibcperm.NewIBCMiddleware(
transferStack = ibcperm.NewIBCMiddleware(
// receive: perm -> fee -> move -> router -> transfer
feeMiddleware,
// ics4wrapper: not used
Expand Down Expand Up @@ -638,11 +628,21 @@ func NewInitiaApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
nftTransferIBCModule := ibcnfttransfer.NewIBCModule(*app.NftTransferKeeper)

// create move middleware for nft-transfer
moveMiddleware := moveibcmiddleware.NewIBCMiddleware(
// receive: move -> nft-transfer
nftTransferIBCModule,
// ics4wrapper: not used
nil,
moveKeeper,
)

nftTransferStack = ibcperm.NewIBCMiddleware(
// receive: perm -> fee -> nft transfer
ibcfee.NewIBCMiddleware(
// receive: channel -> fee -> nft transfer
nftTransferIBCModule,
// receive: channel -> fee -> move -> nft transfer
moveMiddleware,
*app.IBCFeeKeeper,
),
// ics4wrapper: not used
Expand Down
14 changes: 7 additions & 7 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func SetupWithGenesisAccounts(
) *InitiaApp {
app, genesisState := setup(nil, true)

if len(genAccs) == 0 {
privAcc := secp256k1.GenPrivKey()
genAccs = []authtypes.GenesisAccount{
authtypes.NewBaseAccount(privAcc.PubKey().Address().Bytes(), privAcc.PubKey(), 0, 0),
}
}

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
Expand All @@ -95,13 +102,6 @@ func SetupWithGenesisAccounts(
valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
}

if genAccs == nil || len(genAccs) == 0 {
privAcc := secp256k1.GenPrivKey()
genAccs = []authtypes.GenesisAccount{
authtypes.NewBaseAccount(privAcc.PubKey().Address().Bytes(), privAcc.PubKey(), 0, 0),
}
}

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

Expand Down

0 comments on commit 70af2d3

Please sign in to comment.