Beispiel #1
0
def test_validate_pattern_raise_no_base58_characters():
    pattern = 'containIO'
    coin_symbol = 'BTC'

    with pytest.raises(Exception) as exc_info:
        validate_pattern(pattern, coin_symbol, False)
    assert str(exc_info.value) == 'pattern containIO contains not allowed characters: IO'
Beispiel #2
0
def test_validate_pattern_raise_impossible_prefix():
    pattern = '211'
    coin_symbol = 'BTC'
    btc_range = '1111111111111111111111111-1QLbz7JHiBTspS962RLKV8GndWFwiEaqKL'
    error_message = 'Impossible prefix! Choose different one from {} range' \
                    '(characters order is {})'.format(btc_range, base58)

    with pytest.raises(Exception) as exc_info:
        validate_pattern(pattern, coin_symbol, False)
    assert str(exc_info.value) == error_message
Beispiel #3
0
def test_validate_pattern_success():
    pattern = '123456'
    coin_symbol = 'BTC'

    result = validate_pattern(pattern, coin_symbol, False)

    assert result is True
Beispiel #4
0
def start_workers(args):
    coin_symbol = args.symbol
    pattern = args.pattern
    workers = args.cores
    compressed = not args.uncompressed
    segwit = args.segwit
    output_dir = args.output_dir
    input_script = args.input_script
    if segwit and not compressed:
        raise ValueError(
            'Segwit addresses must used compressed public key representation')
    jobs = []
    try:
        validate_pattern(pattern, coin_symbol, segwit)
        if input_script:
            validate_hex_script(input_script)
            address = convert_script_to_p2sh_address(
                input_script, coins[coin_symbol]['script_prefix_bytes'])
            if output_dir:
                save_qrcode(address, output_dir)
            print(address)
            return
    except ValueError as exc:
        logger.error(exc)
        return
    print(
        f'Looking for pattern {pattern} for {coins[coin_symbol]["name"]} using {workers} workers'
    )
    stop = multiprocessing.Event()
    found = multiprocessing.Event()
    for i in range(workers):
        p = multiprocessing.Process(
            target=generate_address,
            args=(i, coins[coin_symbol], pattern, compressed, segwit,
                  output_dir, found, stop),
        )
        jobs.append(p)
        p.start()
    found.wait()
Beispiel #5
0
def start_workers(args):
    coin_symbol = args.symbol
    pattern = args.pattern
    workers = args.cores
    compressed = not args.uncompressed
    segwit = args.segwit
    output_dir = args.output_dir
    input_script = args.input_script
    if segwit and not compressed:
        raise Exception(
            'Segwit addresses must used compressed public key representation')
    jobs = []
    try:
        validate_pattern(pattern, coin_symbol, segwit)
        if input_script:
            validate_hex_script(input_script)
            address = convert_script_to_p2sh_address(
                input_script, coins[coin_symbol]['script_prefix_bytes'])
            save_qr_code(output_dir, address, None)
            print(address)
            return
    except Exception as e:
        logger.error(e)
        return
    print('Looking for pattern {} for {} using {} workers'.format(
        pattern, coins[coin_symbol]['name'], workers))
    quit = multiprocessing.Event()
    found = multiprocessing.Event()
    for i in range(workers):
        p = multiprocessing.Process(target=generate_address,
                                    args=(i, coins[coin_symbol], pattern,
                                          compressed, segwit, output_dir,
                                          found, quit))
        jobs.append(p)
        p.start()
    found.wait()