mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 15:11:21 +00:00
base grpc support
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Applications
|
||||
type Application interface {
|
||||
|
||||
@ -36,3 +40,70 @@ type BlockchainAware interface {
|
||||
// diffs: changed validators from app to TendermintCore
|
||||
EndBlock(height uint64) (diffs []*Validator)
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
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) {
|
||||
return &ResponseInfo{app.app.Info()}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
|
||||
return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) AppendTx(ctx context.Context, req *RequestAppendTx) (*ResponseAppendTx, error) {
|
||||
r := app.app.AppendTx(req.Tx)
|
||||
return &ResponseAppendTx{r.Code, r.Data, r.Log}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
|
||||
r := app.app.CheckTx(req.Tx)
|
||||
return &ResponseCheckTx{r.Code, r.Data, r.Log}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
|
||||
r := app.app.Query(req.Query)
|
||||
return &ResponseQuery{r.Code, r.Data, r.Log}, nil
|
||||
}
|
||||
|
||||
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) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
chainAware.InitChain(req.Validators)
|
||||
}
|
||||
return &ResponseInitChain{}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
chainAware.BeginBlock(req.Height)
|
||||
}
|
||||
return &ResponseBeginBlock{}, nil
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
diffs := chainAware.EndBlock(req.Height)
|
||||
return &ResponseEndBlock{diffs}, nil
|
||||
}
|
||||
return &ResponseEndBlock{}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user