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
|
||||
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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{}}}}}},
|
||||
|
|
Loading…
Reference in a new issue