2020-03-05 11:50:06 +00:00
|
|
|
package result
|
|
|
|
|
2020-03-11 14:00:42 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
)
|
2020-03-05 11:50:06 +00:00
|
|
|
|
|
|
|
// NEP5Balances is a result for the getnep5balances RPC call.
|
|
|
|
type NEP5Balances struct {
|
2020-03-18 10:39:16 +00:00
|
|
|
Balances []NEP5Balance `json:"balance"`
|
2020-03-05 11:50:06 +00:00
|
|
|
Address string `json:"address"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NEP5Balance represents balance for the single token contract.
|
|
|
|
type NEP5Balance struct {
|
2020-07-09 12:36:13 +00:00
|
|
|
Asset util.Uint160 `json:"assethash"`
|
2020-03-05 11:50:06 +00:00
|
|
|
Amount string `json:"amount"`
|
2020-07-09 12:36:13 +00:00
|
|
|
LastUpdated uint32 `json:"lastupdatedblock"`
|
2020-03-05 11:50:06 +00:00
|
|
|
}
|
2020-03-05 12:16:03 +00:00
|
|
|
|
2020-03-11 14:00:42 +00:00
|
|
|
// nep5Balance is an auxilliary struct for proper Asset marshaling.
|
|
|
|
type nep5Balance struct {
|
2020-07-09 12:36:13 +00:00
|
|
|
Asset string `json:"assethash"`
|
2020-03-11 14:00:42 +00:00
|
|
|
Amount string `json:"amount"`
|
2020-07-09 12:36:13 +00:00
|
|
|
LastUpdated uint32 `json:"lastupdatedblock"`
|
2020-03-11 14:00:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 12:16:03 +00:00
|
|
|
// NEP5Transfers is a result for the getnep5transfers RPC.
|
|
|
|
type NEP5Transfers struct {
|
|
|
|
Sent []NEP5Transfer `json:"sent"`
|
|
|
|
Received []NEP5Transfer `json:"received"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NEP5Transfer represents single NEP5 transfer event.
|
|
|
|
type NEP5Transfer struct {
|
2020-04-21 11:26:57 +00:00
|
|
|
Timestamp uint64 `json:"timestamp"`
|
2020-07-09 12:36:13 +00:00
|
|
|
Asset util.Uint160 `json:"assethash"`
|
2020-07-09 12:42:23 +00:00
|
|
|
Address string `json:"transferaddress,omitempty"`
|
2020-03-05 12:16:03 +00:00
|
|
|
Amount string `json:"amount"`
|
2020-07-09 12:42:23 +00:00
|
|
|
Index uint32 `json:"blockindex"`
|
|
|
|
NotifyIndex uint32 `json:"transfernotifyindex"`
|
|
|
|
TxHash util.Uint256 `json:"txhash"`
|
2020-03-05 12:16:03 +00:00
|
|
|
}
|
2020-03-11 14:00:42 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|