How to use the blockcypher.utils.is_valid_hash 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 / test_blockcypher.py View on Github external
def test_invalid_hash(self):
        assert not is_valid_hash(self.invalid_hash), self.invalid_hash
github blockcypher / blockcypher-python / test_blockcypher.py View on Github external
def test_valid_hash(self):
        assert is_valid_hash(self.valid_hash), self.valid_hash
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 / explorer / metadata / views.py View on Github external
def add_metadata_to_tx(request, coin_symbol, tx_hash):
    if not is_valid_hash(tx_hash):
        return Http404

    initial = {}
    form = BaseMetadataForm(initial=initial)
    if request.method == 'POST':
        form = BaseMetadataForm(data=request.POST)
        if form.is_valid():
            metadata_key = form.cleaned_data.get('metadata_key')
            metadata_value = form.cleaned_data.get('metadata_value')

            results = put_metadata(
                    metadata_dict={metadata_key: metadata_value},
                    tx_hash=tx_hash,
                    coin_symbol=coin_symbol,
                    api_key=BLOCKCYPHER_API_KEY,
                    private=False,
github blockcypher / explorer / homepage / views.py View on Github external
def home(request):
    form = SearchForm(initial={
        'search_string': '16Fg2yjwrbtC6fZp61EV9mNVKmwCzGasw5',
        'coin_symbol': 'btc',
        })
    if request.method == 'POST':
        form = SearchForm(data=request.POST)
        if form.is_valid():
            redirect_url = None
            search_string = form.cleaned_data['search_string']
            coin_symbol = form.cleaned_data['coin_symbol']
            kwargs = {'coin_symbol': coin_symbol}
            if is_valid_block_num(search_string):
                kwargs['block_representation'] = search_string
                redirect_url = reverse('block_overview', kwargs=kwargs)
            elif is_valid_hash(search_string):
                if coin_symbol in SHA_COINS:
                    if is_valid_sha_block_hash(search_string):
                        kwargs['block_representation'] = search_string
                        redirect_url = reverse('block_overview', kwargs=kwargs)
                    else:
                        kwargs['tx_hash'] = search_string
                        redirect_url = reverse('transaction_overview', kwargs=kwargs)
                elif coin_symbol in SCRYPT_COINS:
                    # Try to see if it's a valid TX hash
                    tx_details = get_transaction_details(
                            tx_hash=search_string,
                            coin_symbol=coin_symbol,
                            limit=1,
                            api_key=BLOCKCYPHER_API_KEY,
                            )
                    if 'error' in tx_details:
github blockcypher / explorer / metadata / views.py View on Github external
def add_metadata_to_block(request, coin_symbol, block_hash):
    if not is_valid_hash(block_hash):
        return Http404

    initial = {}
    form = BaseMetadataForm(initial=initial)
    if request.method == 'POST':
        form = BaseMetadataForm(data=request.POST)
        if form.is_valid():
            metadata_key = form.cleaned_data.get('metadata_key')
            metadata_value = form.cleaned_data.get('metadata_value')

            results = put_metadata(
                    metadata_dict={metadata_key: metadata_value},
                    block_hash=block_hash,
                    coin_symbol=coin_symbol,
                    api_key=BLOCKCYPHER_API_KEY,
                    private=False,
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
github blockcypher / bcwallet / bcwallet / bc_utils.py View on Github external
def get_tx_url(tx_hash, coin_symbol):
    assert is_valid_coin_symbol(coin_symbol), coin_symbol
    assert is_valid_hash(tx_hash), tx_hash
    return 'https://live.blockcypher.com/%s/tx/%s/' % (coin_symbol, tx_hash)
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def get_transaction_details(tx_hash, coin_symbol='btc', limit=None, tx_input_offset=None, tx_output_offset=None,
        include_hex=False, show_confidence=False, confidence_only=False, api_key=None):
    """
    Takes a tx_hash, coin_symbol, and limit and returns the transaction details

    Optional:
      - limit: # inputs/ouputs to include (applies to both)
      - tx_input_offset: input offset
      - tx_output_offset: output offset
      - include_hex: include the raw TX hex
      - show_confidence: adds confidence information to unconfirmed TXRefs.
      - confidence_only: show only the confidence statistics and don't return the rest of the endpoint details (faster)

    """

    assert is_valid_hash(tx_hash), tx_hash
    assert is_valid_coin_symbol(coin_symbol), coin_symbol

    added = 'txs/{}{}'.format(tx_hash, '/confidence' if confidence_only else  '')
    url = make_url(coin_symbol, added)

    params = {}
    if api_key:
        params['token'] = api_key
    if limit:
        params['limit'] = limit
    if tx_input_offset:
        params['inStart'] = tx_input_offset
    if tx_output_offset:
        params['outStart'] = tx_output_offset
    if include_hex:
        params['includeHex'] = 'true'