2017-08-21 14:13:58 -07:00
|
|
|
package sdk
|
2017-06-01 11:01:19 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
abci "github.com/tendermint/abci/types"
|
2017-07-03 09:10:46 -07:00
|
|
|
"github.com/tendermint/tmlibs/log"
|
2017-06-01 11:01:19 -07:00
|
|
|
|
2017-08-21 14:13:58 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/state"
|
2017-06-01 11:01:19 -07:00
|
|
|
)
|
|
|
|
|
2017-10-17 06:47:33 -07:00
|
|
|
const (
|
|
|
|
// ModuleNameBase is the module name for internal functionality
|
|
|
|
ModuleNameBase = "base"
|
|
|
|
// ChainKey is the option key for setting the chain id
|
|
|
|
ChainKey = "chain_id"
|
|
|
|
)
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// Handler is anything that processes a transaction.
|
|
|
|
// Must handle checktx and delivertx
|
2017-07-03 09:10:46 -07:00
|
|
|
type Handler interface {
|
2017-07-30 14:26:25 -07:00
|
|
|
// Checker verifies there are valid fees and estimates work
|
2017-07-03 09:10:46 -07:00
|
|
|
Checker
|
2017-07-30 14:26:25 -07:00
|
|
|
// Deliver performs the tx once it makes it in the block
|
2017-10-23 11:42:16 -07:00
|
|
|
Deliverer
|
2017-06-27 10:22:25 -07:00
|
|
|
}
|
|
|
|
|
2017-07-30 14:26:25 -07:00
|
|
|
// Checker verifies there are valid fees and estimates work
|
2017-06-27 10:22:25 -07:00
|
|
|
type Checker interface {
|
2017-10-23 11:42:16 -07:00
|
|
|
CheckTx(ctx Context, store state.SimpleDB, tx interface{}) (CheckResult, error)
|
2017-06-27 10:22:25 -07:00
|
|
|
}
|
|
|
|
|
2017-08-04 04:50:55 -07:00
|
|
|
// CheckerFunc (like http.HandlerFunc) is a shortcut for making wrappers
|
2017-10-23 11:42:16 -07:00
|
|
|
type CheckerFunc func(Context, state.SimpleDB, interface{}) (CheckResult, error)
|
2017-06-27 11:53:06 -07:00
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
func (c CheckerFunc) CheckTx(ctx Context, store state.SimpleDB, tx interface{}) (CheckResult, error) {
|
2017-06-27 11:53:06 -07:00
|
|
|
return c(ctx, store, tx)
|
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// Deliverer performs the tx once it makes it in the block
|
|
|
|
type Deliverer interface {
|
|
|
|
DeliverTx(ctx Context, store state.SimpleDB, tx interface{}) (DeliverResult, error)
|
2017-06-27 11:53:06 -07:00
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// DelivererFunc (like http.HandlerFunc) is a shortcut for making wrappers
|
|
|
|
type DelivererFunc func(Context, state.SimpleDB, interface{}) (DeliverResult, error)
|
2017-06-27 11:53:06 -07:00
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
func (c DelivererFunc) DeliverTx(ctx Context, store state.SimpleDB, tx interface{}) (DeliverResult, error) {
|
2017-06-27 11:53:06 -07:00
|
|
|
return c(ctx, store, tx)
|
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
// Lifecycle actions, not tied to the tx handler
|
2017-08-04 04:50:55 -07:00
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// Ticker can be executed every block.
|
|
|
|
// Called from BeginBlock
|
|
|
|
type Ticker interface {
|
|
|
|
Tick(Context, state.SimpleDB) ([]*abci.Validator, error)
|
2017-07-29 17:22:45 -07:00
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// TickerFunc allows a function to implement the interface
|
|
|
|
type TickerFunc func(Context, state.SimpleDB) ([]*abci.Validator, error)
|
2017-07-03 09:10:46 -07:00
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
func (t TickerFunc) Tick(ctx Context, store state.SimpleDB) ([]*abci.Validator, error) {
|
|
|
|
return t(ctx, store)
|
2017-07-30 09:41:41 -07:00
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// InitValidator sets the initial validator set.
|
|
|
|
// Called from InitChain
|
|
|
|
type InitValidator interface {
|
|
|
|
InitValidators(logger log.Logger, store state.SimpleDB,
|
|
|
|
vals []*abci.Validator)
|
2017-08-04 04:50:55 -07:00
|
|
|
}
|
|
|
|
|
2017-10-23 11:42:16 -07:00
|
|
|
// InitStater sets state from the genesis file
|
|
|
|
//
|
|
|
|
// TODO: Think if this belongs here, in genesis, or somewhere else
|
|
|
|
type InitStater interface {
|
|
|
|
InitState(logger log.Logger, store state.SimpleDB,
|
|
|
|
module, key, value string) (string, error)
|
2017-07-03 09:10:46 -07:00
|
|
|
}
|