use request structs for InitChain and BeginBlock

This commit is contained in:
Ethan Buchman
2017-09-18 15:51:48 -04:00
parent a072429659
commit f279171a28
12 changed files with 56 additions and 54 deletions
+9 -8
View File
@@ -4,27 +4,28 @@ import (
context "golang.org/x/net/context"
)
// Applications
// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI
type Application interface {
// Info/Query Connection
Info() ResponseInfo // Return application info
SetOption(key string, value string) (log string) // Set application option
Query(reqQuery RequestQuery) ResponseQuery // Query for state
Query(RequestQuery) ResponseQuery // Query for state
// Mempool Connection
CheckTx(tx []byte) Result // Validate a tx for the mempool
// Consensus Connection
InitChain(validators []*Validator) // Initialize blockchain with validators from TendermintCore
BeginBlock(hash []byte, header *Header) // Signals the beginning of a block
DeliverTx(tx []byte) Result // Deliver a tx for full processing
InitChain(RequestInitChain) // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) // Signals the beginning of a block
DeliverTx(tx []byte) Result // Deliver a tx for full processing
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
}
//------------------------------------
// GRPC wrapper for application
// GRPCApplication is a GRPC wrapper for Application
type GRPCApplication struct {
app Application
}
@@ -71,12 +72,12 @@ 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.Validators)
app.app.InitChain(*req)
return &ResponseInitChain{}, nil // NOTE: empty return
}
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
app.app.BeginBlock(req.Hash, req.Header)
app.app.BeginBlock(*req)
return &ResponseBeginBlock{}, nil // NOTE: empty return
}
+2 -2
View File
@@ -31,10 +31,10 @@ func (app *BaseApplication) Query(reqQuery RequestQuery) (resQuery ResponseQuery
return
}
func (app *BaseApplication) InitChain(validators []*Validator) {
func (app *BaseApplication) InitChain(reqInitChain RequestInitChain) {
}
func (app *BaseApplication) BeginBlock(hash []byte, header *Header) {
func (app *BaseApplication) BeginBlock(reqBeginBlock RequestBeginBlock) {
}
func (app *BaseApplication) EndBlock(height uint64) (resEndBlock ResponseEndBlock) {
+4 -4
View File
@@ -55,15 +55,15 @@ func ToRequestQuery(reqQuery RequestQuery) *Request {
}
}
func ToRequestInitChain(validators []*Validator) *Request {
func ToRequestInitChain(reqInitChain RequestInitChain) *Request {
return &Request{
Value: &Request_InitChain{&RequestInitChain{validators}},
Value: &Request_InitChain{&reqInitChain},
}
}
func ToRequestBeginBlock(hash []byte, header *Header) *Request {
func ToRequestBeginBlock(reqBeginBlock RequestBeginBlock) *Request {
return &Request{
Value: &Request_BeginBlock{&RequestBeginBlock{hash, header}},
Value: &Request_BeginBlock{&reqBeginBlock},
}
}
+1
View File
@@ -6,6 +6,7 @@ import (
"github.com/tendermint/go-wire/data"
)
// Result is a common result object for ABCI calls.
// CONTRACT: a zero Result is OK.
type Result struct {
Code CodeType `json:"code"`