Documentation ¶
Index ¶
- Variables
- type Application
- func (a *Application) BeginBlock(request tendermintabci.RequestBeginBlock) (response tendermintabci.ResponseBeginBlock)
- func (a *Application) CheckTx(p []byte) (response tendermintabci.ResponseCheckTx)
- func (a *Application) Commit() (response tendermintabci.ResponseCommit)
- func (a *Application) DeliverTx(p []byte) (response tendermintabci.ResponseDeliverTx)
- func (a *Application) EndBlock(request tendermintabci.RequestEndBlock) (response tendermintabci.ResponseEndBlock)
- func (a *Application) Info(tendermintabci.RequestInfo) (response tendermintabci.ResponseInfo)
- func (a *Application) InitChain(request tendermintabci.RequestInitChain) (response tendermintabci.ResponseInitChain)
- func (a *Application) Query(query tendermintabci.RequestQuery) (response tendermintabci.ResponseQuery)
- func (a *Application) SetOption(request tendermintabci.RequestSetOption) (response tendermintabci.ResponseSetOption)
- type State
Constants ¶
This section is empty.
Variables ¶
var ( ErrCASFailure = errors.New("CAS failure") ErrKeyNotFound = errors.New("key not found") )
Errors related to the state.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application implements the Tendermint ABCI.
func NewApplication ¶
func NewApplication(initial io.Reader, persist io.WriteCloser, logger log.Logger) (*Application, error)
NewApplication returns a Tendermint application server, implementing the ABCI. If initial is non-nil, initial state is populated from it. If persist is non-nil, state is persisted there on each Tendermint commit.
func (*Application) BeginBlock ¶
func (a *Application) BeginBlock(request tendermintabci.RequestBeginBlock) (response tendermintabci.ResponseBeginBlock)
BeginBlock implements ABCI and demarcates the start of a block (of transactions) in the chain.
func (*Application) CheckTx ¶
func (a *Application) CheckTx(p []byte) (response tendermintabci.ResponseCheckTx)
CheckTx implements ABCI and is invoked before DeliverTx. Invalid transactions can be rejected before they're persisted or gossiped. This is an optimization step: simply returning OK won't affect correctness.
func (*Application) Commit ¶
func (a *Application) Commit() (response tendermintabci.ResponseCommit)
Commit implements ABCI and persists the current state. A hash of that state is returned to the caller, i.e. the Tendermint core machinery.
func (*Application) DeliverTx ¶
func (a *Application) DeliverTx(p []byte) (response tendermintabci.ResponseDeliverTx)
DeliverTx implements ABCI and is used for all writes.
func (*Application) EndBlock ¶
func (a *Application) EndBlock(request tendermintabci.RequestEndBlock) (response tendermintabci.ResponseEndBlock)
EndBlock implements ABCI and demarcates the end of a block (of transactions) in the chain.
func (*Application) Info ¶
func (a *Application) Info(tendermintabci.RequestInfo) (response tendermintabci.ResponseInfo)
Info implements ABCI and is called by Tendermint prior to InitChain as a sort of handshake.
When either the app or Tendermint restarts, they need to sync to a common chain height. When an ABCI connection is first established, Tendermint will call Info on the Query connection. The response should contain the LastBlockHeight and LastBlockAppHash; the former is the last block for which the app ran Commit successfully, and the latter is the response from that Commit.
Using this information, Tendermint will determine what needs to be replayed, if anything, against the app, to ensure both Tendermint and the app are synced to the latest block height. If the app returns a LastBlockHeight of 0, Tendermint will just replay all blocks.
The data and version fields may contain arbitrary app-specific information.
func (*Application) InitChain ¶
func (a *Application) InitChain(request tendermintabci.RequestInitChain) (response tendermintabci.ResponseInitChain)
InitChain implements ABCI and is called once, at genesis.
Certain request parameters come from the genesis file. The time is the genesis time; if this is relevant to the application, it must be preferred to system time. Chain ID uniquely identifies the blockchain. AppStateBytes is the Amino/JSON-serialized initial application state.
ConsensusParams describe attributes of Tendermint behavior. If the application wants to change any of them, it can include modified values in its response. Those modifications must be deterministic, all nodes must return the same params for the same InitChain.
If the application returns an empty validator set, the initial validator set will be the validators proposed in the request. If the application returns a nonempty validator set, the initial validator set will be those validators, regardless of what was proposed in the request. This allows the app to decide if it wants to accept the initial validators proposed by Tendermint or if it wants to use a different one. For example, validators may be computed based on some application-specific information in the genesis file.
func (*Application) Query ¶
func (a *Application) Query(query tendermintabci.RequestQuery) (response tendermintabci.ResponseQuery)
Query implements ABCI and is used for reads. In this application, we interpret the data as the key, and return the current value.
func (*Application) SetOption ¶
func (a *Application) SetOption(request tendermintabci.RequestSetOption) (response tendermintabci.ResponseSetOption)
SetOption implements ABCI and configures non-consensus-critical (i.e. non-deterministic) aspects of the application. For example, min-fee: 100fermion could set the minimum fee required for CheckTx; but not DeliverTx, as that would be consensus critical.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State provides a key-value store with compare-and-swap mutability. Persistence is achieved by manually invoking Commit (and Restore).
func NewState ¶
func NewState() *State
NewState returns a new, empty state. Load persisted data, if any, via Restore.
func (*State) Commit ¶
func (s *State) Commit(wc io.WriteCloser) (err error)
Commit the current state to the WriteCloser. On success, close the WriteCloser, increment the commit count, and update the last commit hash.
func (*State) CompareAndSwap ¶
CompareAndSwap sets key to new if and only if its current value is old. Returns ErrCASFailure if the current value is not old.