How to use the blockcypher.utils.is_valid_address_for_coinsymbol function in blockcypher

To help you get started, we’ve selected a few blockcypher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def get_address_full(address, coin_symbol='btc', txn_limit=None, inout_limit=None,
        api_key=None, before_bh=None, after_bh=None, show_confidence=False, confirmations=0):

    assert is_valid_address_for_coinsymbol(
            b58_address=address,
            coin_symbol=coin_symbol), address
    assert isinstance(show_confidence, bool), show_confidence

    url = make_url(coin_symbol, 'addrs', **{address: 'full'})

    params = {}
    if txn_limit:
        params['limit'] = txn_limit
    if api_key:
        params['token'] = api_key
    if before_bh:
        params['before'] = before_bh
    if after_bh:
        params['after'] = after_bh
    if confirmations:
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def get_valid_metadata_identifier(coin_symbol, address, tx_hash, block_hash):
    err_msg = 'Please supply only one of: address, tx_hash, or block_hash'
    assert sum([1 for x in (address, tx_hash, block_hash) if x]) == 1, err_msg

    if address:
        assert is_valid_address_for_coinsymbol(
                b58_address=address,
                coin_symbol=coin_symbol), address
        return dict(addrs=address)
    elif tx_hash:
        assert is_valid_hash(tx_hash), tx_hash
        return dict(txs=tx_hash)

    elif block_hash:
        assert is_valid_block_representation(
                block_representation=block_hash,
                coin_symbol=coin_symbol)
        return dict(blocks=block_hash)
    else:
        raise Exception('Logic Fail: This Should Not Be Possible')
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def subscribe_to_address_webhook(callback_url, subscription_address, event='tx-confirmation', confirmations=0, confidence=0.00, coin_symbol='btc', api_key=None):
    '''
    Subscribe to transaction webhooks on a given address.
    Webhooks for transaction broadcast and each confirmation (up to 6).

    Returns the blockcypher ID of the subscription
    '''
    assert is_valid_coin_symbol(coin_symbol)
    assert is_valid_address_for_coinsymbol(subscription_address, coin_symbol)
    assert api_key, 'api_key required'

    url = make_url(coin_symbol, 'hooks')

    params = {'token': api_key}
    data = {
        'event': event,
        'url': callback_url,
        'address': subscription_address,
    }

    if event == 'tx-confirmation' and confirmations:
        data['confirmations'] = confirmations
    elif event == 'tx-confidence' and confidence:
        data['confidence'] = confidence
github blockcypher / bcwallet / bcwallet / cl_utils.py View on Github external
if not destination_address:
        err_str = 'No entry, please enter something'
        if quit_ok:
            err_str += " (or Q to quit)"
        puts(colored.red(err_str))
        return get_crypto_address(
                coin_symbol=coin_symbol,
                user_prompt=user_prompt,
                quit_ok=quit_ok,
                )

    if quit_ok and destination_address in ['q', 'Q', 'b', 'B']:
        return False

    if is_valid_address_for_coinsymbol(destination_address,
            coin_symbol=coin_symbol):
        return destination_address
    else:
        puts('Invalid %s address, please try again' % display_shortname)
        return get_crypto_address(
                coin_symbol=coin_symbol,
                user_prompt=user_prompt,
                quit_ok=quit_ok,
                )
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def add_address_to_wallet(wallet_name, address, api_key, omit_addresses=False, coin_symbol='btc'):
    assert is_valid_address_for_coinsymbol(address, coin_symbol)
    assert api_key, 'api_key required'
    assert is_valid_wallet_name(wallet_name), wallet_name
    assert isinstance(omit_addresses, bool), omit_addresses

    params = {'token': api_key}
    data = {'addresses': [address]}

    if omit_addresses:
        data['omitWalletAddresses'] = 'true'

    url = make_url(coin_symbol, 'wallets/{}/addresses'.format(wallet_name))
    r = requests.post(url, json=data, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r)
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def get_address_overview(address, coin_symbol='btc', api_key=None):
    '''
    Takes an address and coin_symbol and return the address details
    '''

    assert is_valid_address_for_coinsymbol(b58_address=address,
            coin_symbol=coin_symbol)

    url = make_url(coin_symbol, 'addrs', **{address: 'balance'})

    params = {}
    if api_key:
        params['token'] = api_key

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r)
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
Signature takes place locally (client-side) after unsigned transaction is verified.

    Returns the tx_hash of the newly broadcast tx.

    A change_address *must* be specified, except for a sweep (set to_satoshis = -1)

    Note that this currently only supports compressed private keys.
    '''

    assert is_valid_coin_symbol(coin_symbol), coin_symbol
    assert isinstance(to_satoshis, int), to_satoshis
    assert api_key, 'api_key required'

    if change_address:
        err_msg = '%s not a valid address for %s' % (change_address, coin_symbol)
        assert is_valid_address_for_coinsymbol(change_address, coin_symbol), err_msg
    else:
        assert to_satoshis == -1, 'you must supply a change address or sweep'

    err_msg = '%s not a valid address for %s' % (to_address, coin_symbol)
    assert is_valid_address_for_coinsymbol(to_address, coin_symbol), err_msg

    # TODO: calculate from address from pubkeys
    # err_msg = '%s is not a p2sh address' % to_address
    # assert from_address[0] in COIN_SYMBOL_MAPPINGS[coin_symbol]['multisig_prefix_list'], err_msg

    assert isinstance(all_from_pubkeys, (list, tuple))
    assert len(all_from_pubkeys) > 1

    assert isinstance(from_privkeys_to_use, (list, tuple)), from_privkeys_to_use

    for from_privkey in from_privkeys_to_use: