Merge pull request #785 from nspcc-dev/feature/uint160_marshalling

util: JSONify uint160 using LE instead of BE
This commit is contained in:
Roman Khimov 2020-03-24 12:41:07 +03:00 committed by GitHub
commit 751e79d480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 58 deletions

View file

@ -66,7 +66,9 @@ func (p *Parameter) MarshalJSON() ([]byte, error) {
resultErr error
)
switch p.Type {
case BoolType, StringType, Hash256Type, Hash160Type:
case Hash160Type:
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)
case IntegerType:
val, ok := p.Value.(int64)
@ -200,7 +202,7 @@ func (p *Parameter) UnmarshalJSON(data []byte) (err error) {
if err = json.Unmarshal(r.Value, &h); err != nil {
return
}
p.Value = h
p.Value = h.Reverse() // Hash160 should be marshaled in BE but default marshaler uses LE.
case Hash256Type:
var h util.Uint256
if err = json.Unmarshal(r.Value, &h); err != nil {