Exemplo n.º 1
0
def single_address(request, address):
    currency = request.GET.get('currency', None)

    if not currency:
        try:
            guess_currency_result = guess_currency_from_address(address)
        except Exception as exc:
            return TemplateResponse(
                request, "single_address.html", {
                    'crypto_data_json': crypto_data_json,
                    'service_info_json': service_info_json,
                    'address': address,
                    'currency': None,
                    'transactions': [],
                    'currency_name': None,
                    'currency_icon': None,
                })

        if len(guess_currency_result) == 1:
            currency, currency_name = guess_currency_result[0]
        else:
            return http.HttpResponseRedirect(
                reverse("address_disambiguation", kwargs={'address': address}))
    else:
        currency = currency.lower()
        crypto_name = currency_name = crypto_data[currency]['name']

    error, response = _cached_fetch(currency=currency,
                                    currency_name=currency_name,
                                    service_id="fallback",
                                    address=address,
                                    Service=None,
                                    service_mode="historical_transactions")

    if not error:
        txs = response['transactions']
    else:
        txs = []

    return TemplateResponse(
        request, "single_address.html", {
            'crypto_data_json': crypto_data_json,
            'service_info_json': service_info_json,
            'address': address,
            'currency': currency,
            'transactions': txs,
            'currency_name': currency_name,
            'currency_icon': "logos/" + currency.lower() + "-logo.png",
        })
Exemplo n.º 2
0
def single_address(request, address):
    currency = request.GET.get('currency', None)

    if not currency:
        try:
            guess_currency_result = guess_currency_from_address(address)
        except Exception as exc:
            return TemplateResponse(request, "single_address.html", {
                'crypto_data_json': crypto_data_json,
                'service_info_json': service_info_json,
                'address': address,
                'currency': None,
                'transactions': [],
                'currency_name': None,
                'currency_icon': None,
            })

        if len(guess_currency_result) == 1:
            currency, currency_name = guess_currency_result[0]
        else:
            return http.HttpResponseRedirect(
                reverse("address_disambiguation", kwargs={'address': address})
            )
    else:
        currency = currency.lower()
        crypto_name = currency_name = crypto_data[currency]['name']

    error, response = _cached_fetch(
        currency=currency, currency_name=currency_name, service_id="fallback",
        address=address, Service=None, service_mode="historical_transactions"
    )

    if not error:
        txs = response['transactions']
    else:
        txs = []

    return TemplateResponse(request, "single_address.html", {
        'crypto_data_json': crypto_data_json,
        'service_info_json': service_info_json,
        'address': address,
        'currency': currency,
        'transactions': txs,
        'currency_name': currency_name,
        'currency_icon': "logos/" + currency.lower() + "-logo.png",
    })
Exemplo n.º 3
0
def address_disambiguation(request, address):
    """
    When the user tried to lookup a currency that has a duplicate address byte
    take them to this page where they can choose which currency they meant.
    """
    guess_currency_result = guess_currency_from_address(address)
    balances = {}
    for crypto, name in guess_currency_result:
        try:
            balance = get_address_balance(crypto, address)
        except Exception as exc:
            balance = str(exc)

        balances[crypto.upper()] = {'balance': balance, 'name': name}

    return TemplateResponse(request, "address_disambiguation.html", {
        'balances': balances,
        'address': address,
    })
Exemplo n.º 4
0
def address_disambiguation(request, address):
    """
    When the user tried to lookup a currency that has a duplicate address byte
    take them to this page where they can choose which currency they meant.
    """
    guess_currency_result = guess_currency_from_address(address)
    balances = {}
    for crypto, name in guess_currency_result:
        try:
            balance = get_address_balance(crypto, address)
        except Exception as exc:
            balance = str(exc)

        balances[crypto.upper()] = {'balance': balance, 'name': name}

    return TemplateResponse(request, "address_disambiguation.html", {
        'balances': balances,
        'address': address,
    })
Exemplo n.º 5
0
def perform_lookup(request, service_mode, service_id):
    """
    Passes on this request to the API, then return their response normalized to
    a single API. service_mode == (address_balance, historical_transactions)
    """
    include_raw = request.GET.get('include_raw', False)

    extended_fetch = (request.GET.get('extended_fetch', 'false').lower()
                      == 'true' and service_mode == 'historical_transactions')

    paranoid = service_id.startswith("paranoid")
    average_mode = service_id.startswith("average")
    private_mode = service_id.startswith("private")
    random_mode = False

    if service_id == "random":
        service_id = "fallback"
        random_mode = True

    if service_id == "fallback" or paranoid or average_mode or private_mode:
        Service = None
    else:
        try:
            Service = services_by_id[int(service_id)]
        except IndexError:
            return http.JsonResponse(
                {
                    'error':
                    "Unknown Service ID: %s. This service may have been decomissioned."
                    % service_id
                },
                status=400)

    address = request.GET.get('address', None)
    addresses = request.GET.get('addresses', [])
    xpub = request.GET.get('xpub', None)
    fiat = request.GET.get('fiat', None)
    txid = request.GET.get('txid', None)

    block_args = {
        'latest': request.GET.get('latest', ''),
        'block_hash': request.GET.get("block_hash", ''),
        'block_number': request.GET.get("block_number", '')
    }

    currency = request.GET.get("currency", None)
    if service_mode == 'push_tx':
        currency = request.POST['currency']

    if not currency:
        try:
            guess_currency_result = guess_currency_from_address(address)
        except ValueError as exc:
            return http.JsonResponse({'error': str(exc)}, status=400)

        if len(guess_currency_result) == 1:
            currency, currency_name = guess_currency_result[0]
        else:
            msg = "Address may be one of %s, please specify which one by using the `currency` parameter" % (
                ', '.join([x[0] for x in guess_currency_result]))
            return http.JsonResponse({'error': msg}, status=400)
    else:
        currency_name = crypto_data[currency]['name']
        currency = currency.lower()

    if not currency:
        return http.JsonResponse(
            {'error': "Currency Not Recognized: %s" % currency_name},
            status=400)

    if service_mode == 'push_tx':  # don't go inside cache function
        try:
            result = push_tx(currency, request.POST['tx'])
            return http.JsonResponse({'txid': result})
        except Exception as exc:
            return http.JsonResponse(
                {'error': "%s: %s" % (exc.__class__.__name__, str(exc))},
                status=500)

    errors, response_dict = _cached_fetch(**locals())
    if errors:
        return http.JsonResponse(response_dict, status=500)

    return http.JsonResponse(response_dict)
Exemplo n.º 6
0
def perform_lookup(request, service_mode, service_id):
    """
    Passes on this request to the API, then return their response normalized to
    a single API. service_mode == (address_balance, historical_transactions)
    """
    include_raw = request.GET.get('include_raw', False)

    extended_fetch = (
        request.GET.get('extended_fetch', 'false').lower() == 'true' and
        service_mode == 'historical_transactions'
    )

    paranoid = service_id.startswith("paranoid")
    average_mode = service_id.startswith("average")
    private_mode = service_id.startswith("private")
    random_mode = False

    if service_id == "random":
        service_id = "fallback"
        random_mode = True

    if service_id == "fallback" or paranoid or average_mode or private_mode:
        Service = None
    else:
        try:
            Service = services_by_id[int(service_id)]
        except IndexError:
            return http.JsonResponse({
                'error': "Unknown Service ID: %s. This service may have been decomissioned." % service_id
            }, status=400)

    address = request.GET.get('address', None)
    addresses = request.GET.get('addresses', [])
    xpub = request.GET.get('xpub', None)
    fiat = request.GET.get('fiat', None)
    txid = request.GET.get('txid', None)

    block_args = {
        'latest': request.GET.get('latest', ''),
        'block_hash': request.GET.get("block_hash", ''),
        'block_number': request.GET.get("block_number", '')
    }

    currency = request.GET.get("currency", None)
    if service_mode == 'push_tx':
        currency = request.POST['currency']

    if not currency:
        try:
            guess_currency_result = guess_currency_from_address(address)
        except ValueError as exc:
            return http.JsonResponse({'error': str(exc)}, status=400)

        if len(guess_currency_result) == 1:
            currency, currency_name = guess_currency_result[0]
        else:
            msg = "Address may be one of %s, please specify which one by using the `currency` parameter" % (
                ', '.join([x[0] for x in guess_currency_result])
            )
            return http.JsonResponse({'error': msg}, status=400)
    else:
        currency_name = crypto_data[currency]['name']
        currency = currency.lower()

    if not currency:
        return http.JsonResponse({
            'error': "Currency Not Recognized: %s" % currency_name
        }, status=400)

    if service_mode == 'push_tx': # don't go inside cache function
        try:
            result = push_tx(currency, request.POST['tx'])
            return http.JsonResponse({
                'txid': result
            })
        except Exception as exc:
            return http.JsonResponse({
                'error': "%s: %s" % (exc.__class__.__name__, str(exc))
            }, status=500)

    errors, response_dict = _cached_fetch(**locals())
    if errors:
        return http.JsonResponse(response_dict, status=500)

    return http.JsonResponse(response_dict)