Skip to content

Commit

Permalink
full transaction history on address page, pagination, hide forwarding…
Browse files Browse the repository at this point in the history
…, and more
  • Loading branch information
Michael Flaxman committed Mar 16, 2016
1 parent 496b78d commit a9eb85d
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 263 deletions.
29 changes: 11 additions & 18 deletions addresses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

from blockexplorer.settings import BLOCKCYPHER_PUBLIC_KEY, BLOCKCYPHER_API_KEY, WEBHOOK_SECRET_KEY, BASE_URL

from blockcypher.api import get_address_details, get_address_overview, subscribe_to_address_webhook, get_forwarding_address_details, unsubscribe_from_webhook
from blockcypher.api import get_address_full, get_address_overview, subscribe_to_address_webhook, get_forwarding_address_details, unsubscribe_from_webhook
from blockcypher.constants import COIN_SYMBOL_MAPPINGS
from blockcypher.utils import flatten_txns_by_hash

from users.models import AuthUser, LoggedLogin
from addresses.models import AddressSubscription, AddressForwarding
Expand Down Expand Up @@ -66,7 +65,9 @@ def is_bot(user_agent):
@render_to('address_overview.html')
def address_overview(request, coin_symbol, address, wallet_name=None):

TXNS_PER_PAGE = 100
TXNS_PER_PAGE = 10

before_bh = request.GET.get('before')

try:
user_agent = request.META.get('HTTP_USER_AGENT')
Expand All @@ -77,12 +78,13 @@ def address_overview(request, coin_symbol, address, wallet_name=None):
else:
confirmations = 0

address_details = get_address_details(
address_details = get_address_full(
address=address,
coin_symbol=coin_symbol,
txn_limit=TXNS_PER_PAGE,
confirmations=confirmations,
api_key=BLOCKCYPHER_API_KEY,
before_bh=before_bh,
)
except AssertionError:
msg = _('Invalid Address')
Expand Down Expand Up @@ -161,19 +163,10 @@ def address_overview(request, coin_symbol, address, wallet_name=None):
})
messages.info(request, msg, extra_tags='safe')

confirmed_txrefs = address_details.get('txrefs', [])

all_transactions = address_details.get('unconfirmed_txrefs', []) + confirmed_txrefs

flattened_txs = flatten_txns_by_hash(all_transactions, nesting=False)
# import pprint; pprint.pprint(flattened_txs, width=1)

if confirmed_txrefs:
max_bh = confirmed_txrefs[-1]['block_height']
else:
max_bh = None
all_transactions = address_details.get('txs', [])
# import pprint; pprint.pprint(all_transactions, width=1)

api_url = 'https://api.blockcypher.com/v1/%s/%s/addrs/%s' % (
api_url = 'https://api.blockcypher.com/v1/%s/%s/addrs/%s/full?limit=50' % (
COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_code'],
COIN_SYMBOL_MAPPINGS[coin_symbol]['blockcypher_network'],
address)
Expand All @@ -189,8 +182,8 @@ def address_overview(request, coin_symbol, address, wallet_name=None):
'unconfirmed_balance_satoshis': address_details['unconfirmed_balance'],
'confirmed_balance_satoshis': address_details['balance'],
'total_balance_satoshis': address_details['final_balance'],
'flattened_txs': flattened_txs,
'max_bh': max_bh,
'flattened_txs': all_transactions,
'before_bh': before_bh,
'num_confirmed_txns': address_details['n_tx'],
'num_unconfirmed_txns': address_details['unconfirmed_n_tx'],
'num_all_txns': address_details['final_n_tx'],
Expand Down
33 changes: 21 additions & 12 deletions blockexplorer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import re
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
Expand All @@ -33,6 +34,12 @@
else:
TEMPLATE_DEBUG = False

# DDT can cause extreme slowness clocking template rendering CPU times
if os.getenv('DISABLE_DEBUG_TOOLBAR') == 'False':
DISABLE_DEBUG_TOOLBAR = False
else:
DISABLE_DEBUG_TOOLBAR = True

ALLOWED_HOSTS = [
'live.blockcypher.com',
'blockcypher.herokuapp.com',
Expand Down Expand Up @@ -89,7 +96,6 @@
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

# Parse database configuration from $DATABASE_URL
import dj_database_url
# http://stackoverflow.com/a/11100175
DJ_DEFAULT_URL = os.getenv('DJ_DEFAULT_URL', 'postgres://localhost')
DATABASES = {'default': dj_database_url.config(default=DJ_DEFAULT_URL)}
Expand Down Expand Up @@ -149,9 +155,10 @@
CSRF_COOKIE_SECURE = True
MIDDLEWARE_CLASSES += ('blockexplorer.middleware.SSLMiddleware',)
else:
# FIXME: this should work on staging too, but I can't get it to work with gunicorn
DEBUG_TOOLBAR_PATCH_SETTINGS = True
BASE_URL = 'http://%s' % SITE_DOMAIN
if not DISABLE_DEBUG_TOOLBAR:
# FIXME: this should work on staging too, but I can't get it to work with gunicorn
DEBUG_TOOLBAR_PATCH_SETTINGS = True


IS_PRODUCTION = (SITE_DOMAIN == PRODUCTION_DOMAIN)
Expand All @@ -160,15 +167,17 @@
EMAIL_DEV_PREFIX = False
else:
EMAIL_DEV_PREFIX = True
# Enable debug toolbar on local and staging
MIDDLEWARE_CLASSES = ('debug_toolbar.middleware.DebugToolbarMiddleware',) + MIDDLEWARE_CLASSES
INSTALLED_APPS += ('debug_toolbar', )

# Debug Toolbar
INTERNAL_IPS = (
'127.0.0.1',
'localhost',
)
if not DISABLE_DEBUG_TOOLBAR:
# Enable debug toolbar on local and staging
MIDDLEWARE_CLASSES = ('debug_toolbar.middleware.DebugToolbarMiddleware',) + MIDDLEWARE_CLASSES
INSTALLED_APPS += ('debug_toolbar', )

if not DISABLE_DEBUG_TOOLBAR:
# Debug Toolbar
INTERNAL_IPS = (
'127.0.0.1',
'localhost',
)

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bitcoin==1.1.29
blockcypher==1.0.64
blockcypher==1.0.69
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.7.1
Expand Down
Loading

0 comments on commit a9eb85d

Please sign in to comment.