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