From c5911c2f10675de574e60f5e9a2a36149263b585 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 10 Sep 2019 19:30:32 +0300 Subject: [PATCH] vm/cli: add support for bool type as 'run' parameter --- pkg/vm/cli/cli.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index 686fb337d..55ac6ab71 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -88,12 +88,15 @@ var commands = []*ishell.Cmd{ is an operation name, passed as a first parameter to Main() (and it can't be 'help' at the moment) is a parameter (can be repeated multiple times) specified - as :, where type can be 'int' or 'string' and value is - a value of this type (string is pushed as a byte array value); passing - parameters without operation is not supported + as :, where type can be: + 'bool': supports 'false' and 'true' values + '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 -effectively 'run' only supports contracts with signatures like this: +Passing parameters without operation is not supported. Parameters are packed +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{} Example: @@ -122,7 +125,7 @@ Example: }, } -// VMCLI object for interacting with the VM. + // VMCLI object for interacting with the VM. type VMCLI struct { vm *vm.VM shell *ishell.Shell @@ -322,6 +325,14 @@ func parseArgs(args []string) ([]vm.StackItem, error) { value := typeAndVal[1] 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": val, err := strconv.Atoi(value) if err != nil {