forked from TrueCloudLab/neoneo-go
rpc/request: add (*Param).GetUint160FromAddressOrHex()
Allow to get address from both representations.
This commit is contained in:
parent
3f2f0be2c2
commit
62bb130ccb
2 changed files with 29 additions and 0 deletions
|
@ -163,6 +163,16 @@ func (p *Param) GetUint160FromAddress() (util.Uint160, error) {
|
||||||
return address.StringToUint160(s)
|
return address.StringToUint160(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUint160FromAddressOrHex returns Uint160 value of the parameter that was
|
||||||
|
// supplied either as raw hex or as an address.
|
||||||
|
func (p *Param) GetUint160FromAddressOrHex() (util.Uint160, error) {
|
||||||
|
u, err := p.GetUint160FromHex()
|
||||||
|
if err == nil {
|
||||||
|
return u, err
|
||||||
|
}
|
||||||
|
return p.GetUint160FromAddress()
|
||||||
|
}
|
||||||
|
|
||||||
// GetFuncParam returns current parameter as a function call parameter.
|
// GetFuncParam returns current parameter as a function call parameter.
|
||||||
func (p *Param) GetFuncParam() (FuncParam, error) {
|
func (p *Param) GetFuncParam() (FuncParam, error) {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
|
|
|
@ -205,6 +205,25 @@ func TestParamGetUint160FromAddress(t *testing.T) {
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParam_GetUint160FromAddressOrHex(t *testing.T) {
|
||||||
|
in := "NPAsqZkx9WhNd4P72uhZxBhLinSuNkxfB8"
|
||||||
|
inHex, _ := address.StringToUint160(in)
|
||||||
|
|
||||||
|
t.Run("Address", func(t *testing.T) {
|
||||||
|
p := Param{StringT, in}
|
||||||
|
u, err := p.GetUint160FromAddressOrHex()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, inHex, u)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Hex", func(t *testing.T) {
|
||||||
|
p := Param{StringT, inHex.StringLE()}
|
||||||
|
u, err := p.GetUint160FromAddressOrHex()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, inHex, u)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParamGetFuncParam(t *testing.T) {
|
func TestParamGetFuncParam(t *testing.T) {
|
||||||
fp := FuncParam{
|
fp := FuncParam{
|
||||||
Type: smartcontract.StringType,
|
Type: smartcontract.StringType,
|
||||||
|
|
Loading…
Reference in a new issue