-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
31 lines (25 loc) · 1.18 KB
/
functions.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
def get_last_network_block(network):
network.network_type == 'tron'
last_block_networks = {
'ethereum': (network.w3.eth.block_number - network.confirmation_blocks),
'tron': (
network.get_block_data('latest')['number'] - network.confirmation_blocks
)
}
return last_block_networks[network.network_type]
def get_event_data(network, last_block_checked, last_block_network, event):
if network.network_type == 'ethereum':
event_filter = event.createFilter(
fromBlock=last_block_checked, toBlock=last_block_network
)
events= event_filter.get_all_entries()
elif network.network_type == 'tron':
url = \
f'{network.endpoint}/v1/contracts/{network.swap_address}/events?event_name={event}' \
f'&min_block_timestamp={last_block_checked["timestamp"]}' \
f'&max_block_timestamp={last_block_network["timestamp"]}'
events = requests.get(url).json()['data']
return events
def get_block_data(network, identifer):
if network.network_type == 'tron':
return network.tron.trx.get_block(identifer)['block_header']['raw_data']