Browse Source

refactor code

pull/1780/head
Anton Kaliaev 7 years ago
parent
commit
0176a834d1
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 8 additions and 26 deletions
  1. +4
    -13
      client/grpc_client.go
  2. +4
    -13
      client/socket_client.go

+ 4
- 13
client/grpc_client.go View File

@ -104,7 +104,7 @@ func (cli *grpcClient) StopForError(err error) {
func (cli *grpcClient) Error() error {
cli.mtx.Lock()
defer cli.mtx.Unlock()
return cli.err
return errors.Wrap(cli.err, types.HumanCode(types.CodeType_InternalError))
}
// Set listener for all responses
@ -270,18 +270,12 @@ func (cli *grpcClient) SetOptionSync(key string, value string) (log string, err
func (cli *grpcClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
reqres := cli.DeliverTxAsync(tx)
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetDeliverTx(), nil
return reqres.Response.GetDeliverTx(), cli.Error()
}
func (cli *grpcClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
reqres := cli.CheckTxAsync(tx)
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetCheckTx(), nil
return reqres.Response.GetCheckTx(), cli.Error()
}
func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
@ -291,10 +285,7 @@ func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery,
func (cli *grpcClient) CommitSync() (*types.ResponseCommit, error) {
reqres := cli.CommitAsync()
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetCommit(), nil
return reqres.Response.GetCommit(), cli.Error()
}
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) error {


+ 4
- 13
client/socket_client.go View File

@ -116,7 +116,7 @@ func (cli *socketClient) StopForError(err error) {
func (cli *socketClient) Error() error {
cli.mtx.Lock()
defer cli.mtx.Unlock()
return cli.err
return errors.Wrap(cli.err, types.HumanCode(types.CodeType_InternalError))
}
// Set listener for all responses
@ -306,19 +306,13 @@ func (cli *socketClient) SetOptionSync(key string, value string) (log string, er
func (cli *socketClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
reqres := cli.queueRequest(types.ToRequestDeliverTx(tx))
cli.FlushSync()
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetDeliverTx(), nil
return reqres.Response.GetDeliverTx(), cli.Error()
}
func (cli *socketClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
reqres := cli.queueRequest(types.ToRequestCheckTx(tx))
cli.FlushSync()
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetCheckTx(), nil
return reqres.Response.GetCheckTx(), cli.Error()
}
func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
@ -330,10 +324,7 @@ func (cli *socketClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery
func (cli *socketClient) CommitSync() (*types.ResponseCommit, error) {
reqres := cli.queueRequest(types.ToRequestCommit())
cli.FlushSync()
if err := cli.Error(); err != nil {
return nil, errors.Wrap(err, types.HumanCode(types.CodeType_InternalError))
}
return reqres.Response.GetCommit(), nil
return reqres.Response.GetCommit(), cli.Error()
}
func (cli *socketClient) InitChainSync(params types.RequestInitChain) error {


Loading…
Cancel
Save