-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_next_tx.py
49 lines (37 loc) · 1.61 KB
/
get_next_tx.py
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
import asyncio
import time
from pytoncenter import get_client
from pytoncenter.v3.models import *
"""
Take this transaction as example:
https://testnet.tonviewer.com/transaction/84b7c9467a0a24e7a59a5e224e9ef8803563621f4710fe8536ae7803fe245d61
The output transactions should be:
1. ae4bf0c6a14506c6440e063d779768d464cabc87b5f552ba04ed31e9d79d9f93
2. 754ae0725ab41d3c627e8ca992e250cbc3db239e82d02d93a7b4aebba55ba358
"""
async def main():
client = get_client(version="v3", network="testnet")
print("==============Reommanded way (Fast)=====================")
start = time.monotonic()
txs, _ = await client.get_adjacent_transactions(
GetAdjacentTransactionsRequest(
hash="84b7c9467a0a24e7a59a5e224e9ef8803563621f4710fe8536ae7803fe245d61",
direction="out",
)
)
for _tx in txs:
print("Out Msg Hash", _tx.in_msg.hash, " -> Transaction hash", _tx.hash)
end = time.monotonic()
print("Time elapsed:", end - start)
print("==============Alternative way (Slow)=====================")
start = time.monotonic()
tx, _ = await client.get_transactions(GetTransactionByHashRequest(hash="84b7c9467a0a24e7a59a5e224e9ef8803563621f4710fe8536ae7803fe245d61"))
assert tx is not None
for out_msg in tx.out_msgs:
txs, _ = await client.get_transaction_by_message(GetTransactionByMessageRequest(direction="in", msg_hash=out_msg.hash))
for _tx in txs:
print("Out Msg Hash", out_msg.hash, " -> Transaction hash", _tx.hash)
end = time.monotonic()
print("Time elapsed:", end - start)
if __name__ == "__main__":
asyncio.run(main())