add version/block/config to Info. add header to BeginBlock

This commit is contained in:
Ethan Buchman
2016-11-16 13:32:01 -05:00
parent eece35eeeb
commit debbf122db
13 changed files with 414 additions and 149 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ type Client interface {
FlushSync() error
EchoSync(msg string) (res types.Result)
InfoSync() (res types.Result)
InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo)
SetOptionSync(key string, value string) (res types.Result)
AppendTxSync(tx []byte) (res types.Result)
CheckTxSync(tx []byte) (res types.Result)
@@ -33,11 +33,11 @@ type Client interface {
CommitSync() (res types.Result)
InitChainAsync(validators []*types.Validator) *ReqRes
BeginBlockAsync(height uint64) *ReqRes
BeginBlockAsync(header *types.Header) *ReqRes
EndBlockAsync(height uint64) *ReqRes
InitChainSync(validators []*types.Validator) (err error)
BeginBlockSync(height uint64) (err error)
BeginBlockSync(header *types.Header) (err error)
EndBlockSync(height uint64) (changedValidators []*types.Validator, err error)
}
+6 -6
View File
@@ -200,8 +200,8 @@ func (cli *grpcClient) InitChainAsync(validators []*types.Validator) *ReqRes {
return cli.finishAsyncCall(req, &types.Response{&types.Response_InitChain{res}})
}
func (cli *grpcClient) BeginBlockAsync(height uint64) *ReqRes {
req := types.ToRequestBeginBlock(height)
func (cli *grpcClient) BeginBlockAsync(header *types.Header) *ReqRes {
req := types.ToRequestBeginBlock(header)
res, err := cli.client.BeginBlock(context.Background(), req.GetBeginBlock(), grpc.FailFast(true))
if err != nil {
cli.StopForError(err)
@@ -262,13 +262,13 @@ func (cli *grpcClient) FlushSync() error {
return nil
}
func (cli *grpcClient) InfoSync() (res types.Result) {
func (cli *grpcClient) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
reqres := cli.InfoAsync()
if res := cli.checkErrGetResult(); res.IsErr() {
return res
}
resp := reqres.Response.GetInfo()
return types.NewResultOK([]byte(resp.Info), LOG)
return types.NewResultOK([]byte(resp.Info), LOG), r.TmspInfo, r.LastBlock, r.Config
}
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
@@ -321,8 +321,8 @@ func (cli *grpcClient) InitChainSync(validators []*types.Validator) (err error)
return cli.Error()
}
func (cli *grpcClient) BeginBlockSync(height uint64) (err error) {
cli.BeginBlockAsync(height)
func (cli *grpcClient) BeginBlockSync(header *types.Header) (err error) {
cli.BeginBlockAsync(header)
return cli.Error()
}
+11 -11
View File
@@ -51,11 +51,11 @@ func (app *localClient) EchoAsync(msg string) *ReqRes {
func (app *localClient) InfoAsync() *ReqRes {
app.mtx.Lock()
info := app.Application.Info()
info, tmspInfo, blockInfo, configInfo := app.Application.Info()
app.mtx.Unlock()
return app.callback(
types.ToRequestInfo(),
types.ToResponseInfo(info),
types.ToResponseInfo(info, tmspInfo, blockInfo, configInfo),
)
}
@@ -122,14 +122,14 @@ func (app *localClient) InitChainAsync(validators []*types.Validator) *ReqRes {
return reqRes
}
func (app *localClient) BeginBlockAsync(height uint64) *ReqRes {
func (app *localClient) BeginBlockAsync(header *types.Header) *ReqRes {
app.mtx.Lock()
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
bcApp.BeginBlock(height)
bcApp.BeginBlock(header)
}
app.mtx.Unlock()
return app.callback(
types.ToRequestBeginBlock(height),
types.ToRequestBeginBlock(header),
types.ToResponseBeginBlock(),
)
}
@@ -157,11 +157,11 @@ func (app *localClient) EchoSync(msg string) (res types.Result) {
return types.OK.SetData([]byte(msg))
}
func (app *localClient) InfoSync() (res types.Result) {
func (app *localClient) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
app.mtx.Lock()
info := app.Application.Info()
app.mtx.Unlock()
return types.OK.SetData([]byte(info))
defer app.mtx.Unlock()
info, tmspInfo, blockInfo, configInfo := app.Application.Info()
return types.OK.SetData([]byte(info)), tmspInfo, blockInfo, configInfo
}
func (app *localClient) SetOptionSync(key string, value string) (res types.Result) {
@@ -208,10 +208,10 @@ func (app *localClient) InitChainSync(validators []*types.Validator) (err error)
return nil
}
func (app *localClient) BeginBlockSync(height uint64) (err error) {
func (app *localClient) BeginBlockSync(header *types.Header) (err error) {
app.mtx.Lock()
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
bcApp.BeginBlock(height)
bcApp.BeginBlock(header)
}
app.mtx.Unlock()
return nil
+7 -7
View File
@@ -263,8 +263,8 @@ func (cli *socketClient) InitChainAsync(validators []*types.Validator) *ReqRes {
return cli.queueRequest(types.ToRequestInitChain(validators))
}
func (cli *socketClient) BeginBlockAsync(height uint64) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(height))
func (cli *socketClient) BeginBlockAsync(header *types.Header) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(header))
}
func (cli *socketClient) EndBlockAsync(height uint64) *ReqRes {
@@ -292,14 +292,14 @@ func (cli *socketClient) FlushSync() error {
return cli.Error()
}
func (cli *socketClient) InfoSync() (res types.Result) {
func (cli *socketClient) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
reqres := cli.queueRequest(types.ToRequestInfo())
cli.FlushSync()
if err := cli.Error(); err != nil {
return types.ErrInternalError.SetLog(err.Error())
return types.ErrInternalError.SetLog(err.Error()), nil, nil, nil
}
resp := reqres.Response.GetInfo()
return types.Result{Code: OK, Data: []byte(resp.Info), Log: LOG}
return types.Result{Code: OK, Data: []byte(resp.Info), Log: LOG}, resp.TmspInfo, resp.LastBlock, resp.Config
}
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
@@ -361,8 +361,8 @@ func (cli *socketClient) InitChainSync(validators []*types.Validator) (err error
return nil
}
func (cli *socketClient) BeginBlockSync(height uint64) (err error) {
cli.queueRequest(types.ToRequestBeginBlock(height))
func (cli *socketClient) BeginBlockSync(header *types.Header) (err error) {
cli.queueRequest(types.ToRequestBeginBlock(header))
cli.FlushSync()
if err := cli.Error(); err != nil {
return err