mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-20 08:26:31 +00:00
remove Result from the client package
plus make Client interface more consistent. All *Sync functions now return an error as a second return param. Deliver/Check/Commit use Code to indicate errors and have IsErr() func defined on ResponseXYZ structs.
This commit is contained in:
@ -24,21 +24,21 @@ type Client interface {
|
|||||||
CommitAsync() *ReqRes
|
CommitAsync() *ReqRes
|
||||||
|
|
||||||
FlushSync() error
|
FlushSync() error
|
||||||
EchoSync(msg string) (res types.Result)
|
EchoSync(msg string) (*types.ResponseEcho, error)
|
||||||
InfoSync(types.RequestInfo) (resInfo types.ResponseInfo, err error)
|
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
|
||||||
SetOptionSync(key string, value string) (res types.Result)
|
SetOptionSync(key string, value string) (log string, err error)
|
||||||
DeliverTxSync(tx []byte) (res types.Result)
|
DeliverTxSync(tx []byte) *types.ResponseDeliverTx
|
||||||
CheckTxSync(tx []byte) (res types.Result)
|
CheckTxSync(tx []byte) *types.ResponseCheckTx
|
||||||
QuerySync(types.RequestQuery) (resQuery types.ResponseQuery, err error)
|
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
|
||||||
CommitSync() (res types.Result)
|
CommitSync() *types.ResponseCommit
|
||||||
|
|
||||||
InitChainAsync(types.RequestInitChain) *ReqRes
|
InitChainAsync(types.RequestInitChain) *ReqRes
|
||||||
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
|
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
|
||||||
EndBlockAsync(height uint64) *ReqRes
|
EndBlockAsync(height uint64) *ReqRes
|
||||||
|
|
||||||
InitChainSync(types.RequestInitChain) (err error)
|
InitChainSync(types.RequestInitChain) error
|
||||||
BeginBlockSync(types.RequestBeginBlock) (err error)
|
BeginBlockSync(types.RequestBeginBlock) error
|
||||||
EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error)
|
EndBlockSync(height uint64) (*types.ResponseEndBlock, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -240,104 +240,71 @@ func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response)
|
|||||||
return reqres
|
return reqres
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) checkErrGetResult() types.Result {
|
|
||||||
if err := cli.Error(); err != nil {
|
|
||||||
// StopForError should already have been called if error is set
|
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
|
||||||
}
|
|
||||||
return types.Result{}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func (cli *grpcClient) EchoSync(msg string) (res types.Result) {
|
|
||||||
reqres := cli.EchoAsync(msg)
|
|
||||||
if res := cli.checkErrGetResult(); res.IsErr() {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
resp := reqres.Response.GetEcho()
|
|
||||||
return types.NewResultOK([]byte(resp.Message), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cli *grpcClient) FlushSync() error {
|
func (cli *grpcClient) FlushSync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) InfoSync(req types.RequestInfo) (resInfo types.ResponseInfo, err error) {
|
func (cli *grpcClient) EchoSync(msg string) (*types.ResponseEcho, error) {
|
||||||
|
reqres := cli.EchoAsync(msg)
|
||||||
|
// StopForError should already have been called if error is set
|
||||||
|
return reqres.Response.GetEcho(), cli.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *grpcClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
||||||
reqres := cli.InfoAsync(req)
|
reqres := cli.InfoAsync(req)
|
||||||
if err = cli.Error(); err != nil {
|
return reqres.Response.GetInfo(), cli.Error()
|
||||||
return resInfo, err
|
|
||||||
}
|
|
||||||
if info := reqres.Response.GetInfo(); info != nil {
|
|
||||||
return *info, nil
|
|
||||||
}
|
|
||||||
return resInfo, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
|
func (cli *grpcClient) SetOptionSync(key string, value string) (log string, err error) {
|
||||||
reqres := cli.SetOptionAsync(key, value)
|
reqres := cli.SetOptionAsync(key, value)
|
||||||
if res := cli.checkErrGetResult(); res.IsErr() {
|
if err := cli.Error(); err != nil {
|
||||||
return res
|
return "", err
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetSetOption()
|
return reqres.Response.GetSetOption().Log, nil
|
||||||
return types.Result{Code: OK, Data: nil, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) DeliverTxSync(tx []byte) (res types.Result) {
|
func (cli *grpcClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
||||||
reqres := cli.DeliverTxAsync(tx)
|
reqres := cli.DeliverTxAsync(tx)
|
||||||
if res := cli.checkErrGetResult(); res.IsErr() {
|
if err := cli.Error(); err != nil {
|
||||||
return res
|
return &types.ResponseDeliverTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetDeliverTx()
|
return reqres.Response.GetDeliverTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) CheckTxSync(tx []byte) (res types.Result) {
|
func (cli *grpcClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
||||||
reqres := cli.CheckTxAsync(tx)
|
reqres := cli.CheckTxAsync(tx)
|
||||||
if res := cli.checkErrGetResult(); res.IsErr() {
|
if err := cli.Error(); err != nil {
|
||||||
return res
|
return &types.ResponseCheckTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetCheckTx()
|
return reqres.Response.GetCheckTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) QuerySync(reqQuery types.RequestQuery) (resQuery types.ResponseQuery, err error) {
|
func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
reqres := cli.QueryAsync(reqQuery)
|
reqres := cli.QueryAsync(req)
|
||||||
if err = cli.Error(); err != nil {
|
return reqres.Response.GetQuery(), cli.Error()
|
||||||
return resQuery, err
|
|
||||||
}
|
|
||||||
if resQuery_ := reqres.Response.GetQuery(); resQuery_ != nil {
|
|
||||||
return *resQuery_, nil
|
|
||||||
}
|
|
||||||
return resQuery, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) CommitSync() (res types.Result) {
|
func (cli *grpcClient) CommitSync() *types.ResponseCommit {
|
||||||
reqres := cli.CommitAsync()
|
reqres := cli.CommitAsync()
|
||||||
if res := cli.checkErrGetResult(); res.IsErr() {
|
if err := cli.Error(); err != nil {
|
||||||
return res
|
return &types.ResponseCommit{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetCommit()
|
return reqres.Response.GetCommit()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) (err error) {
|
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
cli.InitChainAsync(params)
|
cli.InitChainAsync(params)
|
||||||
return cli.Error()
|
return cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
|
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) error {
|
||||||
cli.BeginBlockAsync(params)
|
cli.BeginBlockAsync(params)
|
||||||
return cli.Error()
|
return cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) {
|
func (cli *grpcClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
|
||||||
reqres := cli.EndBlockAsync(height)
|
reqres := cli.EndBlockAsync(height)
|
||||||
if err := cli.Error(); err != nil {
|
return reqres.Response.GetEndBlock(), cli.Error()
|
||||||
return resEndBlock, err
|
|
||||||
}
|
|
||||||
if blk := reqres.Response.GetEndBlock(); blk != nil {
|
|
||||||
return *blk, nil
|
|
||||||
}
|
|
||||||
return resEndBlock, nil
|
|
||||||
}
|
}
|
||||||
|
@ -146,71 +146,71 @@ func (app *localClient) FlushSync() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) EchoSync(msg string) (res types.Result) {
|
func (app *localClient) EchoSync(msg string) (*types.ResponseEcho, error) {
|
||||||
return types.OK.SetData([]byte(msg))
|
return &types.ResponseEcho{msg}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) InfoSync(req types.RequestInfo) (resInfo types.ResponseInfo, err error) {
|
func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
defer app.mtx.Unlock()
|
res := app.Application.Info(req)
|
||||||
resInfo = app.Application.Info(req)
|
|
||||||
return resInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (app *localClient) SetOptionSync(key string, value string) (res types.Result) {
|
|
||||||
app.mtx.Lock()
|
|
||||||
log := app.Application.SetOption(key, value)
|
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return types.OK.SetLog(log)
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) DeliverTxSync(tx []byte) (res types.ResponseDeliverTx) {
|
func (app *localClient) SetOptionSync(key string, value string) (log string, err error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res = app.Application.DeliverTx(tx)
|
log = app.Application.SetOption(key, value)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return res
|
return log, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CheckTxSync(tx []byte) (res types.ResponseCheckTx) {
|
func (app *localClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res = app.Application.CheckTx(tx)
|
res := app.Application.DeliverTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return res
|
return &res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) QuerySync(reqQuery types.RequestQuery) (resQuery types.ResponseQuery, err error) {
|
func (app *localClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
resQuery = app.Application.Query(reqQuery)
|
res := app.Application.CheckTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return resQuery, nil
|
return &res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CommitSync() (res types.ResponseCommit) {
|
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res = app.Application.Commit()
|
res := app.Application.Query(req)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return res
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) InitChainSync(params types.RequestInitChain) (err error) {
|
func (app *localClient) CommitSync() *types.ResponseCommit {
|
||||||
|
app.mtx.Lock()
|
||||||
|
res := app.Application.Commit()
|
||||||
|
app.mtx.Unlock()
|
||||||
|
return &res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *localClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
app.Application.InitChain(params)
|
app.Application.InitChain(params)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
|
func (app *localClient) BeginBlockSync(params types.RequestBeginBlock) error {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
app.Application.BeginBlock(params)
|
app.Application.BeginBlock(params)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) {
|
func (app *localClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
resEndBlock = app.Application.EndBlock(height)
|
res := app.Application.EndBlock(height)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return resEndBlock, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
@ -271,111 +271,85 @@ func (cli *socketClient) EndBlockAsync(height uint64) *ReqRes {
|
|||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func (cli *socketClient) EchoSync(msg string) (res types.Result) {
|
|
||||||
reqres := cli.queueRequest(types.ToRequestEcho(msg))
|
|
||||||
cli.FlushSync()
|
|
||||||
if err := cli.Error(); err != nil {
|
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
|
||||||
}
|
|
||||||
resp := reqres.Response.GetEcho()
|
|
||||||
return types.Result{Code: OK, Data: []byte(resp.Message)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cli *socketClient) FlushSync() error {
|
func (cli *socketClient) FlushSync() error {
|
||||||
reqRes := cli.queueRequest(types.ToRequestFlush())
|
reqRes := cli.queueRequest(types.ToRequestFlush())
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
reqRes.Wait() // NOTE: if we don't flush the queue, its possible to get stuck here
|
reqRes.Wait() // NOTE: if we don't flush the queue, its possible to get stuck here
|
||||||
return cli.Error()
|
return cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) InfoSync(req types.RequestInfo) (resInfo types.ResponseInfo, err error) {
|
func (cli *socketClient) EchoSync(msg string) (*types.ResponseEcho, error) {
|
||||||
reqres := cli.queueRequest(types.ToRequestInfo(req))
|
reqres := cli.queueRequest(types.ToRequestEcho(msg))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
return reqres.Response.GetEcho(), cli.Error()
|
||||||
return resInfo, err
|
|
||||||
}
|
|
||||||
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
|
|
||||||
return *resInfo_, nil
|
|
||||||
}
|
|
||||||
return resInfo, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
|
func (cli *socketClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
||||||
|
reqres := cli.queueRequest(types.ToRequestInfo(req))
|
||||||
|
cli.FlushSync()
|
||||||
|
return reqres.Response.GetInfo(), cli.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *socketClient) SetOptionSync(key string, value string) (log string, err error) {
|
||||||
reqres := cli.queueRequest(types.ToRequestSetOption(key, value))
|
reqres := cli.queueRequest(types.ToRequestSetOption(key, value))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
return "", err
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetSetOption()
|
return reqres.Response.GetSetOption().Log, nil
|
||||||
return types.Result{Code: OK, Data: nil, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) DeliverTxSync(tx []byte) (res types.Result) {
|
func (cli *socketClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
||||||
reqres := cli.queueRequest(types.ToRequestDeliverTx(tx))
|
reqres := cli.queueRequest(types.ToRequestDeliverTx(tx))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
return &types.ResponseDeliverTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetDeliverTx()
|
return reqres.Response.GetDeliverTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) CheckTxSync(tx []byte) (res types.Result) {
|
func (cli *socketClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
||||||
reqres := cli.queueRequest(types.ToRequestCheckTx(tx))
|
reqres := cli.queueRequest(types.ToRequestCheckTx(tx))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
return &types.ResponseCheckTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetCheckTx()
|
return reqres.Response.GetCheckTx()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) QuerySync(reqQuery types.RequestQuery) (resQuery types.ResponseQuery, err error) {
|
func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
reqres := cli.queueRequest(types.ToRequestQuery(reqQuery))
|
reqres := cli.queueRequest(types.ToRequestQuery(req))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
return reqres.Response.GetQuery(), cli.Error()
|
||||||
return resQuery, err
|
|
||||||
}
|
|
||||||
if resQuery_ := reqres.Response.GetQuery(); resQuery_ != nil {
|
|
||||||
return *resQuery_, nil
|
|
||||||
}
|
|
||||||
return resQuery, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) CommitSync() (res types.Result) {
|
func (cli *socketClient) CommitSync() *types.ResponseCommit {
|
||||||
reqres := cli.queueRequest(types.ToRequestCommit())
|
reqres := cli.queueRequest(types.ToRequestCommit())
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return types.ErrInternalError.SetLog(err.Error())
|
return &types.ResponseCommit{Code: types.CodeType_InternalError, Log: err.Error()}
|
||||||
}
|
}
|
||||||
resp := reqres.Response.GetCommit()
|
return reqres.Response.GetCommit()
|
||||||
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) InitChainSync(params types.RequestInitChain) (err error) {
|
func (cli *socketClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
cli.queueRequest(types.ToRequestInitChain(params))
|
cli.queueRequest(types.ToRequestInitChain(params))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
return cli.Error()
|
return cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) BeginBlockSync(params types.RequestBeginBlock) (err error) {
|
func (cli *socketClient) BeginBlockSync(params types.RequestBeginBlock) error {
|
||||||
cli.queueRequest(types.ToRequestBeginBlock(params))
|
cli.queueRequest(types.ToRequestBeginBlock(params))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
return cli.Error()
|
return cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) {
|
func (cli *socketClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
|
||||||
reqres := cli.queueRequest(types.ToRequestEndBlock(height))
|
reqres := cli.queueRequest(types.ToRequestEndBlock(height))
|
||||||
cli.FlushSync()
|
cli.FlushSync()
|
||||||
if err := cli.Error(); err != nil {
|
return reqres.Response.GetEndBlock(), cli.Error()
|
||||||
return resEndBlock, err
|
|
||||||
}
|
|
||||||
if blk := reqres.Response.GetEndBlock(); blk != nil {
|
|
||||||
return *blk, nil
|
|
||||||
}
|
|
||||||
return resEndBlock, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -327,9 +327,12 @@ func cmdConsole(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
// Have the application echo a message
|
// Have the application echo a message
|
||||||
func cmdEcho(cmd *cobra.Command, args []string) error {
|
func cmdEcho(cmd *cobra.Command, args []string) error {
|
||||||
resEcho := client.EchoSync(args[0])
|
res, err := client.EchoSync(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Data: resEcho.Data,
|
Data: []byte(res.Message),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -340,21 +343,24 @@ func cmdInfo(cmd *cobra.Command, args []string) error {
|
|||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
version = args[0]
|
version = args[0]
|
||||||
}
|
}
|
||||||
resInfo, err := client.InfoSync(types.RequestInfo{version})
|
res, err := client.InfoSync(types.RequestInfo{version})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Data: []byte(resInfo.Data),
|
Data: []byte(res.Data),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set an option on the application
|
// Set an option on the application
|
||||||
func cmdSetOption(cmd *cobra.Command, args []string) error {
|
func cmdSetOption(cmd *cobra.Command, args []string) error {
|
||||||
resSetOption := client.SetOptionSync(args[0], args[1])
|
log, err := client.SetOptionSync(args[0], args[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Log: resSetOption.Log,
|
Log: log,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func startApp(abciApp string) *process.Process {
|
|||||||
os.Stdout,
|
os.Stdout,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("running abci_app: " + err.Error())
|
panicf("running abci_app: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO a better way to handle this?
|
// TODO a better way to handle this?
|
||||||
@ -41,57 +41,54 @@ func startClient(abciType string) abcicli.Client {
|
|||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
client.SetLogger(logger.With("module", "abcicli"))
|
client.SetLogger(logger.With("module", "abcicli"))
|
||||||
if _, err := client.Start(); err != nil {
|
if _, err := client.Start(); err != nil {
|
||||||
panic("connecting to abci_app: " + err.Error())
|
panicf("connecting to abci_app: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOption(client abcicli.Client, key, value string) {
|
func setOption(client abcicli.Client, key, value string) {
|
||||||
res := client.SetOptionSync(key, value)
|
_, err := client.SetOptionSync(key, value)
|
||||||
_, _, log := res.Code, res.Data, res.Log
|
if err != nil {
|
||||||
if res.IsErr() {
|
panicf("setting %v=%v: \nerr: %v", key, value, err)
|
||||||
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func commit(client abcicli.Client, hashExp []byte) {
|
func commit(client abcicli.Client, hashExp []byte) {
|
||||||
res := client.CommitSync()
|
res := client.CommitSync()
|
||||||
_, data, _ := res.Code, res.Data, res.Log
|
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panic(fmt.Sprintf("committing err %v\n", res))
|
panicf("committing err %v\n", res)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(res.Data, hashExp) {
|
if !bytes.Equal(res.Data, hashExp) {
|
||||||
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
|
panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
|
||||||
data, hashExp))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||||
res := client.DeliverTxSync(txBytes)
|
res := client.DeliverTxSync(txBytes)
|
||||||
code, data, log := res.Code, res.Data, res.Log
|
if res.Code != codeExp {
|
||||||
if code != codeExp {
|
panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
|
||||||
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
|
|
||||||
code, codeExp, log))
|
|
||||||
}
|
}
|
||||||
if !bytes.Equal(data, dataExp) {
|
if !bytes.Equal(res.Data, dataExp) {
|
||||||
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
|
panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
|
||||||
data, dataExp))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
/*func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||||
res := client.CheckTxSync(txBytes)
|
res := client.CheckTxSync(txBytes)
|
||||||
code, data, log := res.Code, res.Data, res.Log
|
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
|
panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
|
||||||
}
|
}
|
||||||
if code != codeExp {
|
if res.Code != codeExp {
|
||||||
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||||
code, codeExp, log))
|
res.Code, codeExp, res.Log)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(data, dataExp) {
|
if !bytes.Equal(res.Data, dataExp) {
|
||||||
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
|
panicf("CheckTx response data was unexpected. Got %X expected %X",
|
||||||
data, dataExp))
|
res.Data, dataExp)
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
func panicf(format string, a ...interface{}) {
|
||||||
|
panic(fmt.Sprintf(format, a))
|
||||||
|
}
|
||||||
|
@ -106,6 +106,7 @@ func (r *ResponseCheckTx) Result() Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsErr returns true if Code is something other than OK.
|
||||||
func (r ResponseCheckTx) IsErr() bool {
|
func (r ResponseCheckTx) IsErr() bool {
|
||||||
return r.Code != CodeType_OK
|
return r.Code != CodeType_OK
|
||||||
}
|
}
|
||||||
@ -120,6 +121,7 @@ func (r *ResponseDeliverTx) Result() Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsErr returns true if Code is something other than OK.
|
||||||
func (r ResponseDeliverTx) IsErr() bool {
|
func (r ResponseDeliverTx) IsErr() bool {
|
||||||
return r.Code != CodeType_OK
|
return r.Code != CodeType_OK
|
||||||
}
|
}
|
||||||
@ -145,3 +147,8 @@ func (r *ResponseQuery) Result() *ResultQuery {
|
|||||||
Log: r.Log,
|
Log: r.Log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsErr returns true if Code is something other than OK.
|
||||||
|
func (r ResponseCommit) IsErr() bool {
|
||||||
|
return r.Code != CodeType_OK
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user