def run_bridge(): # pylint: disable=too-many-statements runners = [] logger = get_logger(logger_name='runner') required_configs = ['MODE', 'secret_node', 'multisig_acc_addr', 'chain_id'] cfg = Config(required=required_configs) try: configure_secretcli(cfg) except RuntimeError: logger = get_logger(logger_name='runner') logger.error('Failed to set up secretcli') sys.exit(1) if cfg.get('token', ''): signer = Pkcs11CryptoStore(store=cfg["PKCS11_MODULE"], token=cfg["token"], user_pin=cfg["user_pin"], label=cfg.get('label')) else: signer = LocalCryptoStore(private_key=bytes_from_hex( cfg['eth_private_key']), account=cfg['eth_address']) logger.info(f'Starting with ETH address {signer.address}') with database(db=cfg['db_name'], host=cfg['db_host'], password=cfg['db_password'], username=cfg['db_username']): eth_wallet = MultisigWallet(w3, cfg['multisig_wallet_address']) secret_account = SecretAccount(cfg['multisig_acc_addr'], cfg['secret_key_name']) eth_signer = EtherSigner(eth_wallet, signer, dst_network="Secret", config=cfg) s20_signer = Secret20Signer(secret_account, eth_wallet, cfg) runners.append(eth_signer) runners.append(s20_signer) if cfg['MODE'].lower() == 'leader': eth_leader = EtherLeader(eth_wallet, signer, dst_network="Secret", config=cfg) secret_leader = SecretAccount(cfg['multisig_acc_addr'], cfg['multisig_key_name']) s20_leader = Secret20Leader(secret_leader, eth_wallet, src_network="Ethereum", config=cfg) runners.append(eth_leader) runners.append(s20_leader) run_all(runners)
def __init__(self, secret_multisig: SecretAccount, contract: MultisigWallet, src_network: str, config: Config, *args, **kwargs): super().__init__(*args, **kwargs) token_map = {} pairs = TokenPairing.objects(dst_network=self.network, src_network=src_network) for pair in pairs: token_map.update( {pair.src_address: Token(pair.dst_address, pair.dst_coin)}) self.multisig_name = secret_multisig.name self.config = config self.manager = SecretManager(contract, token_map, secret_multisig, config) self.logger = get_logger( db_name=self.config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.multisig_name}")) self.stop_event = Event() super().__init__(group=None, name="SecretLeader", target=self.run, **kwargs)
def __init__(self, multisig_wallet: MultisigWallet, signer: CryptoManagerBase, dst_network: str, config: Config, **kwargs): self.config = config self.multisig_wallet = multisig_wallet self.erc20 = erc20_contract() token_map = {} pairs = TokenPairing.objects(dst_network=dst_network, src_network=self.network) for pair in pairs: token_map.update( {pair.dst_address: Token(pair.src_address, pair.src_coin)}) self.signer = signer # self.private_key = private_key # self.default_account = account self.token_map = token_map self.logger = get_logger(db_name=self.config['db_name'], logger_name=config.get( 'logger_name', self.__class__.__name__)) self.stop_event = Event() super().__init__(group=None, name="EtherLeader", target=self.run, **kwargs)
def __init__(self, contract: MultisigWallet, token_to_secret_map: Dict[str, Token], s20_multisig_account: SecretAccount, config: Config, **kwargs): self.contract = contract self.s20_map = token_to_secret_map self.config = config self.multisig = s20_multisig_account self.event_listener = EthEventListener(contract, config) self.logger = get_logger( db_name=self.config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.multisig.name}")) self.stop_signal = Event() self.account_num = 0 self.sequence_lock = Lock() self.sequence = 0 self.update_sequence() self.event_listener.register( self._handle, contract.tracked_event(), ) super().__init__(group=None, name="SecretManager", target=self.run, **kwargs)
def __init__(self, multisig_wallet: MultisigWallet, private_key: bytes, account: str, config: Config, **kwargs): self.config = config self.multisig_wallet = multisig_wallet self.private_key = private_key self.default_account = account self.logger = get_logger(db_name=self.config['db_name'], logger_name=config.get('logger_name', self.__class__.__name__)) self.stop_event = Event() super().__init__(group=None, name="EtherLeader", target=self.run, **kwargs)
def __init__(self, multisig_wallet: MultisigWallet, private_key: bytes, account: str, config: Config): # todo: simplify this, pylint is right self.multisig_wallet = multisig_wallet self.private_key = private_key self.account = account self.config = config self.logger = get_logger(db_name=config['db_name'], logger_name=config.get('logger_name', f"{self.__class__.__name__}-{self.account[0:5]}")) self.submissions_lock = Lock() self.catch_up_complete = False self.cache = self._create_cache() self.thread_pool = ThreadPoolExecutor()
def __init__(self, contract: EthereumContract, config: Config, **kwargs): # Note: each event listener can listen to one contract at a time self.id = next(self._ids) self.contract = contract self.config = config self.callbacks = Callbacks() self.logger = get_logger(db_name=config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.id}")) self.events = [] self.stop_event = Event() self.confirmations = config['eth_confirmations'] super().__init__(group=None, name=f"EventListener-{config.get('logger_name', '')}", target=self.run, **kwargs)
def __init__(self, contract: MultisigWallet, private_key: bytes, account: str, config: Config, **kwargs): self.account = account self.private_key = private_key self.event_listener = EthEventListener(contract, config) self.stop_event = Event() self.logger = get_logger( db_name=config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.account[0:5]}")) self.signer = EthSignerImpl(contract, self.private_key, self.account, config) super().__init__(group=None, name=f"{self.__class__.__name__}-{self.account[0:5]}", target=self.run, **kwargs)
def __init__(self, secret_multisig: SecretAccount, s20_contract: Token, contract: EthereumContract, config: Config, *args, **kwargs): super().__init__(*args, **kwargs) self.multisig_name = secret_multisig.name self.config = config self.manager = SecretManager(contract, s20_contract, secret_multisig, config) self.logger = get_logger( db_name=self.config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.multisig_name}")) self.stop_event = Event() super().__init__(group=None, name="SecretLeader", target=self.run, **kwargs)
def __init__(self, contract: MultisigWallet, signer: CryptoManagerBase, dst_network: str, config: Config, **kwargs): self.account = signer.address # self.private_key = private_key self.event_listener = EthEventListener(contract, config) self.stop_event = Event() self.logger = get_logger( db_name=config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.account[0:5]}")) self.config = config self.signer = EthSignerImpl(contract, signer, dst_network, config) super().__init__(group=None, name=f"{self.__class__.__name__}-{self.account[0:5]}", target=self.run, **kwargs) self.setDaemon(True) # so tests don't hang
def __init__(self, multisig_contract: MultisigWallet, signer: CryptoManagerBase, dst_network: str, config: Config): # todo: simplify this, pylint is right self.multisig_contract = multisig_contract self.account = signer.address self.signer = signer self.config = config self.logger = get_logger( db_name=config['db_name'], logger_name=config.get( 'logger_name', f"{self.__class__.__name__}-{self.account[0:5]}")) self.erc20 = erc20_contract() self.catch_up_complete = False self.token_map = {} pairs = TokenPairing.objects(dst_network=dst_network, src_network=self.network) for pair in pairs: self.token_map.update( {pair.src_address: Token(pair.dst_address, pair.dst_coin)}) self.tracked_tokens = self.token_map.keys()