Skip to content

Commit 6225ec3

Browse files
authored
Merge pull request #44 from ainblockchain/release/v1.2.0
Release/v1.2.0
2 parents da10459 + 3a5b0df commit 6225ec3

File tree

11 files changed

+664
-90
lines changed

11 files changed

+664
-90
lines changed

.github/workflows/docs.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ jobs:
77
build:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/setup-python@v2
10+
- uses: actions/setup-python@v5
11+
with:
12+
python-version: '3.11'
1113
- uses: actions/checkout@master
1214
with:
1315
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

ain/ain.py

+263-54
Original file line numberDiff line numberDiff line change
@@ -64,87 +64,262 @@ def setSigner(self, signer: Signer):
6464

6565
# TODO(kriii): Return objects typing.
6666

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(
6892
self,
69-
blockHashOrBlockNumber: Union[str, int],
93+
blockNumber: int,
7094
returnTransactionObjects: bool = False,
7195
) -> Any:
72-
"""Gets a block with the given hash or block number.
96+
"""Gets a block with the given block number.
7397
7498
Args:
75-
blockHashOrBlockNumber (Union[str, int]): The block hash or the block number.
99+
blockNumber (int): The block number.
76100
returnTransactionObjects (bool): If `True`, returns the full transaction objects.
77101
If `False`, returns only the transaction hashes. Default to `False`.
78102
79103
Returns:
80-
The block with the given hash or block number.
104+
The block with the given block number.
81105
"""
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.
100143
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(
102220
self,
103-
blockHashOrBlockNumber: Union[str, int],
221+
address: str,
104222
) -> Any:
105-
"""Gets an address of the proposer of the given block.
223+
"""Fetches the information of the given validator address.
106224
107225
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.
109243
244+
Args:
245+
blockNumber (int): The block number.
246+
110247
Returns:
111-
The address of the proposer of the given block.
248+
The list of validators of the given block.
112249
"""
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+
)
123253

124-
async def getValidators(
254+
async def getValidatorsByHash(
125255
self,
126-
blockHashOrBlockNumber: Union[str, int],
256+
blockHash: str,
127257
) -> Any:
128-
"""Gets the list of validators for a given block
258+
"""Fetches the validator list of a block with a block hash.
129259
130260
Args:
131-
blockHashOrBlockNumber (Union[str, int]): The block hash or the block number.
261+
blockHash (str): The block hash.
132262
133263
Returns:
134-
The list of validators for a given block.
264+
The list of validators of the given block.
135265
"""
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+
)
146301

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:
148323
"""Gets a transaction with the given transaction hash.
149324
150325
Args:
@@ -155,6 +330,40 @@ async def getTransaction(self, transactionHash: str) -> Any:
155330
"""
156331
return await self.provider.send("ain_getTransactionByHash", {"hash": transactionHash})
157332

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+
158367
async def getStateUsage(self, appName: str) -> Any:
159368
"""Gets a state usage with the given app name.
160369

0 commit comments

Comments
 (0)