1 package types // nolint: goimports
4 context "golang.org/x/net/context"
7 // Application is an interface that enables any finite, deterministic state machine
8 // to be driven by a blockchain-based replication engine via the ABCI
9 type Application interface {
10 // Info/Query Connection
11 Info(RequestInfo) ResponseInfo // Return application info
12 SetOption(key string, value string) (log string) // Set application option
13 Query(RequestQuery) ResponseQuery // Query for state
16 CheckTx(tx []byte) Result // Validate a tx for the mempool
18 // Consensus Connection
19 InitChain(RequestInitChain) // Initialize blockchain with validators and other info from TendermintCore
20 BeginBlock(RequestBeginBlock) // Signals the beginning of a block
21 DeliverTx(tx []byte) Result // Deliver a tx for full processing
22 EndBlock(height uint64) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
23 Commit() Result // Commit the state and return the application Merkle root hash
26 //------------------------------------
28 // GRPCApplication is a GRPC wrapper for Application
29 type GRPCApplication struct {
33 func NewGRPCApplication(app Application) *GRPCApplication {
34 return &GRPCApplication{app}
37 func (app *GRPCApplication) Echo(ctx context.Context, req *RequestEcho) (*ResponseEcho, error) {
38 return &ResponseEcho{req.Message}, nil
41 func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
42 return &ResponseFlush{}, nil
45 func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
46 resInfo := app.app.Info(*req)
50 func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
51 return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
54 func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
55 r := app.app.DeliverTx(req.Tx)
56 return &ResponseDeliverTx{r.Code, r.Data, r.Log}, nil
59 func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
60 r := app.app.CheckTx(req.Tx)
61 return &ResponseCheckTx{r.Code, r.Data, r.Log}, nil
64 func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
65 resQuery := app.app.Query(*req)
69 func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
71 return &ResponseCommit{r.Code, r.Data, r.Log}, nil
74 func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
75 app.app.InitChain(*req)
76 return &ResponseInitChain{}, nil // NOTE: empty return
79 func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
80 app.app.BeginBlock(*req)
81 return &ResponseBeginBlock{}, nil // NOTE: empty return
84 func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
85 resEndBlock := app.app.EndBlock(req.Height)
86 return &resEndBlock, nil