rpc/client: accept address as util.Uint160 in GetNEPXXTransfers
We're using proper util.Uint160 values everywhere in the client.
This commit is contained in:
parent
ce9d0b22cf
commit
f1145c8943
2 changed files with 23 additions and 15 deletions
|
@ -323,7 +323,7 @@ func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[strin
|
||||||
// GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter
|
// GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter
|
||||||
// is mandatory, while all the others are optional. Limit and page parameters are
|
// 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.
|
// 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)
|
params, err := packTransfersParams(address, start, stop, limit, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -335,8 +335,8 @@ func (c *Client) GetNEP11Transfers(address string, start, stop *uint64, limit, p
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func packTransfersParams(address string, start, stop *uint64, limit, page *int) (*request.RawParams, error) {
|
func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) (*request.RawParams, error) {
|
||||||
params := request.NewRawParams(address)
|
params := request.NewRawParams(address.StringLE())
|
||||||
if start != nil {
|
if start != nil {
|
||||||
params.Values = append(params.Values, *start)
|
params.Values = append(params.Values, *start)
|
||||||
if stop != nil {
|
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.
|
// 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
|
// These parameters are positional in the JSON-RPC call, you can't specify limit
|
||||||
// and not specify start/stop for example.
|
// 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)
|
params, err := packTransfersParams(address, start, stop, limit, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -613,7 +613,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
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"}}`,
|
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{} {
|
result: func(c *Client) interface{} {
|
||||||
|
@ -648,9 +652,13 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
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{} {
|
result: func(c *Client) interface{} {
|
||||||
assetHash, err := util.Uint160DecodeStringLE("600c4f5200db36177e3e8a09e9f18e2fc7d12a0f")
|
assetHash, err := util.Uint160DecodeStringLE("600c4f5200db36177e3e8a09e9f18e2fc7d12a0f")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -673,7 +681,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
TxHash: txHash,
|
TxHash: txHash,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Address: "AbHgdBaWEnHkCiLtDZXjhvhaAK2cwFh5pF",
|
Address: "NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1351,20 +1359,20 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
{
|
{
|
||||||
name: "getnep11transfers_invalid_params_error",
|
name: "getnep11transfers_invalid_params_error",
|
||||||
invoke: func(c *Client) (interface{}, 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",
|
name: "getnep17transfers_invalid_params_error",
|
||||||
invoke: func(c *Client) (interface{}, 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",
|
name: "getnep17transfers_invalid_params_error 2",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
var stop uint64
|
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) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
var start uint64
|
var start uint64
|
||||||
var limit int
|
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) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
var start, stop uint64
|
var start, stop uint64
|
||||||
var page int
|
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",
|
name: "getnep11transfers_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, 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",
|
name: "getnep17transfers_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetNEP17Transfers("", nil, nil, nil, nil)
|
return c.GetNEP17Transfers(util.Uint160{}, nil, nil, nil, nil)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue