rpc: SendTransaction
returns error message for invalid tx on broadcast sync mode (#159)
* SendTransaction returns error message for invalid tx - use sync broadcast - treat error response to error return Closes: #158 * Apply suggestions from code review Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
04bacbdd1b
commit
6d5a59646a
@ -403,9 +403,13 @@ func (e *PublicEthAPI) SendTransaction(args rpctypes.SendTxArgs) (common.Hash, e
|
||||
|
||||
// Broadcast transaction in sync mode (default)
|
||||
// NOTE: If error is encountered on the node, the broadcast will not return an error
|
||||
asyncCtx := e.clientCtx.WithBroadcastMode(flags.BroadcastAsync)
|
||||
if _, err := asyncCtx.BroadcastTx(txBytes); err != nil {
|
||||
e.logger.WithError(err).Errorln("failed to broadcast Eth tx")
|
||||
syncCtx := e.clientCtx.WithBroadcastMode(flags.BroadcastSync)
|
||||
rsp, err := syncCtx.BroadcastTx(txBytes)
|
||||
if err != nil || rsp.Code != 0 {
|
||||
if err == nil {
|
||||
err = errors.New(rsp.RawLog)
|
||||
}
|
||||
e.logger.WithError(err).Errorln("failed to broadcast tx")
|
||||
return txHash, err
|
||||
}
|
||||
|
||||
@ -463,10 +467,13 @@ func (e *PublicEthAPI) SendRawTransaction(data hexutil.Bytes) (common.Hash, erro
|
||||
tmTx := tmtypes.Tx(txBytes)
|
||||
txHash := common.BytesToHash(tmTx.Hash())
|
||||
|
||||
asyncCtx := e.clientCtx.WithBroadcastMode(flags.BroadcastAsync)
|
||||
|
||||
if _, err := asyncCtx.BroadcastTx(txBytes); err != nil {
|
||||
e.logger.WithError(err).Errorln("failed to broadcast eth tx")
|
||||
syncCtx := e.clientCtx.WithBroadcastMode(flags.BroadcastSync)
|
||||
rsp, err := syncCtx.BroadcastTx(txBytes)
|
||||
if err != nil || rsp.Code != 0 {
|
||||
if err == nil {
|
||||
err = errors.New(rsp.RawLog)
|
||||
}
|
||||
e.logger.WithError(err).Errorln("failed to broadcast tx")
|
||||
return txHash, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user