rpc/client: implement GetRawTransaction, fix #586

This commit is contained in:
Roman Khimov 2020-03-03 20:43:57 +03:00
parent f01766131b
commit a9d8c9e0d3
2 changed files with 38 additions and 14 deletions

View file

@ -21,6 +21,7 @@ Supported methods
getaccountstate
getblock
getclaimable
getrawtransaction
getunspents
invoke
invokefunction
@ -47,7 +48,6 @@ Unsupported methods
getnewaddress
getpeers
getrawmempool
getrawtransaction
getstorage
gettransactionheight
gettxout

View file

@ -93,6 +93,43 @@ func (c *Client) GetClaimable(address string) (*result.ClaimableInfo, error) {
return resp, nil
}
// GetRawTransaction returns a transaction by hash.
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
var (
params = request.NewRawParams(hash.StringLE())
resp string
err error
)
if err = c.performRequest("getrawtransaction", params, &resp); err != nil {
return nil, err
}
txBytes, err := hex.DecodeString(resp)
if err != nil {
return nil, err
}
r := io.NewBinReaderFromBuf(txBytes)
tx := new(transaction.Transaction)
tx.DecodeBinary(r)
if r.Err != nil {
return nil, r.Err
}
return tx, nil
}
// GetRawTransactionVerbose returns a transaction wrapper with additional
// metadata by transaction's hash.
func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) {
var (
params = request.NewRawParams(hash.StringLE(), 1)
resp = &result.TransactionOutputRaw{}
err error
)
if err = c.performRequest("getrawtransaction", params, &resp); err != nil {
return nil, err
}
return resp, nil
}
// GetUnspents returns UTXOs for the given NEO account.
func (c *Client) GetUnspents(address string) (*result.Unspents, error) {
var (
@ -145,19 +182,6 @@ func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*resul
return resp, nil
}
// getRawTransaction queries a transaction by hash.
// missing output wrapper at the moment, thus commented out
// func (c *Client) getRawTransaction(hash string, verbose bool) (*response, error) {
// var (
// params = request.NewRawParams(hash, verbose)
// resp = &response{}
// )
// if err := c.performRequest("getrawtransaction", params, resp); err != nil {
// return nil, err
// }
// 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