# Path: blockexplorer/settings.py
# BLOCKCYPHER_PUBLIC_KEY = '31c49f33f35c85a8f4d9845a754f7c8e'
# 
# BLOCKCYPHER_API_KEY = os.getenv('BLOCKCYPHER_API_KEY')
# 
# Path: homepage/forms.py
# class SearchForm(forms.Form):
#     search_string = forms.CharField(
#         required=True,
#         min_length=1,
#         max_length=128,
#     )
# 
#     coin_symbol = forms.ChoiceField(
#         required=False,
#         choices=COIN_CHOICES,
#     )
# 
#     def clean_search_string(self):
#         search_string = self.cleaned_data['search_string'].strip()
#         # process possible Wallet Names
#         if is_valid_wallet_name(search_string):
#             return search_string
# 
#         # get rid of non alphanumerics
#         if search_string.lower().startswith("0x"):
#             search_string = search_string[2:].lower()
#         search_string = re.sub(r'[^a-zA-Z0-9]+', '', search_string)
#         if is_valid_hash(search_string) or is_valid_address(search_string) or is_valid_eth_address(search_string) or is_valid_block_num(search_string):
#             return search_string
#         else:
#             err_msg = _('Not a valid address, transaction hash, or block number')
#             raise forms.ValidationError(err_msg)
# 
# class UnitChoiceForm(forms.Form):
#     unit_choice = forms.ChoiceField(
#         label='',
#         required=True,
#         choices=UNIT_CHOICES_DJANGO,
#         widget=forms.Select(attrs={'onchange': 'this.form.submit()'}),
#     )


from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from annoying.decorators import render_to
from blockexplorer.decorators import assert_valid_coin_symbol
from blockexplorer.settings import BLOCKCYPHER_PUBLIC_KEY, BLOCKCYPHER_API_KEY
from blockexplorer.walletname import lookup_wallet_name, is_valid_wallet_name
from homepage.forms import SearchForm, UnitChoiceForm
from blockcypher.api import get_transaction_details, get_block_overview, get_blocks_overview, get_latest_block_height, get_broadcast_transactions, get_blockchain_fee_estimates
from blockcypher.utils import is_valid_hash, is_valid_ethash_block_hash, is_valid_block_num, is_valid_sha_block_hash, is_valid_address, is_valid_eth_address
from blockcypher.constants import ETHASH_COINS, SHA_COINS, SCRYPT_COINS, COIN_SYMBOL_MAPPINGS
from operator import itemgetter







@render_to('home.html')
def home(request):
    form = SearchForm(initial={
        'search_string': '16Fg2yjwrbtC6fZp61EV9mNVKmwCzGasw5',
        'coin_symbol': 'btc',
        })
    if request.method == 'POST':

# Path: blockexplorer/settings.py
# BLOCKCYPHER_PUBLIC_KEY = '31c49f33f35c85a8f4d9845a754f7c8e'
# 
# BLOCKCYPHER_API_KEY = os.getenv('BLOCKCYPHER_API_KEY')
# 
# Path: homepage/forms.py
# class SearchForm(forms.Form):
#     search_string = forms.CharField(
#         required=True,
#         min_length=1,
#         max_length=128,
#     )
# 
#     coin_symbol = forms.ChoiceField(
#         required=False,
#         choices=COIN_CHOICES,
#     )
# 
#     def clean_search_string(self):
#         search_string = self.cleaned_data['search_string'].strip()
#         # process possible Wallet Names
#         if is_valid_wallet_name(search_string):
#             return search_string
# 
#         # get rid of non alphanumerics
#         if search_string.lower().startswith("0x"):
#             search_string = search_string[2:].lower()
#         search_string = re.sub(r'[^a-zA-Z0-9]+', '', search_string)
#         if is_valid_hash(search_string) or is_valid_address(search_string) or is_valid_eth_address(search_string) or is_valid_block_num(search_string):
#             return search_string
#         else:
#             err_msg = _('Not a valid address, transaction hash, or block number')
#             raise forms.ValidationError(err_msg)
# 
# class UnitChoiceForm(forms.Form):
#     unit_choice = forms.ChoiceField(
#         label='',
#         required=True,
#         choices=UNIT_CHOICES_DJANGO,
#         widget=forms.Select(attrs={'onchange': 'this.form.submit()'}),
#     )


# Path: homepage/views.py
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from annoying.decorators import render_to
from blockexplorer.decorators import assert_valid_coin_symbol
from blockexplorer.settings import BLOCKCYPHER_PUBLIC_KEY, BLOCKCYPHER_API_KEY
from blockexplorer.walletname import lookup_wallet_name, is_valid_wallet_name
from homepage.forms import SearchForm, UnitChoiceForm
from blockcypher.api import get_transaction_details, get_block_overview, get_blocks_overview, get_latest_block_height, get_broadcast_transactions, get_blockchain_fee_estimates
from blockcypher.utils import is_valid_hash, is_valid_ethash_block_hash, is_valid_block_num, is_valid_sha_block_hash, is_valid_address, is_valid_eth_address
from blockcypher.constants import ETHASH_COINS, SHA_COINS, SCRYPT_COINS, COIN_SYMBOL_MAPPINGS
from operator import itemgetter








@render_to('home.html')
def home(request):
    form = SearchForm(initial={
        'search_string': '16Fg2yjwrbtC6fZp61EV9mNVKmwCzGasw5',
        'coin_symbol': 'btc',
        })
    if request.method == 'POST':

        form = SearchForm(data=request.POST)