Beispiel #1
0
def block_overview(request, coin_symbol, block_representation):

    TXNS_PER_PAGE = 20

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # TODO: fail gracefully if the user picks a number of pages that is too large
    # Waiting on @matthieu's change to API first (currently throws 502)

    try:
        block_details = get_block_details(
            block_representation=block_representation,
            coin_symbol=coin_symbol,
            txn_limit=TXNS_PER_PAGE,
            txn_offset=(current_page - 1) * TXNS_PER_PAGE,
            api_key=BLOCKCYPHER_API_KEY,
        )
    except AssertionError:
        msg = _('Invalid Block Representation')
        messages.warning(request, msg)
        redir_url = reverse('coin_overview',
                            kwargs={'coin_symbol': coin_symbol})
        return HttpResponseRedirect(redir_url)

    # import pprint; pprint.pprint(block_details, width=1)

    if 'error' in block_details:
        msg = _('Sorry, that block was not found')
        messages.warning(request, msg)
        return HttpResponseRedirect(reverse('home'))

    # Technically this is not the only API call used on this page
    api_url = 'https://api.blockcypher.com/v1/%s/%s/blocks/%s' % (
        COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_code'],
        COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_network'],
        block_representation,
    )

    return {
        'coin_symbol':
        coin_symbol,
        'api_url':
        api_url,
        'block_details':
        block_details,
        'current_page':
        current_page,
        'max_pages':
        get_max_pages(num_items=block_details['n_tx'],
                      items_per_page=TXNS_PER_PAGE),
    }
Beispiel #2
0
def block_overview(request, coin_symbol, block_representation):

    TXNS_PER_PAGE = 20

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # TODO: fail gracefully if the user picks a number of pages that is too large
    # Waiting on @matthieu's change to API first (currently throws 502)

    try:
        block_details = get_block_details(
                block_representation=block_representation,
                coin_symbol=coin_symbol,
                txn_limit=TXNS_PER_PAGE,
                in_out_limit=25,
                txn_offset=(current_page-1)*TXNS_PER_PAGE,
                api_key=BLOCKCYPHER_API_KEY,
                )
    except AssertionError:
        msg = _('Invalid Block Representation')
        messages.warning(request, msg)
        redir_url = reverse('coin_overview', kwargs={'coin_symbol': coin_symbol})
        return HttpResponseRedirect(redir_url)

    # import pprint; pprint.pprint(block_details, width=1)

    if 'error' in block_details:
        msg = _('Sorry, that block was not found')
        messages.warning(request, msg)
        return HttpResponseRedirect(reverse('home'))

    # Technically this is not the only API call used on this page
    api_url = 'https://api.blockcypher.com/v1/%s/%s/blocks/%s' % (
            COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_code'],
            COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_network'],
            block_representation,
            )

    return {
            'coin_symbol': coin_symbol,
            'api_url': api_url,
            'block_details': block_details,
            'current_page': current_page,
            'max_pages': get_max_pages(num_items=block_details['n_tx'], items_per_page=TXNS_PER_PAGE),
            }
Beispiel #3
0
def block_overview(request, coin_symbol, block_representation):

    TXNS_PER_PAGE = 5

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # TODO: fail gracefully if the user picks a number of pages that is too large
    # Waiting on @matthieu's change to API first (currently throws 502)
    block_details = get_block_details(
        block_representation=block_representation,
        coin_symbol=coin_symbol,
        txn_limit=TXNS_PER_PAGE,
        txn_offset=(current_page - 1) * TXNS_PER_PAGE,
        api_key=BLOCKCYPHER_API_KEY,
    )

    # import pprint; pprint.pprint(block_details, width=1)

    if 'error' in block_details:
        msg = _('Sorry, that block was not found')
        messages.warning(request, msg)
        return HttpResponseRedirect(reverse('home'))

    # Technically this is not the only API call used on this page
    api_url = get_block_overview_url(block_representation=block_representation,
                                     coin_symbol=coin_symbol)

    return {
        'coin_symbol':
        coin_symbol,
        'api_url':
        api_url,
        'block_details':
        block_details,
        'current_page':
        current_page,
        'max_pages':
        get_max_pages(num_items=block_details['n_tx'],
                      items_per_page=TXNS_PER_PAGE),
    }
Beispiel #4
0
def block_overview(request, coin_symbol, block_representation):

    TXNS_PER_PAGE = 5

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # TODO: fail gracefully if the user picks a number of pages that is too large
    # Waiting on @matthieu's change to API first (currently throws 502)
    block_details = get_block_details(
            block_representation=block_representation,
            coin_symbol=coin_symbol,
            txn_limit=TXNS_PER_PAGE,
            txn_offset=(current_page-1)*TXNS_PER_PAGE,
            api_key=BLOCKCYPHER_API_KEY,
            )

    # import pprint; pprint.pprint(block_details, width=1)

    if 'error' in block_details:
        msg = _('Sorry, that block was not found')
        messages.warning(request, msg)
        return HttpResponseRedirect(reverse('home'))

    # Technically this is not the only API call used on this page
    api_url = get_block_overview_url(block_representation=block_representation, coin_symbol=coin_symbol)

    return {
            'coin_symbol': coin_symbol,
            'api_url': api_url,
            'block_details': block_details,
            'current_page': current_page,
            'max_pages': get_max_pages(num_items=block_details['n_tx'], items_per_page=TXNS_PER_PAGE),
            }