From 8ff2d35723683a4c4150e236bd4063f09213aa44 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 27 Aug 2020 12:07:02 +0300 Subject: [PATCH] rpc: support 0x form of Uint256 in requests --- pkg/rpc/request/param.go | 3 ++- pkg/rpc/request/param_test.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/request/param.go b/pkg/rpc/request/param.go index cd78a1078..92cd23c85 100644 --- a/pkg/rpc/request/param.go +++ b/pkg/rpc/request/param.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "strconv" + "strings" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" @@ -127,7 +128,7 @@ func (p *Param) GetUint256() (util.Uint256, error) { return util.Uint256{}, err } - return util.Uint256DecodeStringLE(s) + return util.Uint256DecodeStringLE(strings.TrimPrefix(s, "0x")) } // GetUint160FromHex returns Uint160 value of the parameter encoded in hex. diff --git a/pkg/rpc/request/param_test.go b/pkg/rpc/request/param_test.go index feaee36a7..91312f278 100644 --- a/pkg/rpc/request/param_test.go +++ b/pkg/rpc/request/param_test.go @@ -123,6 +123,11 @@ func TestParamGetUint256(t *testing.T) { assert.Equal(t, u256, u) require.Nil(t, err) + p = Param{StringT, "0x" + gas} + u, err = p.GetUint256() + require.NoError(t, err) + assert.Equal(t, u256, u) + p = Param{StringT, 42} _, err = p.GetUint256() require.NotNil(t, err)