mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 15:11:21 +00:00
DeliverTxSync/CheckTxSync/CommitSync now return error as well
This commit is contained in:
@ -27,10 +27,10 @@ type Client interface {
|
|||||||
EchoSync(msg string) (*types.ResponseEcho, error)
|
EchoSync(msg string) (*types.ResponseEcho, error)
|
||||||
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
|
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
|
||||||
SetOptionSync(key string, value string) (log string, err error)
|
SetOptionSync(key string, value string) (log string, err error)
|
||||||
DeliverTxSync(tx []byte) *types.ResponseDeliverTx
|
DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error)
|
||||||
CheckTxSync(tx []byte) *types.ResponseCheckTx
|
CheckTxSync(tx []byte) (*types.ResponseCheckTx, error)
|
||||||
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
|
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
|
||||||
CommitSync() *types.ResponseCommit
|
CommitSync() (*types.ResponseCommit, error)
|
||||||
|
|
||||||
InitChainAsync(types.RequestInitChain) *ReqRes
|
InitChainAsync(types.RequestInitChain) *ReqRes
|
||||||
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
|
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
context "golang.org/x/net/context"
|
context "golang.org/x/net/context"
|
||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
|
|
||||||
@ -267,20 +268,20 @@ func (cli *grpcClient) SetOptionSync(key string, value string) (log string, err
|
|||||||
return reqres.Response.GetSetOption().Log, nil
|
return reqres.Response.GetSetOption().Log, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
func (cli *grpcClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
|
||||||
reqres := cli.DeliverTxAsync(tx)
|
reqres := cli.DeliverTxAsync(tx)
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return &types.ResponseDeliverTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetDeliverTx()
|
return reqres.Response.GetDeliverTx(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
func (cli *grpcClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
|
||||||
reqres := cli.CheckTxAsync(tx)
|
reqres := cli.CheckTxAsync(tx)
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return &types.ResponseCheckTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetCheckTx()
|
return reqres.Response.GetCheckTx(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
@ -288,12 +289,12 @@ func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery,
|
|||||||
return reqres.Response.GetQuery(), cli.Error()
|
return reqres.Response.GetQuery(), cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) CommitSync() *types.ResponseCommit {
|
func (cli *grpcClient) CommitSync() (*types.ResponseCommit, error) {
|
||||||
reqres := cli.CommitAsync()
|
reqres := cli.CommitAsync()
|
||||||
if err := cli.Error(); err != nil {
|
if err := cli.Error(); err != nil {
|
||||||
return &types.ResponseCommit{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetCommit()
|
return reqres.Response.GetCommit(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) error {
|
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
|
@ -166,18 +166,18 @@ func (app *localClient) SetOptionSync(key string, value string) (log string, err
|
|||||||
return log, nil
|
return log, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
func (app *localClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.DeliverTx(tx)
|
res := app.Application.DeliverTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
func (app *localClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.CheckTx(tx)
|
res := app.Application.CheckTx(tx)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
@ -187,11 +187,11 @@ func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery,
|
|||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CommitSync() *types.ResponseCommit {
|
func (app *localClient) CommitSync() (*types.ResponseCommit, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Commit()
|
res := app.Application.Commit()
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) InitChainSync(params types.RequestInitChain) error {
|
func (app *localClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
|
@ -3,13 +3,13 @@ package abcicli
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"container/list"
|
"container/list"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
@ -303,22 +303,22 @@ func (cli *socketClient) SetOptionSync(key string, value string) (log string, er
|
|||||||
return reqres.Response.GetSetOption().Log, nil
|
return reqres.Response.GetSetOption().Log, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) DeliverTxSync(tx []byte) *types.ResponseDeliverTx {
|
func (cli *socketClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
|
||||||
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.ResponseDeliverTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetDeliverTx()
|
return reqres.Response.GetDeliverTx(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) CheckTxSync(tx []byte) *types.ResponseCheckTx {
|
func (cli *socketClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
|
||||||
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.ResponseCheckTx{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetCheckTx()
|
return reqres.Response.GetCheckTx(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
@ -327,13 +327,13 @@ func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery
|
|||||||
return reqres.Response.GetQuery(), cli.Error()
|
return reqres.Response.GetQuery(), cli.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) CommitSync() *types.ResponseCommit {
|
func (cli *socketClient) CommitSync() (*types.ResponseCommit, error) {
|
||||||
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.ResponseCommit{Code: types.CodeType_InternalError, Log: err.Error()}
|
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
|
||||||
}
|
}
|
||||||
return reqres.Response.GetCommit()
|
return reqres.Response.GetCommit(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) InitChainSync(params types.RequestInitChain) error {
|
func (cli *socketClient) InitChainSync(params types.RequestInitChain) error {
|
||||||
|
@ -371,7 +371,10 @@ func cmdDeliverTx(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
res := client.DeliverTxSync(txBytes)
|
res, err := client.DeliverTxSync(txBytes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Code: res.Code,
|
Code: res.Code,
|
||||||
Data: res.Data,
|
Data: res.Data,
|
||||||
@ -386,7 +389,10 @@ func cmdCheckTx(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
res := client.CheckTxSync(txBytes)
|
res, err := client.CheckTxSync(txBytes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Code: res.Code,
|
Code: res.Code,
|
||||||
Data: res.Data,
|
Data: res.Data,
|
||||||
@ -397,7 +403,10 @@ func cmdCheckTx(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
// Get application Merkle root hash
|
// Get application Merkle root hash
|
||||||
func cmdCommit(cmd *cobra.Command, args []string) error {
|
func cmdCommit(cmd *cobra.Command, args []string) error {
|
||||||
res := client.CommitSync()
|
res, err := client.CommitSync()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
printResponse(cmd, args, response{
|
printResponse(cmd, args, response{
|
||||||
Code: res.Code,
|
Code: res.Code,
|
||||||
Data: res.Data,
|
Data: res.Data,
|
||||||
|
@ -281,10 +281,12 @@ func runClientTests(t *testing.T, client abcicli.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string) {
|
func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string) {
|
||||||
ar := app.DeliverTxSync(tx)
|
ar, err := app.DeliverTxSync(tx)
|
||||||
|
require.NoError(t, err)
|
||||||
require.False(t, ar.IsErr(), ar)
|
require.False(t, ar.IsErr(), ar)
|
||||||
// repeating tx doesn't raise error
|
// repeating tx doesn't raise error
|
||||||
ar = app.DeliverTxSync(tx)
|
ar, err = app.DeliverTxSync(tx)
|
||||||
|
require.NoError(t, err)
|
||||||
require.False(t, ar.IsErr(), ar)
|
require.False(t, ar.IsErr(), ar)
|
||||||
|
|
||||||
// make sure query is fine
|
// make sure query is fine
|
||||||
|
@ -55,7 +55,10 @@ func setOption(client abcicli.Client, key, value string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func commit(client abcicli.Client, hashExp []byte) {
|
func commit(client abcicli.Client, hashExp []byte) {
|
||||||
res := client.CommitSync()
|
res, err := client.CommitSync()
|
||||||
|
if err != nil {
|
||||||
|
panicf("client error: %v", err)
|
||||||
|
}
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panicf("committing err %v\n", res)
|
panicf("committing err %v\n", res)
|
||||||
}
|
}
|
||||||
@ -65,7 +68,10 @@ func commit(client abcicli.Client, hashExp []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, err := client.DeliverTxSync(txBytes)
|
||||||
|
if err != nil {
|
||||||
|
panicf("client error: %v", err)
|
||||||
|
}
|
||||||
if res.Code != codeExp {
|
if res.Code != codeExp {
|
||||||
panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
|
panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
|
||||||
}
|
}
|
||||||
@ -75,7 +81,10 @@ func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, da
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*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, err := client.CheckTxSync(txBytes)
|
||||||
|
if err != nil {
|
||||||
|
panicf("client error: %v", err)
|
||||||
|
}
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
|
panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
|
||||||
}
|
}
|
||||||
|
@ -47,3 +47,12 @@ var (
|
|||||||
CodeType_BaseUnknownPubKey: "Error (base) unknown pubkey",
|
CodeType_BaseUnknownPubKey: "Error (base) unknown pubkey",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HumanCode transforms code into a more humane format, such as "Internal error" instead of 0.
|
||||||
|
func HumanCode(code CodeType) string {
|
||||||
|
s, ok := code2string[code]
|
||||||
|
if !ok {
|
||||||
|
return "Unknown code"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user