This repository was archived by the owner on May 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.py
More file actions
64 lines (45 loc) · 1.97 KB
/
init.py
File metadata and controls
64 lines (45 loc) · 1.97 KB
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
56
57
58
59
60
61
"""Initialization for the migration service"""
import logging
from flask_log_request_id import RequestID, RequestIDLogFilter
from flask_log_request_id.parser import amazon_elb_trace_id
import uuid
import kin
from kin.utils import create_channels
import flask
from flask_cors import CORS
from datadog import DogStatsd
import config
def req_id_generator() -> str:
"""
Generate a unique request id, used when the request id cannot be fetched from the elb headers
"""
# 8 chars long should be long enough, add the 'Generated' prefix to know not to search for this id in the elb logs
return f'Generated-{str(uuid.uuid4())[:8]}'
# Setup app
app = flask.Flask(__name__)
# Allow CORS
CORS(app)
# Inject request id to a request's context
RequestID(app, request_id_parser=amazon_elb_trace_id, request_id_generator=req_id_generator)
# Setup logging
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s | level=%(levelname)s | request_id=%(request_id)s | %(message)s'))
handler.addFilter(RequestIDLogFilter())
logging.root.addHandler(handler)
logger = logging.getLogger('migration')
logger.setLevel('INFO')
kin_logger = logging.getLogger('kin')
kin_logger.setLevel('ERROR')
# Setup DogStatsd
statsd = DogStatsd(host=config.STATSD_HOST, port=config.STATSD_PORT, namespace='migration')
# Setup kin
# Passphrase is not needed for the old environment since we don't send any txs to it
old_env = kin.Environment('OLD', config.OLD_HORIZON, '')
new_env = kin.Environment('NEW', config.NEW_HORIZON, config.NEW_PASSPHRASE)
old_client = kin.KinClient(old_env)
new_client = kin.KinClient(new_env)
channels = create_channels(config.MAIN_SEED, new_env, config.CHANNEL_COUNT, 0, config.CHANNEL_SALT)
main_account = new_client.kin_account(config.MAIN_SEED, channels, app_id=config.APP_ID)
logger.info(f'Initialized app with address: {main_account.keypair.public_address}, '
f'Old horizon: {config.OLD_HORIZON}, '
f'New horizon: {config.NEW_HORIZON}')