From aa2dbe9caf844976a665b6501375daf0ed0b570f Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 6 Aug 2022 13:16:07 +0300 Subject: [PATCH] smartcontract: accept Parameter in NewParameterFromValue While it makes little sense, there can be a situation where this function will get predefined Parameters in some way. --- pkg/smartcontract/parameter.go | 9 +++++++++ pkg/smartcontract/parameter_test.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/smartcontract/parameter.go b/pkg/smartcontract/parameter.go index e4496fd20..dbd3c5342 100644 --- a/pkg/smartcontract/parameter.go +++ b/pkg/smartcontract/parameter.go @@ -303,6 +303,10 @@ func NewParameterFromValue(value interface{}) (Parameter, error) { case uint64: result.Type = IntegerType result.Value = new(big.Int).SetUint64(v) + case *Parameter: + result = *v + case Parameter: + result = v case util.Uint160: result.Type = Hash160Type case util.Uint256: @@ -321,6 +325,11 @@ func NewParameterFromValue(value interface{}) (Parameter, error) { } result.Type = ArrayType result.Value = arr + case []Parameter: + arr := make([]Parameter, len(v)) + copy(arr, v) + result.Type = ArrayType + result.Value = arr case []*keys.PublicKey: return NewParameterFromValue(keys.PublicKeys(v)) case keys.PublicKeys: diff --git a/pkg/smartcontract/parameter_test.go b/pkg/smartcontract/parameter_test.go index 181901876..72b1070f7 100644 --- a/pkg/smartcontract/parameter_test.go +++ b/pkg/smartcontract/parameter_test.go @@ -616,6 +616,16 @@ func TestParameterFromValue(t *testing.T) { expType: IntegerType, expVal: big.NewInt(100), }, + { + value: Parameter{ByteArrayType, []byte{1, 2, 3}}, + expType: ByteArrayType, + expVal: []byte{1, 2, 3}, + }, + { + value: &Parameter{ByteArrayType, []byte{1, 2, 3}}, + expType: ByteArrayType, + expVal: []byte{1, 2, 3}, + }, { value: util.Uint160{1, 2, 3}, expType: Hash160Type, @@ -641,6 +651,11 @@ func TestParameterFromValue(t *testing.T) { expType: ArrayType, expVal: []Parameter{{ByteArrayType, []byte{1, 2, 3}}, {ByteArrayType, []byte{3, 2, 1}}}, }, + { + value: []Parameter{{ByteArrayType, []byte{1, 2, 3}}, {ByteArrayType, []byte{3, 2, 1}}}, + expType: ArrayType, + expVal: []Parameter{{ByteArrayType, []byte{1, 2, 3}}, {ByteArrayType, []byte{3, 2, 1}}}, + }, { value: []*keys.PublicKey{pk1.PublicKey(), pk2.PublicKey()}, expType: ArrayType,