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:
Roman Khimov 2022-07-07 20:03:10 +03:00
parent 113cb0fac3
commit 9462ed71d8
7 changed files with 124 additions and 158 deletions

View file

@ -172,11 +172,14 @@ func (c *Client) Close() {
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{
JSONRPC: request.JSONRPCVersion,
Method: method,
Params: p.Values,
Params: p,
ID: c.getNextRequestID(),
}

View file

@ -38,7 +38,7 @@ var errNetworkNotInitialized = errors.New("RPC client network is not initialized
// filled for standard sig/multisig signers.
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
var (
params = request.NewRawParams(tx.Bytes())
params = []interface{}{tx.Bytes()}
resp = new(result.NetworkFee)
)
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.
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) {
var (
params = request.NewRawParams(hash.StringLE())
params = []interface{}{hash.StringLE()}
resp = new(result.ApplicationLog)
)
if trig != nil {
params.Values = append(params.Values, trig.String())
params = append(params, trig.String())
}
if err := c.performRequest("getapplicationlog", params, resp); err != nil {
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.
func (c *Client) GetBestBlockHash() (util.Uint256, error) {
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, nil
@ -74,7 +74,7 @@ func (c *Client) GetBestBlockHash() (util.Uint256, error) {
// GetBlockCount returns the number of blocks in the blockchain.
func (c *Client) GetBlockCount() (uint32, error) {
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, nil
@ -83,22 +83,22 @@ func (c *Client) GetBlockCount() (uint32, error) {
// GetBlockByIndex returns a block by its height. You should initialize network magic
// with Init before calling GetBlockByIndex.
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
// with Init before calling GetBlockByHash.
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 (
resp []byte
err error
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
}
r := io.NewBinReaderFromBuf(resp)
@ -118,19 +118,20 @@ func (c *Client) getBlock(params request.RawParams) (*block.Block, error) {
// 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.
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
// its hash. You should initialize network magic with Init before calling GetBlockByHashVerbose.
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 (
resp = &result.Block{}
err error
params = []interface{}{param, 1} // 1 for verbose.
resp = &result.Block{}
err error
)
sr, err := c.StateRootInHeader()
if err != nil {
@ -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.
func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
var (
params = request.NewRawParams(index)
params = []interface{}{index}
resp = util.Uint256{}
)
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.
func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
var (
params = request.NewRawParams(hash.StringLE())
params = []interface{}{hash.StringLE()}
resp []byte
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.
func (c *Client) GetBlockHeaderCount() (uint32, error) {
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, nil
@ -194,7 +195,7 @@ func (c *Client) GetBlockHeaderCount() (uint32, error) {
// according to the specified script hash.
func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) {
var (
params = request.NewRawParams(hash.StringLE(), 1)
params = []interface{}{hash.StringLE(), 1}
resp = &result.Header{}
)
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.
func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) {
var (
params = request.NewRawParams(index)
params = []interface{}{index}
resp fixedn.Fixed8
)
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.
func (c *Client) GetConnectionCount() (int, error) {
var (
params = request.NewRawParams()
resp int
)
if err := c.performRequest("getconnectioncount", params, &resp); err != nil {
var resp int
if err := c.performRequest("getconnectioncount", nil, &resp); err != nil {
return resp, err
}
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.
func (c *Client) GetCommittee() (keys.PublicKeys, error) {
var (
params = request.NewRawParams()
resp = new(keys.PublicKeys)
)
if err := c.performRequest("getcommittee", params, resp); err != nil {
var resp = new(keys.PublicKeys)
if err := c.performRequest("getcommittee", nil, resp); err != nil {
return nil, err
}
return *resp, nil
@ -257,7 +254,7 @@ func (c *Client) GetContractStateByID(id int32) (*state.Contract, error) {
// getContractState is an internal representation of GetContractStateBy* methods.
func (c *Client) getContractState(param interface{}) (*state.Contract, error) {
var (
params = request.NewRawParams(param)
params = []interface{}{param}
resp = &state.Contract{}
)
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.
func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
var (
params = request.NewRawParams()
resp []state.NativeContract
)
if err := c.performRequest("getnativecontracts", params, &resp); err != nil {
var resp []state.NativeContract
if err := c.performRequest("getnativecontracts", nil, &resp); err != nil {
return resp, err
}
@ -288,7 +282,7 @@ func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
// GetNEP11Balances is a wrapper for getnep11balances RPC.
func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error) {
params := request.NewRawParams(address.StringLE())
params := []interface{}{address.StringLE()}
resp := new(result.NEP11Balances)
if err := c.performRequest("getnep11balances", params, resp); err != nil {
return nil, err
@ -298,7 +292,7 @@ func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances,
// GetNEP17Balances is a wrapper for getnep17balances RPC.
func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error) {
params := request.NewRawParams(address.StringLE())
params := []interface{}{address.StringLE()}
resp := new(result.NEP17Balances)
if err := c.performRequest("getnep17balances", params, resp); err != nil {
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,
// while for all others []byte (which can be nil).
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{})
if err := c.performRequest("getnep11properties", params, &resp); err != nil {
return nil, err
@ -346,22 +340,22 @@ func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, li
return nil, err
}
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 resp, nil
}
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) (*request.RawParams, error) {
params := request.NewRawParams(address.StringLE())
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) ([]interface{}, error) {
params := []interface{}{address.StringLE()}
if start != nil {
params.Values = append(params.Values, *start)
params = append(params, *start)
if stop != nil {
params.Values = append(params.Values, *stop)
params = append(params, *stop)
if limit != nil {
params.Values = append(params.Values, *limit)
params = append(params, *limit)
if page != nil {
params.Values = append(params.Values, *page)
params = append(params, *page)
}
} else if page != nil {
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 {
return nil, errors.New("bad parameters")
}
return &params, nil
return params, nil
}
// 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
}
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 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.
func (c *Client) GetPeers() (*result.GetPeers, error) {
var (
params = request.NewRawParams()
resp = &result.GetPeers{}
)
if err := c.performRequest("getpeers", params, resp); err != nil {
var resp = &result.GetPeers{}
if err := c.performRequest("getpeers", nil, resp); err != nil {
return resp, err
}
return resp, nil
@ -406,11 +398,9 @@ func (c *Client) GetPeers() (*result.GetPeers, error) {
// GetRawMemPool returns a list of unconfirmed transactions in the memory.
func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
var (
params = request.NewRawParams()
resp = new([]util.Uint256)
)
if err := c.performRequest("getrawmempool", params, resp); err != nil {
var resp = new([]util.Uint256)
if err := c.performRequest("getrawmempool", nil, resp); err != nil {
return *resp, err
}
return *resp, nil
@ -419,7 +409,7 @@ func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
// GetRawTransaction returns a transaction by hash.
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
var (
params = request.NewRawParams(hash.StringLE())
params = []interface{}{hash.StringLE()}
resp []byte
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.
func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) {
var (
params = request.NewRawParams(hash.StringLE(), 1)
params = []interface{}{hash.StringLE(), 1} // 1 for verbose.
resp = &result.TransactionOutputRaw{}
err error
)
@ -452,7 +442,7 @@ func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.Transactio
// historical contract hash and historical item key.
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error) {
var (
params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey)
params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey}
resp []byte
)
if err := c.performRequest("getstate", params, &resp); err != nil {
@ -471,17 +461,17 @@ func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.
historicalPrefix = []byte{}
}
var (
params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix)
params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix}
resp result.FindStates
)
if start == nil && maxCount != nil {
start = []byte{}
}
if start != nil {
params.Values = append(params.Values, start)
params = append(params, start)
}
if maxCount != nil {
params.Values = append(params.Values, *maxCount)
params = append(params, *maxCount)
}
if err := c.performRequest("findstates", params, &resp); err != nil {
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.
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.
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)
if err := c.performRequest("getstateroot", params, resp); err != nil {
if err := c.performRequest("getstateroot", []interface{}{param}, resp); err != nil {
return nil, err
}
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.
func (c *Client) GetStateHeight() (*result.StateHeight, error) {
var (
params = request.NewRawParams()
resp = new(result.StateHeight)
)
if err := c.performRequest("getstateheight", params, resp); err != nil {
var resp = new(result.StateHeight)
if err := c.performRequest("getstateheight", nil, resp); err != nil {
return nil, err
}
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.
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.
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
if err := c.performRequest("getstorage", params, &resp); err != nil {
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.
func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) {
var (
params = request.NewRawParams(hash.StringLE())
params = []interface{}{hash.StringLE()}
resp uint32
)
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.
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
var (
params = request.NewRawParams(address)
params = []interface{}{address}
resp result.UnclaimedGas
)
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
// validator status.
func (c *Client) GetCandidates() ([]result.Candidate, error) {
var (
params = request.NewRawParams()
resp = new([]result.Candidate)
)
if err := c.performRequest("getcandidates", params, resp); err != nil {
var resp = new([]result.Candidate)
if err := c.performRequest("getcandidates", nil, resp); err != nil {
return nil, err
}
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.
func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
var (
params = request.NewRawParams()
resp = new([]result.Validator)
)
if err := c.performRequest("getnextblockvalidators", params, resp); err != nil {
var resp = new([]result.Validator)
if err := c.performRequest("getnextblockvalidators", nil, resp); err != nil {
return nil, err
}
return *resp, nil
@ -588,11 +572,9 @@ func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
// GetVersion returns the version information about the queried node.
func (c *Client) GetVersion() (*result.Version, error) {
var (
params = request.NewRawParams()
resp = &result.Version{}
)
if err := c.performRequest("getversion", params, resp); err != nil {
var resp = &result.Version{}
if err := c.performRequest("getversion", nil, resp); err != nil {
return nil, err
}
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.
// NOTE: This is a test invoke and will not affect the blockchain.
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)
}
@ -610,7 +592,7 @@ func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*res
// 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) {
var p = request.NewRawParams(height, script)
var p = []interface{}{height, script}
return c.invokeSomething("invokescripthistoric", p, signers)
}
@ -619,7 +601,7 @@ func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []tr
// hash.
// 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) {
var p = request.NewRawParams(blockHash.StringLE(), script)
var p = []interface{}{blockHash.StringLE(), script}
return c.invokeSomething("invokescripthistoric", p, signers)
}
@ -628,7 +610,7 @@ func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, sign
// stateroot hash.
// 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) {
var p = request.NewRawParams(stateroot.StringLE(), script)
var p = []interface{}{stateroot.StringLE(), script}
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.
// 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) {
var p = request.NewRawParams(contract.StringLE(), operation, params)
var p = []interface{}{contract.StringLE(), operation, params}
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.
// 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) {
var p = request.NewRawParams(height, contract.StringLE(), operation, params)
var p = []interface{}{height, contract.StringLE(), operation, params}
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.
// 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) {
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)
}
@ -663,7 +645,7 @@ func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uin
// by the specified stateroot hash.
// 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) {
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)
}
@ -671,7 +653,7 @@ func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.U
// 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) {
var p = request.NewRawParams(contract.StringLE(), params)
var p = []interface{}{contract.StringLE(), params}
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.
// 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) {
var p = request.NewRawParams(height, contract.StringLE(), params)
var p = []interface{}{height, contract.StringLE(), params}
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.
// 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) {
var p = request.NewRawParams(blockHash.StringLE(), contract.StringLE(), params)
var p = []interface{}{blockHash.StringLE(), contract.StringLE(), params}
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.
// 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) {
var p = request.NewRawParams(stateroot.StringLE(), contract.StringLE(), params)
var p = []interface{}{stateroot.StringLE(), contract.StringLE(), params}
return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...)
}
// 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)
if signers != nil {
if witnesses == nil {
p.Values = append(p.Values, signers)
p = append(p, signers)
} 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))
@ -719,7 +701,7 @@ func (c *Client) invokeSomething(method string, p request.RawParams, signers []t
Witness: witnesses[i],
}
}
p.Values = append(p.Values, signersWithWitnesses)
p = append(p, signersWithWitnesses)
}
}
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.
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) {
var (
params = request.NewRawParams(rawTX.Bytes())
params = []interface{}{rawTX.Bytes()}
resp = new(result.RelayResult)
)
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.
func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
var (
params request.RawParams
params []interface{}
resp = new(result.RelayResult)
)
buf := io.NewBufBinWriter()
@ -754,7 +736,7 @@ func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) {
if err := buf.Err; err != nil {
return util.Uint256{}, err
}
params = request.NewRawParams(buf.Bytes())
params = []interface{}{buf.Bytes()}
if err := c.performRequest("submitblock", params, resp); err != nil {
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.
// 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))
}
@ -997,7 +979,7 @@ func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uin
if err != nil {
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 {
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.
func (c *Client) ValidateAddress(address string) error {
var (
params = request.NewRawParams(address)
params = []interface{}{address}
resp = &result.ValidateAddress{}
)
@ -1161,7 +1143,7 @@ func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount
maxItemsCount = config.DefaultMaxIteratorResultItems
}
var (
params = request.NewRawParams(sessionID.String(), iteratorID.String(), maxItemsCount)
params = []interface{}{sessionID.String(), iteratorID.String(), maxItemsCount}
resp []json.RawMessage
)
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.
func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error) {
var resp bool
params := request.NewRawParams(sessionID.String())
params := []interface{}{sessionID.String()}
if err := c.performRequest("terminatesession", params, &resp); err != nil {
return false, err
}

View file

@ -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
if err := c.performRequest("subscribe", params, &resp); err != nil {
@ -338,7 +338,7 @@ func (c *WSClient) performUnsubscription(id string) error {
if !c.subscriptions[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
}
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
// add any filters.
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
params := request.NewRawParams("block_added")
params := []interface{}{"block_added"}
if primary != nil {
params.Values = append(params.Values, request.BlockFilter{Primary: *primary})
params = append(params, request.BlockFilter{Primary: *primary})
}
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
// value is treated as missing filter.
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 {
params.Values = append(params.Values, request.TxFilter{Sender: sender, Signer: signer})
params = append(params, request.TxFilter{Sender: sender, Signer: signer})
}
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
// restrictions.
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 {
params.Values = append(params.Values, request.NotificationFilter{Contract: contract, Name: name})
params = append(params, request.NotificationFilter{Contract: contract, Name: name})
}
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
// transactions, nil value means no filtering.
func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error) {
params := request.NewRawParams("transaction_executed")
params := []interface{}{"transaction_executed"}
if state != nil {
if *state != "HALT" && *state != "FAULT" {
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)
}
@ -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
// restrictions.
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 {
params.Values = append(params.Values, request.TxFilter{Sender: sender, Signer: mainSigner})
params = append(params, request.TxFilter{Sender: sender, Signer: mainSigner})
}
return c.performSubscription(params)
}
@ -421,7 +421,7 @@ func (c *WSClient) UnsubscribeAll() error {
for id := range c.subscriptions {
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
}
if !resp {

View file

@ -16,22 +16,6 @@ const (
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 (
// 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

View file

@ -3,7 +3,6 @@ package rpcbroadcaster
import (
"time"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"go.uber.org/zap"
)
@ -11,7 +10,7 @@ import (
type RPCBroadcaster struct {
Clients map[string]*RPCClient
Log *zap.Logger
Responses chan request.RawParams
Responses chan []interface{}
close chan struct{}
finished chan struct{}
@ -25,7 +24,7 @@ func NewRPCBroadcaster(log *zap.Logger, sendTimeout time.Duration) *RPCBroadcast
Log: log,
close: make(chan struct{}),
finished: make(chan struct{}),
Responses: make(chan request.RawParams),
Responses: make(chan []interface{}),
sendTimeout: sendTimeout,
}
}
@ -66,7 +65,7 @@ drain:
}
// 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 {
case <-r.close:
case r.Responses <- params:

View file

@ -5,7 +5,6 @@ import (
"time"
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"go.uber.org/zap"
)
@ -15,17 +14,17 @@ type RPCClient struct {
addr string
close chan struct{}
finished chan struct{}
responses chan request.RawParams
responses chan []interface{}
log *zap.Logger
sendTimeout time.Duration
method SendMethod
}
// 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.
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{
addr: addr,
close: r.close,

View file

@ -9,7 +9,6 @@ import (
"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/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/oracle"
"go.uber.org/zap"
@ -35,7 +34,7 @@ func New(cfg config.OracleConfiguration, log *zap.Logger) oracle.Broadcaster {
}
for i := range cfg.Nodes {
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
}
@ -45,12 +44,12 @@ func (r *oracleBroadcaster) SendResponse(priv *keys.PrivateKey, resp *transactio
pub := priv.PublicKey()
data := GetMessage(pub.Bytes(), resp.ID, txSig)
msgSig := priv.Sign(data)
params := request.NewRawParams(
params := []interface{}{
base64.StdEncoding.EncodeToString(pub.Bytes()),
resp.ID,
base64.StdEncoding.EncodeToString(txSig),
base64.StdEncoding.EncodeToString(msgSig),
)
}
r.SendParams(params)
}