Merge pull request #1920 from nspcc-dev/fix/rpcparam
rpc/request: allow to provide bool parameters
This commit is contained in:
commit
e6bb89e5a9
3 changed files with 14 additions and 0 deletions
|
@ -69,6 +69,7 @@ const (
|
||||||
defaultT paramType = iota
|
defaultT paramType = iota
|
||||||
StringT
|
StringT
|
||||||
NumberT
|
NumberT
|
||||||
|
BooleanT
|
||||||
ArrayT
|
ArrayT
|
||||||
FuncParamT
|
FuncParamT
|
||||||
BlockFilterT
|
BlockFilterT
|
||||||
|
@ -106,6 +107,8 @@ func (p *Param) GetBoolean() bool {
|
||||||
return p.Value != 0
|
return p.Value != 0
|
||||||
case StringT:
|
case StringT:
|
||||||
return p.Value != ""
|
return p.Value != ""
|
||||||
|
case BooleanT:
|
||||||
|
return p.Value == true
|
||||||
default:
|
default:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -263,9 +266,11 @@ func (p Param) GetSignersWithWitnesses() ([]transaction.Signer, []transaction.Wi
|
||||||
func (p *Param) UnmarshalJSON(data []byte) error {
|
func (p *Param) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
var num float64
|
var num float64
|
||||||
|
var b bool
|
||||||
// To unmarshal correctly we need to pass pointers into the decoder.
|
// To unmarshal correctly we need to pass pointers into the decoder.
|
||||||
var attempts = [...]Param{
|
var attempts = [...]Param{
|
||||||
{NumberT, &num},
|
{NumberT, &num},
|
||||||
|
{BooleanT, &b},
|
||||||
{StringT, &s},
|
{StringT, &s},
|
||||||
{FuncParamT, &FuncParam{}},
|
{FuncParamT, &FuncParam{}},
|
||||||
{BlockFilterT, &BlockFilter{}},
|
{BlockFilterT, &BlockFilter{}},
|
||||||
|
@ -293,6 +298,8 @@ func (p *Param) UnmarshalJSON(data []byte) error {
|
||||||
p.Value = int(*val)
|
p.Value = int(*val)
|
||||||
case *string:
|
case *string:
|
||||||
p.Value = *val
|
p.Value = *val
|
||||||
|
case *bool:
|
||||||
|
p.Value = *val
|
||||||
case *FuncParam:
|
case *FuncParam:
|
||||||
p.Value = *val
|
p.Value = *val
|
||||||
case *BlockFilter:
|
case *BlockFilter:
|
||||||
|
|
|
@ -114,6 +114,9 @@ func CreateFunctionInvocationScript(contract util.Uint160, method string, params
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
emit.String(script.BinWriter, strconv.Itoa(num))
|
emit.String(script.BinWriter, strconv.Itoa(num))
|
||||||
|
case BooleanT:
|
||||||
|
val := params[i].GetBoolean()
|
||||||
|
emit.Bool(script.BinWriter, val)
|
||||||
case ArrayT:
|
case ArrayT:
|
||||||
slice, err := params[i].GetArray()
|
slice, err := params[i].GetArray()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -26,6 +26,9 @@ func TestInvocationScriptCreationGood(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
ps: Params{{Type: NumberT, Value: 42}},
|
ps: Params{{Type: NumberT, Value: 42}},
|
||||||
script: "1f0c0234320c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52",
|
script: "1f0c0234320c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52",
|
||||||
|
}, {
|
||||||
|
ps: Params{{Type: StringT, Value: "m"}, {Type: BooleanT, Value: true}},
|
||||||
|
script: "11db201f0c016d0c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52",
|
||||||
}, {
|
}, {
|
||||||
ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{}}},
|
ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{}}},
|
||||||
script: "10c01f0c01610c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52",
|
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: 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.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: 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: 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.BoolType, Value: Param{Type: StringT, Value: "qwerty"}}}}}},
|
||||||
{{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.UnknownType, Value: Param{}}}}}},
|
{{Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.UnknownType, Value: Param{}}}}}},
|
||||||
|
|
Loading…
Reference in a new issue