12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import os
- import redis
- import pickle
- import pandas as pd
- from typing import Any, Dict
- from flask import Flask
- from config import Config
- from flask_sqlalchemy import SQLAlchemy
- from flask_migrate import Migrate
- from ens import ENS
- from web3 import Web3
- app: Any = Flask(__name__)
- app.config.from_object(Config)
- db: SQLAlchemy = SQLAlchemy(app) # init SQLite DB
- migrate: Migrate = Migrate(app, db)
- rds = redis.Redis(host='localhost', port=6380, db=0)
- class InfuraAuth:
- def __init__(self):
- self._id: str = os.environ['INFURA_ALPHA_ID']
- self._secret: str = os.environ['INFURA_ALPHA_SECRET']
- def auth(self) -> Dict[str, Any]:
- return dict(id=self._id, secret=self._secret)
- def get_w3(infura: InfuraAuth) -> Web3:
- auth_dict: Dict[str, Any] = infura.auth()
- uri: str = f'https://:{auth_dict["secret"]}@mainnet.infura.io/v3/{auth_dict["id"]}'
- w3 = Web3(Web3.HTTPProvider(uri))
- return w3
- def get_ens(w3: Web3) -> ENS:
- return ENS.fromWeb3(w3)
- infura: InfuraAuth = InfuraAuth()
- w3: Web3 = get_w3(infura)
- ns: ENS = get_ens(w3)
- def get_realpath(path: str) -> str:
- base_dir: str = os.path.dirname(__file__)
- path: str = os.path.join(base_dir, path)
- return os.path.realpath(path)
- known_addresses: pd.DataFrame = pd.read_csv(
- get_realpath('static/data/known_addresses.csv'))
- tornado_pools: pd.DataFrame = pd.read_csv(
- get_realpath('static/data/tornado.csv'))
- with open(get_realpath('static/data/transaction_reveal_dist.pickle'), 'rb') as fp:
- reveal_dists: Dict[str, Dict[int, int]] = pickle.load(fp)
- from app import views, models
|