forked from TrueCloudLab/neoneo-go
Merge pull request #819 from nspcc-dev/fix/util160_marshalling
smartcontract: fix uint160 marshalling in smartcontract.Parameter
This commit is contained in:
commit
f64aa201c7
2 changed files with 6 additions and 8 deletions
|
@ -63,9 +63,7 @@ func (p *Parameter) MarshalJSON() ([]byte, error) {
|
||||||
resultErr error
|
resultErr error
|
||||||
)
|
)
|
||||||
switch p.Type {
|
switch p.Type {
|
||||||
case Hash160Type:
|
case BoolType, StringType, Hash160Type, Hash256Type:
|
||||||
resultRawValue, resultErr = json.Marshal(p.Value.(util.Uint160).Reverse()) // Hash160 should be marshaled in BE but default marshaler uses LE.
|
|
||||||
case BoolType, StringType, Hash256Type:
|
|
||||||
resultRawValue, resultErr = json.Marshal(p.Value)
|
resultRawValue, resultErr = json.Marshal(p.Value)
|
||||||
case IntegerType:
|
case IntegerType:
|
||||||
val, ok := p.Value.(int64)
|
val, ok := p.Value.(int64)
|
||||||
|
@ -161,7 +159,7 @@ func (p *Parameter) UnmarshalJSON(data []byte) (err error) {
|
||||||
if err = json.Unmarshal(r.Value, &h); err != nil {
|
if err = json.Unmarshal(r.Value, &h); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Value = h.Reverse() // Hash160 should be marshaled in BE but default marshaler uses LE.
|
p.Value = h
|
||||||
case Hash256Type:
|
case Hash256Type:
|
||||||
var h util.Uint256
|
var h util.Uint256
|
||||||
if err = json.Unmarshal(r.Value, &h); err != nil {
|
if err = json.Unmarshal(r.Value, &h); err != nil {
|
||||||
|
|
|
@ -104,8 +104,8 @@ var marshalJSONTestCases = []struct {
|
||||||
input: Parameter{
|
input: Parameter{
|
||||||
Type: Hash160Type,
|
Type: Hash160Type,
|
||||||
Value: util.Uint160{
|
Value: util.Uint160{
|
||||||
0x0b, 0xcd, 0x29, 0x78, 0x63, 0x4d, 0x96, 0x1c, 0x24, 0xf5,
|
0xd6, 0x24, 0x87, 0x12, 0xff, 0x97, 0x22, 0x80, 0xa0, 0xae,
|
||||||
0xae, 0xa0, 0x80, 0x22, 0x97, 0xff, 0x12, 0x87, 0x24, 0xd6,
|
0xf5, 0x24, 0x1c, 0x96, 0x4d, 0x63, 0x78, 0x29, 0xcd, 0xb,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
result: `{"type":"Hash160","value":"0x0bcd2978634d961c24f5aea0802297ff128724d6"}`,
|
result: `{"type":"Hash160","value":"0x0bcd2978634d961c24f5aea0802297ff128724d6"}`,
|
||||||
|
@ -197,8 +197,8 @@ var unmarshalJSONTestCases = []struct {
|
||||||
result: Parameter{
|
result: Parameter{
|
||||||
Type: Hash160Type,
|
Type: Hash160Type,
|
||||||
Value: util.Uint160{
|
Value: util.Uint160{
|
||||||
0x0b, 0xcd, 0x29, 0x78, 0x63, 0x4d, 0x96, 0x1c, 0x24, 0xf5,
|
0xd6, 0x24, 0x87, 0x12, 0xff, 0x97, 0x22, 0x80, 0xa0, 0xae,
|
||||||
0xae, 0xa0, 0x80, 0x22, 0x97, 0xff, 0x12, 0x87, 0x24, 0xd6,
|
0xf5, 0x24, 0x1c, 0x96, 0x4d, 0x63, 0x78, 0x29, 0xcd, 0xb,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue