From b4f8d66bd32e2d8c8d9f35d23ded691261967ffd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 4 Mar 2020 19:47:10 +0300 Subject: [PATCH] smartcontract: allow to marshal nil parameters --- pkg/smartcontract/param_context.go | 6 +++++- pkg/smartcontract/param_context_test.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/smartcontract/param_context.go b/pkg/smartcontract/param_context.go index 147e00c9f..14f953f6b 100644 --- a/pkg/smartcontract/param_context.go +++ b/pkg/smartcontract/param_context.go @@ -66,7 +66,11 @@ func (p *Parameter) MarshalJSON() ([]byte, error) { case BoolType, IntegerType, StringType, Hash256Type, Hash160Type: resultRawValue, resultErr = json.Marshal(p.Value) 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: var value = make([]rawParameter, 0) for _, parameter := range p.Value.([]Parameter) { diff --git a/pkg/smartcontract/param_context_test.go b/pkg/smartcontract/param_context_test.go index b6870e8eb..565ca95d6 100644 --- a/pkg/smartcontract/param_context_test.go +++ b/pkg/smartcontract/param_context_test.go @@ -30,6 +30,10 @@ var marshalJSONTestCases = []struct { input: Parameter{Type: ByteArrayType, Value: []byte{0x01, 0x02, 0x03}}, result: `{"type":"ByteArray","value":"010203"}`, }, + { + input: Parameter{Type: ByteArrayType}, + result: `{"type":"ByteArray","value":null}`, + }, { input: Parameter{ Type: PublicKeyType,