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.
|
|
|
|
func NewHandler(ck CoinKeeper) sdk.Handler {
|
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case SendMsg:
|
|
|
|
return handleSendMsg(ctx, ck, msg)
|
|
|
|
case IssueMsg:
|
|
|
|
return handleIssueMsg(ctx, ck, msg)
|
|
|
|
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-01-17 16:59:40 -08:00
|
|
|
// Handle SendMsg.
|
2018-02-08 23:43:08 -08:00
|
|
|
func handleSendMsg(ctx sdk.Context, ck CoinKeeper, msg SendMsg) 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-03-27 10:42:09 -07:00
|
|
|
err := ck.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle IssueMsg.
|
2018-02-08 23:43:08 -08:00
|
|
|
func handleIssueMsg(ctx sdk.Context, ck CoinKeeper, msg IssueMsg) sdk.Result {
|
2018-01-17 16:59:40 -08:00
|
|
|
panic("not implemented yet")
|
2018-01-03 17:20:21 -08:00
|
|
|
}
|