mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
smartcontract: allow to marshal nil parameters
This commit is contained in:
parent
7cde58f731
commit
b4f8d66bd3
2 changed files with 9 additions and 1 deletions
|
@ -66,7 +66,11 @@ func (p *Parameter) MarshalJSON() ([]byte, error) {
|
||||||
case BoolType, IntegerType, StringType, Hash256Type, Hash160Type:
|
case BoolType, IntegerType, StringType, Hash256Type, Hash160Type:
|
||||||
resultRawValue, resultErr = json.Marshal(p.Value)
|
resultRawValue, resultErr = json.Marshal(p.Value)
|
||||||
case PublicKeyType, ByteArrayType, SignatureType:
|
case PublicKeyType, ByteArrayType, SignatureType:
|
||||||
resultRawValue, resultErr = json.Marshal(hex.EncodeToString(p.Value.([]byte)))
|
if p.Value == nil {
|
||||||
|
resultRawValue = []byte("null")
|
||||||
|
} else {
|
||||||
|
resultRawValue, resultErr = json.Marshal(hex.EncodeToString(p.Value.([]byte)))
|
||||||
|
}
|
||||||
case ArrayType:
|
case ArrayType:
|
||||||
var value = make([]rawParameter, 0)
|
var value = make([]rawParameter, 0)
|
||||||
for _, parameter := range p.Value.([]Parameter) {
|
for _, parameter := range p.Value.([]Parameter) {
|
||||||
|
|
|
@ -30,6 +30,10 @@ var marshalJSONTestCases = []struct {
|
||||||
input: Parameter{Type: ByteArrayType, Value: []byte{0x01, 0x02, 0x03}},
|
input: Parameter{Type: ByteArrayType, Value: []byte{0x01, 0x02, 0x03}},
|
||||||
result: `{"type":"ByteArray","value":"010203"}`,
|
result: `{"type":"ByteArray","value":"010203"}`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: Parameter{Type: ByteArrayType},
|
||||||
|
result: `{"type":"ByteArray","value":null}`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: Parameter{
|
input: Parameter{
|
||||||
Type: PublicKeyType,
|
Type: PublicKeyType,
|
||||||
|
|
Loading…
Reference in a new issue