Пример #1
0
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)
Пример #2
0
def run_bridge():  # pylint: disable=too-many-statements
    runners = []
    logger = get_logger(logger_name='runner', loglevel=config.log_level)
    try:
        configure_secretcli(config)
    except RuntimeError:
        logger = get_logger(logger_name='runner', loglevel=config.log_level)
        logger.error('Failed to set up secretcli')
        sys.exit(1)

    if config.token:
        signer = Pkcs11CryptoStore(store=config.pkcs11_module,
                                   token=config.token,
                                   user_pin=config.user_pin,
                                   label=config.label)
    else:
        signer = LocalCryptoStore(private_key=bytes_from_hex(
            config.eth_private_key),
                                  account=config.eth_address)

    logger.info(f'Starting with ETH address {signer.address}')

    uri = config.db_uri
    if not uri:
        db = config.db_name or 'test_db'
        host = config.db_host or 'localhost'
        password = config.db_password
        username = config.db_username
        uri = f"mongodb+srv://{username}:{password}@{host}/{db}?retryWrites=true&w=majority"

    with database(uri):
        eth_wallet = MultisigWallet(w3, config.multisig_wallet_address)
        secret_account = SecretAccount(config.multisig_acc_addr,
                                       config.secret_key_name)

        eth_signer = EtherSigner(eth_wallet, signer, config=config)
        s20_signer = Secret20Signer(secret_account, eth_wallet, config)

        runners.append(s20_signer)

        if config.mode.lower() == 'signer':
            runners.append(eth_signer)

        if config.mode.lower() == 'leader':
            eth_leader = EtherLeader(eth_wallet, signer, config=config)

            secret_leader = SecretAccount(config.multisig_acc_addr,
                                          config.multisig_key_name)
            s20_leader = Secret20Leader(secret_leader,
                                        eth_wallet,
                                        config=config)

            runners.append(eth_leader)
            runners.append(s20_leader)

        # run_all(runners)
        run(runners, config)
Пример #3
0
def ethr_signers(multisig_wallet, configuration: Config, ether_accounts,
                 erc20_token) -> List[EtherSigner]:
    res = []

    # token_map = {erc20_token.address: Token(configuration['secret_swap_contract_address'],
    #                                         configuration['secret_token_name'])}
    # token_map = configuration["token_map_eth"]
    # we will manually create the last signer in test_3
    for acc in ether_accounts[1:]:
        private_key = acc.key
        address = acc.address
        signer = LocalCryptoStore(private_key=private_key, account=address)
        res.append(EtherSigner(multisig_wallet, signer, config=configuration))

    yield res

    for signer in res:
        signer.stop()
    rmtree(Path.joinpath(Path.home(), ".bridge_test"), ignore_errors=True)
Пример #4
0
def ethr_leader(multisig_account, configuration: Config, web3_provider,
                erc20_token, multisig_wallet, ether_accounts):
    configuration['leader_key'] = ether_accounts[0].key
    configuration['leader_acc_addr'] = normalize_address(
        ether_accounts[0].address)
    configuration['eth_start_block'] = web3_provider.eth.blockNumber

    # token_map = configuration["token_map_scrt"]
    signer = LocalCryptoStore(private_key=configuration['leader_key'],
                              account=configuration['leader_acc_addr'])
    leader = EtherLeader(multisig_wallet,
                         signer,
                         dst_network="Secret",
                         config=configuration)

    leader.start()
    yield leader
    leader.stop()