forked from TrueCloudLab/neoneo-go
cli: support Null as an argument for invocation-related commands
This commit is contained in:
parent
7eb87afab8
commit
af658bc3e5
3 changed files with 18 additions and 1 deletions
|
@ -32,7 +32,8 @@ const (
|
|||
'signature', 'bool', 'int', 'hash160', 'hash256', 'bytes', 'key' or 'string'.
|
||||
Array types are also supported: use special space-separated '[' and ']'
|
||||
symbols around array values to denote array bounds. Nested arrays are also
|
||||
supported.
|
||||
supported. Null parameter is supported via 'nil' keyword without additional
|
||||
type specification.
|
||||
|
||||
There is ability to provide an argument of 'bytearray' type via file. Use a
|
||||
special 'filebytes' argument type for this with a filepath specified after
|
||||
|
@ -60,6 +61,8 @@ const (
|
|||
following logic:
|
||||
- anything that can be interpreted as a decimal integer gets
|
||||
an 'int' type
|
||||
- 'nil' string gets 'Any' NEP-14 parameter type and nil value which corresponds
|
||||
to Null stackitem
|
||||
- 'true' and 'false' strings get 'bool' type
|
||||
- valid Neo addresses and 20 bytes long hex-encoded strings get 'hash160'
|
||||
type
|
||||
|
@ -76,6 +79,7 @@ const (
|
|||
Examples:
|
||||
* 'int:42' is an integer with a value of 42
|
||||
* '42' is an integer with a value of 42
|
||||
* 'nil' is a parameter with Any NEP-14 type and nil value (corresponds to Null stackitem)
|
||||
* 'bad' is a string with a value of 'bad'
|
||||
* 'dead' is a byte array with a value of 'dead'
|
||||
* 'string:dead' is a string with a value of 'dead'
|
||||
|
|
|
@ -327,6 +327,8 @@ func adjustValToType(typ ParamType, val string) (interface{}, error) {
|
|||
return pub.Bytes(), nil
|
||||
case StringType:
|
||||
return val, nil
|
||||
case AnyType:
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, errors.New("unsupported parameter type")
|
||||
}
|
||||
|
@ -347,6 +349,10 @@ func inferParamType(val string) ParamType {
|
|||
return IntegerType
|
||||
}
|
||||
|
||||
if val == "nil" {
|
||||
return AnyType
|
||||
}
|
||||
|
||||
if val == "true" || val == "false" {
|
||||
return BoolType
|
||||
}
|
||||
|
|
|
@ -155,6 +155,9 @@ func TestInferParamType(t *testing.T) {
|
|||
}, {
|
||||
in: "dead",
|
||||
out: ByteArrayType,
|
||||
}, {
|
||||
in: "nil",
|
||||
out: AnyType,
|
||||
}}
|
||||
for _, inout := range inouts {
|
||||
out := inferParamType(inout.in)
|
||||
|
@ -323,6 +326,10 @@ func TestAdjustValToType(t *testing.T) {
|
|||
typ: InteropInterfaceType,
|
||||
val: "",
|
||||
err: true,
|
||||
}, {
|
||||
typ: AnyType,
|
||||
val: "nil",
|
||||
out: nil,
|
||||
}}
|
||||
|
||||
for _, inout := range inouts {
|
||||
|
|
Loading…
Reference in a new issue