everything takes Request, returns Response; expect DeliverTx/CheckTx/Commit

This commit is contained in:
Ethan Buchman
2017-11-27 19:04:21 +00:00
parent 67d2a5f66d
commit c7f54fb56c
15 changed files with 174 additions and 291 deletions

View File

@ -5,22 +5,24 @@ import (
)
// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI
// to be driven by a blockchain-based replication engine via the ABCI.
// All methods take a RequestXxx argument and return a ResponseXxx argument,
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
type Application interface {
// Info/Query Connection
Info(RequestInfo) ResponseInfo // Return application info
SetOption(key string, value string) (log string) // Set application option
Query(RequestQuery) ResponseQuery // Query for state
Info(RequestInfo) ResponseInfo // Return application info
SetOption(RequestSetOption) ResponseSetOption // Set application option
Query(RequestQuery) ResponseQuery // Query for state
// Mempool Connection
CheckTx(tx []byte) ResponseCheckTx // Validate a tx for the mempool
// Consensus Connection
InitChain(RequestInitChain) // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) // Signals the beginning of a block
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(height uint64) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
}
//------------------------------------
@ -48,7 +50,8 @@ func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*Respon
}
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
resSetOption := app.app.SetOption(*req)
return &resSetOption, nil
}
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
@ -72,16 +75,16 @@ func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*Re
}
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
app.app.InitChain(*req)
return &ResponseInitChain{}, nil // NOTE: empty return
resInitChain := app.app.InitChain(*req)
return &resInitChain, nil
}
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
app.app.BeginBlock(*req)
return &ResponseBeginBlock{}, nil // NOTE: empty return
resBeginBlock := app.app.BeginBlock(*req)
return &resBeginBlock, nil
}
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
resEndBlock := app.app.EndBlock(req.Height)
resEndBlock := app.app.EndBlock(*req)
return &resEndBlock, nil
}

View File

@ -11,8 +11,8 @@ func (BaseApplication) Info(req RequestInfo) ResponseInfo {
return ResponseInfo{}
}
func (BaseApplication) SetOption(key string, value string) (log string) {
return ""
func (BaseApplication) SetOption(req RequestSetOption) ResponseSetOption {
return ResponseSetOption{}
}
func (BaseApplication) DeliverTx(tx []byte) ResponseDeliverTx {
@ -31,12 +31,14 @@ func (BaseApplication) Query(req RequestQuery) ResponseQuery {
return ResponseQuery{Code: CodeType_OK}
}
func (BaseApplication) InitChain(req RequestInitChain) {
func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
return ResponseInitChain{}
}
func (BaseApplication) BeginBlock(req RequestBeginBlock) {
func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
return ResponseBeginBlock{}
}
func (BaseApplication) EndBlock(height uint64) ResponseEndBlock {
func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
return ResponseEndBlock{}
}

View File

@ -25,21 +25,21 @@ func ToRequestInfo(req RequestInfo) *Request {
}
}
func ToRequestSetOption(key string, value string) *Request {
func ToRequestSetOption(req RequestSetOption) *Request {
return &Request{
Value: &Request_SetOption{&RequestSetOption{key, value}},
Value: &Request_SetOption{&req},
}
}
func ToRequestDeliverTx(txBytes []byte) *Request {
func ToRequestDeliverTx(tx []byte) *Request {
return &Request{
Value: &Request_DeliverTx{&RequestDeliverTx{txBytes}},
Value: &Request_DeliverTx{&RequestDeliverTx{tx}},
}
}
func ToRequestCheckTx(txBytes []byte) *Request {
func ToRequestCheckTx(tx []byte) *Request {
return &Request{
Value: &Request_CheckTx{&RequestCheckTx{txBytes}},
Value: &Request_CheckTx{&RequestCheckTx{tx}},
}
}
@ -67,9 +67,9 @@ func ToRequestBeginBlock(req RequestBeginBlock) *Request {
}
}
func ToRequestEndBlock(height uint64) *Request {
func ToRequestEndBlock(req RequestEndBlock) *Request {
return &Request{
Value: &Request_EndBlock{&RequestEndBlock{height}},
Value: &Request_EndBlock{&req},
}
}
@ -93,57 +93,57 @@ func ToResponseFlush() *Response {
}
}
func ToResponseInfo(resInfo ResponseInfo) *Response {
func ToResponseInfo(res ResponseInfo) *Response {
return &Response{
Value: &Response_Info{&resInfo},
Value: &Response_Info{&res},
}
}
func ToResponseSetOption(log string) *Response {
func ToResponseSetOption(res ResponseSetOption) *Response {
return &Response{
Value: &Response_SetOption{&ResponseSetOption{log}},
Value: &Response_SetOption{&res},
}
}
func ToResponseDeliverTx(code CodeType, data []byte, log string, tags []*KVPair) *Response {
func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
return &Response{
Value: &Response_DeliverTx{&ResponseDeliverTx{code, data, log, tags}},
Value: &Response_DeliverTx{&res},
}
}
func ToResponseCheckTx(code CodeType, data []byte, log string) *Response {
func ToResponseCheckTx(res ResponseCheckTx) *Response {
return &Response{
Value: &Response_CheckTx{&ResponseCheckTx{code, data, log}},
Value: &Response_CheckTx{&res},
}
}
func ToResponseCommit(code CodeType, data []byte, log string) *Response {
func ToResponseCommit(res ResponseCommit) *Response {
return &Response{
Value: &Response_Commit{&ResponseCommit{code, data, log}},
Value: &Response_Commit{&res},
}
}
func ToResponseQuery(resQuery ResponseQuery) *Response {
func ToResponseQuery(res ResponseQuery) *Response {
return &Response{
Value: &Response_Query{&resQuery},
Value: &Response_Query{&res},
}
}
func ToResponseInitChain() *Response {
func ToResponseInitChain(res ResponseInitChain) *Response {
return &Response{
Value: &Response_InitChain{&ResponseInitChain{}},
Value: &Response_InitChain{&res},
}
}
func ToResponseBeginBlock() *Response {
func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
return &Response{
Value: &Response_BeginBlock{&ResponseBeginBlock{}},
Value: &Response_BeginBlock{&res},
}
}
func ToResponseEndBlock(resEndBlock ResponseEndBlock) *Response {
func ToResponseEndBlock(res ResponseEndBlock) *Response {
return &Response{
Value: &Response_EndBlock{&resEndBlock},
Value: &Response_EndBlock{&res},
}
}