Пример #1
0
def main(
        rpc_provider: HTTPProvider,
        private_key: str,
        private_key_password_file: str,
        state_file: str,
        channel_manager_address: str,
        minimum_amount: int,
        gas_price: int,
):
    if minimum_amount <= 0:
        click.echo('Minimum amount need to be at least 1')
        sys.exit(1)
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = utils.privkey_to_addr(private_key)

    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
    config.NETWORK_CFG.set_defaults(int(web3.version.network))
    web3.eth.defaultAccount = receiver_address
    channel_manager_address = (
        channel_manager_address or config.NETWORK_CFG.channel_manager_address
    )
    channel_manager_contract = make_channel_manager_contract(web3, channel_manager_address)

    if not state_file:
        state_file_name = "%s_%s.db" % (
            channel_manager_address[:10],
            receiver_address[:10]
        )
        app_dir = click.get_app_dir('microraiden')
        if not os.path.exists(app_dir):
            click.echo('No state file or directory found!')
            sys.exit(1)
        state_file = os.path.join(app_dir, state_file_name)

    try:
        click.echo('Loading state file from {}'.format(state_file))
        state = ChannelManagerState.load(state_file)
    except StateFileException:
        click.echo('Error reading state file')
        traceback.print_exc()
        sys.exit(1)
    if not is_same_address(state.receiver, receiver_address):
        click.echo('Private key does not match receiver address in state file')
        sys.exit(1)
    elif not is_same_address(state.contract_address, channel_manager_address):
        click.echo('Channel manager contract address mismatch')
        sys.exit(1)

    click.echo('Withdrawing all paid tokens with at least {} due from '
               'receiver {}'.format(minimum_amount, receiver_address))
    withdraw_from_channels(
        private_key,
        state,
        channel_manager_contract,
        minimum_amount,
        gas_price * denoms.gwei if gas_price else None,
    )
Пример #2
0
def main(
    rpc_provider: HTTPProvider,
    private_key: str,
    private_key_password_file: str,
    state_file: str,
    channel_manager_address: str,
    minimum_amount: int,
    gas_price: int,
):
    if minimum_amount <= 0:
        click.echo('Minimum amount need to be at least 1')
        sys.exit(1)
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = utils.privkey_to_addr(private_key)

    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
    config.NETWORK_CFG.set_defaults(int(web3.version.network))
    web3.eth.defaultAccount = receiver_address
    channel_manager_address = (channel_manager_address
                               or config.NETWORK_CFG.channel_manager_address)
    channel_manager_contract = make_channel_manager_contract(
        web3, channel_manager_address)

    if not state_file:
        state_file_name = "%s_%s.db" % (channel_manager_address[:10],
                                        receiver_address[:10])
        app_dir = click.get_app_dir('microraiden')
        if not os.path.exists(app_dir):
            click.echo('No state file or directory found!')
            sys.exit(1)
        state_file = os.path.join(app_dir, state_file_name)

    try:
        click.echo('Loading state file from {}'.format(state_file))
        state = ChannelManagerState.load(state_file)
    except StateFileException:
        click.echo('Error reading state file')
        traceback.print_exc()
        sys.exit(1)
    if not is_same_address(state.receiver, receiver_address):
        click.echo('Private key does not match receiver address in state file')
        sys.exit(1)
    elif not is_same_address(state.contract_address, channel_manager_address):
        click.echo('Channel manager contract address mismatch')
        sys.exit(1)

    click.echo('Withdrawing all paid tokens with at least {} due from '
               'receiver {}'.format(minimum_amount, receiver_address))
    withdraw_from_channels(
        private_key,
        state,
        channel_manager_contract,
        minimum_amount,
        gas_price * denoms.gwei if gas_price else None,
    )
Пример #3
0
def main(
        rpc_provider: HTTPProvider,
        private_key: str,
        private_key_password_file: str,
        state_file: str,
        channel_manager_address: str
):
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)

    if not state_file:
        state_file_name = "%s_%s.json" % (channel_manager_address[:10], receiver_address[:10])
        app_dir = click.get_app_dir('microraiden')
        state_file = os.path.join(app_dir, state_file_name)

    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
    web3.eth.defaultAccount = receiver_address
    channel_manager_address = (
        channel_manager_address or config.CHANNEL_MANAGER_ADDRESS[web3.version.network]
    )
    channel_manager_contract = make_channel_manager_contract(web3, channel_manager_address)

    try:
        click.echo('Loading state file from {}'.format(state_file))
        state = ChannelManagerState.load(state_file)
    except StateFileException:
        click.echo('Error reading state file')
        traceback.print_exc()
        sys.exit(1)
    if not is_same_address(state.receiver, receiver_address):
        click.echo('Private key does not match receiver address in state file')
        sys.exit(1)
    elif not is_same_address(state.contract_address, channel_manager_address):
        click.echo('Channel manager contract address mismatch')
        sys.exit(1)

    click.echo('Closing all open channels with valid balance proofs for '
               'receiver {}'.format(receiver_address))
    close_open_channels(private_key, state, channel_manager_contract)