forked from stellar/go
/
responses.go
240 lines (211 loc) · 6.75 KB
/
responses.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package horizon
import (
"encoding/base64"
"encoding/json"
"time"
)
type Problem struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Extras map[string]json.RawMessage `json:"extras,omitempty"`
}
type Account struct {
Links struct {
Self Link `json:"self"`
Transactions Link `json:"transactions"`
Operations Link `json:"operations"`
Payments Link `json:"payments"`
Effects Link `json:"effects"`
Offers Link `json:"offers"`
} `json:"_links"`
HistoryAccount
Sequence string `json:"sequence"`
SubentryCount int32 `json:"subentry_count"`
InflationDestination string `json:"inflation_destination,omitempty"`
HomeDomain string `json:"home_domain,omitempty"`
Thresholds AccountThresholds `json:"thresholds"`
Flags AccountFlags `json:"flags"`
Balances []Balance `json:"balances"`
Signers []Signer `json:"signers"`
Data map[string]string `json:"data"`
}
func (a Account) GetNativeBalance() string {
for _, balance := range a.Balances {
if balance.Asset.Type == "native" {
return balance.Balance
}
}
return "0"
}
// MustGetData returns decoded value for a given key. If the key does
// not exist, empty slice will be returned. If there is an error
// decoding a value, it will panic.
func (this *Account) MustGetData(key string) []byte {
bytes, err := this.GetData(key)
if err != nil {
panic(err)
}
return bytes
}
// GetData returns decoded value for a given key. If the key does
// not exist, empty slice will be returned.
func (this *Account) GetData(key string) ([]byte, error) {
return base64.StdEncoding.DecodeString(this.Data[key])
}
type AccountFlags struct {
AuthRequired bool `json:"auth_required"`
AuthRevocable bool `json:"auth_revocable"`
}
type AccountThresholds struct {
LowThreshold byte `json:"low_threshold"`
MedThreshold byte `json:"med_threshold"`
HighThreshold byte `json:"high_threshold"`
}
type Asset struct {
Type string `json:"asset_type"`
Code string `json:"asset_code,omitempty"`
Issuer string `json:"asset_issuer,omitempty"`
}
type Balance struct {
Balance string `json:"balance"`
Limit string `json:"limit,omitempty"`
Asset
}
type HistoryAccount struct {
ID string `json:"id"`
PT string `json:"paging_token"`
AccountID string `json:"account_id"`
}
type Ledger struct {
Links struct {
Self Link `json:"self"`
Transactions Link `json:"transactions"`
Operations Link `json:"operations"`
Payments Link `json:"payments"`
Effects Link `json:"effects"`
} `json:"_links"`
ID string `json:"id"`
PT string `json:"paging_token"`
Hash string `json:"hash"`
PrevHash string `json:"prev_hash,omitempty"`
Sequence int32 `json:"sequence"`
TransactionCount int32 `json:"transaction_count"`
OperationCount int32 `json:"operation_count"`
ClosedAt time.Time `json:"closed_at"`
TotalCoins string `json:"total_coins"`
FeePool string `json:"fee_pool"`
BaseFee int32 `json:"base_fee"`
BaseReserve string `json:"base_reserve"`
MaxTxSetSize int32 `json:"max_tx_set_size"`
ProtocolVersion int32 `json:"protocol_version"`
}
type Link struct {
Href string `json:"href"`
Templated bool `json:"templated,omitempty"`
}
type Offer struct {
Links struct {
Self Link `json:"self"`
OfferMaker Link `json:"offer_maker"`
} `json:"_links"`
ID int64 `json:"id"`
PT string `json:"paging_token"`
Seller string `json:"seller"`
Selling Asset `json:"selling"`
Buying Asset `json:"buying"`
Amount string `json:"amount"`
PriceR Price `json:"price_r"`
Price string `json:"price"`
}
type OrderBookSummary struct {
Bids []PriceLevel `json:"bids"`
Asks []PriceLevel `json:"asks"`
Selling Asset `json:"base"`
Buying Asset `json:"counter"`
}
type TransactionSuccess struct {
Links struct {
Transaction Link `json:"transaction"`
} `json:"_links"`
Hash string `json:"hash"`
Ledger int32 `json:"ledger"`
Env string `json:"envelope_xdr"`
Result string `json:"result_xdr"`
Meta string `json:"result_meta_xdr"`
}
// TransactionResultCodes represent a summary of result codes returned from
// a single xdr TransactionResult
type TransactionResultCodes struct {
TransactionCode string `json:"transaction"`
OperationCodes []string `json:"operations,omitempty"`
}
type Signer struct {
PublicKey string `json:"public_key"`
Weight int32 `json:"weight"`
Key string `json:"key"`
Type string `json:"type"`
}
type OffersPage struct {
Links struct {
Self Link `json:"self"`
Next Link `json:"next"`
Prev Link `json:"prev"`
} `json:"_links"`
Embedded struct {
Records []Offer `json:"records"`
} `json:"_embedded"`
}
type Payment struct {
ID string `json:"id"`
Type string `json:"type"`
PagingToken string `json:"paging_token"`
Links struct {
Transaction struct {
Href string `json:"href"`
} `json:"transaction"`
} `json:"_links"`
// payment/path_payment fields
From string `json:"from"`
To string `json:"to"`
AssetType string `json:"asset_type"`
AssetCode string `json:"asset_code"`
AssetIssuer string `json:"asset_issuer"`
Amount string `json:"amount"`
// transaction fields
Memo struct {
Type string `json:"memo_type"`
Value string `json:"memo"`
}
}
type Price struct {
N int32 `json:"n"`
D int32 `json:"d"`
}
type PriceLevel struct {
PriceR Price `json:"price_r"`
Price string `json:"price"`
Amount string `json:"amount"`
}
type Transaction struct {
ID string `json:"id"`
PagingToken string `json:"paging_token"`
Hash string `json:"hash"`
Ledger int32 `json:"ledger"`
LedgerCloseTime time.Time `json:"created_at"`
Account string `json:"source_account"`
AccountSequence string `json:"source_account_sequence"`
FeePaid int32 `json:"fee_paid"`
OperationCount int32 `json:"operation_count"`
EnvelopeXdr string `json:"envelope_xdr"`
ResultXdr string `json:"result_xdr"`
ResultMetaXdr string `json:"result_meta_xdr"`
FeeMetaXdr string `json:"fee_meta_xdr"`
MemoType string `json:"memo_type"`
Memo string `json:"memo,omitempty"`
Signatures []string `json:"signatures"`
ValidAfter string `json:"valid_after,omitempty"`
ValidBefore string `json:"valid_before,omitempty"`
}