vm/cli: add support for bool type as 'run' parameter

This commit is contained in:
Roman Khimov 2019-09-10 19:30:32 +03:00
parent 982bdcd704
commit c5911c2f10

View file

@ -88,12 +88,15 @@ var commands = []*ishell.Cmd{
<operation> is an operation name, passed as a first parameter to Main() (and it <operation> is an operation name, passed as a first parameter to Main() (and it
can't be 'help' at the moment) can't be 'help' at the moment)
<parameter> is a parameter (can be repeated multiple times) specified <parameter> is a parameter (can be repeated multiple times) specified
as <type>:<value>, where type can be 'int' or 'string' and value is as <type>:<value>, where type can be:
a value of this type (string is pushed as a byte array value); passing 'bool': supports 'false' and 'true' values
parameters without operation is not supported 'int': supports integers as values
'string': supports strings as values (that are pushed as a byte array
values to the stack)
Parameters are packed into array before they're passed to the script. so Passing parameters without operation is not supported. Parameters are packed
effectively 'run' only supports contracts with signatures like this: into array before they're passed to the script, so effectively 'run' only
supports contracts with signatures like this:
func Main(operation string, args []interface{}) interface{} func Main(operation string, args []interface{}) interface{}
Example: Example:
@ -322,6 +325,14 @@ func parseArgs(args []string) ([]vm.StackItem, error) {
value := typeAndVal[1] value := typeAndVal[1]
switch typ { switch typ {
case "bool":
if value == "false" {
items[i] = vm.NewBoolItem(false)
} else if value == "true" {
items[i] = vm.NewBoolItem(true)
} else {
return nil, errors.New("failed to parse bool parameter")
}
case "int": case "int":
val, err := strconv.Atoi(value) val, err := strconv.Atoi(value)
if err != nil { if err != nil {