/
fullaccount.go
58 lines (48 loc) · 1.78 KB
/
fullaccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package types
//go:generate ffjson $GOFILE
import (
"encoding/json"
"github.com/juju/errors"
"github.com/pquerna/ffjson/ffjson"
)
type FullAccountInfos []FullAccountInfo
type FullAccountInfo struct {
ID GrapheneID
AccountInfo AccountInfo
}
type AccountInfo struct {
Account Account `json:"account"`
RegistrarName string `json:"registrar_name"`
ReferrerName string `json:"referrer_name"`
LifetimeReferrerName string `json:"lifetime_referrer_name"`
CashbackBalance VestingBalance `json:"cashback_balance"`
Balances AccountBalances `json:"balances"`
VestingBalances VestingBalances `json:"vesting_balances"`
LimitOrders LimitOrders `json:"limit_orders"`
CallOrders CallOrders `json:"call_orders"`
SettleOrders SettleOrders `json:"settle_orders"`
Statistics AccountStatistics `json:"statistics"`
Assets GrapheneIDs `json:"assets"`
//Proposals []interface{} `json:"proposals"`
//Withdraws []interface{} `json:"withdraws"`
// Votes Votes `json:"votes"`
}
func (p FullAccountInfo) MarshalJSON() ([]byte, error) {
ret := make([]interface{}, 2)
ret[0] = p.ID.ID()
ret[1] = p.AccountInfo
return ffjson.Marshal(ret)
}
func (p *FullAccountInfo) UnmarshalJSON(data []byte) error {
raw := make([]json.RawMessage, 2)
if err := ffjson.Unmarshal(data, &raw); err != nil {
return errors.Annotate(err, "unmarshal [raw]")
}
if err := ffjson.Unmarshal(raw[0], &p.ID); err != nil {
return errors.Annotate(err, "unmarshal [id]")
}
if err := ffjson.Unmarshal(raw[1], &p.AccountInfo); err != nil {
return errors.Annotate(err, "unmarshal [AccountInfo]")
}
return nil
}