2018-01-12 11:49:53 -08:00
|
|
|
package bank
|
2018-01-03 17:20:21 -08:00
|
|
|
|
|
|
|
import (
|
2018-01-17 16:59:40 -08:00
|
|
|
"reflect"
|
2018-01-26 06:22:56 -08:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-01-03 17:20:21 -08:00
|
|
|
)
|
|
|
|
|
2018-03-27 10:42:09 -07:00
|
|
|
// NewHandler returns a handler for "bank" type messages.
|
2018-04-18 21:49:24 -07:00
|
|
|
func NewHandler(k Keeper) sdk.Handler {
|
2018-03-27 10:42:09 -07:00
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
|
|
|
switch msg := msg.(type) {
|
2018-04-18 21:49:24 -07:00
|
|
|
case MsgSend:
|
|
|
|
return handleMsgSend(ctx, k, msg)
|
|
|
|
case MsgIssue:
|
|
|
|
return handleMsgIssue(ctx, k, msg)
|
2018-03-27 10:42:09 -07:00
|
|
|
default:
|
|
|
|
errMsg := "Unrecognized bank Msg type: " + reflect.TypeOf(msg).Name()
|
|
|
|
return sdk.ErrUnknownRequest(errMsg).Result()
|
|
|
|
}
|
2018-01-17 16:59:40 -08:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 17:20:21 -08:00
|
|
|
|
2018-04-18 21:49:24 -07:00
|
|
|
// Handle MsgSend.
|
|
|
|
func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
|
2018-01-17 16:59:40 -08:00
|
|
|
// NOTE: totalIn == totalOut should already have been checked
|
2018-01-03 17:20:21 -08:00
|
|
|
|
2018-04-18 21:49:24 -07:00
|
|
|
err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
|
2018-03-27 10:42:09 -07:00
|
|
|
if err != nil {
|
|
|
|
return err.Result()
|
2018-01-03 17:20:21 -08:00
|
|
|
}
|
2018-01-17 16:59:40 -08:00
|
|
|
|
2018-02-23 04:53:49 -08:00
|
|
|
// TODO: add some tags so we can search it!
|
2018-01-17 16:59:40 -08:00
|
|
|
return sdk.Result{} // TODO
|
|
|
|
}
|
|
|
|
|
2018-04-18 21:49:24 -07:00
|
|
|
// Handle MsgIssue.
|
|
|
|
func handleMsgIssue(ctx sdk.Context, k Keeper, msg MsgIssue) sdk.Result {
|
2018-01-17 16:59:40 -08:00
|
|
|
panic("not implemented yet")
|
2018-01-03 17:20:21 -08:00
|
|
|
}
|