__init__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import redis
  3. import pickle
  4. import pandas as pd
  5. from typing import Any, Dict
  6. from flask import Flask
  7. from config import Config
  8. from flask_sqlalchemy import SQLAlchemy
  9. from flask_migrate import Migrate
  10. from ens import ENS
  11. from web3 import Web3
  12. app: Any = Flask(__name__)
  13. app.config.from_object(Config)
  14. db: SQLAlchemy = SQLAlchemy(app) # init SQLite DB
  15. migrate: Migrate = Migrate(app, db)
  16. rds = redis.Redis(host='localhost', port=6380, db=0)
  17. class InfuraAuth:
  18. def __init__(self):
  19. self._id: str = os.environ['INFURA_ALPHA_ID']
  20. self._secret: str = os.environ['INFURA_ALPHA_SECRET']
  21. def auth(self) -> Dict[str, Any]:
  22. return dict(id=self._id, secret=self._secret)
  23. def get_w3(infura: InfuraAuth) -> Web3:
  24. auth_dict: Dict[str, Any] = infura.auth()
  25. uri: str = f'https://:{auth_dict["secret"]}@mainnet.infura.io/v3/{auth_dict["id"]}'
  26. w3 = Web3(Web3.HTTPProvider(uri))
  27. return w3
  28. def get_ens(w3: Web3) -> ENS:
  29. return ENS.fromWeb3(w3)
  30. infura: InfuraAuth = InfuraAuth()
  31. w3: Web3 = get_w3(infura)
  32. ns: ENS = get_ens(w3)
  33. def get_realpath(path: str) -> str:
  34. base_dir: str = os.path.dirname(__file__)
  35. path: str = os.path.join(base_dir, path)
  36. return os.path.realpath(path)
  37. known_addresses: pd.DataFrame = pd.read_csv(
  38. get_realpath('static/data/known_addresses.csv'))
  39. tornado_pools: pd.DataFrame = pd.read_csv(
  40. get_realpath('static/data/tornado.csv'))
  41. with open(get_realpath('static/data/transaction_reveal_dist.pickle'), 'rb') as fp:
  42. reveal_dists: Dict[str, Dict[int, int]] = pickle.load(fp)
  43. from app import views, models