cosmos-sdk/handler.go

89 lines
2.3 KiB
Go
Raw Normal View History

2017-06-01 11:01:19 -07:00
package basecoin
import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire/data"
"github.com/tendermint/tmlibs/log"
2017-06-01 11:01:19 -07:00
2017-07-06 05:23:38 -07:00
"github.com/tendermint/basecoin/state"
2017-06-01 11:01:19 -07:00
)
// Handler is anything that processes a transaction
type Handler interface {
Checker
Deliver
SetOptioner
Named
// TODO: flesh these out as well
2017-07-06 05:23:38 -07:00
// InitChain(store state.KVStore, vals []*abci.Validator)
// BeginBlock(store state.KVStore, hash []byte, header *abci.Header)
// EndBlock(store state.KVStore, height uint64) abci.ResponseEndBlock
}
type Named interface {
Name() string
}
type Checker interface {
2017-07-06 05:23:38 -07:00
CheckTx(ctx Context, store state.KVStore, tx Tx) (Result, error)
}
// CheckerFunc (like http.HandlerFunc) is a shortcut for making wrapers
2017-07-06 05:23:38 -07:00
type CheckerFunc func(Context, state.KVStore, Tx) (Result, error)
2017-07-06 05:23:38 -07:00
func (c CheckerFunc) CheckTx(ctx Context, store state.KVStore, tx Tx) (Result, error) {
return c(ctx, store, tx)
}
type Deliver interface {
2017-07-06 05:23:38 -07:00
DeliverTx(ctx Context, store state.KVStore, tx Tx) (Result, error)
}
// DeliverFunc (like http.HandlerFunc) is a shortcut for making wrapers
2017-07-06 05:23:38 -07:00
type DeliverFunc func(Context, state.KVStore, Tx) (Result, error)
2017-07-06 05:23:38 -07:00
func (c DeliverFunc) DeliverTx(ctx Context, store state.KVStore, tx Tx) (Result, error) {
return c(ctx, store, tx)
}
type SetOptioner interface {
2017-07-06 05:23:38 -07:00
SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error)
}
// SetOptionFunc (like http.HandlerFunc) is a shortcut for making wrapers
2017-07-06 05:23:38 -07:00
type SetOptionFunc func(log.Logger, state.KVStore, string, string, string) (string, error)
2017-07-06 05:23:38 -07:00
func (c SetOptionFunc) SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) {
return c(l, store, module, key, value)
2017-06-01 11:01:19 -07:00
}
// Result captures any non-error abci result
// to make sure people use error for error cases
type Result struct {
Data data.Bytes
Log string
}
func (r Result) ToABCI() abci.Result {
return abci.Result{
Data: r.Data,
Log: r.Log,
}
}
// placeholders
// holders
type NopCheck struct{}
2017-07-06 05:23:38 -07:00
func (_ NopCheck) CheckTx(Context, state.KVStore, Tx) (r Result, e error) { return }
type NopDeliver struct{}
2017-07-06 05:23:38 -07:00
func (_ NopDeliver) DeliverTx(Context, state.KVStore, Tx) (r Result, e error) { return }
type NopOption struct{}
2017-07-06 05:23:38 -07:00
func (_ NopOption) SetOption(log.Logger, state.KVStore, string, string, string) (string, error) {
return "", nil
}