-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_handler.py
56 lines (47 loc) · 1.99 KB
/
lambda_handler.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
50
51
52
53
54
55
import json
import traceback
from config import INFURA_URL_HTTPS, NET_ID, INFURA_URL_HTTPS_1
from repository import Repository
from transfers_handler import TransfersHandler
from staking_handler import StakingHandler, UnBondedStakingHandler
from uniswap_event_handler import UniswapV2TransfersHandler
processor_map = {
'AGIX': {'TRANSFER': TransfersHandler, 'LPWETH':UniswapV2TransfersHandler, 'LPUSDT':UniswapV2TransfersHandler, 'STAKE1': StakingHandler},
'SDAO': {'TRANSFER': TransfersHandler, 'LPWETH':UniswapV2TransfersHandler, 'LPUSDT':UniswapV2TransfersHandler, 'STAKE1': StakingHandler,
'STAKE2': StakingHandler, 'STAKE3' : UnBondedStakingHandler}
}
def response(status, message):
return {
'statusCode': status,
'body': json.dumps(message)
}
def lambda_handler(event, context):
if 'token' not in event or 'type' not in event:
return response(500,"Invalid payload provided " + str(event))
token = event['token']
type = event['type']
transfer_type= token + "_" + type
if token not in processor_map and type not in processor_map[token]:
return response(500,"Unknown token or type - " + str(event))
status_code = 200
message = 'Success'
repository = Repository()
insert_job_status = 'INSERT INTO job_runs ' + \
'(name, end_block_number, context, row_created, row_updated) ' + \
'VALUES (%s, %s, %s, current_timestamp, current_timestamp) '
tp = None
try:
infura_url=INFURA_URL_HTTPS
if token == 'AGIX':
infura_url = INFURA_URL_HTTPS_1
tp = processor_map[token][type](infura_url, NET_ID, transfer_type, repository)
tp.process()
except Exception as e:
traceback.print_exc()
status_code = 500
message = repr(e)
print(message)
if tp is not None:
tp._repository.execute(insert_job_status, [str(token + "_" + type), 0, message])
event['message'] = message
return response(status_code, event)