Exemplo n.º 1
0
def send_crypto(args):
    logging.basicConfig(level=logging.INFO,
                        format='%(message)s',
                        stream=sys.stdout)
    coin_symbol = args.coin_symbol.upper()
    destination_address = args.address
    input_addresses = args.input_addresses.split(
        ',') if args.input_addresses else []
    unlocking_scripts = args.unlocking_scripts.split(
        ',') if args.unlocking_scripts else []
    wif_private_keys = args.wif_private_keys.split(
        ',') if args.wif_private_keys else []
    satoshis = args.satoshis
    fee = args.fee
    minimum_input_threshold = args.minimum_input_threshold
    maximum_input_threshold = args.maximum_input_threshold
    limit_inputs = args.limit_inputs
    if (minimum_input_threshold and maximum_input_threshold
            and minimum_input_threshold > maximum_input_threshold):
        logger.error(
            'Minimum input threshold cannot be bigger than maximum input value!'
        )
        return
    if not wif_private_keys and not input_addresses:
        logger.error('You must provide wif_private_keys or input_addresses!')
        return
    if len(unlocking_scripts) != len(input_addresses):
        logger.error(
            'Number of unlocking scripts must match number of input addresses!'
        )
        return
    try:
        if destination_address:
            validate_address(destination_address, coin_symbol)
        for wif_private_key in wif_private_keys:
            validate_wif_private_key(wif_private_key, coin_symbol)
        for unlocking_script in unlocking_scripts:
            validate_hex_script(unlocking_script)
    except Exception as e:
        logger.error(e)
        return
    if not coins[coin_symbol].get('apis'):
        logger.error(
            'No api has been defined for the coin {}'.format(coin_symbol))
        return

    result = send_from_private_keys(
        coin=coins[coin_symbol],
        wif_private_keys=wif_private_keys,
        input_addresses=input_addresses,
        unlocking_scripts=unlocking_scripts,
        destination_address=destination_address,
        satoshis=satoshis,
        fee=fee,
        minimum_input_threshold=minimum_input_threshold,
        maximum_input_threshold=maximum_input_threshold,
        limit_inputs=limit_inputs)

    return result
Exemplo n.º 2
0
def test_validate_wif_private_key_uncompressed_failure():
    btc_wif_private_key_uncompressed = '5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh'

    with pytest.raises(Exception) as exc_info:
        validate_wif_private_key(btc_wif_private_key_uncompressed, 'LTC')
    assert str(
        exc_info.value
    ) == 'Incorrect secret prefix 0x80 in wif private key for coin LTC'
Exemplo n.º 3
0
def test_validate_wif_private_key_compressd_failure():
    btc_wif_private_key_compressed = 'KwDiDMtpksBAcfyHsVS5XzmirtyjKWSeaeM9U1QppugixMUeKMqp'

    with pytest.raises(Exception) as exc_info:
        validate_wif_private_key(btc_wif_private_key_compressed, 'LTC')
    assert str(
        exc_info.value
    ) == 'Incorrect secret prefix 0x80 in wif private key for coin LTC'
Exemplo n.º 4
0
def sweep_address(args):
    logging.basicConfig(level=logging.INFO, format='%(message)s', stream=sys.stdout)
    coin_symbol = args.coin_symbol
    destination_address = args.address
    wif_private_key = args.wif_private_key
    fee = args.fee
    minimum_input_threshold = args.minimum_input_threshold
    maximum_input_threshold = args.maximum_input_threshold
    batch_size = args.batch_size
    if (
        minimum_input_threshold
        and maximum_input_threshold
        and minimum_input_threshold > maximum_input_threshold
    ):
        logger.error('Minimum input threshold cannot be bigger than maximum input value!')
        return
    try:
        coin = coins[coin_symbol]
        validate_wif_private_key(wif_private_key, coin_symbol)
        if destination_address:
            validate_address(destination_address, coin_symbol)
        else:
            destination_address = convert_wif_private_key_to_address(
                wif_private_key, coin['address_prefix_bytes']
            )
    except ValueError as e:
        logger.error(e)
        return
    if not coin.get('apis'):
        logger.error('No api has been defined for the coin %s', {coin_symbol})
        return
    try:
        utxos = get_utxo_from_private_keys(
            coin=coin,
            wif_private_keys=[wif_private_key],
            minimum_input_threshold=minimum_input_threshold,
            maximum_input_threshold=maximum_input_threshold,
        )
        utxos = list(utxos)
        batches_counter = 1 + len(utxos) // batch_size
        for i in range(batches_counter):
            batch_utxos = utxos[batch_size * i : batch_size * (i + 1)]
            satoshis = sum(utxo['satoshis'] for utxo in batch_utxos)
            if satoshis < fee:
                raise ValueError(f'Fee {fee} is larger than sum of batch inputs {satoshis}')
            result = send_utxos(coin, batch_utxos, destination_address, satoshis - fee, fee)
            print(result)
    except ValueError as exc:
        logger.exception(exc)
Exemplo n.º 5
0
def test_validate_wif_private_key_uncompressed_success():
    btc_wif_private_key_uncompressed = '5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh'

    result_uncompressed = validate_wif_private_key(
        btc_wif_private_key_uncompressed, 'BTC')

    assert result_uncompressed
Exemplo n.º 6
0
def test_validate_wif_private_key_compressed_success():
    btc_wif_private_key_compressed = 'KwDiDMtpksBAcfyHsVS5XzmirtyjKWSeaeM9U1QppugixMUeKMqp'

    result_compressed = validate_wif_private_key(
        btc_wif_private_key_compressed, 'BTC')

    assert result_compressed