How to use the blockcypher.utils.is_valid_coin_symbol 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_wallet_balance(wallet_name, api_key, omit_addresses=False, coin_symbol='btc'):
    '''
    This is particularly useful over get_wallet_transactions and
    get_wallet_addresses in cases where you have lots of addresses/transactions.
    Much less data to return.
    '''
    assert is_valid_coin_symbol(coin_symbol)
    assert api_key
    assert len(wallet_name) <= 25, wallet_name
    assert isinstance(omit_addresses, bool), omit_addresses

    params = {'token': api_key}
    if omit_addresses:
        params['omitWalletAddresses'] = 'true'

    url = make_url(coin_symbol, 'addrs/{}/balance'.format(wallet_name))

    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
def get_wallet_addresses(wallet_name, api_key, is_hd_wallet=False,
        zero_balance=None, used=None, omit_addresses=False, coin_symbol='btc'):
    '''
    Returns a list of wallet addresses as well as some meta-data
    '''
    assert is_valid_coin_symbol(coin_symbol)
    assert api_key
    assert len(wallet_name) <= 25, wallet_name
    assert zero_balance in (None, True, False)
    assert used in (None, True, False)
    assert isinstance(omit_addresses, bool), omit_addresses

    params = {'token': api_key}
    kwargs = {'hd/' if is_hd_wallet else '': wallet_name} # hack!
    url = make_url(coin_symbol, 'wallets', **kwargs)

    if zero_balance is True:
        params['zerobalance'] = 'true'
    elif zero_balance is False:
        params['zerobalance'] = 'false'
    if used is True:
        params['used'] = 'true'
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def generate_new_address(coin_symbol='btc', api_key=None):
    '''
    Takes a coin_symbol and returns a new address with it's public and private keys.

    This method will create the address server side, which is inherently insecure and should only be used for testing.

    If you want to create a secure address client-side using python, please check out bitmerchant:

        from bitmerchant.wallet import Wallet
        Wallet.new_random_wallet()

    https://github.com/sbuss/bitmerchant
    '''

    assert api_key, 'api_key required'
    assert is_valid_coin_symbol(coin_symbol)

    if coin_symbol not in ('btc-testnet', 'bcy'):
        WARNING_MSG = [
                'Generating private key details server-side.',
                'You really should do this client-side.',
                'See https://github.com/sbuss/bitmerchant for an example.',
                ]
        print(' '.join(WARNING_MSG))

    url = make_url(coin_symbol, 'addrs')
    params = {'token': api_key}

    r = requests.post(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
def get_block_overview(block_representation, coin_symbol='btc', txn_limit=None,
        txn_offset=None, api_key=None):
    """
    Takes a block_representation, coin_symbol and txn_limit and gets an overview
    of that block, including up to X transaction ids.
    Note that block_representation may be the block number or block hash
    """

    assert is_valid_coin_symbol(coin_symbol)
    assert is_valid_block_representation(
            block_representation=block_representation,
            coin_symbol=coin_symbol)

    url = make_url(coin_symbol, **dict(blocks=block_representation))

    params = {}
    if api_key:
        params['token'] = api_key
    if txn_limit:
        params['limit'] = txn_limit
    if txn_offset:
        params['txstart'] = txn_offset

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    response_dict = get_valid_json(r)
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def derive_hd_address(api_key=None, wallet_name=None, num_addresses=1,
        subchain_index=None, coin_symbol='btc'):
    '''
    Returns a new address (without access to the private key) and adds it to
    your HD wallet (previously created using create_hd_wallet).

    This method will traverse/discover a new address server-side from your
    previously supplied extended public key, the server will never see your
    private key. It is therefor safe for production use.

    You may also include a subchain_index directive if your wallet has multiple
    subchain_indices and you'd like to specify which one should be traversed.
    '''

    assert is_valid_coin_symbol(coin_symbol)
    assert api_key, 'api_key required'
    assert wallet_name, wallet_name
    assert isinstance(num_addresses, int), num_addresses

    url = make_url(coin_symbol, 'wallets/hd', **{wallet_name, 'addresses/derive'})
    params = {'token': api_key}
    if subchain_index:
        params['subchain_index'] = subchain_index
    if num_addresses > 1:
        params['count'] = num_addresses

    r = requests.post(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
def get_blockchain_overview(coin_symbol='btc', api_key=None):
    assert is_valid_coin_symbol(coin_symbol)

    url = make_url(coin_symbol)

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

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    response_dict = get_valid_json(r)


    response_dict['time'] = parser.parse(response_dict['time'])

    return response_dict
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def get_transactions_details(tx_hash_list, coin_symbol='btc', limit=None, api_key=None):
    """
    Takes a list of tx_hashes, coin_symbol, and limit and returns the transaction details

    Limit applies to both num inputs and num outputs.
    TODO: add offsetting once supported
    """

    for tx_hash in tx_hash_list:
        assert is_valid_hash(tx_hash)
    assert is_valid_coin_symbol(coin_symbol)

    if len(tx_hash_list) == 0:
        return []
    elif len(tx_hash_list) == 1:
        return [get_transaction_details(tx_hash=tx_hash_list[0],
                                        coin_symbol=coin_symbol,
                                        limit=limit,
                                        api_key=api_key
                                        )]

    url = make_url(coin_symbol, **dict(txs=';'.join(tx_hash_list)))

    params = {}
    if api_key:
        params['token'] = api_key
    if limit:
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def _get_pushtx_url(coin_symbol='btc'):
    """
    Used for pushing hexadecimal transactions to the network
    """
    assert is_valid_coin_symbol(coin_symbol)
    return make_url(coin_symbol, **dict(txs='push'))