From c95d1401136e55ed6d14a5ddc77b12b5366534dd Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 22 Nov 2022 15:18:37 +0300 Subject: [PATCH] rpcclient: always return tx hash from sendrawtransaction Let upper-layer APIs like actor.Send() return it as well. Server can return "already exists" which is an error and yet at the same time a very special one, in many cases it means we can proceed with waiting for the TX to settle. --- pkg/rpcclient/rpc.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/rpcclient/rpc.go b/pkg/rpcclient/rpc.go index 112689bea..0e7147baa 100644 --- a/pkg/rpcclient/rpc.go +++ b/pkg/rpcclient/rpc.go @@ -692,17 +692,16 @@ func (c *Client) invokeSomething(method string, p []interface{}, signers []trans return resp, nil } -// SendRawTransaction broadcasts a transaction over the NEO network. -// The given hex string needs to be signed with a keypair. -// When the result of the response object is true, the TX has successfully -// been broadcasted to the network. +// SendRawTransaction broadcasts the given transaction to the Neo network. +// It always returns transaction hash, when successful (no error) this is the +// hash returned from server, when not it's a locally calculated rawTX hash. func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) { var ( params = []interface{}{rawTX.Bytes()} resp = new(result.RelayResult) ) if err := c.performRequest("sendrawtransaction", params, resp); err != nil { - return util.Uint256{}, err + return rawTX.Hash(), err } return resp.Hash, nil }