x/ibc-transfer: remove alias.go usage (#6427)
* x/ibc-transfer: remove alias.go usage * Fix formatting Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>
This commit is contained in:
parent
6a0ac5b67d
commit
0286a4a5dc
|
@ -31,6 +31,8 @@ import (
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||||
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
|
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
|
||||||
|
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
|
||||||
|
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
||||||
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
||||||
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
|
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
|
||||||
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||||
|
@ -95,7 +97,7 @@ var (
|
||||||
stakingtypes.BondedPoolName: {auth.Burner, auth.Staking},
|
stakingtypes.BondedPoolName: {auth.Burner, auth.Staking},
|
||||||
stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking},
|
stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking},
|
||||||
govtypes.ModuleName: {auth.Burner},
|
govtypes.ModuleName: {auth.Burner},
|
||||||
transfer.ModuleName: {auth.Minter, auth.Burner},
|
ibctransfertypes.ModuleName: {auth.Minter, auth.Burner},
|
||||||
}
|
}
|
||||||
|
|
||||||
// module accounts that are allowed to receive tokens
|
// module accounts that are allowed to receive tokens
|
||||||
|
@ -138,7 +140,7 @@ type SimApp struct {
|
||||||
ParamsKeeper paramskeeper.Keeper
|
ParamsKeeper paramskeeper.Keeper
|
||||||
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
|
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
|
||||||
EvidenceKeeper evidence.Keeper
|
EvidenceKeeper evidence.Keeper
|
||||||
TransferKeeper transfer.Keeper
|
TransferKeeper ibctransferkeeper.Keeper
|
||||||
|
|
||||||
// make scoped keepers public for test purposes
|
// make scoped keepers public for test purposes
|
||||||
ScopedIBCKeeper capability.ScopedKeeper
|
ScopedIBCKeeper capability.ScopedKeeper
|
||||||
|
@ -168,7 +170,7 @@ func NewSimApp(
|
||||||
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
|
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
|
||||||
minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
|
minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
|
||||||
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
|
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
|
||||||
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
|
evidence.StoreKey, ibctransfertypes.StoreKey, capability.StoreKey,
|
||||||
)
|
)
|
||||||
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
|
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
|
||||||
memKeys := sdk.NewMemoryStoreKeys(capability.MemStoreKey)
|
memKeys := sdk.NewMemoryStoreKeys(capability.MemStoreKey)
|
||||||
|
@ -201,7 +203,7 @@ func NewSimApp(
|
||||||
// add capability keeper and ScopeToModule for ibc module
|
// add capability keeper and ScopeToModule for ibc module
|
||||||
app.CapabilityKeeper = capability.NewKeeper(appCodec, keys[capability.StoreKey], memKeys[capability.MemStoreKey])
|
app.CapabilityKeeper = capability.NewKeeper(appCodec, keys[capability.StoreKey], memKeys[capability.MemStoreKey])
|
||||||
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
|
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
|
||||||
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(transfer.ModuleName)
|
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
|
||||||
|
|
||||||
// add keepers
|
// add keepers
|
||||||
app.AccountKeeper = auth.NewAccountKeeper(
|
app.AccountKeeper = auth.NewAccountKeeper(
|
||||||
|
@ -254,8 +256,8 @@ func NewSimApp(
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create Transfer Keepers
|
// Create Transfer Keepers
|
||||||
app.TransferKeeper = transfer.NewKeeper(
|
app.TransferKeeper = ibctransferkeeper.NewKeeper(
|
||||||
appCodec, keys[transfer.StoreKey],
|
appCodec, keys[ibctransfertypes.StoreKey],
|
||||||
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
|
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
|
||||||
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
|
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
|
||||||
)
|
)
|
||||||
|
@ -263,7 +265,7 @@ func NewSimApp(
|
||||||
|
|
||||||
// Create static IBC router, add transfer route, then set and seal it
|
// Create static IBC router, add transfer route, then set and seal it
|
||||||
ibcRouter := port.NewRouter()
|
ibcRouter := port.NewRouter()
|
||||||
ibcRouter.AddRoute(transfer.ModuleName, transferModule)
|
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
|
||||||
app.IBCKeeper.SetRouter(ibcRouter)
|
app.IBCKeeper.SetRouter(ibcRouter)
|
||||||
|
|
||||||
// create evidence keeper with router
|
// create evidence keeper with router
|
||||||
|
@ -314,7 +316,7 @@ func NewSimApp(
|
||||||
app.mm.SetOrderInitGenesis(
|
app.mm.SetOrderInitGenesis(
|
||||||
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
|
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
|
||||||
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName,
|
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName,
|
||||||
ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName,
|
ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, ibctransfertypes.ModuleName,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
"github.com/cosmos/cosmos-sdk/x/evidence"
|
"github.com/cosmos/cosmos-sdk/x/evidence"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
|
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
||||||
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
|
@ -163,7 +163,7 @@ func TestAppImportExport(t *testing.T) {
|
||||||
{app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}},
|
{app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}},
|
||||||
{app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}},
|
{app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}},
|
||||||
{app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}},
|
{app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}},
|
||||||
{app.keys[transfer.StoreKey], newApp.keys[transfer.StoreKey], [][]byte{}},
|
{app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, skp := range storeKeysPrefixes {
|
for _, skp := range storeKeysPrefixes {
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package transfer
|
|
||||||
|
|
||||||
// autogenerated code using github.com/rigelrozanski/multitool
|
|
||||||
// aliases generated for the following subdirectories:
|
|
||||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper
|
|
||||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc-transfer/types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
EventTypeTimeout = types.EventTypeTimeout
|
|
||||||
EventTypePacket = types.EventTypePacket
|
|
||||||
EventTypeChannelClose = types.EventTypeChannelClose
|
|
||||||
AttributeKeyReceiver = types.AttributeKeyReceiver
|
|
||||||
AttributeKeyValue = types.AttributeKeyValue
|
|
||||||
AttributeKeyRefundReceiver = types.AttributeKeyRefundReceiver
|
|
||||||
AttributeKeyRefundValue = types.AttributeKeyRefundValue
|
|
||||||
AttributeKeyAckSuccess = types.AttributeKeyAckSuccess
|
|
||||||
AttributeKeyAckError = types.AttributeKeyAckError
|
|
||||||
ModuleName = types.ModuleName
|
|
||||||
StoreKey = types.StoreKey
|
|
||||||
RouterKey = types.RouterKey
|
|
||||||
QuerierRoute = types.QuerierRoute
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// functions aliases
|
|
||||||
NewKeeper = keeper.NewKeeper
|
|
||||||
RegisterCodec = types.RegisterCodec
|
|
||||||
GetEscrowAddress = types.GetEscrowAddress
|
|
||||||
GetDenomPrefix = types.GetDenomPrefix
|
|
||||||
NewMsgTransfer = types.NewMsgTransfer
|
|
||||||
RegisterInterfaces = types.RegisterInterfaces
|
|
||||||
|
|
||||||
// variable aliases
|
|
||||||
ModuleCdc = types.ModuleCdc
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
Keeper = keeper.Keeper
|
|
||||||
BankKeeper = types.BankKeeper
|
|
||||||
ChannelKeeper = types.ChannelKeeper
|
|
||||||
ClientKeeper = types.ClientKeeper
|
|
||||||
ConnectionKeeper = types.ConnectionKeeper
|
|
||||||
FungibleTokenPacketData = types.FungibleTokenPacketData
|
|
||||||
FungibleTokenPacketAcknowledgement = types.FungibleTokenPacketAcknowledgement
|
|
||||||
MsgTransfer = types.MsgTransfer
|
|
||||||
)
|
|
|
@ -4,11 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitGenesis binds to portid from genesis state
|
// InitGenesis binds to portid from genesis state
|
||||||
func InitGenesis(ctx sdk.Context, keeper Keeper, state types.GenesisState) {
|
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState) {
|
||||||
keeper.SetPort(ctx, state.PortID)
|
keeper.SetPort(ctx, state.PortID)
|
||||||
|
|
||||||
// Only try to bind to port if it is not already bound, since we may already own
|
// Only try to bind to port if it is not already bound, since we may already own
|
||||||
|
@ -25,12 +26,12 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state types.GenesisState) {
|
||||||
// check if the module account exists
|
// check if the module account exists
|
||||||
moduleAcc := keeper.GetTransferAccount(ctx)
|
moduleAcc := keeper.GetTransferAccount(ctx)
|
||||||
if moduleAcc == nil {
|
if moduleAcc == nil {
|
||||||
panic(fmt.Sprintf("%s module account has not been set", ModuleName))
|
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportGenesis exports transfer module's portID into its geneis state
|
// ExportGenesis exports transfer module's portID into its geneis state
|
||||||
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState {
|
||||||
return types.GenesisState{
|
return types.GenesisState{
|
||||||
PortID: keeper.GetPort(ctx),
|
PortID: keeper.GetPort(ctx),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,17 @@ package transfer
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHandler returns sdk.Handler for IBC token transfer module messages
|
// NewHandler returns sdk.Handler for IBC token transfer module messages
|
||||||
func NewHandler(k Keeper) sdk.Handler {
|
func NewHandler(k keeper.Keeper) sdk.Handler {
|
||||||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
||||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *MsgTransfer:
|
case *types.MsgTransfer:
|
||||||
return handleMsgTransfer(ctx, k, msg)
|
return handleMsgTransfer(ctx, k, msg)
|
||||||
default:
|
default:
|
||||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ICS-20 transfer message type: %T", msg)
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ICS-20 transfer message type: %T", msg)
|
||||||
|
@ -20,7 +22,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// See createOutgoingPacket in spec:https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
|
// See createOutgoingPacket in spec:https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
|
||||||
func handleMsgTransfer(ctx sdk.Context, k Keeper, msg *MsgTransfer) (*sdk.Result, error) {
|
func handleMsgTransfer(ctx sdk.Context, k keeper.Keeper, msg *types.MsgTransfer) (*sdk.Result, error) {
|
||||||
if err := k.SendTransfer(
|
if err := k.SendTransfer(
|
||||||
ctx, msg.SourcePort, msg.SourceChannel, msg.Amount, msg.Sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
|
ctx, msg.SourcePort, msg.SourceChannel, msg.Amount, msg.Sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -32,9 +34,9 @@ func handleMsgTransfer(ctx sdk.Context, k Keeper, msg *MsgTransfer) (*sdk.Result
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
sdk.EventTypeMessage,
|
sdk.EventTypeMessage,
|
||||||
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
||||||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()),
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()),
|
||||||
sdk.NewAttribute(AttributeKeyReceiver, msg.Receiver),
|
sdk.NewAttribute(types.AttributeKeyReceiver, msg.Receiver),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() {
|
||||||
suite.Require().Nil(err, "transfer module could not claim capability")
|
suite.Require().Nil(err, "transfer module could not claim capability")
|
||||||
|
|
||||||
ctx := suite.chainA.GetContext()
|
ctx := suite.chainA.GetContext()
|
||||||
msg := transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0)
|
msg := types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0)
|
||||||
res, err := handler(ctx, msg)
|
res, err := handler(ctx, msg)
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
suite.Require().Nil(res, "%+v", res) // channel does not exist
|
suite.Require().Nil(res, "%+v", res) // channel does not exist
|
||||||
|
@ -105,14 +105,14 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() {
|
||||||
suite.Require().NotNil(res, "%+v", res) // successfully executed
|
suite.Require().NotNil(res, "%+v", res) // successfully executed
|
||||||
|
|
||||||
// test when the source is false
|
// test when the source is false
|
||||||
msg = transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0)
|
msg = types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins2, testAddr1, testAddr2.String(), 110, 0)
|
||||||
_ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins2)
|
_ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins2)
|
||||||
|
|
||||||
res, err = handler(ctx, msg)
|
res, err = handler(ctx, msg)
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
suite.Require().Nil(res, "%+v", res) // incorrect denom prefix
|
suite.Require().Nil(res, "%+v", res) // incorrect denom prefix
|
||||||
|
|
||||||
msg = transfer.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins1, testAddr1, testAddr2.String(), 110, 0)
|
msg = types.NewMsgTransfer(testPort1, testChannel1, testPrefixedCoins1, testAddr1, testAddr2.String(), 110, 0)
|
||||||
suite.chainA.App.BankKeeper.SetSupply(ctx, bank.NewSupply(testPrefixedCoins1))
|
suite.chainA.App.BankKeeper.SetSupply(ctx, bank.NewSupply(testPrefixedCoins1))
|
||||||
_ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins1)
|
_ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins1)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/rest"
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/rest"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/simulation"
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
||||||
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
|
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
|
||||||
|
@ -42,12 +43,12 @@ type AppModuleBasic struct{}
|
||||||
|
|
||||||
// Name implements AppModuleBasic interface
|
// Name implements AppModuleBasic interface
|
||||||
func (AppModuleBasic) Name() string {
|
func (AppModuleBasic) Name() string {
|
||||||
return ModuleName
|
return types.ModuleName
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterCodec implements AppModuleBasic interface
|
// RegisterCodec implements AppModuleBasic interface
|
||||||
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
||||||
RegisterCodec(cdc)
|
types.RegisterCodec(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultGenesis returns default genesis state as raw bytes for the ibc
|
// DefaultGenesis returns default genesis state as raw bytes for the ibc
|
||||||
|
@ -60,7 +61,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
|
||||||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error {
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error {
|
||||||
var gs types.GenesisState
|
var gs types.GenesisState
|
||||||
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
|
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gs.Validate()
|
return gs.Validate()
|
||||||
|
@ -78,22 +79,22 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
|
||||||
|
|
||||||
// GetQueryCmd implements AppModuleBasic interface
|
// GetQueryCmd implements AppModuleBasic interface
|
||||||
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
|
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
|
||||||
return cli.GetQueryCmd(clientCtx.Codec, QuerierRoute)
|
return cli.GetQueryCmd(clientCtx.Codec, types.QuerierRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInterfaceTypes registers module concrete types into protobuf Any.
|
// RegisterInterfaceTypes registers module concrete types into protobuf Any.
|
||||||
func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) {
|
func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) {
|
||||||
RegisterInterfaces(registry)
|
types.RegisterInterfaces(registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppModule represents the AppModule for this module
|
// AppModule represents the AppModule for this module
|
||||||
type AppModule struct {
|
type AppModule struct {
|
||||||
AppModuleBasic
|
AppModuleBasic
|
||||||
keeper Keeper
|
keeper keeper.Keeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppModule creates a new 20-transfer module
|
// NewAppModule creates a new 20-transfer module
|
||||||
func NewAppModule(k Keeper) AppModule {
|
func NewAppModule(k keeper.Keeper) AppModule {
|
||||||
return AppModule{
|
return AppModule{
|
||||||
keeper: k,
|
keeper: k,
|
||||||
}
|
}
|
||||||
|
@ -106,12 +107,12 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||||
|
|
||||||
// Route implements the AppModule interface
|
// Route implements the AppModule interface
|
||||||
func (am AppModule) Route() sdk.Route {
|
func (am AppModule) Route() sdk.Route {
|
||||||
return sdk.NewRoute(RouterKey, NewHandler(am.keeper))
|
return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper))
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuerierRoute implements the AppModule interface
|
// QuerierRoute implements the AppModule interface
|
||||||
func (AppModule) QuerierRoute() string {
|
func (AppModule) QuerierRoute() string {
|
||||||
return QuerierRoute
|
return types.QuerierRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQuerierHandler implements the AppModule interface
|
// NewQuerierHandler implements the AppModule interface
|
||||||
|
@ -285,16 +286,16 @@ func (am AppModule) OnRecvPacket(
|
||||||
ctx sdk.Context,
|
ctx sdk.Context,
|
||||||
packet channeltypes.Packet,
|
packet channeltypes.Packet,
|
||||||
) (*sdk.Result, []byte, error) {
|
) (*sdk.Result, []byte, error) {
|
||||||
var data FungibleTokenPacketData
|
var data types.FungibleTokenPacketData
|
||||||
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
||||||
return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
||||||
}
|
}
|
||||||
acknowledgement := FungibleTokenPacketAcknowledgement{
|
acknowledgement := types.FungibleTokenPacketAcknowledgement{
|
||||||
Success: true,
|
Success: true,
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
if err := am.keeper.OnRecvPacket(ctx, packet, data); err != nil {
|
if err := am.keeper.OnRecvPacket(ctx, packet, data); err != nil {
|
||||||
acknowledgement = FungibleTokenPacketAcknowledgement{
|
acknowledgement = types.FungibleTokenPacketAcknowledgement{
|
||||||
Success: false,
|
Success: false,
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
}
|
}
|
||||||
|
@ -302,10 +303,10 @@ func (am AppModule) OnRecvPacket(
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
EventTypePacket,
|
types.EventTypePacket,
|
||||||
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
||||||
sdk.NewAttribute(AttributeKeyReceiver, data.Receiver),
|
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
|
||||||
sdk.NewAttribute(AttributeKeyValue, data.Amount.String()),
|
sdk.NewAttribute(types.AttributeKeyValue, data.Amount.String()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -319,11 +320,11 @@ func (am AppModule) OnAcknowledgementPacket(
|
||||||
packet channeltypes.Packet,
|
packet channeltypes.Packet,
|
||||||
acknowledgement []byte,
|
acknowledgement []byte,
|
||||||
) (*sdk.Result, error) {
|
) (*sdk.Result, error) {
|
||||||
var ack FungibleTokenPacketAcknowledgement
|
var ack types.FungibleTokenPacketAcknowledgement
|
||||||
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
|
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
|
||||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
|
||||||
}
|
}
|
||||||
var data FungibleTokenPacketData
|
var data types.FungibleTokenPacketData
|
||||||
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
||||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -334,19 +335,19 @@ func (am AppModule) OnAcknowledgementPacket(
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
EventTypePacket,
|
types.EventTypePacket,
|
||||||
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
||||||
sdk.NewAttribute(AttributeKeyReceiver, data.Receiver),
|
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
|
||||||
sdk.NewAttribute(AttributeKeyValue, data.Amount.String()),
|
sdk.NewAttribute(types.AttributeKeyValue, data.Amount.String()),
|
||||||
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)),
|
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if !ack.Success {
|
if !ack.Success {
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
EventTypePacket,
|
types.EventTypePacket,
|
||||||
sdk.NewAttribute(AttributeKeyAckError, ack.Error),
|
sdk.NewAttribute(types.AttributeKeyAckError, ack.Error),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -360,7 +361,7 @@ func (am AppModule) OnTimeoutPacket(
|
||||||
ctx sdk.Context,
|
ctx sdk.Context,
|
||||||
packet channeltypes.Packet,
|
packet channeltypes.Packet,
|
||||||
) (*sdk.Result, error) {
|
) (*sdk.Result, error) {
|
||||||
var data FungibleTokenPacketData
|
var data types.FungibleTokenPacketData
|
||||||
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
|
||||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -371,10 +372,10 @@ func (am AppModule) OnTimeoutPacket(
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
EventTypeTimeout,
|
types.EventTypeTimeout,
|
||||||
sdk.NewAttribute(AttributeKeyRefundReceiver, data.Sender),
|
sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender),
|
||||||
sdk.NewAttribute(AttributeKeyRefundValue, data.Amount.String()),
|
sdk.NewAttribute(types.AttributeKeyRefundValue, data.Amount.String()),
|
||||||
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue