forked from TrueCloudLab/neoneo-go
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.
This commit is contained in:
parent
c0705e45c9
commit
aa2dbe9caf
2 changed files with 24 additions and 0 deletions
|
@ -303,6 +303,10 @@ func NewParameterFromValue(value interface{}) (Parameter, error) {
|
||||||
case uint64:
|
case uint64:
|
||||||
result.Type = IntegerType
|
result.Type = IntegerType
|
||||||
result.Value = new(big.Int).SetUint64(v)
|
result.Value = new(big.Int).SetUint64(v)
|
||||||
|
case *Parameter:
|
||||||
|
result = *v
|
||||||
|
case Parameter:
|
||||||
|
result = v
|
||||||
case util.Uint160:
|
case util.Uint160:
|
||||||
result.Type = Hash160Type
|
result.Type = Hash160Type
|
||||||
case util.Uint256:
|
case util.Uint256:
|
||||||
|
@ -321,6 +325,11 @@ func NewParameterFromValue(value interface{}) (Parameter, error) {
|
||||||
}
|
}
|
||||||
result.Type = ArrayType
|
result.Type = ArrayType
|
||||||
result.Value = arr
|
result.Value = arr
|
||||||
|
case []Parameter:
|
||||||
|
arr := make([]Parameter, len(v))
|
||||||
|
copy(arr, v)
|
||||||
|
result.Type = ArrayType
|
||||||
|
result.Value = arr
|
||||||
case []*keys.PublicKey:
|
case []*keys.PublicKey:
|
||||||
return NewParameterFromValue(keys.PublicKeys(v))
|
return NewParameterFromValue(keys.PublicKeys(v))
|
||||||
case keys.PublicKeys:
|
case keys.PublicKeys:
|
||||||
|
|
|
@ -616,6 +616,16 @@ func TestParameterFromValue(t *testing.T) {
|
||||||
expType: IntegerType,
|
expType: IntegerType,
|
||||||
expVal: big.NewInt(100),
|
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},
|
value: util.Uint160{1, 2, 3},
|
||||||
expType: Hash160Type,
|
expType: Hash160Type,
|
||||||
|
@ -641,6 +651,11 @@ func TestParameterFromValue(t *testing.T) {
|
||||||
expType: ArrayType,
|
expType: ArrayType,
|
||||||
expVal: []Parameter{{ByteArrayType, []byte{1, 2, 3}}, {ByteArrayType, []byte{3, 2, 1}}},
|
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()},
|
value: []*keys.PublicKey{pk1.PublicKey(), pk2.PublicKey()},
|
||||||
expType: ArrayType,
|
expType: ArrayType,
|
||||||
|
|
Loading…
Reference in a new issue