tendermint/types/application.go

139 lines
4.2 KiB
Go
Raw Normal View History

2017-09-22 06:45:50 -07:00
package types // nolint: goimports
2015-11-02 07:39:53 -08:00
2016-05-17 21:54:32 -07:00
import (
context "golang.org/x/net/context"
)
// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI.
// All methods take a ParamsXxx argument and return a ResultXxx argument,
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
2015-11-02 07:39:53 -08:00
type Application interface {
2017-02-06 16:08:37 -08:00
// Info/Query Connection
Info(ParamsInfo) ResultInfo // Return application info
SetOption(ParamsSetOption) ResultSetOption // Set application option
Query(ParamsQuery) ResultQuery // Query for state
2017-02-06 16:08:37 -08:00
// Mempool Connection
CheckTx(tx []byte) ResultCheckTx // Validate a tx for the mempool
2017-02-06 16:08:37 -08:00
// Consensus Connection
InitChain(ParamsInitChain) ResultInitChain // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(ParamsBeginBlock) ResultBeginBlock // Signals the beginning of a block
DeliverTx(tx []byte) ResultDeliverTx // Deliver a tx for full processing
EndBlock(ParamsEndBlock) ResultEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResultCommit // Commit the state and return the application Merkle root hash
2016-02-28 19:19:29 -08:00
}
2016-05-17 21:54:32 -07:00
2017-11-30 21:51:20 -08:00
//-------------------------------------------------------
// BaseApplication is a base form of Application
var _ Application = (*BaseApplication)(nil)
type BaseApplication struct {
}
func NewBaseApplication() *BaseApplication {
return &BaseApplication{}
}
func (BaseApplication) Info(req ParamsInfo) ResultInfo {
return ResultInfo{}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) SetOption(req ParamsSetOption) ResultSetOption {
return ResultSetOption{}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) DeliverTx(tx []byte) ResultDeliverTx {
return ResultDeliverTx{Code: CodeTypeOK}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) CheckTx(tx []byte) ResultCheckTx {
return ResultCheckTx{Code: CodeTypeOK}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) Commit() ResultCommit {
return ResultCommit{}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) Query(req ParamsQuery) ResultQuery {
return ResultQuery{Code: CodeTypeOK}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) InitChain(req ParamsInitChain) ResultInitChain {
return ResultInitChain{}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) BeginBlock(req ParamsBeginBlock) ResultBeginBlock {
return ResultBeginBlock{}
2017-11-30 21:51:20 -08:00
}
func (BaseApplication) EndBlock(req ParamsEndBlock) ResultEndBlock {
return ResultEndBlock{}
2017-11-30 21:51:20 -08:00
}
//-------------------------------------------------------
// GRPCApplication is a GRPC wrapper for Application
2016-05-17 21:54:32 -07:00
type GRPCApplication struct {
app Application
}
func NewGRPCApplication(app Application) *GRPCApplication {
return &GRPCApplication{app}
}
func (app *GRPCApplication) Echo(ctx context.Context, req *ParamsEcho) (*ResultEcho, error) {
return &ResultEcho{req.Message}, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) Flush(ctx context.Context, req *ParamsFlush) (*ResultFlush, error) {
return &ResultFlush{}, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) Info(ctx context.Context, req *ParamsInfo) (*ResultInfo, error) {
2017-11-27 12:16:35 -08:00
res := app.app.Info(*req)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) SetOption(ctx context.Context, req *ParamsSetOption) (*ResultSetOption, error) {
2017-11-27 12:16:35 -08:00
res := app.app.SetOption(*req)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *ParamsDeliverTx) (*ResultDeliverTx, error) {
2017-11-27 12:16:35 -08:00
res := app.app.DeliverTx(req.Tx)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) CheckTx(ctx context.Context, req *ParamsCheckTx) (*ResultCheckTx, error) {
2017-11-27 12:16:35 -08:00
res := app.app.CheckTx(req.Tx)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) Query(ctx context.Context, req *ParamsQuery) (*ResultQuery, error) {
2017-11-27 12:16:35 -08:00
res := app.app.Query(*req)
return &res, nil
2017-01-10 06:49:26 -08:00
}
func (app *GRPCApplication) Commit(ctx context.Context, req *ParamsCommit) (*ResultCommit, error) {
2017-11-27 12:16:35 -08:00
res := app.app.Commit()
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) InitChain(ctx context.Context, req *ParamsInitChain) (*ResultInitChain, error) {
2017-11-27 12:16:35 -08:00
res := app.app.InitChain(*req)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *ParamsBeginBlock) (*ResultBeginBlock, error) {
2017-11-27 12:16:35 -08:00
res := app.app.BeginBlock(*req)
return &res, nil
2016-05-17 21:54:32 -07:00
}
func (app *GRPCApplication) EndBlock(ctx context.Context, req *ParamsEndBlock) (*ResultEndBlock, error) {
2017-11-27 12:16:35 -08:00
res := app.app.EndBlock(*req)
return &res, nil
2016-05-17 21:54:32 -07:00
}