2022-07-21 19:39:53 +00:00
|
|
|
package rpcclient
|
2018-03-05 08:53:09 +00:00
|
|
|
|
2018-12-21 09:32:18 +00:00
|
|
|
import (
|
2021-11-17 21:08:10 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/hex"
|
2022-06-15 18:23:29 +00:00
|
|
|
"encoding/json"
|
2020-08-06 14:44:08 +00:00
|
|
|
"errors"
|
2020-07-21 07:31:45 +00:00
|
|
|
"fmt"
|
2018-12-21 09:32:18 +00:00
|
|
|
|
2022-06-15 18:23:29 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2020-03-03 17:26:56 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
2020-06-09 09:12:56 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2020-09-21 12:34:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-12-01 08:40:58 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
2020-03-03 17:26:56 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2022-07-22 16:09:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
2021-02-08 10:43:11 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-11-10 11:30:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2022-06-15 18:23:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2018-12-21 09:32:18 +00:00
|
|
|
)
|
2018-03-25 16:21:00 +00:00
|
|
|
|
2020-10-14 15:13:20 +00:00
|
|
|
var errNetworkNotInitialized = errors.New("RPC client network is not initialized")
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// CalculateNetworkFee calculates network fee for the transaction. The transaction may
|
2021-03-24 17:32:48 +00:00
|
|
|
// have empty witnesses for contract signers and may have only verification scripts
|
|
|
|
// filled for standard sig/multisig signers.
|
|
|
|
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{tx.Bytes()}
|
2021-06-04 17:44:58 +00:00
|
|
|
resp = new(result.NetworkFee)
|
2021-03-24 17:32:48 +00:00
|
|
|
)
|
2021-06-04 17:44:58 +00:00
|
|
|
if err := c.performRequest("calculatenetworkfee", params, resp); err != nil {
|
2021-03-24 17:32:48 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
2021-06-04 17:44:58 +00:00
|
|
|
return resp.Value, nil
|
2021-03-24 17:32:48 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetApplicationLog returns a contract log based on the specified txid.
|
2020-11-10 11:30:00 +00:00
|
|
|
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) {
|
2020-03-11 14:14:05 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE()}
|
2020-11-11 15:43:28 +00:00
|
|
|
resp = new(result.ApplicationLog)
|
2020-03-11 14:14:05 +00:00
|
|
|
)
|
2020-11-10 11:30:00 +00:00
|
|
|
if trig != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, trig.String())
|
2020-11-10 11:30:00 +00:00
|
|
|
}
|
2020-03-11 14:14:05 +00:00
|
|
|
if err := c.performRequest("getapplicationlog", params, resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBestBlockHash returns the hash of the tallest block in the blockchain.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetBestBlockHash() (util.Uint256, error) {
|
|
|
|
var resp = util.Uint256{}
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getbestblockhash", nil, &resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBlockCount returns the number of blocks in the blockchain.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetBlockCount() (uint32, error) {
|
|
|
|
var resp uint32
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getblockcount", nil, &resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-09-07 16:09:53 +00:00
|
|
|
// GetBlockByIndex returns a block by its height. In-header stateroot option
|
|
|
|
// must be initialized with Init before calling this method.
|
2020-03-03 17:26:56 +00:00
|
|
|
func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getBlock(index)
|
2020-03-03 17:26:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 16:09:53 +00:00
|
|
|
// GetBlockByHash returns a block by its hash. In-header stateroot option
|
|
|
|
// must be initialized with Init before calling this method.
|
2020-03-03 17:26:56 +00:00
|
|
|
func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getBlock(hash.StringLE())
|
2020-03-03 17:26:56 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) getBlock(param any) (*block.Block, error) {
|
2020-03-03 17:26:56 +00:00
|
|
|
var (
|
2020-11-06 14:37:58 +00:00
|
|
|
resp []byte
|
2020-03-03 17:26:56 +00:00
|
|
|
err error
|
|
|
|
b *block.Block
|
|
|
|
)
|
2023-04-03 10:34:24 +00:00
|
|
|
if err = c.performRequest("getblock", []any{param}, &resp); err != nil {
|
2020-03-03 17:26:56 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-06 14:37:58 +00:00
|
|
|
r := io.NewBinReaderFromBuf(resp)
|
2023-10-09 19:34:33 +00:00
|
|
|
sr, err := c.stateRootInHeader()
|
2022-02-21 10:41:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
b = block.New(sr)
|
2020-03-03 17:26:56 +00:00
|
|
|
b.DecodeBinary(r)
|
|
|
|
if r.Err != nil {
|
|
|
|
return nil, r.Err
|
|
|
|
}
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBlockByIndexVerbose returns a block wrapper with additional metadata by
|
2022-09-07 16:09:53 +00:00
|
|
|
// its height. In-header stateroot option must be initialized with Init before
|
|
|
|
// calling this method.
|
2020-03-23 14:31:28 +00:00
|
|
|
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
2020-03-03 17:26:56 +00:00
|
|
|
func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getBlockVerbose(index)
|
2020-03-03 17:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBlockByHashVerbose returns a block wrapper with additional metadata by
|
2022-09-07 16:09:53 +00:00
|
|
|
// its hash. In-header stateroot option must be initialized with Init before
|
|
|
|
// calling this method.
|
2020-03-03 17:26:56 +00:00
|
|
|
func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getBlockVerbose(hash.StringLE())
|
2020-03-03 17:26:56 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) getBlockVerbose(param any) (*result.Block, error) {
|
2020-03-03 17:26:56 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{param, 1} // 1 for verbose.
|
2022-07-07 17:03:10 +00:00
|
|
|
resp = &result.Block{}
|
|
|
|
err error
|
2020-03-03 17:26:56 +00:00
|
|
|
)
|
2023-10-09 19:34:33 +00:00
|
|
|
sr, err := c.stateRootInHeader()
|
2022-02-21 10:41:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-10-14 15:13:20 +00:00
|
|
|
}
|
2022-02-21 10:41:14 +00:00
|
|
|
resp.Header.StateRootEnabled = sr
|
2020-03-24 17:11:49 +00:00
|
|
|
if err = c.performRequest("getblock", params, resp); err != nil {
|
2020-03-03 17:26:56 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBlockHash returns the hash value of the corresponding block based on the specified index.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{index}
|
2020-03-11 14:14:05 +00:00
|
|
|
resp = util.Uint256{}
|
|
|
|
)
|
|
|
|
if err := c.performRequest("getblockhash", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBlockHeader returns the corresponding block header information from a serialized hex string
|
2022-09-07 16:09:53 +00:00
|
|
|
// according to the specified script hash. In-header stateroot option must be
|
|
|
|
// initialized with Init before calling this method.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE()}
|
2020-11-06 14:37:58 +00:00
|
|
|
resp []byte
|
2020-03-11 14:14:05 +00:00
|
|
|
h *block.Header
|
|
|
|
)
|
|
|
|
if err := c.performRequest("getblockheader", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-10-09 19:34:33 +00:00
|
|
|
sr, err := c.stateRootInHeader()
|
2022-02-21 10:41:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-06 14:37:58 +00:00
|
|
|
r := io.NewBinReaderFromBuf(resp)
|
2020-03-11 14:14:05 +00:00
|
|
|
h = new(block.Header)
|
2022-02-21 10:41:14 +00:00
|
|
|
h.StateRootEnabled = sr
|
2020-03-11 14:14:05 +00:00
|
|
|
h.DecodeBinary(r)
|
|
|
|
if r.Err != nil {
|
|
|
|
return nil, r.Err
|
|
|
|
}
|
|
|
|
return h, nil
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:01:22 +00:00
|
|
|
// GetBlockHeaderCount returns the number of headers in the main chain.
|
|
|
|
func (c *Client) GetBlockHeaderCount() (uint32, error) {
|
|
|
|
var resp uint32
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getblockheadercount", nil, &resp); err != nil {
|
2021-02-07 19:01:22 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBlockHeaderVerbose returns the corresponding block header information from a Json format string
|
2022-09-07 16:09:53 +00:00
|
|
|
// according to the specified script hash. In-header stateroot option must be
|
|
|
|
// initialized with Init before calling this method.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE(), 1}
|
2020-03-11 14:14:05 +00:00
|
|
|
resp = &result.Header{}
|
|
|
|
)
|
2020-03-24 17:11:49 +00:00
|
|
|
if err := c.performRequest("getblockheader", params, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBlockSysFee returns the system fees of the block based on the specified index.
|
2022-09-07 16:59:33 +00:00
|
|
|
// This method is only supported by NeoGo servers.
|
2020-12-01 08:40:58 +00:00
|
|
|
func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) {
|
2020-03-11 14:14:05 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{index}
|
2020-12-01 08:40:58 +00:00
|
|
|
resp fixedn.Fixed8
|
2020-03-11 14:14:05 +00:00
|
|
|
)
|
|
|
|
if err := c.performRequest("getblocksysfee", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetConnectionCount returns the current number of the connections for the node.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetConnectionCount() (int, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp int
|
|
|
|
|
|
|
|
if err := c.performRequest("getconnectioncount", nil, &resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetCommittee returns the current public keys of NEO nodes in the committee.
|
2020-09-21 12:34:04 +00:00
|
|
|
func (c *Client) GetCommittee() (keys.PublicKeys, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = new(keys.PublicKeys)
|
|
|
|
|
|
|
|
if err := c.performRequest("getcommittee", nil, resp); err != nil {
|
2020-09-21 12:34:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return *resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetContractStateByHash queries contract information according to the contract script hash.
|
2020-09-25 16:32:53 +00:00
|
|
|
func (c *Client) GetContractStateByHash(hash util.Uint160) (*state.Contract, error) {
|
|
|
|
return c.getContractState(hash.StringLE())
|
|
|
|
}
|
|
|
|
|
2022-09-07 16:59:33 +00:00
|
|
|
// GetContractStateByAddressOrName queries contract information using the contract
|
|
|
|
// address or name. Notice that name-based queries work only for native contracts,
|
|
|
|
// non-native ones can't be requested this way.
|
2020-09-25 16:32:53 +00:00
|
|
|
func (c *Client) GetContractStateByAddressOrName(addressOrName string) (*state.Contract, error) {
|
|
|
|
return c.getContractState(addressOrName)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetContractStateByID queries contract information according to the contract ID.
|
2022-09-07 16:59:33 +00:00
|
|
|
// Notice that this is supported by all servers only for native contracts,
|
|
|
|
// non-native ones can be requested only from NeoGo servers.
|
2020-09-25 16:32:53 +00:00
|
|
|
func (c *Client) GetContractStateByID(id int32) (*state.Contract, error) {
|
|
|
|
return c.getContractState(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// getContractState is an internal representation of GetContractStateBy* methods.
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) getContractState(param any) (*state.Contract, error) {
|
2020-03-11 14:14:05 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{param}
|
2020-06-09 09:12:56 +00:00
|
|
|
resp = &state.Contract{}
|
2020-03-11 14:14:05 +00:00
|
|
|
)
|
|
|
|
if err := c.performRequest("getcontractstate", params, resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-02-11 09:37:03 +00:00
|
|
|
// GetNativeContracts queries information about native contracts.
|
2024-05-16 15:46:00 +00:00
|
|
|
func (c *Client) GetNativeContracts() ([]state.Contract, error) {
|
|
|
|
var resp []state.Contract
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getnativecontracts", nil, &resp); err != nil {
|
2021-02-11 09:37:03 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
2022-02-22 12:39:42 +00:00
|
|
|
|
|
|
|
// Update native contract hashes.
|
|
|
|
c.cacheLock.Lock()
|
|
|
|
for _, cs := range resp {
|
|
|
|
c.cache.nativeHashes[cs.Manifest.Name] = cs.Hash
|
|
|
|
}
|
|
|
|
c.cacheLock.Unlock()
|
|
|
|
|
2021-02-11 09:37:03 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-11-17 21:08:10 +00:00
|
|
|
// GetNEP11Balances is a wrapper for getnep11balances RPC.
|
|
|
|
func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
params := []any{address.StringLE()}
|
2021-11-17 21:08:10 +00:00
|
|
|
resp := new(result.NEP11Balances)
|
|
|
|
if err := c.performRequest("getnep11balances", params, resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-24 08:14:25 +00:00
|
|
|
// GetNEP17Balances is a wrapper for getnep17balances RPC.
|
|
|
|
func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
params := []any{address.StringLE()}
|
2020-11-24 08:14:25 +00:00
|
|
|
resp := new(result.NEP17Balances)
|
|
|
|
if err := c.performRequest("getnep17balances", params, resp); err != nil {
|
2020-03-05 11:50:06 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-11-17 21:08:10 +00:00
|
|
|
// GetNEP11Properties is a wrapper for getnep11properties RPC. We recommend using
|
2022-08-19 07:37:22 +00:00
|
|
|
// nep11 package and Properties method there to receive proper VM types and work with them.
|
2022-04-20 18:30:09 +00:00
|
|
|
// This method is provided mostly for the sake of completeness. For well-known
|
2021-11-17 21:08:10 +00:00
|
|
|
// attributes like "description", "image", "name" and "tokenURI" it returns strings,
|
2022-04-20 18:30:09 +00:00
|
|
|
// while for all others []byte (which can be nil).
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]any, error) {
|
|
|
|
params := []any{asset.StringLE(), hex.EncodeToString(token)}
|
|
|
|
resp := make(map[string]any)
|
2021-11-17 21:08:10 +00:00
|
|
|
if err := c.performRequest("getnep11properties", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for k, v := range resp {
|
|
|
|
if v == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
str, ok := v.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("value is not a string")
|
|
|
|
}
|
|
|
|
if result.KnownNEP11Properties[k] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
val, err := base64.StdEncoding.DecodeString(str)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp[k] = val
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter
|
2024-11-07 15:02:04 +00:00
|
|
|
// is mandatory, while all others are optional. start and stop parameters are
|
|
|
|
// timestamps in milliseconds (just like block timestamps are). limit and page
|
|
|
|
// parameters are only supported by NeoGo servers and can only be specified
|
|
|
|
// with start and stop (since they're positional in the protocol).
|
2021-11-18 14:00:48 +00:00
|
|
|
func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error) {
|
2021-11-17 21:08:10 +00:00
|
|
|
params, err := packTransfersParams(address, start, stop, limit, page)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp := new(result.NEP11Transfers)
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getnep11transfers", params, resp); err != nil {
|
2021-11-17 21:08:10 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) ([]any, error) {
|
|
|
|
params := []any{address.StringLE()}
|
2020-09-14 19:12:49 +00:00
|
|
|
if start != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, *start)
|
2020-09-14 19:12:49 +00:00
|
|
|
if stop != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, *stop)
|
2020-09-14 19:12:49 +00:00
|
|
|
if limit != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, *limit)
|
2020-09-14 19:12:49 +00:00
|
|
|
if page != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, *page)
|
2020-09-14 19:12:49 +00:00
|
|
|
}
|
|
|
|
} else if page != nil {
|
|
|
|
return nil, errors.New("bad parameters")
|
|
|
|
}
|
|
|
|
} else if limit != nil || page != nil {
|
|
|
|
return nil, errors.New("bad parameters")
|
|
|
|
}
|
|
|
|
} else if stop != nil || limit != nil || page != nil {
|
|
|
|
return nil, errors.New("bad parameters")
|
|
|
|
}
|
2022-07-07 17:03:10 +00:00
|
|
|
return params, nil
|
2021-11-17 21:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetNEP17Transfers is a wrapper for getnep17transfers RPC. Address parameter
|
2024-11-07 15:02:04 +00:00
|
|
|
// is mandatory while all the others are optional. start and stop parameters
|
|
|
|
// are timestamps in milliseconds (just like block timestamps are). limit and page
|
|
|
|
// parameters are only supported by NeoGo servers and can only be specified
|
|
|
|
// with start and stop (since they're positional in the protocol).
|
2021-11-18 14:00:48 +00:00
|
|
|
func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error) {
|
2021-11-17 21:08:10 +00:00
|
|
|
params, err := packTransfersParams(address, start, stop, limit, page)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-24 08:14:25 +00:00
|
|
|
resp := new(result.NEP17Transfers)
|
2022-07-07 17:03:10 +00:00
|
|
|
if err := c.performRequest("getnep17transfers", params, resp); err != nil {
|
2020-03-05 12:16:03 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetPeers returns a list of the nodes that the node is currently connected to/disconnected from.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetPeers() (*result.GetPeers, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = &result.GetPeers{}
|
|
|
|
|
|
|
|
if err := c.performRequest("getpeers", nil, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetRawMemPool returns a list of unconfirmed transactions in the memory.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = new([]util.Uint256)
|
|
|
|
|
|
|
|
if err := c.performRequest("getrawmempool", nil, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return *resp, err
|
|
|
|
}
|
|
|
|
return *resp, nil
|
|
|
|
}
|
|
|
|
|
2022-02-21 10:41:14 +00:00
|
|
|
// GetRawTransaction returns a transaction by hash.
|
2020-03-03 17:43:57 +00:00
|
|
|
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE()}
|
2020-11-06 14:37:58 +00:00
|
|
|
resp []byte
|
2020-03-03 17:43:57 +00:00
|
|
|
err error
|
|
|
|
)
|
|
|
|
if err = c.performRequest("getrawtransaction", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-03-25 16:18:01 +00:00
|
|
|
tx, err := transaction.NewTransactionFromBytes(resp)
|
2020-04-13 09:02:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-03-03 17:43:57 +00:00
|
|
|
}
|
|
|
|
return tx, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawTransactionVerbose returns a transaction wrapper with additional
|
2022-02-21 10:41:14 +00:00
|
|
|
// metadata by transaction's hash.
|
2020-03-23 14:31:28 +00:00
|
|
|
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
2020-03-03 17:43:57 +00:00
|
|
|
func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE(), 1} // 1 for verbose.
|
2020-03-03 17:43:57 +00:00
|
|
|
resp = &result.TransactionOutputRaw{}
|
|
|
|
err error
|
|
|
|
)
|
2020-03-24 17:11:49 +00:00
|
|
|
if err = c.performRequest("getrawtransaction", params, resp); err != nil {
|
2020-03-03 17:43:57 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-03-23 09:03:22 +00:00
|
|
|
// GetProof returns existence proof of storage item state by the given stateroot
|
|
|
|
// historical contract hash and historical item key.
|
|
|
|
func (c *Client) GetProof(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) (*result.ProofWithKey, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey}
|
2023-03-23 09:03:22 +00:00
|
|
|
resp = &result.ProofWithKey{}
|
|
|
|
)
|
|
|
|
if err := c.performRequest("getproof", params, resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyProof returns value by the given stateroot and proof.
|
|
|
|
func (c *Client) VerifyProof(stateroot util.Uint256, proof *result.ProofWithKey) ([]byte, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{stateroot.StringLE(), proof.String()}
|
2023-03-23 09:03:22 +00:00
|
|
|
resp []byte
|
|
|
|
)
|
|
|
|
if err := c.performRequest("verifyproof", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-10-07 09:03:37 +00:00
|
|
|
// GetState returns historical contract storage item state by the given stateroot,
|
|
|
|
// historical contract hash and historical item key.
|
|
|
|
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey}
|
2021-10-07 09:03:37 +00:00
|
|
|
resp []byte
|
|
|
|
)
|
|
|
|
if err := c.performRequest("getstate", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-10-07 13:56:27 +00:00
|
|
|
// FindStates returns historical contract storage item states by the given stateroot,
|
2022-04-20 18:30:09 +00:00
|
|
|
// historical contract hash and historical prefix. If `start` path is specified, items
|
2021-10-07 13:56:27 +00:00
|
|
|
// starting from `start` path are being returned (excluding item located at the start path).
|
2022-04-20 18:30:09 +00:00
|
|
|
// If `maxCount` specified, the maximum number of items to be returned equals to `maxCount`.
|
2021-10-07 13:56:27 +00:00
|
|
|
func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, historicalPrefix []byte,
|
|
|
|
start []byte, maxCount *int) (result.FindStates, error) {
|
2022-01-18 11:56:17 +00:00
|
|
|
if historicalPrefix == nil {
|
|
|
|
historicalPrefix = []byte{}
|
|
|
|
}
|
2021-10-07 13:56:27 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix}
|
2021-10-07 13:56:27 +00:00
|
|
|
resp result.FindStates
|
|
|
|
)
|
2022-01-18 11:56:17 +00:00
|
|
|
if start == nil && maxCount != nil {
|
|
|
|
start = []byte{}
|
|
|
|
}
|
|
|
|
if start != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, start)
|
2022-01-18 11:56:17 +00:00
|
|
|
}
|
2021-10-07 13:56:27 +00:00
|
|
|
if maxCount != nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
params = append(params, *maxCount)
|
2021-10-07 13:56:27 +00:00
|
|
|
}
|
|
|
|
if err := c.performRequest("findstates", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStateRootByHeight returns the state root for the specified height.
|
2022-01-17 08:59:13 +00:00
|
|
|
func (c *Client) GetStateRootByHeight(height uint32) (*state.MPTRoot, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getStateRoot(height)
|
2022-01-17 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStateRootByBlockHash returns the state root for the block with the specified hash.
|
2022-01-17 08:59:13 +00:00
|
|
|
func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
return c.getStateRoot(hash)
|
2022-01-17 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) getStateRoot(param any) (*state.MPTRoot, error) {
|
2022-01-17 08:59:13 +00:00
|
|
|
var resp = new(state.MPTRoot)
|
2023-04-03 10:34:24 +00:00
|
|
|
if err := c.performRequest("getstateroot", []any{param}, resp); err != nil {
|
2022-01-17 08:59:13 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStateHeight returns the current validated and local node state height.
|
2021-07-22 17:02:59 +00:00
|
|
|
func (c *Client) GetStateHeight() (*result.StateHeight, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = new(result.StateHeight)
|
|
|
|
|
|
|
|
if err := c.performRequest("getstateheight", nil, resp); err != nil {
|
2021-07-22 17:02:59 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStorageByID returns the stored value according to the contract ID and the stored key.
|
2020-06-23 14:27:23 +00:00
|
|
|
func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
return c.getStorage([]any{id, key})
|
2020-06-23 14:27:23 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStorageByHash returns the stored value according to the contract script hash and the stored key.
|
2020-06-23 14:27:23 +00:00
|
|
|
func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
return c.getStorage([]any{hash.StringLE(), key})
|
2020-06-23 14:27:23 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) getStorage(params []any) ([]byte, error) {
|
2021-02-07 15:27:19 +00:00
|
|
|
var resp []byte
|
2020-03-11 14:14:05 +00:00
|
|
|
if err := c.performRequest("getstorage", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-07 15:27:19 +00:00
|
|
|
return resp, nil
|
2020-03-11 14:14:05 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 16:29:22 +00:00
|
|
|
// GetStorageByIDHistoric returns the historical stored value according to the
|
|
|
|
// contract ID and, stored key and specified stateroot.
|
|
|
|
func (c *Client) GetStorageByIDHistoric(root util.Uint256, id int32, key []byte) ([]byte, error) {
|
|
|
|
return c.getStorageHistoric([]any{root.StringLE(), id, key})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStorageByHashHistoric returns the historical stored value according to the
|
|
|
|
// contract script hash, the stored key and specified stateroot.
|
|
|
|
func (c *Client) GetStorageByHashHistoric(root util.Uint256, hash util.Uint160, key []byte) ([]byte, error) {
|
|
|
|
return c.getStorageHistoric([]any{root.StringLE(), hash.StringLE(), key})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) getStorageHistoric(params []any) ([]byte, error) {
|
|
|
|
var resp []byte
|
|
|
|
if err := c.performRequest("getstoragehistoric", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-08-22 16:00:43 +00:00
|
|
|
// FindStorageByHash returns contract storage items by the given contract hash and prefix.
|
|
|
|
// If `start` index is specified, items starting from `start` index are being returned
|
|
|
|
// (including item located at the start index).
|
|
|
|
func (c *Client) FindStorageByHash(contractHash util.Uint160, prefix []byte, start *int) (result.FindStorage, error) {
|
|
|
|
var params = []any{contractHash.StringLE(), prefix}
|
|
|
|
if start != nil {
|
|
|
|
params = append(params, *start)
|
2023-10-18 17:12:05 +00:00
|
|
|
} else {
|
|
|
|
// C# node expects `start` parameter in any case.
|
|
|
|
params = append(params, 0)
|
2023-08-22 16:00:43 +00:00
|
|
|
}
|
|
|
|
return c.findStorage(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindStorageByID returns contract storage items by the given contract ID and prefix.
|
|
|
|
// If `start` index is specified, items starting from `start` index are being returned
|
|
|
|
// (including item located at the start index).
|
|
|
|
func (c *Client) FindStorageByID(contractID int32, prefix []byte, start *int) (result.FindStorage, error) {
|
|
|
|
var params = []any{contractID, prefix}
|
|
|
|
if start != nil {
|
|
|
|
params = append(params, *start)
|
2023-10-18 17:12:05 +00:00
|
|
|
} else {
|
|
|
|
// C# node expects `start` parameter in any case.
|
|
|
|
params = append(params, 0)
|
2023-08-22 16:00:43 +00:00
|
|
|
}
|
|
|
|
return c.findStorage(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) findStorage(params []any) (result.FindStorage, error) {
|
|
|
|
var resp result.FindStorage
|
|
|
|
if err := c.performRequest("findstorage", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindStorageByHashHistoric returns historical contract storage items by the given stateroot,
|
|
|
|
// historical contract hash and historical prefix. If `start` index is specified, then items
|
|
|
|
// starting from `start` index are being returned (including item located at the start index).
|
|
|
|
func (c *Client) FindStorageByHashHistoric(stateroot util.Uint256, historicalContractHash util.Uint160, historicalPrefix []byte,
|
|
|
|
start *int) (result.FindStorage, error) {
|
|
|
|
if historicalPrefix == nil {
|
|
|
|
historicalPrefix = []byte{}
|
|
|
|
}
|
|
|
|
var params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix}
|
|
|
|
if start != nil {
|
|
|
|
params = append(params, start)
|
|
|
|
}
|
|
|
|
return c.findStorageHistoric(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindStorageByIDHistoric returns historical contract storage items by the given stateroot,
|
|
|
|
// historical contract ID and historical prefix. If `start` index is specified, then items
|
|
|
|
// starting from `start` index are being returned (including item located at the start index).
|
|
|
|
func (c *Client) FindStorageByIDHistoric(stateroot util.Uint256, historicalContractID int32, historicalPrefix []byte,
|
|
|
|
start *int) (result.FindStorage, error) {
|
|
|
|
if historicalPrefix == nil {
|
|
|
|
historicalPrefix = []byte{}
|
|
|
|
}
|
|
|
|
var params = []any{stateroot.StringLE(), historicalContractID, historicalPrefix}
|
|
|
|
if start != nil {
|
|
|
|
params = append(params, start)
|
|
|
|
}
|
|
|
|
return c.findStorageHistoric(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) findStorageHistoric(params []any) (result.FindStorage, error) {
|
|
|
|
var resp result.FindStorage
|
|
|
|
if err := c.performRequest("findstoragehistoric", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetTransactionHeight returns the block index where the transaction is found.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{hash.StringLE()}
|
2020-03-11 14:14:05 +00:00
|
|
|
resp uint32
|
|
|
|
)
|
|
|
|
if err := c.performRequest("gettransactionheight", params, &resp); err != nil {
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetUnclaimedGas returns the unclaimed GAS amount for the specified address.
|
2020-07-09 14:25:26 +00:00
|
|
|
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
|
2020-03-11 14:14:05 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{address}
|
2020-07-09 14:25:26 +00:00
|
|
|
resp result.UnclaimedGas
|
2020-03-11 14:14:05 +00:00
|
|
|
)
|
2020-06-01 20:27:03 +00:00
|
|
|
if err := c.performRequest("getunclaimedgas", params, &resp); err != nil {
|
2020-07-09 14:25:26 +00:00
|
|
|
return resp, err
|
2020-06-01 20:27:03 +00:00
|
|
|
}
|
2020-07-09 14:25:26 +00:00
|
|
|
return resp, nil
|
2020-03-11 14:14:05 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 13:02:03 +00:00
|
|
|
// GetCandidates returns the current list of NEO candidate node with voting data and
|
|
|
|
// validator status.
|
|
|
|
func (c *Client) GetCandidates() ([]result.Candidate, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = new([]result.Candidate)
|
|
|
|
|
|
|
|
if err := c.performRequest("getcandidates", nil, resp); err != nil {
|
2022-07-01 13:02:03 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return *resp, nil
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:34:43 +00:00
|
|
|
// GetNextBlockValidators returns the current NEO consensus nodes information and voting data.
|
2020-10-01 12:26:54 +00:00
|
|
|
func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = new([]result.Validator)
|
|
|
|
|
|
|
|
if err := c.performRequest("getnextblockvalidators", nil, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return *resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetVersion returns the version information about the queried node.
|
|
|
|
func (c *Client) GetVersion() (*result.Version, error) {
|
2022-07-07 17:03:10 +00:00
|
|
|
var resp = &result.Version{}
|
|
|
|
|
|
|
|
if err := c.performRequest("getversion", nil, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// InvokeScript returns the result of the given script after running it true the VM.
|
|
|
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
2020-07-29 16:57:38 +00:00
|
|
|
func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{script}
|
2020-07-29 16:57:38 +00:00
|
|
|
return c.invokeSomething("invokescript", p, signers)
|
2018-03-05 08:53:09 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 15:13:08 +00:00
|
|
|
// InvokeScriptAtHeight returns the result of the given script after running it
|
|
|
|
// true the VM using the provided chain state retrieved from the specified chain
|
|
|
|
// height.
|
|
|
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
|
|
|
func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{height, script}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokescripthistoric", p, signers)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InvokeScriptWithState returns the result of the given script after running it
|
|
|
|
// true the VM using the provided chain state retrieved from the specified
|
2022-09-09 10:41:45 +00:00
|
|
|
// state root or block hash.
|
2022-04-07 15:13:08 +00:00
|
|
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
2022-09-09 10:41:45 +00:00
|
|
|
func (c *Client) InvokeScriptWithState(stateOrBlock util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{stateOrBlock.StringLE(), script}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokescripthistoric", p, signers)
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// InvokeFunction returns the results after calling the smart contract scripthash
|
2018-03-25 16:21:00 +00:00
|
|
|
// with the given operation and parameters.
|
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
2020-07-29 16:57:38 +00:00
|
|
|
func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{contract.StringLE(), operation, params}
|
2020-07-29 16:57:38 +00:00
|
|
|
return c.invokeSomething("invokefunction", p, signers)
|
2020-07-02 12:53:39 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 15:13:08 +00:00
|
|
|
// InvokeFunctionAtHeight returns the results after calling the smart contract
|
|
|
|
// with the given operation and parameters at the given blockchain state
|
|
|
|
// specified by the blockchain height.
|
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
|
|
|
func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{height, contract.StringLE(), operation, params}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InvokeFunctionWithState returns the results after calling the smart contract
|
|
|
|
// with the given operation and parameters at the given blockchain state defined
|
2022-09-09 10:41:45 +00:00
|
|
|
// by the specified state root or block hash.
|
2022-04-07 15:13:08 +00:00
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
2022-09-09 10:41:45 +00:00
|
|
|
func (c *Client) InvokeFunctionWithState(stateOrBlock util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{stateOrBlock.StringLE(), contract.StringLE(), operation, params}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:23:39 +00:00
|
|
|
// InvokeContractVerify returns the results after calling `verify` method of the smart contract
|
|
|
|
// with the given parameters under verification trigger type.
|
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
|
|
|
func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{contract.StringLE(), params}
|
2020-12-14 12:23:39 +00:00
|
|
|
return c.invokeSomething("invokecontractverify", p, signers, witnesses...)
|
|
|
|
}
|
|
|
|
|
2022-04-07 15:13:08 +00:00
|
|
|
// InvokeContractVerifyAtHeight returns the results after calling `verify` method
|
|
|
|
// of the smart contract with the given parameters under verification trigger type
|
|
|
|
// at the blockchain state specified by the blockchain height.
|
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
|
|
|
func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{height, contract.StringLE(), params}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InvokeContractVerifyWithState returns the results after calling `verify` method
|
|
|
|
// of the smart contract with the given parameters under verification trigger type
|
2022-09-09 10:41:45 +00:00
|
|
|
// at the blockchain state specified by the state root or block hash.
|
2022-04-07 15:13:08 +00:00
|
|
|
// NOTE: this is test invoke and will not affect the blockchain.
|
2022-09-09 10:41:45 +00:00
|
|
|
func (c *Client) InvokeContractVerifyWithState(stateOrBlock util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
2023-04-03 10:34:24 +00:00
|
|
|
var p = []any{stateOrBlock.StringLE(), contract.StringLE(), params}
|
2022-04-07 15:13:08 +00:00
|
|
|
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
|
|
|
}
|
|
|
|
|
2021-05-12 20:17:03 +00:00
|
|
|
// invokeSomething is an inner wrapper for Invoke* functions.
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) invokeSomething(method string, p []any, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
2020-07-02 12:53:39 +00:00
|
|
|
var resp = new(result.Invoke)
|
2020-07-29 16:57:38 +00:00
|
|
|
if signers != nil {
|
2020-12-14 12:23:39 +00:00
|
|
|
if witnesses == nil {
|
2022-07-07 17:03:10 +00:00
|
|
|
p = append(p, signers)
|
2020-12-14 12:23:39 +00:00
|
|
|
} else {
|
|
|
|
if len(witnesses) != len(signers) {
|
|
|
|
return nil, fmt.Errorf("number of witnesses should match number of signers, got %d vs %d", len(witnesses), len(signers))
|
|
|
|
}
|
2022-07-22 16:09:29 +00:00
|
|
|
signersWithWitnesses := make([]neorpc.SignerWithWitness, len(signers))
|
2020-12-14 12:23:39 +00:00
|
|
|
for i := range signersWithWitnesses {
|
2022-07-22 16:09:29 +00:00
|
|
|
signersWithWitnesses[i] = neorpc.SignerWithWitness{
|
2020-12-14 12:23:39 +00:00
|
|
|
Signer: signers[i],
|
|
|
|
Witness: witnesses[i],
|
|
|
|
}
|
|
|
|
}
|
2022-07-07 17:03:10 +00:00
|
|
|
p = append(p, signersWithWitnesses)
|
2020-12-14 12:23:39 +00:00
|
|
|
}
|
2018-03-25 16:21:00 +00:00
|
|
|
}
|
2020-07-02 12:53:39 +00:00
|
|
|
if err := c.performRequest(method, p, resp); err != nil {
|
2018-11-26 15:57:53 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:18:37 +00:00
|
|
|
// 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.
|
2020-07-21 07:31:45 +00:00
|
|
|
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) {
|
2018-03-05 08:53:09 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{rawTX.Bytes()}
|
2020-07-21 07:31:45 +00:00
|
|
|
resp = new(result.RelayResult)
|
2018-03-05 08:53:09 +00:00
|
|
|
)
|
2020-07-21 07:31:45 +00:00
|
|
|
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
2022-11-22 12:18:37 +00:00
|
|
|
return rawTX.Hash(), err
|
2020-02-20 18:08:22 +00:00
|
|
|
}
|
2020-07-21 07:31:45 +00:00
|
|
|
return resp.Hash, nil
|
2018-03-05 08:53:09 +00:00
|
|
|
}
|
2018-12-21 09:32:18 +00:00
|
|
|
|
2020-03-11 14:14:05 +00:00
|
|
|
// SubmitBlock broadcasts a raw block over the NEO network.
|
2020-07-21 07:41:18 +00:00
|
|
|
func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
|
2020-03-11 14:14:05 +00:00
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params []any
|
2020-07-21 07:41:18 +00:00
|
|
|
resp = new(result.RelayResult)
|
2020-03-11 14:14:05 +00:00
|
|
|
)
|
|
|
|
buf := io.NewBufBinWriter()
|
|
|
|
b.EncodeBinary(buf.BinWriter)
|
|
|
|
if err := buf.Err; err != nil {
|
2020-07-21 07:41:18 +00:00
|
|
|
return util.Uint256{}, err
|
2020-03-11 14:14:05 +00:00
|
|
|
}
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{buf.Bytes()}
|
2020-03-11 14:14:05 +00:00
|
|
|
|
2020-07-21 07:41:18 +00:00
|
|
|
if err := c.performRequest("submitblock", params, resp); err != nil {
|
|
|
|
return util.Uint256{}, err
|
2020-03-11 14:14:05 +00:00
|
|
|
}
|
2020-07-21 07:41:18 +00:00
|
|
|
return resp.Hash, nil
|
2020-03-11 14:14:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SubmitRawOracleResponse submits a raw oracle response to the oracle node.
|
2020-09-28 11:58:04 +00:00
|
|
|
// Raw params are used to avoid excessive marshalling.
|
2023-04-03 10:34:24 +00:00
|
|
|
func (c *Client) SubmitRawOracleResponse(ps []any) error {
|
2020-09-28 11:58:04 +00:00
|
|
|
return c.performRequest("submitoracleresponse", ps, new(result.RelayResult))
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:43:11 +00:00
|
|
|
// SubmitP2PNotaryRequest submits given P2PNotaryRequest payload to the RPC node.
|
2023-11-28 17:23:33 +00:00
|
|
|
// It returns fallback transaction hash.
|
2021-02-08 10:43:11 +00:00
|
|
|
func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uint256, error) {
|
|
|
|
var resp = new(result.RelayResult)
|
|
|
|
bytes, err := req.Bytes()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint256{}, fmt.Errorf("failed to encode request: %w", err)
|
|
|
|
}
|
2023-04-03 10:34:24 +00:00
|
|
|
params := []any{bytes}
|
2021-02-08 10:43:11 +00:00
|
|
|
if err := c.performRequest("submitnotaryrequest", params, resp); err != nil {
|
|
|
|
return util.Uint256{}, err
|
|
|
|
}
|
|
|
|
return resp.Hash, nil
|
|
|
|
}
|
|
|
|
|
2020-03-11 14:14:05 +00:00
|
|
|
// ValidateAddress verifies that the address is a correct NEO address.
|
2022-09-07 16:59:33 +00:00
|
|
|
// Consider using [address] package instead to do it locally.
|
2020-03-11 14:14:05 +00:00
|
|
|
func (c *Client) ValidateAddress(address string) error {
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{address}
|
2020-03-11 14:14:05 +00:00
|
|
|
resp = &result.ValidateAddress{}
|
|
|
|
)
|
|
|
|
|
2020-03-24 17:11:49 +00:00
|
|
|
if err := c.performRequest("validateaddress", params, resp); err != nil {
|
2020-03-11 14:14:05 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !resp.IsValid {
|
|
|
|
return errors.New("validateaddress returned false")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-15 06:50:13 +00:00
|
|
|
|
2023-10-09 19:34:33 +00:00
|
|
|
// stateRootInHeader returns true if the state root is contained in the block header.
|
|
|
|
// Requires Init() before use.
|
|
|
|
func (c *Client) stateRootInHeader() (bool, error) {
|
2022-02-21 13:06:43 +00:00
|
|
|
c.cacheLock.RLock()
|
|
|
|
defer c.cacheLock.RUnlock()
|
|
|
|
|
2022-02-21 10:41:14 +00:00
|
|
|
if !c.cache.initDone {
|
|
|
|
return false, errNetworkNotInitialized
|
|
|
|
}
|
|
|
|
return c.cache.stateRootInHeader, nil
|
2020-11-17 12:57:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 18:23:29 +00:00
|
|
|
// TraverseIterator returns a set of iterator values (maxItemsCount at max) for
|
|
|
|
// the specified iterator and session. If result contains no elements, then either
|
|
|
|
// Iterator has no elements or session was expired and terminated by the server.
|
2022-07-06 14:08:53 +00:00
|
|
|
// If maxItemsCount is non-positive, then config.DefaultMaxIteratorResultItems
|
|
|
|
// iterator values will be returned using single `traverseiterator` call.
|
|
|
|
// Note that iterator session lifetime is restricted by the RPC-server
|
|
|
|
// configuration and is being reset each time iterator is accessed. If session
|
|
|
|
// won't be accessed within session expiration time, then it will be terminated
|
|
|
|
// by the RPC-server automatically.
|
2022-06-15 18:23:29 +00:00
|
|
|
func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount int) ([]stackitem.Item, error) {
|
|
|
|
if maxItemsCount <= 0 {
|
|
|
|
maxItemsCount = config.DefaultMaxIteratorResultItems
|
|
|
|
}
|
|
|
|
var (
|
2023-04-03 10:34:24 +00:00
|
|
|
params = []any{sessionID.String(), iteratorID.String(), maxItemsCount}
|
2022-07-06 14:08:53 +00:00
|
|
|
resp []json.RawMessage
|
2022-06-15 18:23:29 +00:00
|
|
|
)
|
2022-07-06 14:08:53 +00:00
|
|
|
if err := c.performRequest("traverseiterator", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result := make([]stackitem.Item, len(resp))
|
|
|
|
for i, iBytes := range resp {
|
|
|
|
itm, err := stackitem.FromJSONWithTypes(iBytes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to unmarshal %d-th iterator value: %w", i, err)
|
2022-06-15 18:23:29 +00:00
|
|
|
}
|
2022-07-06 14:08:53 +00:00
|
|
|
result[i] = itm
|
2022-06-15 18:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TerminateSession tries to terminate the specified session and returns `true` iff
|
|
|
|
// the specified session was found on server.
|
|
|
|
func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error) {
|
|
|
|
var resp bool
|
2023-04-03 10:34:24 +00:00
|
|
|
params := []any{sessionID.String()}
|
2022-06-15 18:23:29 +00:00
|
|
|
if err := c.performRequest("terminatesession", params, &resp); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
2023-08-27 18:49:46 +00:00
|
|
|
|
|
|
|
// GetRawNotaryTransaction returns main or fallback transaction from the
|
|
|
|
// RPC node's notary request pool.
|
|
|
|
func (c *Client) GetRawNotaryTransaction(hash util.Uint256) (*transaction.Transaction, error) {
|
|
|
|
var (
|
|
|
|
params = []any{hash.StringLE()}
|
|
|
|
resp []byte
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if err = c.performRequest("getrawnotarytransaction", params, &resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return transaction.NewTransactionFromBytes(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawNotaryTransactionVerbose returns main or fallback transaction from the
|
|
|
|
// RPC node's notary request pool.
|
|
|
|
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and
|
|
|
|
// io.GetVarSize(t) respectively.
|
|
|
|
func (c *Client) GetRawNotaryTransactionVerbose(hash util.Uint256) (*transaction.Transaction, error) {
|
|
|
|
var (
|
|
|
|
params = []any{hash.StringLE(), 1} // 1 for verbose.
|
|
|
|
resp = &transaction.Transaction{}
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if err = c.performRequest("getrawnotarytransaction", params, resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawNotaryPool returns hashes of main P2PNotaryRequest transactions that
|
|
|
|
// are currently in the RPC node's notary request pool with the corresponding
|
|
|
|
// hashes of fallback transactions.
|
|
|
|
func (c *Client) GetRawNotaryPool() (*result.RawNotaryPool, error) {
|
|
|
|
resp := &result.RawNotaryPool{}
|
|
|
|
if err := c.performRequest("getrawnotarypool", nil, resp); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|