cosmos-sdk/x/bank/handler.go
Jae Kwon ba2b4f0f21 WIP: refactor
Refactor

* No more decorators, but rather types.AntiHandler
* No more handlers, but rather types.MsgHandler
* Ability to pass "stores" in NewXYZHandler()
* Coins live in types, and Accounts have coins
* Coinstore -> bank
2018-01-12 19:17:17 -08:00

41 lines
836 B
Go

package bank
import (
"github.com/cosmos/cosmos-sdk/types"
)
func TransferHandlerFn(newAccStore func(types.KVStore) types.AccountStore) types.Handler {
return func(ctx types.Context, ms types.MultiStore, tx types.Tx) types.Result {
accStore := newAccStore(ms.GetKVStore("main"))
cs := CoinStore{accStore}
sendTx, ok := tx.(SendTx)
if !ok {
panic("tx is not SendTx") // ?
}
// NOTE: totalIn == totalOut should already have been checked
for _, in := range sendTx.Inputs {
_, err := cs.SubtractCoins(in.Address, in.Coins)
if err != nil {
return types.Result{
Code: 1, // TODO
}
}
}
for _, out := range sendTx.Outputs {
_, err := cs.AddCoins(out.Address, out.Coins)
if err != nil {
return types.Result{
Code: 1, // TODO
}
}
}
return types.Result{} // TODO
}
}