forked from TrueCloudLab/neoneo-go
Merge pull request #751 from nspcc-dev/fix/transfer
rpc: marshal Asset hash in LE in getnep5balances RPC
This commit is contained in:
commit
800e3fe4d6
1 changed files with 38 additions and 1 deletions
|
@ -1,6 +1,10 @@
|
|||
package result
|
||||
|
||||
import "github.com/nspcc-dev/neo-go/pkg/util"
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// NEP5Balances is a result for the getnep5balances RPC call.
|
||||
type NEP5Balances struct {
|
||||
|
@ -15,6 +19,13 @@ type NEP5Balance struct {
|
|||
LastUpdated uint32 `json:"last_updated_block"`
|
||||
}
|
||||
|
||||
// nep5Balance is an auxilliary struct for proper Asset marshaling.
|
||||
type nep5Balance struct {
|
||||
Asset string `json:"asset_hash"`
|
||||
Amount string `json:"amount"`
|
||||
LastUpdated uint32 `json:"last_updated_block"`
|
||||
}
|
||||
|
||||
// NEP5Transfers is a result for the getnep5transfers RPC.
|
||||
type NEP5Transfers struct {
|
||||
Sent []NEP5Transfer `json:"sent"`
|
||||
|
@ -32,3 +43,29 @@ type NEP5Transfer struct {
|
|||
NotifyIndex uint32 `json:"transfer_notify_index"`
|
||||
TxHash util.Uint256 `json:"tx_hash"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler interface.
|
||||
func (b *NEP5Balance) MarshalJSON() ([]byte, error) {
|
||||
s := &nep5Balance{
|
||||
Asset: b.Asset.StringLE(),
|
||||
Amount: b.Amount,
|
||||
LastUpdated: b.LastUpdated,
|
||||
}
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler interface.
|
||||
func (b *NEP5Balance) UnmarshalJSON(data []byte) error {
|
||||
s := new(nep5Balance)
|
||||
if err := json.Unmarshal(data, s); err != nil {
|
||||
return err
|
||||
}
|
||||
asset, err := util.Uint160DecodeStringLE(s.Asset)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.Amount = s.Amount
|
||||
b.Asset = asset
|
||||
b.LastUpdated = s.LastUpdated
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue