Skip to content

Commit

Permalink
Fork x/bank (router only) into gaia
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Mar 5, 2019
1 parent 57fe79f commit 9eab29e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)).
Expand Down
3 changes: 1 addition & 2 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 52 additions & 0 deletions cmd/gaia/app/x/bank/handler.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit 9eab29e

Please sign in to comment.