mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
rpc: drop useless RawParams type
It doesn't add anything useful to regular Go types and actually native types are always better to use in the Client. Especially given that this type is not used by any code outside of the Client itself.
This commit is contained in:
parent
113cb0fac3
commit
9462ed71d8
7 changed files with 124 additions and 158 deletions
|
@ -172,11 +172,14 @@ func (c *Client) Close() {
|
||||||
c.cli.CloseIdleConnections()
|
c.cli.CloseIdleConnections()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) performRequest(method string, p request.RawParams, v interface{}) error {
|
func (c *Client) performRequest(method string, p []interface{}, v interface{}) error {
|
||||||
|
if p == nil {
|
||||||
|
p = []interface{}{} // neo-project/neo-modules#742
|
||||||
|
}
|
||||||
var r = request.Raw{
|
var r = request.Raw{
|
||||||
JSONRPC: request.JSONRPCVersion,
|
JSONRPC: request.JSONRPCVersion,
|
||||||
Method: method,
|
Method: method,
|
||||||
Params: p.Values,
|
Params: p,
|
||||||
ID: c.getNextRequestID(),
|
ID: c.getNextRequestID(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ var errNetworkNotInitialized = errors.New("RPC client network is not initialized
|
||||||
// filled for standard sig/multisig signers.
|
// filled for standard sig/multisig signers.
|
||||||
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(tx.Bytes())
|
params = []interface{}{tx.Bytes()}
|
||||||
resp = new(result.NetworkFee)
|
resp = new(result.NetworkFee)
|
||||||
)
|
)
|
||||||
if err := c.performRequest("calculatenetworkfee", params, resp); err != nil {
|
if err := c.performRequest("calculatenetworkfee", params, resp); err != nil {
|
||||||
|
@ -50,11 +50,11 @@ func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
|
||||||
// GetApplicationLog returns a contract log based on the specified txid.
|
// GetApplicationLog returns a contract log based on the specified txid.
|
||||||
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) {
|
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE())
|
params = []interface{}{hash.StringLE()}
|
||||||
resp = new(result.ApplicationLog)
|
resp = new(result.ApplicationLog)
|
||||||
)
|
)
|
||||||
if trig != nil {
|
if trig != nil {
|
||||||
params.Values = append(params.Values, trig.String())
|
params = append(params, trig.String())
|
||||||
}
|
}
|
||||||
if err := c.performRequest("getapplicationlog", params, resp); err != nil {
|
if err := c.performRequest("getapplicationlog", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -65,7 +65,7 @@ func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*resu
|
||||||
// GetBestBlockHash returns the hash of the tallest block in the blockchain.
|
// GetBestBlockHash returns the hash of the tallest block in the blockchain.
|
||||||
func (c *Client) GetBestBlockHash() (util.Uint256, error) {
|
func (c *Client) GetBestBlockHash() (util.Uint256, error) {
|
||||||
var resp = util.Uint256{}
|
var resp = util.Uint256{}
|
||||||
if err := c.performRequest("getbestblockhash", request.NewRawParams(), &resp); err != nil {
|
if err := c.performRequest("getbestblockhash", nil, &resp); err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -74,7 +74,7 @@ func (c *Client) GetBestBlockHash() (util.Uint256, error) {
|
||||||
// GetBlockCount returns the number of blocks in the blockchain.
|
// GetBlockCount returns the number of blocks in the blockchain.
|
||||||
func (c *Client) GetBlockCount() (uint32, error) {
|
func (c *Client) GetBlockCount() (uint32, error) {
|
||||||
var resp uint32
|
var resp uint32
|
||||||
if err := c.performRequest("getblockcount", request.NewRawParams(), &resp); err != nil {
|
if err := c.performRequest("getblockcount", nil, &resp); err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -83,22 +83,22 @@ func (c *Client) GetBlockCount() (uint32, error) {
|
||||||
// GetBlockByIndex returns a block by its height. You should initialize network magic
|
// GetBlockByIndex returns a block by its height. You should initialize network magic
|
||||||
// with Init before calling GetBlockByIndex.
|
// with Init before calling GetBlockByIndex.
|
||||||
func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error) {
|
func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error) {
|
||||||
return c.getBlock(request.NewRawParams(index))
|
return c.getBlock(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockByHash returns a block by its hash. You should initialize network magic
|
// GetBlockByHash returns a block by its hash. You should initialize network magic
|
||||||
// with Init before calling GetBlockByHash.
|
// with Init before calling GetBlockByHash.
|
||||||
func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error) {
|
func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error) {
|
||||||
return c.getBlock(request.NewRawParams(hash.StringLE()))
|
return c.getBlock(hash.StringLE())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getBlock(params request.RawParams) (*block.Block, error) {
|
func (c *Client) getBlock(param interface{}) (*block.Block, error) {
|
||||||
var (
|
var (
|
||||||
resp []byte
|
resp []byte
|
||||||
err error
|
err error
|
||||||
b *block.Block
|
b *block.Block
|
||||||
)
|
)
|
||||||
if err = c.performRequest("getblock", params, &resp); err != nil {
|
if err = c.performRequest("getblock", []interface{}{param}, &resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r := io.NewBinReaderFromBuf(resp)
|
r := io.NewBinReaderFromBuf(resp)
|
||||||
|
@ -118,17 +118,18 @@ func (c *Client) getBlock(params request.RawParams) (*block.Block, error) {
|
||||||
// its height. You should initialize network magic with Init before calling GetBlockByIndexVerbose.
|
// its height. You should initialize network magic with Init before calling GetBlockByIndexVerbose.
|
||||||
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
||||||
func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error) {
|
func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error) {
|
||||||
return c.getBlockVerbose(request.NewRawParams(index, 1))
|
return c.getBlockVerbose(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockByHashVerbose returns a block wrapper with additional metadata by
|
// GetBlockByHashVerbose returns a block wrapper with additional metadata by
|
||||||
// its hash. You should initialize network magic with Init before calling GetBlockByHashVerbose.
|
// its hash. You should initialize network magic with Init before calling GetBlockByHashVerbose.
|
||||||
func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error) {
|
func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error) {
|
||||||
return c.getBlockVerbose(request.NewRawParams(hash.StringLE(), 1))
|
return c.getBlockVerbose(hash.StringLE())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getBlockVerbose(params request.RawParams) (*result.Block, error) {
|
func (c *Client) getBlockVerbose(param interface{}) (*result.Block, error) {
|
||||||
var (
|
var (
|
||||||
|
params = []interface{}{param, 1} // 1 for verbose.
|
||||||
resp = &result.Block{}
|
resp = &result.Block{}
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
@ -146,7 +147,7 @@ func (c *Client) getBlockVerbose(params request.RawParams) (*result.Block, error
|
||||||
// GetBlockHash returns the hash value of the corresponding block based on the specified index.
|
// GetBlockHash returns the hash value of the corresponding block based on the specified index.
|
||||||
func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
|
func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(index)
|
params = []interface{}{index}
|
||||||
resp = util.Uint256{}
|
resp = util.Uint256{}
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getblockhash", params, &resp); err != nil {
|
if err := c.performRequest("getblockhash", params, &resp); err != nil {
|
||||||
|
@ -160,7 +161,7 @@ func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
|
||||||
// with Init before calling GetBlockHeader.
|
// with Init before calling GetBlockHeader.
|
||||||
func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
|
func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE())
|
params = []interface{}{hash.StringLE()}
|
||||||
resp []byte
|
resp []byte
|
||||||
h *block.Header
|
h *block.Header
|
||||||
)
|
)
|
||||||
|
@ -184,7 +185,7 @@ func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
|
||||||
// GetBlockHeaderCount returns the number of headers in the main chain.
|
// GetBlockHeaderCount returns the number of headers in the main chain.
|
||||||
func (c *Client) GetBlockHeaderCount() (uint32, error) {
|
func (c *Client) GetBlockHeaderCount() (uint32, error) {
|
||||||
var resp uint32
|
var resp uint32
|
||||||
if err := c.performRequest("getblockheadercount", request.NewRawParams(), &resp); err != nil {
|
if err := c.performRequest("getblockheadercount", nil, &resp); err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -194,7 +195,7 @@ func (c *Client) GetBlockHeaderCount() (uint32, error) {
|
||||||
// according to the specified script hash.
|
// according to the specified script hash.
|
||||||
func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) {
|
func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE(), 1)
|
params = []interface{}{hash.StringLE(), 1}
|
||||||
resp = &result.Header{}
|
resp = &result.Header{}
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getblockheader", params, resp); err != nil {
|
if err := c.performRequest("getblockheader", params, resp); err != nil {
|
||||||
|
@ -206,7 +207,7 @@ func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error
|
||||||
// GetBlockSysFee returns the system fees of the block based on the specified index.
|
// GetBlockSysFee returns the system fees of the block based on the specified index.
|
||||||
func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) {
|
func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(index)
|
params = []interface{}{index}
|
||||||
resp fixedn.Fixed8
|
resp fixedn.Fixed8
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getblocksysfee", params, &resp); err != nil {
|
if err := c.performRequest("getblocksysfee", params, &resp); err != nil {
|
||||||
|
@ -217,11 +218,9 @@ func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) {
|
||||||
|
|
||||||
// GetConnectionCount returns the current number of the connections for the node.
|
// GetConnectionCount returns the current number of the connections for the node.
|
||||||
func (c *Client) GetConnectionCount() (int, error) {
|
func (c *Client) GetConnectionCount() (int, error) {
|
||||||
var (
|
var resp int
|
||||||
params = request.NewRawParams()
|
|
||||||
resp int
|
if err := c.performRequest("getconnectioncount", nil, &resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getconnectioncount", params, &resp); err != nil {
|
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -229,11 +228,9 @@ func (c *Client) GetConnectionCount() (int, error) {
|
||||||
|
|
||||||
// GetCommittee returns the current public keys of NEO nodes in the committee.
|
// GetCommittee returns the current public keys of NEO nodes in the committee.
|
||||||
func (c *Client) GetCommittee() (keys.PublicKeys, error) {
|
func (c *Client) GetCommittee() (keys.PublicKeys, error) {
|
||||||
var (
|
var resp = new(keys.PublicKeys)
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = new(keys.PublicKeys)
|
if err := c.performRequest("getcommittee", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getcommittee", params, resp); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return *resp, nil
|
return *resp, nil
|
||||||
|
@ -257,7 +254,7 @@ func (c *Client) GetContractStateByID(id int32) (*state.Contract, error) {
|
||||||
// getContractState is an internal representation of GetContractStateBy* methods.
|
// getContractState is an internal representation of GetContractStateBy* methods.
|
||||||
func (c *Client) getContractState(param interface{}) (*state.Contract, error) {
|
func (c *Client) getContractState(param interface{}) (*state.Contract, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(param)
|
params = []interface{}{param}
|
||||||
resp = &state.Contract{}
|
resp = &state.Contract{}
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getcontractstate", params, resp); err != nil {
|
if err := c.performRequest("getcontractstate", params, resp); err != nil {
|
||||||
|
@ -268,11 +265,8 @@ func (c *Client) getContractState(param interface{}) (*state.Contract, error) {
|
||||||
|
|
||||||
// GetNativeContracts queries information about native contracts.
|
// GetNativeContracts queries information about native contracts.
|
||||||
func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
|
func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
|
||||||
var (
|
var resp []state.NativeContract
|
||||||
params = request.NewRawParams()
|
if err := c.performRequest("getnativecontracts", nil, &resp); err != nil {
|
||||||
resp []state.NativeContract
|
|
||||||
)
|
|
||||||
if err := c.performRequest("getnativecontracts", params, &resp); err != nil {
|
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +282,7 @@ func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
|
||||||
|
|
||||||
// GetNEP11Balances is a wrapper for getnep11balances RPC.
|
// GetNEP11Balances is a wrapper for getnep11balances RPC.
|
||||||
func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error) {
|
func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error) {
|
||||||
params := request.NewRawParams(address.StringLE())
|
params := []interface{}{address.StringLE()}
|
||||||
resp := new(result.NEP11Balances)
|
resp := new(result.NEP11Balances)
|
||||||
if err := c.performRequest("getnep11balances", params, resp); err != nil {
|
if err := c.performRequest("getnep11balances", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -298,7 +292,7 @@ func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances,
|
||||||
|
|
||||||
// GetNEP17Balances is a wrapper for getnep17balances RPC.
|
// GetNEP17Balances is a wrapper for getnep17balances RPC.
|
||||||
func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error) {
|
func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error) {
|
||||||
params := request.NewRawParams(address.StringLE())
|
params := []interface{}{address.StringLE()}
|
||||||
resp := new(result.NEP17Balances)
|
resp := new(result.NEP17Balances)
|
||||||
if err := c.performRequest("getnep17balances", params, resp); err != nil {
|
if err := c.performRequest("getnep17balances", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -312,7 +306,7 @@ func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances,
|
||||||
// attributes like "description", "image", "name" and "tokenURI" it returns strings,
|
// attributes like "description", "image", "name" and "tokenURI" it returns strings,
|
||||||
// while for all others []byte (which can be nil).
|
// while for all others []byte (which can be nil).
|
||||||
func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error) {
|
func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error) {
|
||||||
params := request.NewRawParams(asset.StringLE(), hex.EncodeToString(token))
|
params := []interface{}{asset.StringLE(), hex.EncodeToString(token)}
|
||||||
resp := make(map[string]interface{})
|
resp := make(map[string]interface{})
|
||||||
if err := c.performRequest("getnep11properties", params, &resp); err != nil {
|
if err := c.performRequest("getnep11properties", params, &resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -346,22 +340,22 @@ func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, li
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := new(result.NEP11Transfers)
|
resp := new(result.NEP11Transfers)
|
||||||
if err := c.performRequest("getnep11transfers", *params, resp); err != nil {
|
if err := c.performRequest("getnep11transfers", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) (*request.RawParams, error) {
|
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) ([]interface{}, error) {
|
||||||
params := request.NewRawParams(address.StringLE())
|
params := []interface{}{address.StringLE()}
|
||||||
if start != nil {
|
if start != nil {
|
||||||
params.Values = append(params.Values, *start)
|
params = append(params, *start)
|
||||||
if stop != nil {
|
if stop != nil {
|
||||||
params.Values = append(params.Values, *stop)
|
params = append(params, *stop)
|
||||||
if limit != nil {
|
if limit != nil {
|
||||||
params.Values = append(params.Values, *limit)
|
params = append(params, *limit)
|
||||||
if page != nil {
|
if page != nil {
|
||||||
params.Values = append(params.Values, *page)
|
params = append(params, *page)
|
||||||
}
|
}
|
||||||
} else if page != nil {
|
} else if page != nil {
|
||||||
return nil, errors.New("bad parameters")
|
return nil, errors.New("bad parameters")
|
||||||
|
@ -372,7 +366,7 @@ func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page
|
||||||
} else if stop != nil || limit != nil || page != nil {
|
} else if stop != nil || limit != nil || page != nil {
|
||||||
return nil, errors.New("bad parameters")
|
return nil, errors.New("bad parameters")
|
||||||
}
|
}
|
||||||
return ¶ms, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNEP17Transfers is a wrapper for getnep17transfers RPC. Address parameter
|
// GetNEP17Transfers is a wrapper for getnep17transfers RPC. Address parameter
|
||||||
|
@ -386,7 +380,7 @@ func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, li
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := new(result.NEP17Transfers)
|
resp := new(result.NEP17Transfers)
|
||||||
if err := c.performRequest("getnep17transfers", *params, resp); err != nil {
|
if err := c.performRequest("getnep17transfers", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -394,11 +388,9 @@ func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, li
|
||||||
|
|
||||||
// GetPeers returns a list of the nodes that the node is currently connected to/disconnected from.
|
// GetPeers returns a list of the nodes that the node is currently connected to/disconnected from.
|
||||||
func (c *Client) GetPeers() (*result.GetPeers, error) {
|
func (c *Client) GetPeers() (*result.GetPeers, error) {
|
||||||
var (
|
var resp = &result.GetPeers{}
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = &result.GetPeers{}
|
if err := c.performRequest("getpeers", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getpeers", params, resp); err != nil {
|
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -406,11 +398,9 @@ func (c *Client) GetPeers() (*result.GetPeers, error) {
|
||||||
|
|
||||||
// GetRawMemPool returns a list of unconfirmed transactions in the memory.
|
// GetRawMemPool returns a list of unconfirmed transactions in the memory.
|
||||||
func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
|
func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
|
||||||
var (
|
var resp = new([]util.Uint256)
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = new([]util.Uint256)
|
if err := c.performRequest("getrawmempool", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getrawmempool", params, resp); err != nil {
|
|
||||||
return *resp, err
|
return *resp, err
|
||||||
}
|
}
|
||||||
return *resp, nil
|
return *resp, nil
|
||||||
|
@ -419,7 +409,7 @@ func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
|
||||||
// GetRawTransaction returns a transaction by hash.
|
// GetRawTransaction returns a transaction by hash.
|
||||||
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
|
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE())
|
params = []interface{}{hash.StringLE()}
|
||||||
resp []byte
|
resp []byte
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
@ -438,7 +428,7 @@ func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction,
|
||||||
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
// NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
|
||||||
func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) {
|
func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE(), 1)
|
params = []interface{}{hash.StringLE(), 1} // 1 for verbose.
|
||||||
resp = &result.TransactionOutputRaw{}
|
resp = &result.TransactionOutputRaw{}
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
@ -452,7 +442,7 @@ func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.Transactio
|
||||||
// historical contract hash and historical item key.
|
// historical contract hash and historical item key.
|
||||||
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error) {
|
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey)
|
params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey}
|
||||||
resp []byte
|
resp []byte
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getstate", params, &resp); err != nil {
|
if err := c.performRequest("getstate", params, &resp); err != nil {
|
||||||
|
@ -471,17 +461,17 @@ func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.
|
||||||
historicalPrefix = []byte{}
|
historicalPrefix = []byte{}
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix)
|
params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix}
|
||||||
resp result.FindStates
|
resp result.FindStates
|
||||||
)
|
)
|
||||||
if start == nil && maxCount != nil {
|
if start == nil && maxCount != nil {
|
||||||
start = []byte{}
|
start = []byte{}
|
||||||
}
|
}
|
||||||
if start != nil {
|
if start != nil {
|
||||||
params.Values = append(params.Values, start)
|
params = append(params, start)
|
||||||
}
|
}
|
||||||
if maxCount != nil {
|
if maxCount != nil {
|
||||||
params.Values = append(params.Values, *maxCount)
|
params = append(params, *maxCount)
|
||||||
}
|
}
|
||||||
if err := c.performRequest("findstates", params, &resp); err != nil {
|
if err := c.performRequest("findstates", params, &resp); err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
|
@ -491,17 +481,17 @@ func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.
|
||||||
|
|
||||||
// GetStateRootByHeight returns the state root for the specified height.
|
// GetStateRootByHeight returns the state root for the specified height.
|
||||||
func (c *Client) GetStateRootByHeight(height uint32) (*state.MPTRoot, error) {
|
func (c *Client) GetStateRootByHeight(height uint32) (*state.MPTRoot, error) {
|
||||||
return c.getStateRoot(request.NewRawParams(height))
|
return c.getStateRoot(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateRootByBlockHash returns the state root for the block with the specified hash.
|
// GetStateRootByBlockHash returns the state root for the block with the specified hash.
|
||||||
func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, error) {
|
func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, error) {
|
||||||
return c.getStateRoot(request.NewRawParams(hash))
|
return c.getStateRoot(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getStateRoot(params request.RawParams) (*state.MPTRoot, error) {
|
func (c *Client) getStateRoot(param interface{}) (*state.MPTRoot, error) {
|
||||||
var resp = new(state.MPTRoot)
|
var resp = new(state.MPTRoot)
|
||||||
if err := c.performRequest("getstateroot", params, resp); err != nil {
|
if err := c.performRequest("getstateroot", []interface{}{param}, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -509,11 +499,9 @@ func (c *Client) getStateRoot(params request.RawParams) (*state.MPTRoot, error)
|
||||||
|
|
||||||
// GetStateHeight returns the current validated and local node state height.
|
// GetStateHeight returns the current validated and local node state height.
|
||||||
func (c *Client) GetStateHeight() (*result.StateHeight, error) {
|
func (c *Client) GetStateHeight() (*result.StateHeight, error) {
|
||||||
var (
|
var resp = new(result.StateHeight)
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = new(result.StateHeight)
|
if err := c.performRequest("getstateheight", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getstateheight", params, resp); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -521,15 +509,15 @@ func (c *Client) GetStateHeight() (*result.StateHeight, error) {
|
||||||
|
|
||||||
// GetStorageByID returns the stored value according to the contract ID and the stored key.
|
// GetStorageByID returns the stored value according to the contract ID and the stored key.
|
||||||
func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error) {
|
func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error) {
|
||||||
return c.getStorage(request.NewRawParams(id, key))
|
return c.getStorage([]interface{}{id, key})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStorageByHash returns the stored value according to the contract script hash and the stored key.
|
// GetStorageByHash returns the stored value according to the contract script hash and the stored key.
|
||||||
func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error) {
|
func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error) {
|
||||||
return c.getStorage(request.NewRawParams(hash.StringLE(), key))
|
return c.getStorage([]interface{}{hash.StringLE(), key})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getStorage(params request.RawParams) ([]byte, error) {
|
func (c *Client) getStorage(params []interface{}) ([]byte, error) {
|
||||||
var resp []byte
|
var resp []byte
|
||||||
if err := c.performRequest("getstorage", params, &resp); err != nil {
|
if err := c.performRequest("getstorage", params, &resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -540,7 +528,7 @@ func (c *Client) getStorage(params request.RawParams) ([]byte, error) {
|
||||||
// GetTransactionHeight returns the block index where the transaction is found.
|
// GetTransactionHeight returns the block index where the transaction is found.
|
||||||
func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) {
|
func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hash.StringLE())
|
params = []interface{}{hash.StringLE()}
|
||||||
resp uint32
|
resp uint32
|
||||||
)
|
)
|
||||||
if err := c.performRequest("gettransactionheight", params, &resp); err != nil {
|
if err := c.performRequest("gettransactionheight", params, &resp); err != nil {
|
||||||
|
@ -552,7 +540,7 @@ func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) {
|
||||||
// GetUnclaimedGas returns the unclaimed GAS amount for the specified address.
|
// GetUnclaimedGas returns the unclaimed GAS amount for the specified address.
|
||||||
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
|
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(address)
|
params = []interface{}{address}
|
||||||
resp result.UnclaimedGas
|
resp result.UnclaimedGas
|
||||||
)
|
)
|
||||||
if err := c.performRequest("getunclaimedgas", params, &resp); err != nil {
|
if err := c.performRequest("getunclaimedgas", params, &resp); err != nil {
|
||||||
|
@ -564,11 +552,9 @@ func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
|
||||||
// GetCandidates returns the current list of NEO candidate node with voting data and
|
// GetCandidates returns the current list of NEO candidate node with voting data and
|
||||||
// validator status.
|
// validator status.
|
||||||
func (c *Client) GetCandidates() ([]result.Candidate, error) {
|
func (c *Client) GetCandidates() ([]result.Candidate, error) {
|
||||||
var (
|
var resp = new([]result.Candidate)
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = new([]result.Candidate)
|
if err := c.performRequest("getcandidates", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getcandidates", params, resp); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return *resp, nil
|
return *resp, nil
|
||||||
|
@ -576,11 +562,9 @@ func (c *Client) GetCandidates() ([]result.Candidate, error) {
|
||||||
|
|
||||||
// GetNextBlockValidators returns the current NEO consensus nodes information and voting data.
|
// GetNextBlockValidators returns the current NEO consensus nodes information and voting data.
|
||||||
func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
|
func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
|
||||||
var (
|
var resp = new([]result.Validator)
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = new([]result.Validator)
|
if err := c.performRequest("getnextblockvalidators", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getnextblockvalidators", params, resp); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return *resp, nil
|
return *resp, nil
|
||||||
|
@ -588,11 +572,9 @@ func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
|
||||||
|
|
||||||
// GetVersion returns the version information about the queried node.
|
// GetVersion returns the version information about the queried node.
|
||||||
func (c *Client) GetVersion() (*result.Version, error) {
|
func (c *Client) GetVersion() (*result.Version, error) {
|
||||||
var (
|
var resp = &result.Version{}
|
||||||
params = request.NewRawParams()
|
|
||||||
resp = &result.Version{}
|
if err := c.performRequest("getversion", nil, resp); err != nil {
|
||||||
)
|
|
||||||
if err := c.performRequest("getversion", params, resp); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -601,7 +583,7 @@ func (c *Client) GetVersion() (*result.Version, error) {
|
||||||
// InvokeScript returns the result of the given script after running it true the VM.
|
// 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.
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(script)
|
var p = []interface{}{script}
|
||||||
return c.invokeSomething("invokescript", p, signers)
|
return c.invokeSomething("invokescript", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +592,7 @@ func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*res
|
||||||
// height.
|
// height.
|
||||||
// NOTE: This is a test invoke and will not affect the blockchain.
|
// 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) {
|
func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(height, script)
|
var p = []interface{}{height, script}
|
||||||
return c.invokeSomething("invokescripthistoric", p, signers)
|
return c.invokeSomething("invokescripthistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,7 +601,7 @@ func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []tr
|
||||||
// hash.
|
// hash.
|
||||||
// NOTE: This is a test invoke and will not affect the blockchain.
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(blockHash.StringLE(), script)
|
var p = []interface{}{blockHash.StringLE(), script}
|
||||||
return c.invokeSomething("invokescripthistoric", p, signers)
|
return c.invokeSomething("invokescripthistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +610,7 @@ func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, sign
|
||||||
// stateroot hash.
|
// stateroot hash.
|
||||||
// NOTE: This is a test invoke and will not affect the blockchain.
|
// NOTE: This is a test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeScriptWithState(stateroot util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeScriptWithState(stateroot util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(stateroot.StringLE(), script)
|
var p = []interface{}{stateroot.StringLE(), script}
|
||||||
return c.invokeSomething("invokescripthistoric", p, signers)
|
return c.invokeSomething("invokescripthistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,7 +618,7 @@ func (c *Client) InvokeScriptWithState(stateroot util.Uint256, script []byte, si
|
||||||
// with the given operation and parameters.
|
// with the given operation and parameters.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// NOTE: this is test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(contract.StringLE(), operation, params)
|
var p = []interface{}{contract.StringLE(), operation, params}
|
||||||
return c.invokeSomething("invokefunction", p, signers)
|
return c.invokeSomething("invokefunction", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +627,7 @@ func (c *Client) InvokeFunction(contract util.Uint160, operation string, params
|
||||||
// specified by the blockchain height.
|
// specified by the blockchain height.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// 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) {
|
func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(height, contract.StringLE(), operation, params)
|
var p = []interface{}{height, contract.StringLE(), operation, params}
|
||||||
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,7 +636,7 @@ func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, op
|
||||||
// specified by the block hash.
|
// specified by the block hash.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// NOTE: this is test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(blockHash.StringLE(), contract.StringLE(), operation, params)
|
var p = []interface{}{blockHash.StringLE(), contract.StringLE(), operation, params}
|
||||||
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,7 +645,7 @@ func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uin
|
||||||
// by the specified stateroot hash.
|
// by the specified stateroot hash.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// NOTE: this is test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(stateroot.StringLE(), contract.StringLE(), operation, params)
|
var p = []interface{}{stateroot.StringLE(), contract.StringLE(), operation, params}
|
||||||
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
return c.invokeSomething("invokefunctionhistoric", p, signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,7 +653,7 @@ func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.U
|
||||||
// with the given parameters under verification trigger type.
|
// with the given parameters under verification trigger type.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// 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) {
|
func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(contract.StringLE(), params)
|
var p = []interface{}{contract.StringLE(), params}
|
||||||
return c.invokeSomething("invokecontractverify", p, signers, witnesses...)
|
return c.invokeSomething("invokecontractverify", p, signers, witnesses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,7 +662,7 @@ func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontr
|
||||||
// at the blockchain state specified by the blockchain height.
|
// at the blockchain state specified by the blockchain height.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// 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) {
|
func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(height, contract.StringLE(), params)
|
var p = []interface{}{height, contract.StringLE(), params}
|
||||||
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,7 +671,7 @@ func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint1
|
||||||
// at the blockchain state specified by the block hash.
|
// at the blockchain state specified by the block hash.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// NOTE: this is test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeContractVerifyAtBlock(blockHash util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
func (c *Client) InvokeContractVerifyAtBlock(blockHash util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(blockHash.StringLE(), contract.StringLE(), params)
|
var p = []interface{}{blockHash.StringLE(), contract.StringLE(), params}
|
||||||
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,16 +680,16 @@ func (c *Client) InvokeContractVerifyAtBlock(blockHash util.Uint256, contract ut
|
||||||
// at the blockchain state specified by the stateroot hash.
|
// at the blockchain state specified by the stateroot hash.
|
||||||
// NOTE: this is test invoke and will not affect the blockchain.
|
// NOTE: this is test invoke and will not affect the blockchain.
|
||||||
func (c *Client) InvokeContractVerifyWithState(stateroot util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
func (c *Client) InvokeContractVerifyWithState(stateroot util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
var p = request.NewRawParams(stateroot.StringLE(), contract.StringLE(), params)
|
var p = []interface{}{stateroot.StringLE(), contract.StringLE(), params}
|
||||||
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// invokeSomething is an inner wrapper for Invoke* functions.
|
// invokeSomething is an inner wrapper for Invoke* functions.
|
||||||
func (c *Client) invokeSomething(method string, p request.RawParams, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
func (c *Client) invokeSomething(method string, p []interface{}, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
var resp = new(result.Invoke)
|
var resp = new(result.Invoke)
|
||||||
if signers != nil {
|
if signers != nil {
|
||||||
if witnesses == nil {
|
if witnesses == nil {
|
||||||
p.Values = append(p.Values, signers)
|
p = append(p, signers)
|
||||||
} else {
|
} else {
|
||||||
if len(witnesses) != len(signers) {
|
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))
|
return nil, fmt.Errorf("number of witnesses should match number of signers, got %d vs %d", len(witnesses), len(signers))
|
||||||
|
@ -719,7 +701,7 @@ func (c *Client) invokeSomething(method string, p request.RawParams, signers []t
|
||||||
Witness: witnesses[i],
|
Witness: witnesses[i],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.Values = append(p.Values, signersWithWitnesses)
|
p = append(p, signersWithWitnesses)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := c.performRequest(method, p, resp); err != nil {
|
if err := c.performRequest(method, p, resp); err != nil {
|
||||||
|
@ -734,7 +716,7 @@ func (c *Client) invokeSomething(method string, p request.RawParams, signers []t
|
||||||
// been broadcasted to the network.
|
// been broadcasted to the network.
|
||||||
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) {
|
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(rawTX.Bytes())
|
params = []interface{}{rawTX.Bytes()}
|
||||||
resp = new(result.RelayResult)
|
resp = new(result.RelayResult)
|
||||||
)
|
)
|
||||||
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
||||||
|
@ -746,7 +728,7 @@ func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint25
|
||||||
// SubmitBlock broadcasts a raw block over the NEO network.
|
// SubmitBlock broadcasts a raw block over the NEO network.
|
||||||
func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
|
func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
|
||||||
var (
|
var (
|
||||||
params request.RawParams
|
params []interface{}
|
||||||
resp = new(result.RelayResult)
|
resp = new(result.RelayResult)
|
||||||
)
|
)
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
|
@ -754,7 +736,7 @@ func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
|
||||||
if err := buf.Err; err != nil {
|
if err := buf.Err; err != nil {
|
||||||
return util.Uint256{}, err
|
return util.Uint256{}, err
|
||||||
}
|
}
|
||||||
params = request.NewRawParams(buf.Bytes())
|
params = []interface{}{buf.Bytes()}
|
||||||
|
|
||||||
if err := c.performRequest("submitblock", params, resp); err != nil {
|
if err := c.performRequest("submitblock", params, resp); err != nil {
|
||||||
return util.Uint256{}, err
|
return util.Uint256{}, err
|
||||||
|
@ -764,7 +746,7 @@ func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
|
||||||
|
|
||||||
// SubmitRawOracleResponse submits a raw oracle response to the oracle node.
|
// SubmitRawOracleResponse submits a raw oracle response to the oracle node.
|
||||||
// Raw params are used to avoid excessive marshalling.
|
// Raw params are used to avoid excessive marshalling.
|
||||||
func (c *Client) SubmitRawOracleResponse(ps request.RawParams) error {
|
func (c *Client) SubmitRawOracleResponse(ps []interface{}) error {
|
||||||
return c.performRequest("submitoracleresponse", ps, new(result.RelayResult))
|
return c.performRequest("submitoracleresponse", ps, new(result.RelayResult))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +979,7 @@ func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint256{}, fmt.Errorf("failed to encode request: %w", err)
|
return util.Uint256{}, fmt.Errorf("failed to encode request: %w", err)
|
||||||
}
|
}
|
||||||
params := request.NewRawParams(bytes)
|
params := []interface{}{bytes}
|
||||||
if err := c.performRequest("submitnotaryrequest", params, resp); err != nil {
|
if err := c.performRequest("submitnotaryrequest", params, resp); err != nil {
|
||||||
return util.Uint256{}, err
|
return util.Uint256{}, err
|
||||||
}
|
}
|
||||||
|
@ -1007,7 +989,7 @@ func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uin
|
||||||
// ValidateAddress verifies that the address is a correct NEO address.
|
// ValidateAddress verifies that the address is a correct NEO address.
|
||||||
func (c *Client) ValidateAddress(address string) error {
|
func (c *Client) ValidateAddress(address string) error {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(address)
|
params = []interface{}{address}
|
||||||
resp = &result.ValidateAddress{}
|
resp = &result.ValidateAddress{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1161,7 +1143,7 @@ func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount
|
||||||
maxItemsCount = config.DefaultMaxIteratorResultItems
|
maxItemsCount = config.DefaultMaxIteratorResultItems
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(sessionID.String(), iteratorID.String(), maxItemsCount)
|
params = []interface{}{sessionID.String(), iteratorID.String(), maxItemsCount}
|
||||||
resp []json.RawMessage
|
resp []json.RawMessage
|
||||||
)
|
)
|
||||||
if err := c.performRequest("traverseiterator", params, &resp); err != nil {
|
if err := c.performRequest("traverseiterator", params, &resp); err != nil {
|
||||||
|
@ -1183,7 +1165,7 @@ func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount
|
||||||
// the specified session was found on server.
|
// the specified session was found on server.
|
||||||
func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error) {
|
func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error) {
|
||||||
var resp bool
|
var resp bool
|
||||||
params := request.NewRawParams(sessionID.String())
|
params := []interface{}{sessionID.String()}
|
||||||
if err := c.performRequest("terminatesession", params, &resp); err != nil {
|
if err := c.performRequest("terminatesession", params, &resp); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,7 +315,7 @@ func (c *WSClient) makeWsRequest(r *request.Raw) (*response.Raw, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSClient) performSubscription(params request.RawParams) (string, error) {
|
func (c *WSClient) performSubscription(params []interface{}) (string, error) {
|
||||||
var resp string
|
var resp string
|
||||||
|
|
||||||
if err := c.performRequest("subscribe", params, &resp); err != nil {
|
if err := c.performRequest("subscribe", params, &resp); err != nil {
|
||||||
|
@ -338,7 +338,7 @@ func (c *WSClient) performUnsubscription(id string) error {
|
||||||
if !c.subscriptions[id] {
|
if !c.subscriptions[id] {
|
||||||
return errors.New("no subscription with this ID")
|
return errors.New("no subscription with this ID")
|
||||||
}
|
}
|
||||||
if err := c.performRequest("unsubscribe", request.NewRawParams(id), &resp); err != nil {
|
if err := c.performRequest("unsubscribe", []interface{}{id}, &resp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !resp {
|
if !resp {
|
||||||
|
@ -352,9 +352,9 @@ func (c *WSClient) performUnsubscription(id string) error {
|
||||||
// of the client. It can be filtered by primary consensus node index, nil value doesn't
|
// of the client. It can be filtered by primary consensus node index, nil value doesn't
|
||||||
// add any filters.
|
// add any filters.
|
||||||
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
||||||
params := request.NewRawParams("block_added")
|
params := []interface{}{"block_added"}
|
||||||
if primary != nil {
|
if primary != nil {
|
||||||
params.Values = append(params.Values, request.BlockFilter{Primary: *primary})
|
params = append(params, request.BlockFilter{Primary: *primary})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -363,9 +363,9 @@ func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
||||||
// this instance of the client. It can be filtered by the sender and/or the signer, nil
|
// this instance of the client. It can be filtered by the sender and/or the signer, nil
|
||||||
// value is treated as missing filter.
|
// value is treated as missing filter.
|
||||||
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) {
|
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) {
|
||||||
params := request.NewRawParams("transaction_added")
|
params := []interface{}{"transaction_added"}
|
||||||
if sender != nil || signer != nil {
|
if sender != nil || signer != nil {
|
||||||
params.Values = append(params.Values, request.TxFilter{Sender: sender, Signer: signer})
|
params = append(params, request.TxFilter{Sender: sender, Signer: signer})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -375,9 +375,9 @@ func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *uti
|
||||||
// filtered by the contract's hash (that emits notifications), nil value puts no such
|
// filtered by the contract's hash (that emits notifications), nil value puts no such
|
||||||
// restrictions.
|
// restrictions.
|
||||||
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) {
|
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) {
|
||||||
params := request.NewRawParams("notification_from_execution")
|
params := []interface{}{"notification_from_execution"}
|
||||||
if contract != nil || name != nil {
|
if contract != nil || name != nil {
|
||||||
params.Values = append(params.Values, request.NotificationFilter{Contract: contract, Name: name})
|
params = append(params, request.NotificationFilter{Contract: contract, Name: name})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -387,12 +387,12 @@ func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, na
|
||||||
// be filtered by state (HALT/FAULT) to check for successful or failing
|
// be filtered by state (HALT/FAULT) to check for successful or failing
|
||||||
// transactions, nil value means no filtering.
|
// transactions, nil value means no filtering.
|
||||||
func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error) {
|
func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error) {
|
||||||
params := request.NewRawParams("transaction_executed")
|
params := []interface{}{"transaction_executed"}
|
||||||
if state != nil {
|
if state != nil {
|
||||||
if *state != "HALT" && *state != "FAULT" {
|
if *state != "HALT" && *state != "FAULT" {
|
||||||
return "", errors.New("bad state parameter")
|
return "", errors.New("bad state parameter")
|
||||||
}
|
}
|
||||||
params.Values = append(params.Values, request.ExecutionFilter{State: *state})
|
params = append(params, request.ExecutionFilter{State: *state})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -402,9 +402,9 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err
|
||||||
// request sender's hash, or main tx signer's hash, nil value puts no such
|
// request sender's hash, or main tx signer's hash, nil value puts no such
|
||||||
// restrictions.
|
// restrictions.
|
||||||
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) {
|
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) {
|
||||||
params := request.NewRawParams("notary_request_event")
|
params := []interface{}{"notary_request_event"}
|
||||||
if sender != nil {
|
if sender != nil {
|
||||||
params.Values = append(params.Values, request.TxFilter{Sender: sender, Signer: mainSigner})
|
params = append(params, request.TxFilter{Sender: sender, Signer: mainSigner})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ func (c *WSClient) UnsubscribeAll() error {
|
||||||
|
|
||||||
for id := range c.subscriptions {
|
for id := range c.subscriptions {
|
||||||
var resp bool
|
var resp bool
|
||||||
if err := c.performRequest("unsubscribe", request.NewRawParams(id), &resp); err != nil {
|
if err := c.performRequest("unsubscribe", []interface{}{id}, &resp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !resp {
|
if !resp {
|
||||||
|
|
|
@ -16,22 +16,6 @@ const (
|
||||||
JSONRPCVersion = "2.0"
|
JSONRPCVersion = "2.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RawParams is just a slice of abstract values, used to represent parameters
|
|
||||||
// passed from the client to the server.
|
|
||||||
type RawParams struct {
|
|
||||||
Values []interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRawParams creates RawParams from its parameters.
|
|
||||||
func NewRawParams(vals ...interface{}) RawParams {
|
|
||||||
p := RawParams{}
|
|
||||||
p.Values = make([]interface{}, len(vals))
|
|
||||||
for i := 0; i < len(p.Values); i++ {
|
|
||||||
p.Values[i] = vals[i]
|
|
||||||
}
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Raw represents JSON-RPC request. It's generic enough to be used in many
|
// Raw represents JSON-RPC request. It's generic enough to be used in many
|
||||||
// generic JSON-RPC communication scenarios, yet at the same time it's
|
// generic JSON-RPC communication scenarios, yet at the same time it's
|
||||||
|
|
|
@ -3,7 +3,6 @@ package rpcbroadcaster
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
type RPCBroadcaster struct {
|
type RPCBroadcaster struct {
|
||||||
Clients map[string]*RPCClient
|
Clients map[string]*RPCClient
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
Responses chan request.RawParams
|
Responses chan []interface{}
|
||||||
|
|
||||||
close chan struct{}
|
close chan struct{}
|
||||||
finished chan struct{}
|
finished chan struct{}
|
||||||
|
@ -25,7 +24,7 @@ func NewRPCBroadcaster(log *zap.Logger, sendTimeout time.Duration) *RPCBroadcast
|
||||||
Log: log,
|
Log: log,
|
||||||
close: make(chan struct{}),
|
close: make(chan struct{}),
|
||||||
finished: make(chan struct{}),
|
finished: make(chan struct{}),
|
||||||
Responses: make(chan request.RawParams),
|
Responses: make(chan []interface{}),
|
||||||
sendTimeout: sendTimeout,
|
sendTimeout: sendTimeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +65,7 @@ drain:
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendParams sends a request using all clients if the broadcaster is active.
|
// SendParams sends a request using all clients if the broadcaster is active.
|
||||||
func (r *RPCBroadcaster) SendParams(params request.RawParams) {
|
func (r *RPCBroadcaster) SendParams(params []interface{}) {
|
||||||
select {
|
select {
|
||||||
case <-r.close:
|
case <-r.close:
|
||||||
case r.Responses <- params:
|
case r.Responses <- params:
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,17 +14,17 @@ type RPCClient struct {
|
||||||
addr string
|
addr string
|
||||||
close chan struct{}
|
close chan struct{}
|
||||||
finished chan struct{}
|
finished chan struct{}
|
||||||
responses chan request.RawParams
|
responses chan []interface{}
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
sendTimeout time.Duration
|
sendTimeout time.Duration
|
||||||
method SendMethod
|
method SendMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMethod represents an rpc method for sending data to other nodes.
|
// SendMethod represents an rpc method for sending data to other nodes.
|
||||||
type SendMethod func(*client.Client, request.RawParams) error
|
type SendMethod func(*client.Client, []interface{}) error
|
||||||
|
|
||||||
// NewRPCClient returns a new rpc client for the provided address and method.
|
// NewRPCClient returns a new rpc client for the provided address and method.
|
||||||
func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan request.RawParams) *RPCClient {
|
func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan []interface{}) *RPCClient {
|
||||||
return &RPCClient{
|
return &RPCClient{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
close: r.close,
|
close: r.close,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/helpers/rpcbroadcaster"
|
"github.com/nspcc-dev/neo-go/pkg/services/helpers/rpcbroadcaster"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -35,7 +34,7 @@ func New(cfg config.OracleConfiguration, log *zap.Logger) oracle.Broadcaster {
|
||||||
}
|
}
|
||||||
for i := range cfg.Nodes {
|
for i := range cfg.Nodes {
|
||||||
r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*client.Client).SubmitRawOracleResponse,
|
r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*client.Client).SubmitRawOracleResponse,
|
||||||
cfg.ResponseTimeout, make(chan request.RawParams, defaultChanCapacity))
|
cfg.ResponseTimeout, make(chan []interface{}, defaultChanCapacity))
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -45,12 +44,12 @@ func (r *oracleBroadcaster) SendResponse(priv *keys.PrivateKey, resp *transactio
|
||||||
pub := priv.PublicKey()
|
pub := priv.PublicKey()
|
||||||
data := GetMessage(pub.Bytes(), resp.ID, txSig)
|
data := GetMessage(pub.Bytes(), resp.ID, txSig)
|
||||||
msgSig := priv.Sign(data)
|
msgSig := priv.Sign(data)
|
||||||
params := request.NewRawParams(
|
params := []interface{}{
|
||||||
base64.StdEncoding.EncodeToString(pub.Bytes()),
|
base64.StdEncoding.EncodeToString(pub.Bytes()),
|
||||||
resp.ID,
|
resp.ID,
|
||||||
base64.StdEncoding.EncodeToString(txSig),
|
base64.StdEncoding.EncodeToString(txSig),
|
||||||
base64.StdEncoding.EncodeToString(msgSig),
|
base64.StdEncoding.EncodeToString(msgSig),
|
||||||
)
|
}
|
||||||
r.SendParams(params)
|
r.SendParams(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue