def decode_tx(request, coin_symbol): ''' Decode a raw transaction ''' initial = {'coin_symbol': coin_symbol} form = RawTXForm(initial=initial) tx_in_json_str = '' if request.method == 'POST': form = RawTXForm(data=request.POST) if form.is_valid(): # Display the TX tx_hex = form.cleaned_data['tx_hex'] coin_symbol_to_use = form.cleaned_data['coin_symbol'] tx_in_json = decodetx(tx_hex=tx_hex, coin_symbol=coin_symbol_to_use) tx_in_json_str = json.dumps(tx_in_json, indent=4) # print(tx_in_json_str) elif request.method == 'GET': # Preseed tx hex if passed through GET string tx_hex = request.GET.get('t') if tx_hex: initial['tx_hex'] = tx_hex form = RawTXForm(initial=initial) return { 'coin_symbol': coin_symbol, 'form': form, 'tx_in_json_str': tx_in_json_str, }
def decode_tx(request, coin_symbol): ''' Decode a raw transaction ''' initial = {'coin_symbol': coin_symbol} form = RawTXForm(initial=initial) tx_in_json_str, tx_uri, tx_hex = '', '', '' if request.method == 'POST': form = RawTXForm(data=request.POST) if form.is_valid(): # Display the TX tx_hex = form.cleaned_data['tx_hex'] coin_symbol_to_use = form.cleaned_data['coin_symbol'] tx_in_json = decodetx( tx_hex=tx_hex, coin_symbol=coin_symbol_to_use, api_key=BLOCKCYPHER_API_KEY, ) # import pprint; pprint.pprint(tx_in_json, width=1) tx_in_json_str = json.dumps(tx_in_json, indent=4, sort_keys=True) tx_hash = tx_in_json.get('hash') if tx_hash and 'error' not in tx_in_json: # check for existing TX in blockchain transaction_details = get_transaction_details( tx_hash=tx_hash, coin_symbol=coin_symbol_to_use, limit=1, api_key=BLOCKCYPHER_API_KEY, ) if 'error' not in transaction_details: kwargs = { 'coin_symbol': coin_symbol_to_use, 'tx_hash': tx_hash, } tx_uri = reverse('transaction_overview', kwargs=kwargs) elif request.method == 'GET': # Preseed tx hex if passed through GET string tx_hex = request.GET.get('t') if tx_hex: initial['tx_hex'] = tx_hex form = RawTXForm(initial=initial) return { 'coin_symbol': coin_symbol, 'form': form, 'tx_in_json_str': tx_in_json_str, 'tx_uri': tx_uri, 'tx_hex': tx_hex, 'is_input_page': True, }
def decode_tx(request, coin_symbol): """ Decode a raw transaction """ initial = {"coin_symbol": coin_symbol} form = RawTXForm(initial=initial) tx_in_json_str, tx_uri, tx_hex = "", "", "" if request.method == "POST": form = RawTXForm(data=request.POST) if form.is_valid(): # Display the TX tx_hex = form.cleaned_data["tx_hex"] coin_symbol_to_use = form.cleaned_data["coin_symbol"] tx_in_json = decodetx(tx_hex=tx_hex, coin_symbol=coin_symbol_to_use) # import pprint; pprint.pprint(tx_in_json, width=1) tx_in_json_str = json.dumps(tx_in_json, indent=4, sort_keys=True) tx_hash = tx_in_json.get("hash") if tx_hash and "error" not in tx_in_json: # check for existing TX in blockchain transaction_details = get_transaction_details( tx_hash=tx_hash, coin_symbol=coin_symbol_to_use, limit=1, api_key=BLOCKCYPHER_API_KEY ) if "error" not in transaction_details: kwargs = {"coin_symbol": coin_symbol_to_use, "tx_hash": tx_hash} tx_uri = reverse("transaction_overview", kwargs=kwargs) elif request.method == "GET": # Preseed tx hex if passed through GET string tx_hex = request.GET.get("t") if tx_hex: initial["tx_hex"] = tx_hex form = RawTXForm(initial=initial) return { "coin_symbol": coin_symbol, "form": form, "tx_in_json_str": tx_in_json_str, "tx_uri": tx_uri, "tx_hex": tx_hex, }