diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index d5b031272b74..d78d0c49a917 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -11,6 +11,10 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + // TODO: Replace with original x/bank once transfers are enabled and remove + // forked module. + gaiabank "github.com/cosmos/cosmos-sdk/cmd/gaia/app/x/bank" + bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -150,7 +154,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b // register message routes app.Router(). - AddRoute(bank.RouterKey, bank.NewHandler(app.bankKeeper)). + AddRoute(bank.RouterKey, gaiabank.NewHandler(app.bankKeeper)). AddRoute(staking.RouterKey, staking.NewHandler(app.stakingKeeper)). AddRoute(distr.RouterKey, distr.NewHandler(app.distrKeeper)). AddRoute(slashing.RouterKey, slashing.NewHandler(app.slashingKeeper)). diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 74e3969628fe..65a64033ba15 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -11,13 +11,12 @@ import ( "strings" "time" - "github.com/cosmos/cosmos-sdk/x/bank" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/bank" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/mint" diff --git a/cmd/gaia/app/x/bank/handler.go b/cmd/gaia/app/x/bank/handler.go new file mode 100644 index 000000000000..9a2d0ec639c0 --- /dev/null +++ b/cmd/gaia/app/x/bank/handler.go @@ -0,0 +1,52 @@ +package bank + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" +) + +// NewHandler returns a handler for "bank" type messages. +func NewHandler(k bank.Keeper) sdk.Handler { + return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + switch msg := msg.(type) { + case bank.MsgSend: + return handleMsgSend(ctx, k, msg) + case bank.MsgMultiSend: + return handleMsgMultiSend(ctx, k, msg) + default: + errMsg := "Unrecognized bank Msg type: %s" + msg.Type() + return sdk.ErrUnknownRequest(errMsg).Result() + } + } +} + +// Handle MsgSend. +func handleMsgSend(ctx sdk.Context, k bank.Keeper, msg bank.MsgSend) sdk.Result { + if !k.GetSendEnabled(ctx) { + return bank.ErrSendDisabled(k.Codespace()).Result() + } + tags, err := k.SendCoins(ctx, msg.FromAddress, msg.ToAddress, msg.Amount) + if err != nil { + return err.Result() + } + + return sdk.Result{ + Tags: tags, + } +} + +// Handle MsgMultiSend. +func handleMsgMultiSend(ctx sdk.Context, k bank.Keeper, msg bank.MsgMultiSend) sdk.Result { + // NOTE: totalIn == totalOut should already have been checked + if !k.GetSendEnabled(ctx) { + return bank.ErrSendDisabled(k.Codespace()).Result() + } + tags, err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs) + if err != nil { + return err.Result() + } + + return sdk.Result{ + Tags: tags, + } +}