rpc/request: allow to provide bool parameters, fix #1919

This commit is contained in:
Evgeniy Stratonikov 2021-04-28 11:45:14 +03:00
parent 933743ce87
commit da360be5b1
3 changed files with 14 additions and 0 deletions

View file

@ -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: