forked from TrueCloudLab/neoneo-go
smartcontract: marshal Arrays properly
This commit is contained in:
parent
f92fd3c948
commit
b945f4346a
2 changed files with 19 additions and 6 deletions
|
@ -72,16 +72,13 @@ func (p *Parameter) MarshalJSON() ([]byte, error) {
|
||||||
resultRawValue, resultErr = json.Marshal(hex.EncodeToString(p.Value.([]byte)))
|
resultRawValue, resultErr = json.Marshal(hex.EncodeToString(p.Value.([]byte)))
|
||||||
}
|
}
|
||||||
case ArrayType:
|
case ArrayType:
|
||||||
var value = make([]rawParameter, 0)
|
var value = make([]json.RawMessage, 0)
|
||||||
for _, parameter := range p.Value.([]Parameter) {
|
for _, parameter := range p.Value.([]Parameter) {
|
||||||
rawValue, err := json.Marshal(parameter.Value)
|
rawValue, err := json.Marshal(¶meter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
value = append(value, rawParameter{
|
value = append(value, rawValue)
|
||||||
Type: parameter.Type,
|
|
||||||
Value: rawValue,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
resultRawValue, resultErr = json.Marshal(value)
|
resultRawValue, resultErr = json.Marshal(value)
|
||||||
case MapType:
|
case MapType:
|
||||||
|
|
|
@ -51,6 +51,22 @@ var marshalJSONTestCases = []struct {
|
||||||
},
|
},
|
||||||
result: `{"type":"Array","value":[{"type":"String","value":"str 1"},{"type":"Integer","value":2}]}`,
|
result: `{"type":"Array","value":[{"type":"String","value":"str 1"},{"type":"Integer","value":2}]}`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: Parameter{
|
||||||
|
Type: ArrayType,
|
||||||
|
Value: []Parameter{
|
||||||
|
{Type: ByteArrayType, Value: []byte{1, 2}},
|
||||||
|
{
|
||||||
|
Type: ArrayType,
|
||||||
|
Value: []Parameter{
|
||||||
|
{Type: ByteArrayType, Value: []byte{3, 2, 1}},
|
||||||
|
{Type: ByteArrayType, Value: []byte{7, 8, 9}},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: `{"type":"Array","value":[{"type":"ByteArray","value":"0102"},{"type":"Array","value":[` +
|
||||||
|
`{"type":"ByteArray","value":"030201"},{"type":"ByteArray","value":"070809"}]}]}`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: Parameter{
|
input: Parameter{
|
||||||
Type: MapType,
|
Type: MapType,
|
||||||
|
|
Loading…
Reference in a new issue