@@ -64,87 +64,262 @@ def setSigner(self, signer: Signer):
64
64
65
65
# TODO(kriii): Return objects typing.
66
66
67
- async def getBlock (
67
+ async def getLastBlock (self ) -> Any :
68
+ """Fetches the last block.
69
+
70
+ Args:
71
+
72
+ Returns:
73
+ The last block.
74
+ """
75
+ return await self .provider .send (
76
+ "ain_getLastBlock" , {}
77
+ )
78
+
79
+ async def getLastBlockNumber (self ) -> int :
80
+ """Fetches the last block number.
81
+
82
+ Args:
83
+
84
+ Returns:
85
+ The last block number.
86
+ """
87
+ return await self .provider .send (
88
+ "ain_getLastBlockNumber" , {}
89
+ )
90
+
91
+ async def getBlockByNumber (
68
92
self ,
69
- blockHashOrBlockNumber : Union [ str , int ] ,
93
+ blockNumber : int ,
70
94
returnTransactionObjects : bool = False ,
71
95
) -> Any :
72
- """Gets a block with the given hash or block number.
96
+ """Gets a block with the given block number.
73
97
74
98
Args:
75
- blockHashOrBlockNumber (Union[str, int] ): The block hash or the block number.
99
+ blockNumber ( int): The block number.
76
100
returnTransactionObjects (bool): If `True`, returns the full transaction objects.
77
101
If `False`, returns only the transaction hashes. Default to `False`.
78
102
79
103
Returns:
80
- The block with the given hash or block number.
104
+ The block with the given block number.
81
105
"""
82
- if type (blockHashOrBlockNumber ) is str :
83
- return await self .provider .send (
84
- "ain_getBlockByHash" ,
85
- {
86
- "getFullTransactions" : returnTransactionObjects ,
87
- "hash" : blockHashOrBlockNumber ,
88
- },
89
- )
90
- elif type (blockHashOrBlockNumber ) is int :
91
- return await self .provider .send (
92
- "ain_getBlockByNumber" ,
93
- {
94
- "getFullTransactions" : returnTransactionObjects ,
95
- "number" : blockHashOrBlockNumber ,
96
- },
97
- )
98
- else :
99
- raise TypeError ("blockHashOrBlockNumber has invalid type" )
106
+ return await self .provider .send (
107
+ "ain_getBlockByNumber" ,
108
+ {
109
+ "getFullTransactions" : returnTransactionObjects ,
110
+ "number" : blockNumber ,
111
+ },
112
+ )
113
+
114
+ async def getBlockByHash (
115
+ self ,
116
+ blockHash : str ,
117
+ returnTransactionObjects : bool = False ,
118
+ ) -> Any :
119
+ """Gets a block with the given block hash.
120
+
121
+ Args:
122
+ blockHash (str): The block hash.
123
+ returnTransactionObjects (bool): If `True`, returns the full transaction objects.
124
+ If `False`, returns only the transaction hashes. Default to `False`.
125
+
126
+ Returns:
127
+ The block with the given block hash.
128
+ """
129
+ return await self .provider .send (
130
+ "ain_getBlockByHash" ,
131
+ {
132
+ "getFullTransactions" : returnTransactionObjects ,
133
+ "hash" : blockHash ,
134
+ },
135
+ )
136
+
137
+ async def getBlockList (
138
+ self ,
139
+ begin : int ,
140
+ end : int ,
141
+ ) -> List [Any ]:
142
+ """"Fetches blocks with a block number range.
100
143
101
- async def getProposer (
144
+ Args:
145
+ begin (int): The begining block number (inclusive).
146
+ end (int): The ending block number (exclusive).
147
+
148
+ Returns:
149
+ The block list.
150
+ """
151
+ return await self .provider .send (
152
+ "ain_getBlockList" ,
153
+ {
154
+ "from" : begin ,
155
+ "to" : end ,
156
+ },
157
+ )
158
+
159
+ async def getBlockHeadersList (
160
+ self ,
161
+ begin : int ,
162
+ end : int ,
163
+ ) -> List [Any ]:
164
+ """Fetches block headers with a block number range.
165
+
166
+ Args:
167
+ begin (int): The begining block number (inclusive).
168
+ end (int): The ending block number (exclusive).
169
+
170
+ Returns:
171
+ The block headers list.
172
+ """
173
+ return await self .provider .send (
174
+ "ain_getBlockHeadersList" ,
175
+ {
176
+ "from" : begin ,
177
+ "to" : end ,
178
+ },
179
+ )
180
+
181
+ async def getBlockTransactionCountByNumber (
182
+ self ,
183
+ blockNumber : int ,
184
+ ) -> int :
185
+ """Fetches block transaction count with a block number.
186
+
187
+ Args:
188
+ blockNumber (int): The block number.
189
+
190
+ Returns:
191
+ The block transaction count.
192
+ """
193
+ return await self .provider .send (
194
+ "ain_getBlockTransactionCountByNumber" ,
195
+ {
196
+ "number" : blockNumber ,
197
+ },
198
+ )
199
+
200
+ async def getBlockTransactionCountByHash (
201
+ self ,
202
+ blockHash : str ,
203
+ ) -> int :
204
+ """Fetches block transaction count with a block hash.
205
+
206
+ Args:
207
+ blockHash (str): The block hash.
208
+
209
+ Returns:
210
+ The block transaction count.
211
+ """
212
+ return await self .provider .send (
213
+ "ain_getBlockTransactionCountByHash" ,
214
+ {
215
+ "hash" : blockHash ,
216
+ },
217
+ )
218
+
219
+ async def getValidatorInfo (
102
220
self ,
103
- blockHashOrBlockNumber : Union [ str , int ] ,
221
+ address : str ,
104
222
) -> Any :
105
- """Gets an address of the proposer of the given block .
223
+ """Fetches the information of the given validator address .
106
224
107
225
Args:
108
- blockHashOrBlockNumber (Union[str, int]): The block hash or the block number.
226
+ address (str): The block number.
227
+
228
+ Returns:
229
+ The validator information.
230
+ """
231
+ return await self .provider .send (
232
+ "ain_getValidatorInfo" ,
233
+ {
234
+ "address" : address ,
235
+ },
236
+ )
237
+
238
+ async def getValidatorsByNumber (
239
+ self ,
240
+ blockNumber : int ,
241
+ ) -> Any :
242
+ """Fetches the validator list of a block with a block number.
109
243
244
+ Args:
245
+ blockNumber (int): The block number.
246
+
110
247
Returns:
111
- The address of the proposer of the given block.
248
+ The list of validators of the given block.
112
249
"""
113
- if type (blockHashOrBlockNumber ) is str :
114
- return await self .provider .send (
115
- "ain_getProposerByHash" , {"hash" : blockHashOrBlockNumber }
116
- )
117
- elif type (blockHashOrBlockNumber ) is int :
118
- return await self .provider .send (
119
- "ain_getProposerByNumber" , {"number" : blockHashOrBlockNumber }
120
- )
121
- else :
122
- raise TypeError ("blockHashOrBlockNumber has invalid type" )
250
+ return await self .provider .send (
251
+ "ain_getValidatorsByNumber" , {"number" : blockNumber }
252
+ )
123
253
124
- async def getValidators (
254
+ async def getValidatorsByHash (
125
255
self ,
126
- blockHashOrBlockNumber : Union [ str , int ] ,
256
+ blockHash : str ,
127
257
) -> Any :
128
- """Gets the list of validators for a given block
258
+ """Fetches the validator list of a block with a block hash.
129
259
130
260
Args:
131
- blockHashOrBlockNumber (Union[ str, int] ): The block hash or the block number .
261
+ blockHash ( str): The block hash.
132
262
133
263
Returns:
134
- The list of validators for a given block.
264
+ The list of validators of the given block.
135
265
"""
136
- if type (blockHashOrBlockNumber ) is str :
137
- return await self .provider .send (
138
- "ain_getValidatorsByHash" , {"hash" : blockHashOrBlockNumber }
139
- )
140
- elif type (blockHashOrBlockNumber ) is int :
141
- return await self .provider .send (
142
- "ain_getValidatorsByNumber" , {"number" : blockHashOrBlockNumber }
143
- )
144
- else :
145
- raise TypeError ("blockHashOrBlockNumber has invalid type" )
266
+ return await self .provider .send (
267
+ "ain_getValidatorsByHash" , {"hash" : blockHash }
268
+ )
269
+
270
+ async def getProposerByNumber (
271
+ self ,
272
+ blockNumber : int ,
273
+ ) -> str :
274
+ """Fetches the block proproser's address of a block with a block number.
275
+
276
+ Args:
277
+ blockNumber (int): The block number.
278
+
279
+ Returns:
280
+ The address of the proposer of the given block.
281
+ """
282
+ return await self .provider .send (
283
+ "ain_getProposerByNumber" , {"number" : blockNumber }
284
+ )
285
+
286
+ async def getProposerByHash (
287
+ self ,
288
+ blockHash : str ,
289
+ ) -> str :
290
+ """Fetches the block proproser's address of a block with a block hash.
291
+
292
+ Args:
293
+ blockHash (str): The block hash.
294
+
295
+ Returns:
296
+ The address of the proposer of the given block.
297
+ """
298
+ return await self .provider .send (
299
+ "ain_getProposerByHash" , {"hash" : blockHash }
300
+ )
146
301
147
- async def getTransaction (self , transactionHash : str ) -> Any :
302
+ async def getPendingTransactions (self ) -> Any :
303
+ """Fetches pending transactions.
304
+
305
+ Args:
306
+
307
+ Returns:
308
+ The pending transactions.
309
+ """
310
+ return await self .provider .send ("ain_getPendingTransactions" , {})
311
+
312
+ async def getTransactionPoolSizeUtilization (self ) -> Any :
313
+ """Fetches transaction pool size utilization.
314
+
315
+ Args:
316
+
317
+ Returns:
318
+ The transaction pool size utilization.
319
+ """
320
+ return await self .provider .send ("ain_getTransactionPoolSizeUtilization" , {})
321
+
322
+ async def getTransactionByHash (self , transactionHash : str ) -> Any :
148
323
"""Gets a transaction with the given transaction hash.
149
324
150
325
Args:
@@ -155,6 +330,40 @@ async def getTransaction(self, transactionHash: str) -> Any:
155
330
"""
156
331
return await self .provider .send ("ain_getTransactionByHash" , {"hash" : transactionHash })
157
332
333
+ async def getTransactionByBlockHashAndIndex (self , blockHash : str , index : int ) -> Any :
334
+ """Fetches a transaction's information with a block hash and an index.
335
+
336
+ Args:
337
+ blockHash (str): The block hash.
338
+ index (int): The transaction index in the block
339
+
340
+ Returns:
341
+ The transaction with the given parameter values.
342
+ """
343
+ return await self .provider .send (
344
+ "ain_getTransactionByBlockHashAndIndex" ,
345
+ {
346
+ "block_hash" : blockHash ,
347
+ "index" : index
348
+ })
349
+
350
+ async def getTransactionByBlockNumberAndIndex (self , blockNumber : int , index : int ) -> Any :
351
+ """Fetches a transaction's information with a block number and an index.
352
+
353
+ Args:
354
+ blockHash (int): The block number.
355
+ index (int): The transaction index in the block
356
+
357
+ Returns:
358
+ The transaction with the given parameter values.
359
+ """
360
+ return await self .provider .send (
361
+ "ain_getTransactionByBlockNumberAndIndex" ,
362
+ {
363
+ "block_number" : blockNumber ,
364
+ "index" : index
365
+ })
366
+
158
367
async def getStateUsage (self , appName : str ) -> Any :
159
368
"""Gets a state usage with the given app name.
160
369
0 commit comments