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
+6 -6
View File
@@ -20,7 +20,7 @@ type Client interface {
SetOptionAsync(key string, value string) *ReqRes
DeliverTxAsync(tx []byte) *ReqRes
CheckTxAsync(tx []byte) *ReqRes
QueryAsync(reqQuery types.RequestQuery) *ReqRes
QueryAsync(types.RequestQuery) *ReqRes
CommitAsync() *ReqRes
FlushSync() error
@@ -29,15 +29,15 @@ type Client interface {
SetOptionSync(key string, value string) (res types.Result)
DeliverTxSync(tx []byte) (res types.Result)
CheckTxSync(tx []byte) (res types.Result)
QuerySync(reqQuery types.RequestQuery) (resQuery types.ResponseQuery, err error)
QuerySync(types.RequestQuery) (resQuery types.ResponseQuery, err error)
CommitSync() (res types.Result)
InitChainAsync(validators []*types.Validator) *ReqRes
BeginBlockAsync(hash []byte, header *types.Header) *ReqRes
InitChainAsync(types.RequestInitChain) *ReqRes
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
EndBlockAsync(height uint64) *ReqRes
InitChainSync(validators []*types.Validator) (err error)
BeginBlockSync(hash []byte, header *types.Header) (err error)
InitChainSync(types.RequestInitChain) (err error)
BeginBlockSync(types.RequestBeginBlock) (err error)
EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error)
}
+8 -8
View File
@@ -190,8 +190,8 @@ func (cli *grpcClient) CommitAsync() *ReqRes {
return cli.finishAsyncCall(req, &types.Response{&types.Response_Commit{res}})
}
func (cli *grpcClient) InitChainAsync(validators []*types.Validator) *ReqRes {
req := types.ToRequestInitChain(validators)
func (cli *grpcClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
req := types.ToRequestInitChain(params)
res, err := cli.client.InitChain(context.Background(), req.GetInitChain(), grpc.FailFast(true))
if err != nil {
cli.StopForError(err)
@@ -199,8 +199,8 @@ func (cli *grpcClient) InitChainAsync(validators []*types.Validator) *ReqRes {
return cli.finishAsyncCall(req, &types.Response{&types.Response_InitChain{res}})
}
func (cli *grpcClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqRes {
req := types.ToRequestBeginBlock(hash, header)
func (cli *grpcClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
req := types.ToRequestBeginBlock(params)
res, err := cli.client.BeginBlock(context.Background(), req.GetBeginBlock(), grpc.FailFast(true))
if err != nil {
cli.StopForError(err)
@@ -319,13 +319,13 @@ func (cli *grpcClient) CommitSync() (res types.Result) {
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
}
func (cli *grpcClient) InitChainSync(validators []*types.Validator) (err error) {
cli.InitChainAsync(validators)
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) (err error) {
cli.InitChainAsync(params)
return cli.Error()
}
func (cli *grpcClient) BeginBlockSync(hash []byte, header *types.Header) (err error) {
cli.BeginBlockAsync(hash, header)
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
cli.BeginBlockAsync(params)
return cli.Error()
}
+10 -10
View File
@@ -109,23 +109,23 @@ func (app *localClient) CommitAsync() *ReqRes {
)
}
func (app *localClient) InitChainAsync(validators []*types.Validator) *ReqRes {
func (app *localClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
app.mtx.Lock()
app.Application.InitChain(validators)
app.Application.InitChain(params)
reqRes := app.callback(
types.ToRequestInitChain(validators),
types.ToRequestInitChain(params),
types.ToResponseInitChain(),
)
app.mtx.Unlock()
return reqRes
}
func (app *localClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqRes {
func (app *localClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
app.mtx.Lock()
app.Application.BeginBlock(hash, header)
app.Application.BeginBlock(params)
app.mtx.Unlock()
return app.callback(
types.ToRequestBeginBlock(hash, header),
types.ToRequestBeginBlock(params),
types.ToResponseBeginBlock(),
)
}
@@ -192,16 +192,16 @@ func (app *localClient) CommitSync() (res types.Result) {
return res
}
func (app *localClient) InitChainSync(validators []*types.Validator) (err error) {
func (app *localClient) InitChainSync(params types.RequestInitChain) (err error) {
app.mtx.Lock()
app.Application.InitChain(validators)
app.Application.InitChain(params)
app.mtx.Unlock()
return nil
}
func (app *localClient) BeginBlockSync(hash []byte, header *types.Header) (err error) {
func (app *localClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
app.mtx.Lock()
app.Application.BeginBlock(hash, header)
app.Application.BeginBlock(params)
app.mtx.Unlock()
return nil
}
+8 -8
View File
@@ -255,12 +255,12 @@ func (cli *socketClient) CommitAsync() *ReqRes {
return cli.queueRequest(types.ToRequestCommit())
}
func (cli *socketClient) InitChainAsync(validators []*types.Validator) *ReqRes {
return cli.queueRequest(types.ToRequestInitChain(validators))
func (cli *socketClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
return cli.queueRequest(types.ToRequestInitChain(params))
}
func (cli *socketClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(hash, header))
func (cli *socketClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(params))
}
func (cli *socketClient) EndBlockAsync(height uint64) *ReqRes {
@@ -352,8 +352,8 @@ func (cli *socketClient) CommitSync() (res types.Result) {
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
}
func (cli *socketClient) InitChainSync(validators []*types.Validator) (err error) {
cli.queueRequest(types.ToRequestInitChain(validators))
func (cli *socketClient) InitChainSync(params types.RequestInitChain) (err error) {
cli.queueRequest(types.ToRequestInitChain(params))
cli.FlushSync()
if err := cli.Error(); err != nil {
return err
@@ -361,8 +361,8 @@ func (cli *socketClient) InitChainSync(validators []*types.Validator) (err error
return nil
}
func (cli *socketClient) BeginBlockSync(hash []byte, header *types.Header) (err error) {
cli.queueRequest(types.ToRequestBeginBlock(hash, header))
func (cli *socketClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
cli.queueRequest(types.ToRequestBeginBlock(params))
cli.FlushSync()
if err := cli.Error(); err != nil {
return err