smartcontract: make *util.Uint160 and *util.Uint256 usable for parameters

Use Any type for NULL.
This commit is contained in:
Roman Khimov 2022-09-07 22:35:45 +03:00
parent 1e54b422cd
commit 4fb4f5a1ac
2 changed files with 35 additions and 2 deletions

View file

@ -311,6 +311,18 @@ func NewParameterFromValue(value interface{}) (Parameter, error) {
result.Type = Hash160Type
case util.Uint256:
result.Type = Hash256Type
case *util.Uint160:
if v != nil {
return NewParameterFromValue(*v)
}
result.Type = AnyType
result.Value = nil
case *util.Uint256:
if v != nil {
return NewParameterFromValue(*v)
}
result.Type = AnyType
result.Value = nil
case keys.PublicKey:
return NewParameterFromValue(&v)
case *keys.PublicKey:
@ -387,7 +399,7 @@ func ExpandParameterToEmitable(param Parameter) (interface{}, error) {
}
}
return res, nil
case MapType, InteropInterfaceType, UnknownType, AnyType, VoidType:
case MapType, InteropInterfaceType, UnknownType, VoidType:
return nil, fmt.Errorf("unsupported parameter type: %s", t.String())
default:
return param.Value, nil

View file

@ -484,6 +484,10 @@ func TestExpandParameterToEmitable(t *testing.T) {
In: Parameter{Type: SignatureType, Value: []byte{1, 2, 3}},
Expected: []byte{1, 2, 3},
},
{
In: Parameter{Type: AnyType},
Expected: nil,
},
{
In: Parameter{Type: ArrayType, Value: []Parameter{
{
@ -517,7 +521,6 @@ func TestExpandParameterToEmitable(t *testing.T) {
require.NoError(t, bw.Err)
}
errCases := []Parameter{
{Type: AnyType},
{Type: UnknownType},
{Type: MapType},
{Type: InteropInterfaceType},
@ -636,6 +639,24 @@ func TestParameterFromValue(t *testing.T) {
expType: Hash256Type,
expVal: util.Uint256{3, 2, 1},
},
{
value: (*util.Uint160)(nil),
expType: AnyType,
},
{
value: &util.Uint160{1, 2, 3},
expType: Hash160Type,
expVal: util.Uint160{1, 2, 3},
},
{
value: (*util.Uint256)(nil),
expType: AnyType,
},
{
value: &util.Uint256{3, 2, 1},
expType: Hash256Type,
expVal: util.Uint256{3, 2, 1},
},
{
value: pk1.PublicKey(),
expType: PublicKeyType,