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"
|
|
|
|
)
|
|
|
|
|
2017-09-18 12:51:48 -07:00
|
|
|
// Application is an interface that enables any finite, deterministic state machine
|
|
|
|
// to be driven by a blockchain-based replication engine via the ABCI
|
2015-11-02 07:39:53 -08:00
|
|
|
type Application interface {
|
2017-02-06 16:08:37 -08:00
|
|
|
// Info/Query Connection
|
2017-09-22 08:10:39 -07:00
|
|
|
Info(RequestInfo) ResponseInfo // Return application info
|
2017-02-06 16:08:37 -08:00
|
|
|
SetOption(key string, value string) (log string) // Set application option
|
2017-09-18 12:51:48 -07:00
|
|
|
Query(RequestQuery) ResponseQuery // Query for state
|
2017-02-06 16:08:37 -08:00
|
|
|
|
|
|
|
// Mempool Connection
|
|
|
|
CheckTx(tx []byte) Result // Validate a tx for the mempool
|
|
|
|
|
|
|
|
// Consensus Connection
|
2017-09-18 12:51:48 -07:00
|
|
|
InitChain(RequestInitChain) // Initialize blockchain with validators and other info from TendermintCore
|
|
|
|
BeginBlock(RequestBeginBlock) // Signals the beginning of a block
|
2017-09-22 06:45:50 -07:00
|
|
|
DeliverTx(tx []byte) Result // Deliver a tx for full processing
|
2017-02-06 16:08:37 -08:00
|
|
|
EndBlock(height uint64) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
|
|
|
|
Commit() Result // 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-02-06 16:08:37 -08:00
|
|
|
|
2017-09-18 12:51:48 -07: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 *RequestEcho) (*ResponseEcho, error) {
|
|
|
|
return &ResponseEcho{req.Message}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
|
|
|
|
return &ResponseFlush{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
|
2017-09-22 08:10:39 -07:00
|
|
|
resInfo := app.app.Info(*req)
|
2016-12-26 17:44:36 -08:00
|
|
|
return &resInfo, nil
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
|
|
|
|
return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
|
|
|
|
}
|
|
|
|
|
2017-01-12 12:27:08 -08:00
|
|
|
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
|
|
|
|
r := app.app.DeliverTx(req.Tx)
|
2017-11-09 13:52:52 -08:00
|
|
|
return &ResponseDeliverTx{r.Code, r.Data, r.Log, r.Tags}, nil
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
|
|
|
|
r := app.app.CheckTx(req.Tx)
|
2017-11-20 16:21:59 -08:00
|
|
|
return &ResponseCheckTx{r.Code, r.Data, r.Log}, nil
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
|
2017-01-23 23:42:09 -08:00
|
|
|
resQuery := app.app.Query(*req)
|
|
|
|
return &resQuery, nil
|
2017-01-10 06:49:26 -08:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:54:32 -07:00
|
|
|
func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
|
|
|
|
r := app.app.Commit()
|
|
|
|
return &ResponseCommit{r.Code, r.Data, r.Log}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
|
2017-09-18 12:51:48 -07:00
|
|
|
app.app.InitChain(*req)
|
2017-02-06 16:08:37 -08:00
|
|
|
return &ResponseInitChain{}, nil // NOTE: empty return
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
|
2017-09-18 12:51:48 -07:00
|
|
|
app.app.BeginBlock(*req)
|
2017-02-06 16:08:37 -08:00
|
|
|
return &ResponseBeginBlock{}, nil // NOTE: empty return
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
|
2017-02-06 16:08:37 -08:00
|
|
|
resEndBlock := app.app.EndBlock(req.Height)
|
|
|
|
return &resEndBlock, nil
|
2016-05-17 21:54:32 -07:00
|
|
|
}
|