-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain.go
335 lines (265 loc) · 11.6 KB
/
chain.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
package eosrpc
import (
"github.com/TheBoringDude/go-urljoin"
)
const CHAIN_API = "chain"
type AccountProps struct {
AccountName string `json:"account_name"`
}
// GetAccount returns an object containing various details about a specific account on the blockchain.
func (c *ChainAPI) GetAccount(props AccountProps) (GetAccountResponse, error) {
var r = GetAccountResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_account"), props, &r)
return r, err
}
type GetBlockProps struct {
BlockNumOrID string `json:"block_num_or_id"`
}
// GetBlock returns an object containing various details about a specific block on the blockchain.
func (c *ChainAPI) GetBlock(props GetBlockProps) (GetBlockResponse, error) {
var r = GetBlockResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_block"), props, &r)
return r, err
}
type GetBlockInfoProps struct {
BlockNum int `json:"block_num"`
}
// GetBlockInfo is similar to get_block but returns a fixed-size smaller subset of the block data.
func (c *ChainAPI) GetBlockInfo(props GetBlockInfoProps) (GetBlockInfoResponse, error) {
var r = GetBlockInfoResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_block_info"), props, &r)
return r, err
}
// GetInfo returns an object containing various details about a specific block on the blockchain.
func (c *ChainAPI) GetInfo() (GetInfoResponse, error) {
var r = GetInfoResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_info"), emptyMap, &r)
return r, err
}
type TransactionProps struct {
Signatures []string `json:"signatures,omitempty"`
Compression bool `json:"compression,omitempty"`
PackedContextFreeData string `json:"packed_context_free_data,omitempty"`
PackedTrx string `json:"packed_trx,omitempty"`
}
// PushTransaction expects a transaction in JSON format and will attempt to apply it to the blockchain.
func (c *ChainAPI) PushTransaction(props TransactionProps) error {
return request(c.Client, urljoin.UrlJoin(c.ApiUrl, "push_transaction"), props, nil)
}
// SendTransaction expects a transaction in JSON format and will attempt to apply it to the blockchain.
func (c *ChainAPI) SendTransaction(props TransactionProps) error {
return request(c.Client, urljoin.UrlJoin(c.ApiUrl, "send_transaction"), props, nil)
}
type PushTransactionProps []PushTransactionObject
type PushTransactionObject struct {
Expiration string `json:"expiration"`
RefBlockNum int64 `json:"ref_block_num"`
RefBlockPrefix int64 `json:"ref_block_prefix"`
MaxNetUsageWords string `json:"max_net_usage_words"`
MaxCPUUsageMS string `json:"max_cpu_usage_ms"`
DelaySEC int64 `json:"delay_sec"`
ContextFreeActions []TransactionAction `json:"context_free_actions"`
Actions []TransactionAction `json:"actions"`
TransactionExtensions [][]int64 `json:"transaction_extensions,omitempty"`
}
type TransactionAction struct {
Account string `json:"account"`
Name string `json:"name"`
Authorization []Authorization `json:"authorization"`
Data map[string]interface{} `json:"data"`
HexData string `json:"hex_data"`
}
// PushTransactions expects a transaction in JSON format and will attempt to apply it to the blockchain.
func (c *ChainAPI) PushTransactions(props PushTransactionProps) error {
return request(c.Client, urljoin.UrlJoin(c.ApiUrl, "push_transactions"), props, nil)
}
type GetBlockHeaderStateProps struct {
BlockNumOrID string `json:"block_num_or_id"`
}
// GetBlockHeaderState retrieves the block header state.
func (c *ChainAPI) GetBlockHeaderState(props GetBlockHeaderStateProps) (GetBlockHeaderStateResponse, error) {
var r = GetBlockHeaderStateResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_block_header_state"), props, &r)
return r, err
}
// GetABI retrieves the ABI for a contract based on its account name.
func (c *ChainAPI) GetABI(props AccountProps) (GetABIResponse, error) {
var r = GetABIResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_abi"), props, &r)
return r, err
}
type GetCurrencyBalanceProps struct {
Code string `json:"code"`
Account string `json:"account"`
Symbol string `json:"symbol,omitempty"`
}
// GetCurrencyBalance returns the current balance.
func (c *ChainAPI) GetCurrencyBalance(props GetCurrencyBalanceProps) (GetCurrencyBalanceResponse, error) {
var r = GetCurrencyBalanceResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_currency_balance"), props, &r)
return r, err
}
type GetCurrencyStatsProps struct {
Code string `json:"code,omitempty"`
Symbol string `json:"symbol,omitempty"`
}
// GetCurrencyStats retrieves currency stats.
func (c *ChainAPI) GetCurrencyStats(props GetCurrencyStatsProps) (GetCurrencyStatsResponse, error) {
var r interface{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_currency_stats"), props, &r)
return r, err
}
type GetRequiredKeysProps struct {
Transaction Transaction `json:"transaction"`
AvailableKeys []string `json:"available_keys"`
}
// GetRequiredKeys returns the required keys needed to sign a transaction.
func (c *ChainAPI) GetRequiredKeys(props GetRequiredKeysProps) (GetRequiredKeysResponse, error) {
var r = GetRequiredKeysResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_required_keys"), props, &r)
return r, err
}
type GetProducersProps struct {
Limit string `json:"limit"`
LowerBound string `json:"lower_bound"`
JSON bool `json:"json,omitempty"`
}
// GetProducers retrieves producers list.
func (c *ChainAPI) GetProducers(props GetProducersProps) (GetProducersResponse, error) {
var r = GetProducersResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_producers"), props, &r)
return r, err
}
// GetRawCodeAndABI retrieves raw code and ABI for a contract based on account name.
func (c *ChainAPI) GetRawCodeAndABI(props AccountProps) (GetRawCodeAndABIResponse, error) {
var r = GetRawCodeAndABIResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_raw_code_and_abi"), props, &r)
return r, err
}
type GetScheduledTransactionProps struct {
LowerBound string `json:"lower_bound,omitempty"`
Limit int64 `json:"limit"`
JSON bool `json:"json"`
}
// GetScheduledTransaction retrieves the scheduled transaction.
func (c *ChainAPI) GetScheduledTransaction(props GetScheduledTransactionProps) (GetScheduledTransactionResponse, error) {
var r = GetScheduledTransactionResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_scheduled_transaction"), props, &r)
return r, err
}
type GetTableByScopeProps struct {
Code string `json:"code"`
Table string `json:"table,omitempty"`
LowerBound string `json:"lower_bound,omitempty"`
UpperBound string `json:"upper_bound,omitempty"`
Limit int32 `json:"limit,omitempty"`
Reverse bool `json:"reverse,omitempty"`
ShowPayer bool `json:"show_payer,omitempty"`
}
// GetTableByScope retrieves table scope.
func (c *ChainAPI) GetTableByScope(props GetTableByScopeProps) (GetTableByScopeResponse, error) {
var r = GetTableByScopeResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_table_by_scope"), props, &r)
return r, err
}
type GetTableRowsProps struct {
Code string `json:"code"`
Table string `json:"table"`
Scope string `json:"scope"`
IndexPosition string `json:"index_position"`
KeyType string `json:"key_type"`
EncodeType string `json:"encode_type"`
LowerBound string `json:"lower_bound"`
UpperBound string `json:"upper_bound"`
Limit int32 `json:"limit"`
Reverse bool `json:"reverse"`
ShowPayer bool `json:"show_payer"`
JSON bool `json:"json"`
}
// GetTableRows returns an object containing rows from the specified table.
func (c *ChainAPI) GetTableRows(props GetTableRowsProps) (GetTableRowsResponse, error) {
var r = GetTableRowsResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_table_rows"), props, &r)
return r, err
}
type GetKVTableRowsProps struct {
Code string `json:"code"`
Table string `json:"table"`
IndexName string `json:"index_name"`
EncodeType interface{} `json:"encode_type"`
IndexValue string `json:"index_value"`
LowerBound string `json:"lower_bound"`
UpperBound string `json:"upper_bound"`
Limit int64 `json:"limit"`
Reverse bool `json:"reverse"`
}
// GetKVTableRows returns an object containing rows from the specified table.
func (c *ChainAPI) GetKVTableRows(props GetKVTableRowsProps) (GetKVTableRowsResponse, error) {
var r = GetKVTableRowsResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_kv_table_rows"), props, &r)
return r, err
}
type ABIJSONToBinProps struct {
Code string `json:"code,omitempty"`
Action string `json:"action,omitempty"`
Args interface{} `json:"args,omitempty"`
}
// ABIJsonToBin returns an object containing the serialized action data.
func (c *ChainAPI) ABIJsonToBin(props ABIJSONToBinProps) (ABIJsonToBinResponse, error) {
var r = ABIJsonToBinResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "abi_json_to_bin"), props, &r)
return r, err
}
type ABIBinToJSONProps struct {
Code string `json:"code"`
Action string `json:"action"`
Binargs string `json:"binargs"`
}
// ABIBinToJson returns an object containing the deserialized action data.
func (c *ChainAPI) ABIBinToJson(props ABIBinToJSONProps) (ABIBinToJsonResponse, error) {
var r = ABIBinToJsonResponse("")
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "abi_bin_to_json"), props, &r)
return r, err
}
type GetCodeProps struct {
AccountName string `json:"account_name"`
CodeAsWASM int64 `json:"code_as_wasm"`
}
// GetCode returns an object containing the smart contract WASM code.
func (c *ChainAPI) GetCode(props GetCodeProps) (GetCodeResponse, error) {
var r = GetCodeResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_code"), props, &r)
return r, err
}
// GetRawABI returns an object containing smart contract abi.
func (c *ChainAPI) GetRawABI(props AccountProps) (GetRawABIResponse, error) {
var r = GetRawABIResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_raw_abi"), props, &r)
return r, err
}
type GetActivatedProtocolFeaturesProps struct {
Params Params `json:"params"`
}
type Params struct {
LowerBound int64 `json:"lower_bound,omitempty"`
UpperBound int64 `json:"upper_bound,omitempty"`
Limit int64 `json:"limit,omitempty"`
SearchByBlockNum bool `json:"search_by_block_num"`
Reverse bool `json:"reverse"`
}
// GetActivatedProtocolFeatures retreives the activated protocol features for producer node.
func (c *ChainAPI) GetActivatedProtocolFeatures(props GetActivatedProtocolFeaturesProps) (GetActivatedProtocolFeaturesResponse, error) {
var r = GetActivatedProtocolFeaturesResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_activated_protocol_features"), props, &r)
return r, err
}
type GetAccountsByAuthorizersProps struct {
Accounts []string `json:"accounts"`
Keys []string `json:"keys"`
}
// GetAccountsByAuthorizers, given a set of account names and public keys, find all account permission authorities that are, in part or whole, satisfiable.
func (c *ChainAPI) GetAccountsByAuthorizers(props GetAccountsByAuthorizersProps) (GetAccountsByAuthorizersResponse, error) {
var r = GetAccountsByAuthorizersResponse{}
err := request(c.Client, urljoin.UrlJoin(c.ApiUrl, "get_accounts_by_authorizers"), props, &r)
return r, err
}