diff --git a/pkg/rpc/request/param.go b/pkg/rpc/request/param.go index 33ddfbea1..45249257b 100644 --- a/pkg/rpc/request/param.go +++ b/pkg/rpc/request/param.go @@ -69,6 +69,7 @@ const ( defaultT paramType = iota StringT NumberT + BooleanT ArrayT FuncParamT BlockFilterT @@ -106,6 +107,8 @@ func (p *Param) GetBoolean() bool { return p.Value != 0 case StringT: return p.Value != "" + case BooleanT: + return p.Value == true default: return true } @@ -263,9 +266,11 @@ func (p Param) GetSignersWithWitnesses() ([]transaction.Signer, []transaction.Wi func (p *Param) UnmarshalJSON(data []byte) error { var s string var num float64 + var b bool // To unmarshal correctly we need to pass pointers into the decoder. var attempts = [...]Param{ {NumberT, &num}, + {BooleanT, &b}, {StringT, &s}, {FuncParamT, &FuncParam{}}, {BlockFilterT, &BlockFilter{}}, @@ -293,6 +298,8 @@ func (p *Param) UnmarshalJSON(data []byte) error { p.Value = int(*val) case *string: p.Value = *val + case *bool: + p.Value = *val case *FuncParam: p.Value = *val case *BlockFilter: diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index 2edb4ad1f..e02ffbc77 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -114,6 +114,9 @@ func CreateFunctionInvocationScript(contract util.Uint160, method string, params return nil, err } emit.String(script.BinWriter, strconv.Itoa(num)) + case BooleanT: + val := params[i].GetBoolean() + emit.Bool(script.BinWriter, val) case ArrayT: slice, err := params[i].GetArray() if err != nil { diff --git a/pkg/rpc/request/tx_builder_test.go b/pkg/rpc/request/tx_builder_test.go index b79b9d62e..ad445898d 100644 --- a/pkg/rpc/request/tx_builder_test.go +++ b/pkg/rpc/request/tx_builder_test.go @@ -26,6 +26,9 @@ func TestInvocationScriptCreationGood(t *testing.T) { }, { ps: Params{{Type: NumberT, Value: 42}}, script: "1f0c0234320c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", + }, { + ps: Params{{Type: StringT, Value: "m"}, {Type: BooleanT, Value: true}}, + script: "11db201f0c016d0c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{}}}, script: "10c01f0c01610c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", @@ -79,6 +82,7 @@ func TestInvocationScriptCreationBad(t *testing.T) { {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.PublicKeyType, Value: Param{Type: NumberT, Value: 42}}}}}}, {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.PublicKeyType, Value: Param{Type: StringT, Value: "qwerty"}}}}}}, {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.IntegerType, Value: Param{Type: StringT, Value: "qwerty"}}}}}}, + {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.IntegerType, Value: Param{Type: BooleanT, Value: true}}}}}}, {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: NumberT, Value: 42}}}}}}, {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: StringT, Value: "qwerty"}}}}}}, {{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.UnknownType, Value: Param{}}}}}},