Created
February 23, 2021 11:12
-
-
Save andelf/5da24090512ea219767b27684f5771e3 to your computer and use it in GitHub Desktop.
Parse TVM event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tronpy import Tron | |
from tronpy.keys import keccak256 | |
from pprint import pprint | |
client = Tron() | |
txn_id = 'e010654f48b5f94a4ea0305273bac3310b273979e1df61c8fd2334c52686ba6e' | |
txn_info = client.get_transaction_info(txn_id) | |
pprint(txn_info) | |
target_event = 'Transfer(address,address,uint256)' | |
event_hash = keccak256(target_event.encode()).hex() | |
for log in txn_info.get('log', []): | |
if log['topics'][0] == event_hash: | |
print('Transfer!') | |
from_addr = client.to_base58check_address('41' + log['topics'][1][-40:]) | |
print('From', from_addr) | |
to_addr = client.to_base58check_address('41' + log['topics'][2][-40:]) | |
print('To', to_addr) | |
amount = int(log['data'], 16) | |
print('Amount', amount) | |
else: | |
print('unknown event:', log['topics'][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment