rpc: support 0x form of Uint256 in requests

This commit is contained in:
Evgenii Stratonikov 2020-08-27 12:07:02 +03:00
parent b4bcd23c0f
commit db4eecf4dc
2 changed files with 7 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/address"
@ -137,7 +138,7 @@ func (p *Param) GetUint256() (util.Uint256, error) {
return util.Uint256{}, err 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. // GetUint160FromHex returns Uint160 value of the parameter encoded in hex.

View file

@ -173,6 +173,11 @@ func TestParamGetUint256(t *testing.T) {
assert.Equal(t, u256, u) assert.Equal(t, u256, u)
require.Nil(t, err) 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} p = Param{StringT, 42}
_, err = p.GetUint256() _, err = p.GetUint256()
require.NotNil(t, err) require.NotNil(t, err)