From b98fab6b3837781e56b43da2e7c676681ccf5873 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 18 Jan 2022 14:56:17 +0300 Subject: [PATCH] rpc: refactor `findstates` client wrapper 1. Use empty `prefix` instead of nil `preifx` in order to avoid RPC server exceptions. 2. Allow to omit `start` parameter` if `maxCount` is not specified. 3. Use empty `start` instead of nil `start` to avoid RPC server exceptions. --- pkg/rpc/client/rpc.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index a17e3a19a..086876070 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -458,10 +458,19 @@ func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Ui // If `maxCount` specified, then maximum number of items to be returned equals to `maxCount`. func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, historicalPrefix []byte, start []byte, maxCount *int) (result.FindStates, error) { + if historicalPrefix == nil { + historicalPrefix = []byte{} + } var ( - params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix, start) + params = request.NewRawParams(stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix) resp result.FindStates ) + if start == nil && maxCount != nil { + start = []byte{} + } + if start != nil { + params.Values = append(params.Values, start) + } if maxCount != nil { params.Values = append(params.Values, *maxCount) }