-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57fe79f
commit 9eab29e
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |