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'.
|
'signature', 'bool', 'int', 'hash160', 'hash256', 'bytes', 'key' or 'string'.
|
||||||
Array types are also supported: use special space-separated '[' and ']'
|
Array types are also supported: use special space-separated '[' and ']'
|
||||||
symbols around array values to denote array bounds. Nested arrays are also
|
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
|
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
|
special 'filebytes' argument type for this with a filepath specified after
|
||||||
|
@ -60,6 +61,8 @@ const (
|
||||||
following logic:
|
following logic:
|
||||||
- anything that can be interpreted as a decimal integer gets
|
- anything that can be interpreted as a decimal integer gets
|
||||||
an 'int' type
|
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
|
- 'true' and 'false' strings get 'bool' type
|
||||||
- valid Neo addresses and 20 bytes long hex-encoded strings get 'hash160'
|
- valid Neo addresses and 20 bytes long hex-encoded strings get 'hash160'
|
||||||
type
|
type
|
||||||
|
@ -76,6 +79,7 @@ const (
|
||||||
Examples:
|
Examples:
|
||||||
* 'int:42' is an integer with a value of 42
|
* 'int:42' is an integer with a value of 42
|
||||||
* '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'
|
* 'bad' is a string with a value of 'bad'
|
||||||
* 'dead' is a byte array with a value of 'dead'
|
* 'dead' is a byte array with a value of 'dead'
|
||||||
* 'string:dead' is a string 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
|
return pub.Bytes(), nil
|
||||||
case StringType:
|
case StringType:
|
||||||
return val, nil
|
return val, nil
|
||||||
|
case AnyType:
|
||||||
|
return nil, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported parameter type")
|
return nil, errors.New("unsupported parameter type")
|
||||||
}
|
}
|
||||||
|
@ -347,6 +349,10 @@ func inferParamType(val string) ParamType {
|
||||||
return IntegerType
|
return IntegerType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val == "nil" {
|
||||||
|
return AnyType
|
||||||
|
}
|
||||||
|
|
||||||
if val == "true" || val == "false" {
|
if val == "true" || val == "false" {
|
||||||
return BoolType
|
return BoolType
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,9 @@ func TestInferParamType(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
in: "dead",
|
in: "dead",
|
||||||
out: ByteArrayType,
|
out: ByteArrayType,
|
||||||
|
}, {
|
||||||
|
in: "nil",
|
||||||
|
out: AnyType,
|
||||||
}}
|
}}
|
||||||
for _, inout := range inouts {
|
for _, inout := range inouts {
|
||||||
out := inferParamType(inout.in)
|
out := inferParamType(inout.in)
|
||||||
|
@ -323,6 +326,10 @@ func TestAdjustValToType(t *testing.T) {
|
||||||
typ: InteropInterfaceType,
|
typ: InteropInterfaceType,
|
||||||
val: "",
|
val: "",
|
||||||
err: true,
|
err: true,
|
||||||
|
}, {
|
||||||
|
typ: AnyType,
|
||||||
|
val: "nil",
|
||||||
|
out: nil,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, inout := range inouts {
|
for _, inout := range inouts {
|
||||||
|
|
Loading…
Reference in a new issue