OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / abci / types / application.go
1 package types // nolint: goimports
2
3 import (
4         context "golang.org/x/net/context"
5 )
6
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
14
15         // Mempool Connection
16         CheckTx(tx []byte) Result // Validate a tx for the mempool
17
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
24 }
25
26 //------------------------------------
27
28 // GRPCApplication is a GRPC wrapper for Application
29 type GRPCApplication struct {
30         app Application
31 }
32
33 func NewGRPCApplication(app Application) *GRPCApplication {
34         return &GRPCApplication{app}
35 }
36
37 func (app *GRPCApplication) Echo(ctx context.Context, req *RequestEcho) (*ResponseEcho, error) {
38         return &ResponseEcho{req.Message}, nil
39 }
40
41 func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
42         return &ResponseFlush{}, nil
43 }
44
45 func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
46         resInfo := app.app.Info(*req)
47         return &resInfo, nil
48 }
49
50 func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
51         return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
52 }
53
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
57 }
58
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
62 }
63
64 func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
65         resQuery := app.app.Query(*req)
66         return &resQuery, nil
67 }
68
69 func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
70         r := app.app.Commit()
71         return &ResponseCommit{r.Code, r.Data, r.Log}, nil
72 }
73
74 func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
75         app.app.InitChain(*req)
76         return &ResponseInitChain{}, nil // NOTE: empty return
77 }
78
79 func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
80         app.app.BeginBlock(*req)
81         return &ResponseBeginBlock{}, nil // NOTE: empty return
82 }
83
84 func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
85         resEndBlock := app.app.EndBlock(req.Height)
86         return &resEndBlock, nil
87 }