diff --git a/.pending/breaking/sdk/4521-Flatten-x-bank- b/.pending/breaking/sdk/4521-Flatten-x-bank- new file mode 100644 index 000000000000..09dfd25e05ed --- /dev/null +++ b/.pending/breaking/sdk/4521-Flatten-x-bank- @@ -0,0 +1 @@ +#4521 Flatten x/bank structure by hiding module internals. diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 8ee536e554df..33e00cb576be 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -26,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/genaccounts" authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation" "github.com/cosmos/cosmos-sdk/x/bank" - banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation" "github.com/cosmos/cosmos-sdk/x/gov" @@ -605,7 +604,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation { }) return v }(nil), - banksim.SimulateMsgSend(app.accountKeeper, app.bankKeeper), + bank.SimulateMsgSend(app.accountKeeper, app.bankKeeper), }, { func(_ *rand.Rand) int { @@ -616,7 +615,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation { }) return v }(nil), - banksim.SimulateSingleInputMsgMultiSend(app.accountKeeper, app.bankKeeper), + bank.SimulateSingleInputMsgMultiSend(app.accountKeeper, app.bankKeeper), }, { func(_ *rand.Rand) int { diff --git a/x/bank/alias.go b/x/bank/alias.go index 595c3ab61425..75f71aaa018f 100644 --- a/x/bank/alias.go +++ b/x/bank/alias.go @@ -5,7 +5,8 @@ package bank import ( - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" ) const ( @@ -15,22 +16,19 @@ const ( ModuleName = types.ModuleName RouterKey = types.RouterKey DefaultParamspace = types.DefaultParamspace - DefaultSendEnabled = types.DefaultSendEnabled ) var ( // functions aliases - RegisterCodec = types.RegisterCodec - ErrNoInputs = types.ErrNoInputs - ErrNoOutputs = types.ErrNoOutputs - ErrInputOutputMismatch = types.ErrInputOutputMismatch - ErrSendDisabled = types.ErrSendDisabled - NewMsgSend = types.NewMsgSend - NewMsgMultiSend = types.NewMsgMultiSend - NewInput = types.NewInput - NewOutput = types.NewOutput - ValidateInputsOutputs = types.ValidateInputsOutputs - ParamKeyTable = types.ParamKeyTable + RegisterCodec = types.RegisterCodec + ErrNoInputs = types.ErrNoInputs + ErrNoOutputs = types.ErrNoOutputs + ErrInputOutputMismatch = types.ErrInputOutputMismatch + ErrSendDisabled = types.ErrSendDisabled + NewBaseKeeper = keeper.NewBaseKeeper + NewInput = types.NewInput + NewOutput = types.NewOutput + ParamKeyTable = types.ParamKeyTable // variable aliases ModuleCdc = types.ModuleCdc @@ -38,6 +36,8 @@ var ( ) type ( + BaseKeeper = keeper.BaseKeeper // ibc module depends on this + Keeper = keeper.Keeper MsgSend = types.MsgSend MsgMultiSend = types.MsgMultiSend Input = types.Input diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 651021eadb9d..066d406413bf 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -1,11 +1,13 @@ -package bank +package bank_test import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" "github.com/cosmos/cosmos-sdk/x/mock" "github.com/stretchr/testify/require" @@ -95,11 +97,11 @@ func getMockApp(t *testing.T) *mock.App { } // overwrite the mock init chainer -func getInitChainer(mapp *mock.App, keeper BaseKeeper) sdk.InitChainer { +func getInitChainer(mapp *mock.App, keeper keeper.BaseKeeper) sdk.InitChainer { return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { mapp.InitChainer(ctx, req) - bankGenesis := DefaultGenesisState() - InitGenesis(ctx, keeper, bankGenesis) + bankGenesis := bank.DefaultGenesisState() + bank.InitGenesis(ctx, keeper, bankGenesis) return abci.ResponseInitChain{} } diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index f4e5042805a2..eb126492e973 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -1,4 +1,4 @@ -package bank +package bank_test import ( "testing" @@ -7,7 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" "github.com/cosmos/cosmos-sdk/x/mock" ) @@ -17,12 +19,12 @@ func getBenchmarkMockApp() (*mock.App, error) { mapp := mock.NewApp() types.RegisterCodec(mapp.Cdc) - bankKeeper := NewBaseKeeper( + bankKeeper := keeper.NewBaseKeeper( mapp.AccountKeeper, mapp.ParamsKeeper.Subspace(types.DefaultParamspace), types.DefaultCodespace, ) - mapp.Router().AddRoute(types.RouterKey, NewHandler(bankKeeper)) + mapp.Router().AddRoute(types.RouterKey, bank.NewHandler(bankKeeper)) mapp.SetInitChainer(getInitChainer(mapp, bankKeeper)) err := mapp.CompleteSetup() diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 86209a51fe64..6d2335256f43 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" auth "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" ) const ( diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index cb8585db0755..682cfcf00d35 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -11,7 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" ) // RegisterRoutes - Central function to define routes that get registered by the main application diff --git a/x/bank/handler.go b/x/bank/handler.go index 040e440e3da7..a1c4f2adf4a4 100644 --- a/x/bank/handler.go +++ b/x/bank/handler.go @@ -4,12 +4,12 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/tags" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" ) // NewHandler returns a handler for "bank" type messages. -func NewHandler(k Keeper) sdk.Handler { +func NewHandler(k keeper.Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { switch msg := msg.(type) { case types.MsgSend: @@ -26,7 +26,7 @@ func NewHandler(k Keeper) sdk.Handler { } // Handle MsgSend. -func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result { +func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgSend) sdk.Result { if !k.GetSendEnabled(ctx) { return types.ErrSendDisabled(k.Codespace()).Result() } @@ -36,9 +36,9 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result { } resTags := sdk.NewTags( - tags.Category, tags.TxCategory, - tags.Sender, msg.FromAddress.String(), - tags.Recipient, msg.ToAddress.String(), + types.Category, types.TxCategory, + types.Sender, msg.FromAddress.String(), + types.Recipient, msg.ToAddress.String(), ) return sdk.Result{ @@ -47,7 +47,7 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result { } // Handle MsgMultiSend. -func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg types.MsgMultiSend) sdk.Result { +func handleMsgMultiSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgMultiSend) sdk.Result { // NOTE: totalIn == totalOut should already have been checked if !k.GetSendEnabled(ctx) { return types.ErrSendDisabled(k.Codespace()).Result() @@ -57,7 +57,7 @@ func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg types.MsgMultiSend) sdk.R return err.Result() } - resTags = resTags.AppendTag(tags.Category, tags.TxCategory) + resTags = resTags.AppendTag(types.Category, types.TxCategory) return sdk.Result{ Tags: resTags, } diff --git a/x/bank/invariants.go b/x/bank/internal/keeper/invariants.go similarity index 95% rename from x/bank/invariants.go rename to x/bank/internal/keeper/invariants.go index c183c9ebb424..d401c27f5073 100644 --- a/x/bank/invariants.go +++ b/x/bank/internal/keeper/invariants.go @@ -1,4 +1,4 @@ -package bank +package keeper import ( "errors" @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" ) // register bank invariants diff --git a/x/bank/keeper.go b/x/bank/internal/keeper/keeper.go similarity index 97% rename from x/bank/keeper.go rename to x/bank/internal/keeper/keeper.go index 730c96e070e7..718569fadaef 100644 --- a/x/bank/keeper.go +++ b/x/bank/internal/keeper/keeper.go @@ -1,4 +1,4 @@ -package bank +package keeper import ( "fmt" @@ -6,8 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/tags" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" "github.com/cosmos/cosmos-sdk/x/params" ) @@ -340,7 +339,7 @@ func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []types.Inp } allTags = allTags.AppendTag( - tags.Sender, in.Address.String(), + types.Sender, in.Address.String(), ) } @@ -350,7 +349,7 @@ func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []types.Inp return nil, err } allTags = allTags.AppendTag( - tags.Recipient, out.Address.String(), + types.Recipient, out.Address.String(), ) } @@ -386,7 +385,7 @@ func delegateCoins( setAccount(ctx, ak, acc) return sdk.NewTags( - sdk.TagAction, tags.ActionDelegateCoins, + sdk.TagAction, types.ActionDelegateCoins, sdk.TagDelegator, addr.String(), ), nil } @@ -411,7 +410,7 @@ func undelegateCoins( setAccount(ctx, ak, acc) return sdk.NewTags( - sdk.TagAction, tags.ActionUndelegateCoins, + sdk.TagAction, types.ActionUndelegateCoins, sdk.TagDelegator, addr.String(), ), nil } diff --git a/x/bank/keeper_test.go b/x/bank/internal/keeper/keeper_test.go similarity index 93% rename from x/bank/keeper_test.go rename to x/bank/internal/keeper/keeper_test.go index c658d5e46e9c..b87b100c1378 100644 --- a/x/bank/keeper_test.go +++ b/x/bank/internal/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package bank +package keeper import ( "testing" @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" "github.com/cosmos/cosmos-sdk/x/params" ) @@ -120,13 +120,13 @@ func TestKeeper(t *testing.T) { require.True(t, bankKeeper.GetCoins(ctx, addr2).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 10), sdk.NewInt64Coin("foocoin", 8)))) inputs := []types.Input{ - NewInput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 3))), + types.NewInput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 3))), types.NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 3), sdk.NewInt64Coin("foocoin", 2))), } outputs := []types.Output{ - NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 1))), - NewOutput(addr3, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 2), sdk.NewInt64Coin("foocoin", 5))), + types.NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 1))), + types.NewOutput(addr3, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 2), sdk.NewInt64Coin("foocoin", 5))), } bankKeeper.InputOutputCoins(ctx, inputs, outputs) require.True(t, bankKeeper.GetCoins(ctx, addr).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 21), sdk.NewInt64Coin("foocoin", 4)))) @@ -139,7 +139,7 @@ func TestSendKeeper(t *testing.T) { ctx := input.ctx paramSpace := input.pk.Subspace(types.DefaultParamspace) bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace) - sendKeeper := NewBaseSendKeeper(input.ak, paramSpace, DefaultCodespace) + sendKeeper := NewBaseSendKeeper(input.ak, paramSpace, types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) addr := sdk.AccAddress([]byte("addr1")) @@ -186,10 +186,10 @@ func TestSendKeeper(t *testing.T) { func TestViewKeeper(t *testing.T) { input := setupTestInput() ctx := input.ctx - paramSpace := input.pk.Subspace(DefaultParamspace) - bankKeeper := NewBaseKeeper(input.ak, paramSpace, DefaultCodespace) + paramSpace := input.pk.Subspace(types.DefaultParamspace) + bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) - viewKeeper := NewBaseViewKeeper(input.ak, DefaultCodespace) + viewKeeper := NewBaseViewKeeper(input.ak, types.DefaultCodespace) addr := sdk.AccAddress([]byte("addr1")) acc := input.ak.NewAccountWithAddress(ctx, addr) @@ -216,7 +216,7 @@ func TestVestingAccountSend(t *testing.T) { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace) + bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) addr1 := sdk.AccAddress([]byte("addr1")) @@ -250,7 +250,7 @@ func TestVestingAccountReceive(t *testing.T) { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace) + bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) addr1 := sdk.AccAddress([]byte("addr1")) @@ -284,7 +284,7 @@ func TestDelegateCoins(t *testing.T) { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace) + bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) addr1 := sdk.AccAddress([]byte("addr1")) @@ -321,7 +321,7 @@ func TestUndelegateCoins(t *testing.T) { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace) + bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace) bankKeeper.SetSendEnabled(ctx, true) addr1 := sdk.AccAddress([]byte("addr1")) diff --git a/x/bank/types/codec.go b/x/bank/internal/types/codec.go similarity index 100% rename from x/bank/types/codec.go rename to x/bank/internal/types/codec.go diff --git a/x/bank/types/errors.go b/x/bank/internal/types/errors.go similarity index 100% rename from x/bank/types/errors.go rename to x/bank/internal/types/errors.go diff --git a/x/bank/types/key.go b/x/bank/internal/types/key.go similarity index 100% rename from x/bank/types/key.go rename to x/bank/internal/types/key.go diff --git a/x/bank/types/msgs.go b/x/bank/internal/types/msgs.go similarity index 100% rename from x/bank/types/msgs.go rename to x/bank/internal/types/msgs.go diff --git a/x/bank/types/msgs_test.go b/x/bank/internal/types/msgs_test.go similarity index 100% rename from x/bank/types/msgs_test.go rename to x/bank/internal/types/msgs_test.go diff --git a/x/bank/types/params.go b/x/bank/internal/types/params.go similarity index 100% rename from x/bank/types/params.go rename to x/bank/internal/types/params.go diff --git a/x/bank/tags/tags.go b/x/bank/internal/types/tags.go similarity index 95% rename from x/bank/tags/tags.go rename to x/bank/internal/types/tags.go index b4586818335c..9877d7591595 100644 --- a/x/bank/tags/tags.go +++ b/x/bank/internal/types/tags.go @@ -1,4 +1,4 @@ -package tags +package types import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/bank/module.go b/x/bank/module.go index 2499c2e9ab5e..eb0b85634800 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/cosmos/cosmos-sdk/x/bank/client/rest" - "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" ) var ( @@ -29,24 +29,20 @@ type AppModuleBasic struct{} var _ module.AppModuleBasic = AppModuleBasic{} // module name -func (AppModuleBasic) Name() string { - return types.ModuleName -} +func (AppModuleBasic) Name() string { return ModuleName } // register module codec -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - types.RegisterCodec(cdc) -} +func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { RegisterCodec(cdc) } // default genesis state func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState()) + return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) } // module validate genesis func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { var data GenesisState - err := types.ModuleCdc.UnmarshalJSON(bz, &data) + err := ModuleCdc.UnmarshalJSON(bz, &data) if err != nil { return err } @@ -84,24 +80,18 @@ func NewAppModule(keeper Keeper, accountKeeper auth.AccountKeeper) AppModule { } // module name -func (AppModule) Name() string { - return types.ModuleName -} +func (AppModule) Name() string { return ModuleName } // register invariants func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { - RegisterInvariants(ir, am.accountKeeper) + keeper.RegisterInvariants(ir, am.accountKeeper) } // module message route name -func (AppModule) Route() string { - return types.RouterKey -} +func (AppModule) Route() string { return RouterKey } // module handler -func (am AppModule) NewHandler() sdk.Handler { - return NewHandler(am.keeper) -} +func (am AppModule) NewHandler() sdk.Handler { return NewHandler(am.keeper) } // module querier route name func (AppModule) QuerierRoute() string { return "" } @@ -112,7 +102,7 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil } // module init-genesis func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) + ModuleCdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) return []abci.ValidatorUpdate{} } @@ -120,7 +110,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va // module export genesis func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return types.ModuleCdc.MustMarshalJSON(gs) + return ModuleCdc.MustMarshalJSON(gs) } // module begin-block diff --git a/x/bank/simulation/msgs.go b/x/bank/simulation.go similarity index 88% rename from x/bank/simulation/msgs.go rename to x/bank/simulation.go index 327bee2e2fb6..3fe611a9d067 100644 --- a/x/bank/simulation/msgs.go +++ b/x/bank/simulation.go @@ -1,4 +1,4 @@ -package simulation +package bank import ( "fmt" @@ -9,15 +9,16 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/internal/types" "github.com/cosmos/cosmos-sdk/x/mock" "github.com/cosmos/cosmos-sdk/x/simulation" ) // SendTx tests and runs a single msg send where both // accounts already exist. -func SimulateMsgSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Operation { - handler := bank.NewHandler(bk) +func SimulateMsgSend(mapper auth.AccountKeeper, bk keeper.Keeper) simulation.Operation { + handler := NewHandler(bk) return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) ( opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) { @@ -35,7 +36,7 @@ func SimulateMsgSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Opera } func createMsgSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) ( - fromAcc simulation.Account, comment string, msg bank.MsgSend, ok bool) { + fromAcc simulation.Account, comment string, msg types.MsgSend, ok bool) { fromAcc = simulation.RandomAcc(r, accs) toAcc := simulation.RandomAcc(r, accs) @@ -59,12 +60,12 @@ func createMsgSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, map } coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)} - msg = bank.NewMsgSend(fromAcc.Address, toAcc.Address, coins) + msg = types.NewMsgSend(fromAcc.Address, toAcc.Address, coins) return fromAcc, "", msg, true } // Sends and verifies the transition of a msg send. -func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg bank.MsgSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error { +func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg types.MsgSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error { fromAcc := mapper.GetAccount(ctx, msg.FromAddress) AccountNumbers := []uint64{fromAcc.GetAccountNumber()} SequenceNumbers := []uint64{fromAcc.GetSequence()} @@ -76,7 +77,7 @@ func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg b if handler != nil { res := handler(ctx, msg) if !res.IsOK() { - if res.Code == bank.CodeSendDisabled { + if res.Code == types.CodeSendDisabled { return nil } // TODO: Do this in a more 'canonical' way @@ -110,8 +111,8 @@ func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg b // SingleInputSendMsg tests and runs a single msg multisend, with one input and one output, where both // accounts already exist. -func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Operation { - handler := bank.NewHandler(bk) +func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk keeper.Keeper) simulation.Operation { + handler := NewHandler(bk) return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) ( opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) { @@ -129,7 +130,7 @@ func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk bank.Keeper) } func createSingleInputMsgMultiSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) ( - fromAcc simulation.Account, comment string, msg bank.MsgMultiSend, ok bool) { + fromAcc simulation.Account, comment string, msg types.MsgMultiSend, ok bool) { fromAcc = simulation.RandomAcc(r, accs) toAcc := simulation.RandomAcc(r, accs) @@ -154,16 +155,16 @@ func createSingleInputMsgMultiSend(r *rand.Rand, ctx sdk.Context, accs []simulat } coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)} - msg = bank.MsgMultiSend{ - Inputs: []bank.Input{bank.NewInput(fromAcc.Address, coins)}, - Outputs: []bank.Output{bank.NewOutput(toAddr, coins)}, + msg = types.MsgMultiSend{ + Inputs: []types.Input{types.NewInput(fromAcc.Address, coins)}, + Outputs: []types.Output{types.NewOutput(toAddr, coins)}, } return fromAcc, "", msg, true } // Sends and verifies the transition of a msg multisend. This fails if there are repeated inputs or outputs // pass in handler as nil to handle txs, otherwise handle msgs -func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg bank.MsgMultiSend, +func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg types.MsgMultiSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error { initialInputAddrCoins := make([]sdk.Coins, len(msg.Inputs)) @@ -184,7 +185,7 @@ func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, if handler != nil { res := handler(ctx, msg) if !res.IsOK() { - if res.Code == bank.CodeSendDisabled { + if res.Code == types.CodeSendDisabled { return nil } // TODO: Do this in a more 'canonical' way