smartcontract: allow to marshal nil parameters

This commit is contained in:
Evgenii Stratonikov 2020-03-04 19:47:10 +03:00
parent 7cde58f731
commit b4f8d66bd3
2 changed files with 9 additions and 1 deletions

View file

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

View file

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