From f1145c89436957c0e35d0a7050575c465ed4767d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 18 Nov 2021 17:00:48 +0300 Subject: [PATCH] rpc/client: accept address as util.Uint160 in GetNEPXXTransfers We're using proper util.Uint160 values everywhere in the client. --- pkg/rpc/client/rpc.go | 8 ++++---- pkg/rpc/client/rpc_test.go | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index da10e46d5..fbf26ca4d 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -323,7 +323,7 @@ func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[strin // GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter // is mandatory, while all the others are optional. Limit and page parameters are // only supported by NeoGo servers and can only be specified with start and stop. -func (c *Client) GetNEP11Transfers(address string, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error) { +func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error) { params, err := packTransfersParams(address, start, stop, limit, page) if err != nil { return nil, err @@ -335,8 +335,8 @@ func (c *Client) GetNEP11Transfers(address string, start, stop *uint64, limit, p return resp, nil } -func packTransfersParams(address string, start, stop *uint64, limit, page *int) (*request.RawParams, error) { - params := request.NewRawParams(address) +func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) (*request.RawParams, error) { + params := request.NewRawParams(address.StringLE()) if start != nil { params.Values = append(params.Values, *start) if stop != nil { @@ -363,7 +363,7 @@ func packTransfersParams(address string, start, stop *uint64, limit, page *int) // 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) GetNEP17Transfers(address string, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error) { +func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error) { params, err := packTransfersParams(address, start, stop, limit, page) if err != nil { return nil, err diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index a7a58a47d..c4041c353 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -613,7 +613,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ { name: "positive", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP11Transfers("NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe", nil, nil, nil, nil) + hash, err := address.StringToUint160("NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe") + if err != nil { + panic(err) + } + return c.GetNEP11Transfers(hash, nil, nil, nil, nil) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"assethash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transferaddress":"NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP","amount":"1","tokenid":"abcdef","blockindex":436036,"transfernotifyindex":0,"txhash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe"}}`, result: func(c *Client) interface{} { @@ -648,9 +652,13 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ { name: "positive", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP17Transfers("AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF", nil, nil, nil, nil) + hash, err := address.StringToUint160("NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe") + if err != nil { + panic(err) + } + return c.GetNEP17Transfers(hash, nil, nil, nil, nil) }, - serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"assethash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transferaddress":"AYwgBNMepiv5ocGcyNT4mA8zPLTQ8pDBis","amount":"1000000","blockindex":436036,"transfernotifyindex":0,"txhash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF"}}`, + serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"assethash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transferaddress":"AYwgBNMepiv5ocGcyNT4mA8zPLTQ8pDBis","amount":"1000000","blockindex":436036,"transfernotifyindex":0,"txhash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe"}}`, result: func(c *Client) interface{} { assetHash, err := util.Uint160DecodeStringLE("600c4f5200db36177e3e8a09e9f18e2fc7d12a0f") if err != nil { @@ -673,7 +681,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ TxHash: txHash, }, }, - Address: "AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF", + Address: "NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe", } }, }, @@ -1351,20 +1359,20 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ { name: "getnep11transfers_invalid_params_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP11Transfers("", nil, nil, nil, nil) + return c.GetNEP11Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_invalid_params_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP17Transfers("", nil, nil, nil, nil) + return c.GetNEP17Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_invalid_params_error 2", invoke: func(c *Client) (interface{}, error) { var stop uint64 - return c.GetNEP17Transfers("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", nil, &stop, nil, nil) + return c.GetNEP17Transfers(util.Uint160{}, nil, &stop, nil, nil) }, }, { @@ -1372,7 +1380,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ invoke: func(c *Client) (interface{}, error) { var start uint64 var limit int - return c.GetNEP17Transfers("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", &start, nil, &limit, nil) + return c.GetNEP17Transfers(util.Uint160{}, &start, nil, &limit, nil) }, }, { @@ -1380,7 +1388,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ invoke: func(c *Client) (interface{}, error) { var start, stop uint64 var page int - return c.GetNEP17Transfers("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", &start, &stop, nil, &page) + return c.GetNEP17Transfers(util.Uint160{}, &start, &stop, nil, &page) }, }, { @@ -1550,13 +1558,13 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ { name: "getnep11transfers_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP11Transfers("", nil, nil, nil, nil) + return c.GetNEP11Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_unmarshalling_error", invoke: func(c *Client) (interface{}, error) { - return c.GetNEP17Transfers("", nil, nil, nil, nil) + return c.GetNEP17Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, {