Skip to content

Commit

Permalink
feat: load ibc nft-transfer module
Browse files Browse the repository at this point in the history
  • Loading branch information
taramakage committed Aug 24, 2023
1 parent d0ce629 commit cec2a7b
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 8 deletions.
36 changes: 30 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import (
tibcroutingtypes "github.com/bianjieai/tibc-go/modules/tibc/core/26-routing/types"
tibckeeper "github.com/bianjieai/tibc-go/modules/tibc/core/keeper"

nfttransfer "github.com/bianjieai/nft-transfer"
ibcnfttransferkeeper "github.com/bianjieai/nft-transfer/keeper"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"

"github.com/evmos/ethermint/ethereum/eip712"
srvflags "github.com/evmos/ethermint/server/flags"
ethermint "github.com/evmos/ethermint/types"
Expand All @@ -113,6 +117,7 @@ import (
"github.com/irisnet/irishub/lite"
guardiankeeper "github.com/irisnet/irishub/modules/guardian/keeper"
guardiantypes "github.com/irisnet/irishub/modules/guardian/types"
"github.com/irisnet/irishub/modules/internft"
mintkeeper "github.com/irisnet/irishub/modules/mint/keeper"
minttypes "github.com/irisnet/irishub/modules/mint/types"
iristypes "github.com/irisnet/irishub/types"
Expand Down Expand Up @@ -156,8 +161,9 @@ type IrisApp struct {
ConsensusParamsKeeper consensuskeeper.Keeper

//ibc
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCTransferKeeper ibctransferkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCTransferKeeper ibctransferkeeper.Keeper
IBCNFTTransferKeeper ibcnfttransferkeeper.Keeper

// make scoped keepers public for test purposes
scopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -193,9 +199,10 @@ type IrisApp struct {
// simulation manager
sm *module.SimulationManager

transferModule transfer.AppModule
nfttransferModule tibcnfttransfer.AppModule
mttransferModule tibcmttransfer.AppModule
transferModule transfer.AppModule
nfttransferModule tibcnfttransfer.AppModule
mttransferModule tibcmttransfer.AppModule
ibcnfttransferModule nfttransfer.AppModule
}

// NewIrisApp returns a reference to an initialized IrisApp.
Expand Down Expand Up @@ -237,6 +244,7 @@ func NewIrisApp(
consensustypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
ibcnfttransfertypes.StoreKey,
capabilitytypes.StoreKey,
guardiantypes.StoreKey,
tokentypes.StoreKey,
Expand Down Expand Up @@ -306,6 +314,7 @@ func NewIrisApp(
)
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedNFTTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibcnfttransfertypes.ModuleName)

app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
Expand Down Expand Up @@ -468,10 +477,25 @@ func NewIrisApp(
app.transferModule = transfer.NewAppModule(app.IBCTransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.IBCTransferKeeper)

app.IBCNFTTransferKeeper = ibcnfttransferkeeper.NewKeeper(
appCodec,
keys[ibcnfttransfertypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
internft.NewInterNftKeeper(appCodec, app.NFTKeeper, app.AccountKeeper),
scopedNFTTransferKeeper,
)
app.ibcnfttransferModule = nfttransfer.NewAppModule(app.IBCNFTTransferKeeper)
nfttransferIBCModule := nfttransfer.NewIBCModule(app.IBCNFTTransferKeeper)

// routerModule := router.NewAppModule(app.RouterKeeper, transferIBCModule)
// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(ibcnfttransfertypes.ModuleName, nfttransferIBCModule)
app.IBCKeeper.SetRouter(ibcRouter)

app.nfttransferModule = tibcnfttransfer.NewAppModule(app.TIBCNFTTransferKeeper)
Expand Down
12 changes: 12 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
Expand Down Expand Up @@ -74,6 +75,8 @@ import (
tibchost "github.com/bianjieai/tibc-go/modules/tibc/core/24-host"
tibccli "github.com/bianjieai/tibc-go/modules/tibc/core/client/cli"

nfttransfer "github.com/bianjieai/nft-transfer"

"github.com/evmos/ethermint/x/evm"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/feemarket"
Expand Down Expand Up @@ -138,6 +141,7 @@ var (
tibcnfttransfer.AppModuleBasic{},
tibcmttransfer.AppModuleBasic{},
mt.AppModuleBasic{},
nfttransfer.AppModuleBasic{},

evm.AppModuleBasic{},
feemarket.AppModuleBasic{},
Expand Down Expand Up @@ -257,6 +261,7 @@ func appModules(
ibc.NewAppModule(app.IBCKeeper), tibc.NewAppModule(app.TIBCKeeper),
params.NewAppModule(app.ParamsKeeper),
app.transferModule,
app.ibcnfttransferModule,
app.nfttransferModule,
app.mttransferModule,
guardian.NewAppModule(appCodec, app.GuardianKeeper),
Expand Down Expand Up @@ -384,6 +389,7 @@ func simulationModules(
),
ibc.NewAppModule(app.IBCKeeper),
app.transferModule,
app.ibcnfttransferModule,
guardian.NewAppModule(appCodec, app.GuardianKeeper),
token.NewAppModule(
appCodec,
Expand Down Expand Up @@ -488,6 +494,8 @@ func orderBeginBlockers() []string {
tibcnfttypes.ModuleName,
tibcmttypes.ModuleName,
guardiantypes.ModuleName,

ibcnfttransfertypes.ModuleName,
}
}

Expand Down Expand Up @@ -538,6 +546,8 @@ func orderEndBlockers() []string {
tibcnfttypes.ModuleName,
tibcmttypes.ModuleName,
guardiantypes.ModuleName,

ibcnfttransfertypes.ModuleName,
}
}

Expand Down Expand Up @@ -592,5 +602,7 @@ func orderInitBlockers() []string {
guardiantypes.ModuleName,
// NOTE: crisis module must go at the end to check for invariants on each module
crisistypes.ModuleName,

ibcnfttransfertypes.ModuleName,
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/irisnet/irishub
go 1.19

require (
github.com/bianjieai/nft-transfer v1.1.2-beta.0.20230824091700-ad134c96cf57
github.com/bianjieai/tibc-go v0.4.4-0.20230824091732-bbd58021f825
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
Expand Down Expand Up @@ -59,7 +60,6 @@ require (
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bianjieai/ethermint v0.6.1-0.20230824080820-7416e4b8e2c6 h1:eF39/n5pVKfxqanQvNdKAeqKF3Oz3iGDL/cX202HK8g=
github.com/bianjieai/ethermint v0.6.1-0.20230824080820-7416e4b8e2c6/go.mod h1:JEhGmVj5rZX5bTfOqh3nltE2N6+qMI4HVNV2vW6PpOQ=
github.com/bianjieai/nft-transfer v1.1.2-beta.0.20230824091700-ad134c96cf57 h1:L3pt1Rd8Fr8wqY3Nr6PHllxRtYQgj3GRlQcBaFzzZa4=
github.com/bianjieai/nft-transfer v1.1.2-beta.0.20230824091700-ad134c96cf57/go.mod h1:Mzg0WR5zWqosdlJ+sW6LTNBiCeuoKXWPt7E/owSn0Xw=
github.com/bianjieai/tibc-go v0.4.4-0.20230824091732-bbd58021f825 h1:+/6FK0V7uXouVYigb1EvPGuDN1ZDPfBnvzOUbTRe4rg=
github.com/bianjieai/tibc-go v0.4.4-0.20230824091732-bbd58021f825/go.mod h1:OBT3OZWqF8eTyQNGOvHycGg+pkhWWm5RwELT/NRZM9k=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
Expand Down Expand Up @@ -552,7 +554,6 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
Expand Down
49 changes: 49 additions & 0 deletions modules/internft/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package internft

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper"
nfttypes "github.com/irisnet/irismod/modules/nft/types"
)

type (
// AccountKeeper defines the contract required for account APIs.
AccountKeeper interface {
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
// Set an account in the store.
SetAccount(sdk.Context, authtypes.AccountI)
GetModuleAddress(name string) sdk.AccAddress
}
// InterNftKeeper defines the ICS721 Keeper
InterNftKeeper struct {
nk nftkeeper.Keeper
cdc codec.Codec
ak AccountKeeper
cb nfttypes.ClassBuilder
tb nfttypes.TokenBuilder
}

InterClass struct {
ID string
URI string
Data string
}

InterToken struct {
ClassID string
ID string
URI string
Data string
}
)

func (d InterClass) GetID() string { return d.ID }
func (d InterClass) GetURI() string { return d.URI }
func (d InterClass) GetData() string { return d.Data }
func (t InterToken) GetClassID() string { return t.ClassID }
func (t InterToken) GetID() string { return t.ID }
func (t InterToken) GetURI() string { return t.URI }
func (t InterToken) GetData() string { return t.Data }
Loading

0 comments on commit cec2a7b

Please sign in to comment.