x/bank: use internal package (#4521)
Reorganise x/bank packages and leverage internal special package for enhanced encapsulation.
This commit is contained in:
parent
d5fe9b7eef
commit
1e9ca4a15b
|
@ -0,0 +1 @@
|
|||
#4521 Flatten x/bank structure by hiding module internals.
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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{}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
}
|
|
@ -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"))
|
|
@ -1,4 +1,4 @@
|
|||
package tags
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue