From c3d5634efa73dd6ce2c9d7c317aeae76038139ae Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 22 Aug 2016 15:57:20 -0400 Subject: [PATCH] begin block --- proxy/app_conn.go | 10 +++++----- types/protobuf.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 types/protobuf.go diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 5ba1bc15..e19e6f09 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -14,7 +14,7 @@ type AppConnConsensus interface { InitChainSync(validators []*types.Validator) (err error) - BeginBlockSync(height uint64) (err error) + BeginBlockSync(header *types.Header) (err error) AppendTxAsync(tx []byte) *tmspcli.ReqRes EndBlockSync(height uint64) (changedValidators []*types.Validator, err error) CommitSync() (res types.Result) @@ -34,7 +34,7 @@ type AppConnQuery interface { Error() error EchoSync(string) (res types.Result) - InfoSync() (res types.Result) + InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) QuerySync(tx []byte) (res types.Result) // SetOptionSync(key string, value string) (res types.Result) @@ -62,8 +62,8 @@ func (app *appConnConsensus) Error() error { func (app *appConnConsensus) InitChainSync(validators []*types.Validator) (err error) { return app.appConn.InitChainSync(validators) } -func (app *appConnConsensus) BeginBlockSync(height uint64) (err error) { - return app.appConn.BeginBlockSync(height) +func (app *appConnConsensus) BeginBlockSync(header *types.Header) (err error) { + return app.appConn.BeginBlockSync(header) } func (app *appConnConsensus) AppendTxAsync(tx []byte) *tmspcli.ReqRes { return app.appConn.AppendTxAsync(tx) @@ -131,7 +131,7 @@ func (app *appConnQuery) EchoSync(msg string) (res types.Result) { return app.appConn.EchoSync(msg) } -func (app *appConnQuery) InfoSync() (res types.Result) { +func (app *appConnQuery) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) { return app.appConn.InfoSync() } diff --git a/types/protobuf.go b/types/protobuf.go new file mode 100644 index 00000000..c6d33cf2 --- /dev/null +++ b/types/protobuf.go @@ -0,0 +1,37 @@ +package types + +import ( + "github.com/tendermint/tmsp/types" +) + +// Convert tendermint types to protobuf types +var TM2PB = tm2pb{} + +type tm2pb struct{} + +func (tm2pb) Header(header *Header) *types.Header { + return &types.Header{ + ChainId: header.ChainID, + Height: uint64(header.Height), + Time: uint64(header.Time.Unix()), + NumTxs: uint64(header.NumTxs), + LastBlockHash: header.LastBlockHash, + LastBlockParts: TM2PB.PartSetHeader(header.LastBlockParts), + LastCommitHash: header.LastCommitHash, + DataHash: header.DataHash, + } +} + +func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader { + return &types.PartSetHeader{ + Total: uint64(partSetHeader.Total), + Hash: partSetHeader.Hash, + } +} + +func (tm2pb) Validator(val *Validator) *types.Validator { + return &types.Validator{ + PubKey: val.PubKey.Bytes(), + Power: uint64(val.VotingPower), + } +}