forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
responses.go
353 lines (299 loc) · 12.5 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package eos
import (
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
"github.com/eoscanada/eos-go/ecc"
)
/*
{
"server_version": "f537bc50",
"head_block_num": 9,
"last_irreversible_block_num": 8,
"last_irreversible_block_id": "00000008f98f0580d7efe7abc60abaaf8a865c9428a4267df30ff7d1937a1084",
"head_block_id": "00000009ecd0e9fb5719431f4b86f5c9ca1887f6b6f73e5a301aaff740fd6bd3",
"head_block_time": "2018-05-19T07:47:31",
"head_block_producer": "eosio",
"virtual_block_cpu_limit": 100800,
"virtual_block_net_limit": 1056996,
"block_cpu_limit": 99900,
"block_net_limit": 1048576
}
*/
type InfoResp struct {
ServerVersion string `json:"server_version"` // "2cc40a4e"
ChainID SHA256Bytes `json:"chain_id"`
HeadBlockNum uint32 `json:"head_block_num"` // 2465669,
LastIrreversibleBlockNum uint32 `json:"last_irreversible_block_num"` // 2465655
LastIrreversibleBlockID SHA256Bytes `json:"last_irreversible_block_id"` // "00000008f98f0580d7efe7abc60abaaf8a865c9428a4267df30ff7d1937a1084"
HeadBlockID SHA256Bytes `json:"head_block_id"` // "00259f856bfa142d1d60aff77e70f0c4f3eab30789e9539d2684f9f8758f1b88",
HeadBlockTime JSONTime `json:"head_block_time"` // "2018-02-02T04:19:32"
HeadBlockProducer AccountName `json:"head_block_producer"` // "inita"
VirtualBlockCPULimit JSONInt64 `json:"virtual_block_cpu_limit"`
VirtualBlockNetLimit JSONInt64 `json:"virtual_block_net_limit"`
BlockCPULimit JSONInt64 `json:"block_cpu_limit"`
BlockNetLimit JSONInt64 `json:"block_net_limit"`
}
type BlockResp struct {
SignedBlock
ID SHA256Bytes `json:"id"`
BlockNum uint32 `json:"block_num"`
RefBlockPrefix uint32 `json:"ref_block_prefix"`
BlockExtensions []*Extension `json:"block_extensions"`
}
// type BlockTransaction struct {
// Status string `json:"status"`
// CPUUsageUS int `json:"cpu_usage_us"`
// NetUsageWords int `json:"net_usage_words"`
// Trx []json.RawMessage `json:"trx"`
// }
type DBSizeResp struct {
FreeBytes JSONInt64 `json:"free_bytes"`
UsedBytes JSONInt64 `json:"used_bytes"`
Size JSONInt64 `json:"size"`
Indices []struct {
Index string `json:"index"`
RowCount JSONInt64 `json:"row_count"`
} `json:"indices"`
}
type TransactionResp struct {
ID SHA256Bytes `json:"id"`
Receipt struct {
Status TransactionStatus `json:"status"`
CPUUsageMicrosec int `json:"cpu_usage_us"`
NetUsageWords int `json:"net_usage_words"`
PackedTransaction TransactionWithID `json:"trx"`
} `json:"receipt"`
Transaction ProcessedTransaction `json:"trx"`
BlockTime JSONTime `json:"block_time"`
BlockNum uint32 `json:"block_num"`
LastIrreversibleBlock uint32 `json:"last_irreversible_block"`
Traces []ActionTrace `json:"traces"`
}
type ProcessedTransaction struct {
Transaction SignedTransaction `json:"trx"`
}
type ActionTrace struct {
Receipt struct {
Receiver AccountName `json:"receiver"`
ActionDigest string `json:"act_digest"`
GlobalSequence int64 `json:"global_sequence"`
ReceiveSequence int64 `json:"recv_sequence"`
AuthSequence []TransactionTraceAuthSequence `json:"auth_sequence"` // [["account", sequence], ["account", sequence]]
CodeSequence int64 `json:"code_sequence"`
ABISequence int64 `json:"abi_sequence"`
} `json:"receipt"`
Action *Action `json:"act"`
Elapsed int `json:"elapsed"`
CPUUsage int `json:"cpu_usage"`
Console string `json:"console"`
TotalCPUUsage int `json:"total_cpu_usage"`
TransactionID SHA256Bytes `json:"trx_id"`
InlineTraces []*ActionTrace `json:"inline_traces"`
}
type TransactionTraceAuthSequence struct {
Account AccountName
Sequence int64
}
// [ ["account", 123123], ["account2", 345] ]
func (auth *TransactionTraceAuthSequence) UnmarshalJSON(data []byte) error {
var ins []interface{}
if err := json.Unmarshal(data, &ins); err != nil {
return err
}
if len(ins) != 2 {
return fmt.Errorf("expected 2 items, received %d", len(ins))
}
account, ok := ins[0].(string)
if !ok {
return fmt.Errorf("expected 1st item to be a string (account name)")
}
seq, ok := ins[1].(float64)
if !ok {
return fmt.Errorf("expected 2nd item to be a sequence number (float64)")
}
*auth = TransactionTraceAuthSequence{AccountName(account), int64(seq)}
return nil
}
func (auth TransactionTraceAuthSequence) MarshalJSON() (data []byte, err error) {
return json.Marshal([]interface{}{auth.Account, auth.Sequence})
}
type SequencedTransactionResp struct {
SeqNum int `json:"seq_num"`
TransactionResp
}
type TransactionsResp struct {
Transactions []SequencedTransactionResp
}
type ProducerChange struct {
}
type AccountResp struct {
AccountName AccountName `json:"account_name"`
Privileged bool `json:"privileged"`
LastCodeUpdate JSONTime `json:"last_code_update"`
Created JSONTime `json:"created"`
CoreLiquidBalance Asset `json:"core_liquid_balance"`
RAMQuota int64 `json:"ram_quota"`
RAMUsage int64 `json:"ram_usage"`
NetWeight JSONInt64 `json:"net_weight"`
CPUWeight JSONInt64 `json:"cpu_weight"`
NetLimit AccountResourceLimit `json:"net_limit"`
CPULimit AccountResourceLimit `json:"cpu_limit"`
Permissions []Permission `json:"permissions"`
TotalResources TotalResources `json:"total_resources"`
SelfDelegatedBandwidth DelegatedBandwidth `json:"self_delegated_bandwidth"`
RefundRequest *RefundRequest `json:"refund_request"`
VoterInfo VoterInfo `json:"voter_info"`
}
type CurrencyBalanceResp struct {
EOSBalance Asset `json:"eos_balance"`
StakedBalance Asset `json:"staked_balance"`
UnstakingBalance Asset `json:"unstaking_balance"`
LastUnstakingTime JSONTime `json:"last_unstaking_time"`
}
type GetTableRowsRequest struct {
JSON bool `json:"json"`
Scope string `json:"scope"`
Code string `json:"code"`
Table string `json:"table"`
TableKey string `json:"table_key"`
LowerBound string `json:"lower_bound"`
UpperBound string `json:"upper_bound"`
Limit uint32 `json:"limit,omitempty"` // defaults to 10 => chain_plugin.hpp:struct get_table_rows_params
}
type GetTableRowsResp struct {
More bool `json:"more"`
Rows json.RawMessage `json:"rows"` // defer loading, as it depends on `JSON` being true/false.
}
func (resp *GetTableRowsResp) JSONToStructs(v interface{}) error {
return json.Unmarshal(resp.Rows, v)
}
func (resp *GetTableRowsResp) BinaryToStructs(v interface{}) error {
var rows []string
err := json.Unmarshal(resp.Rows, &rows)
if err != nil {
return err
}
outSlice := reflect.ValueOf(v).Elem()
structType := reflect.TypeOf(v).Elem().Elem()
for _, row := range rows {
bin, err := hex.DecodeString(row)
if err != nil {
return err
}
// access the type of the `Slice`, create a bunch of them..
newStruct := reflect.New(structType)
decoder := NewDecoder(bin)
if err := decoder.Decode(newStruct.Interface()); err != nil {
return err
}
outSlice = reflect.Append(outSlice, reflect.Indirect(newStruct))
}
reflect.ValueOf(v).Elem().Set(outSlice)
return nil
}
type Currency struct {
Precision uint8
Name CurrencyName
}
type GetRequiredKeysResp struct {
RequiredKeys []ecc.PublicKey `json:"required_keys"`
}
// PushTransactionFullResp unwraps the responses from a successful `push_transaction`.
// FIXME: REVIEW the actual output, things have moved here.
type PushTransactionFullResp struct {
StatusCode string
TransactionID string `json:"transaction_id"`
Processed TransactionProcessed `json:"processed"` // WARN: is an `fc::variant` in server..
}
type TransactionProcessed struct {
Status string `json:"status"`
ID SHA256Bytes `json:"id"`
ActionTraces []Trace `json:"action_traces"`
DeferredTransactions []string `json:"deferred_transactions"` // that's not right... dig to find what's there..
}
type Trace struct {
Receiver AccountName `json:"receiver"`
// Action Action `json:"act"` // FIXME: how do we unpack that ? what's on the other side anyway?
Console string `json:"console"`
DataAccess []DataAccess `json:"data_access"`
}
type DataAccess struct {
Type string `json:"type"` // "write", "read"?
Code AccountName `json:"code"`
Scope AccountName `json:"scope"`
Sequence int `json:"sequence"`
}
type PushTransactionShortResp struct {
TransactionID string `json:"transaction_id"`
Processed bool `json:"processed"` // WARN: is an `fc::variant` in server..
}
//
type WalletSignTransactionResp struct {
// Ignore the rest of the transaction, so the wallet server
// doesn't forge some transactions on your behalf, and you send it
// to the network.. ... although.. it's better if you can trust
// your wallet !
Signatures []ecc.Signature `json:"signatures"`
}
type MyStruct struct {
Currency
Balance uint64
}
// NetConnectionResp
type NetConnectionsResp struct {
Peer string `json:"peer"`
Connecting bool `json:"connecting"`
Syncing bool `json:"syncing"`
LastHandshake HandshakeMessage `json:"last_handshake"`
}
type NetStatusResp struct {
}
type NetConnectResp string
type NetDisconnectResp string
type Global struct {
MaxBlockNetUsage int `json:"max_block_net_usage"`
TargetBlockNetUsagePct int `json:"target_block_net_usage_pct"`
MaxTransactionNetUsage int `json:"max_transaction_net_usage"`
BasePerTransactionNetUsage int `json:"base_per_transaction_net_usage"`
NetUsageLeeway int `json:"net_usage_leeway"`
ContextFreeDiscountNetUsageNum int `json:"context_free_discount_net_usage_num"`
ContextFreeDiscountNetUsageDen int `json:"context_free_discount_net_usage_den"`
MaxBlockCPUUsage int `json:"max_block_cpu_usage"`
TargetBlockCPUUsagePct int `json:"target_block_cpu_usage_pct"`
MaxTransactionCPUUsage int `json:"max_transaction_cpu_usage"`
MinTransactionCPUUsage int `json:"min_transaction_cpu_usage"`
MaxTransactionLifetime int `json:"max_transaction_lifetime"`
DeferredTrxExpirationWindow int `json:"deferred_trx_expiration_window"`
MaxTransactionDelay int `json:"max_transaction_delay"`
MaxInlineActionSize int `json:"max_inline_action_size"`
MaxInlineActionDepth int `json:"max_inline_action_depth"`
MaxAuthorityDepth int `json:"max_authority_depth"`
MaxRAMSize string `json:"max_ram_size"`
TotalRAMBytesReserved JSONInt64 `json:"total_ram_bytes_reserved"`
TotalRAMStake JSONInt64 `json:"total_ram_stake"`
LastProducerScheduleUpdate string `json:"last_producer_schedule_update"`
LastPervoteBucketFill int64 `json:"last_pervote_bucket_fill,string"`
PervoteBucket int `json:"pervote_bucket"`
PerblockBucket int `json:"perblock_bucket"`
TotalUnpaidBlocks int `json:"total_unpaid_blocks"`
TotalActivatedStake float64 `json:"total_activated_stake,string"`
ThreshActivatedStakeTime int64 `json:"thresh_activated_stake_time,string"`
LastProducerScheduleSize int `json:"last_producer_schedule_size"`
TotalProducerVoteWeight float64 `json:"total_producer_vote_weight,string"`
LastNameClose string `json:"last_name_close"`
}
type Producer struct {
Owner string `json:"owner"`
TotalVotes float64 `json:"total_votes,string"`
ProducerKey string `json:"producer_key"`
IsActive int `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime JSONFloat64 `json:"last_claim_time"`
Location int `json:"location"`
}
type ProducersResp struct {
Producers []Producer `json:"producers"`
}