From 26d4a05e576e1d8014eaf83e79b2ae6748bb73e7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 14 Sep 2020 22:12:49 +0300 Subject: [PATCH] rpc/client: update GetNEP5Transfers call --- pkg/rpc/client/rpc.go | 26 ++++++++++++++++++++++++-- pkg/rpc/client/rpc_test.go | 6 +++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index 6baf4a510..a4fc86dd0 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -245,9 +245,31 @@ func (c *Client) GetNEP5Balances(address util.Uint160) (*result.NEP5Balances, er return resp, nil } -// GetNEP5Transfers is a wrapper for getnep5transfers RPC. -func (c *Client) GetNEP5Transfers(address string) (*result.NEP5Transfers, error) { +// GetNEP5Transfers is a wrapper for getnep5transfers RPC. Address parameter +// is mandatory, while all the others are optional. Start and stop parameters +// are supported since neo-go 0.77.0 and limit and page since neo-go 0.78.0. +// These parameters are positional in the JSON-RPC call, you can't specify limit +// and not specify start/stop for example. +func (c *Client) GetNEP5Transfers(address string, start, stop *uint32, limit, page *int) (*result.NEP5Transfers, error) { params := request.NewRawParams(address) + if start != nil { + params.Values = append(params.Values, *start) + if stop != nil { + params.Values = append(params.Values, *stop) + if limit != nil { + params.Values = append(params.Values, *limit) + if page != nil { + params.Values = append(params.Values, *page) + } + } else if page != nil { + return nil, errors.New("bad parameters") + } + } else if limit != nil || page != nil { + return nil, errors.New("bad parameters") + } + } else if stop != nil || limit != nil || page != nil { + return nil, errors.New("bad parameters") + } resp := new(result.NEP5Transfers) if err := c.performRequest("getnep5transfers", params, resp); err != nil { return nil, err diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index dbe8cba23..8369f2fb2 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -481,7 +481,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ { name: "positive", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP5Transfers("AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF") + return c.GetNEP5Transfers("AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF", nil, nil, nil, nil) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"asset_hash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transfer_address":"AYwgBNMepiv5ocGcyNT4mA8zPLTQ8pDBis","amount":"1000000","block_index":436036,"transfer_notify_index":0,"tx_hash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF"}}`, result: func(c *Client) interface{} { @@ -1138,7 +1138,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ { name: "getnep5transfers_invalid_params_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP5Transfers("") + return c.GetNEP5Transfers("", nil, nil, nil, nil) }, }, { @@ -1320,7 +1320,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ { name: "getnep5transfers_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP5Transfers("") + return c.GetNEP5Transfers("", nil, nil, nil, nil) }, }, {