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 embed_txdata(request, coin_symbol): ''' Embed data in the blockchain with blockcypher's API key ''' initial = {'coin_symbol': coin_symbol} form = EmbedDataForm(initial=initial) if request.method == 'POST': form = EmbedDataForm(data=request.POST) if form.is_valid(): data_to_embed = form.cleaned_data['data_to_embed'] encoding_is_hex = form.cleaned_data['encoding_is_hex'] coin_symbol_to_use = form.cleaned_data['coin_symbol'] results = embed_data( to_embed=data_to_embed, api_key=BLOCKCYPHER_API_KEY, data_is_hex=encoding_is_hex, coin_symbol=coin_symbol_to_use, ) if 'error' in results: messages.warning(request, results.get('error')) elif 'errors' in results: for error in results.get('errors'): messages.warning(request, error) else: # import pprint; pprint.pprint(results, width=1) tx_hash = results['hash'] kwargs = { 'coin_symbol': coin_symbol_to_use, 'tx_hash': tx_hash, } msg = _( 'Data succesfully embedded into TX <strong>%(tx_hash)s</strong>' % { 'tx_hash': tx_hash, }) messages.success(request, msg, extra_tags='safe') return HttpResponseRedirect( reverse('transaction_overview', kwargs=kwargs)) elif request.method == 'GET': # Preseed tx hex if passed through GET string tx_hex = request.GET.get('d') encoding_is_hex = request.GET.get('e') if tx_hex: initial['data_to_embed'] = tx_hex if encoding_is_hex: initial['encoding_is_hex'] = encoding_is_hex if tx_hex or encoding_is_hex: form = RawTXForm(initial=initial) return { 'coin_symbol': coin_symbol, 'form': form, 'is_embed_page': True, # template hack 'is_input_page': True, }
def push_tx(request, coin_symbol): ''' Push a raw TX to the bitcoin network ''' initial = {'coin_symbol': coin_symbol} form = RawTXForm(initial=initial) if request.method == 'POST': form = RawTXForm(data=request.POST) if form.is_valid(): # broadcast the transaction tx_hex = form.cleaned_data['tx_hex'] coin_symbol_to_use = form.cleaned_data['coin_symbol'] result = pushtx(tx_hex=tx_hex, coin_symbol=coin_symbol_to_use, api_key=BLOCKCYPHER_API_KEY) # import pprint; pprint.pprint(result, width=1) if result.get('errors'): for error in result.get('errors'): messages.error(request, error['error']) elif result.get('error'): messages.error(request, result.get('error')) else: success_msg = _('Transaction Successfully Broadcst') messages.success(request, success_msg) url = reverse('transaction_overview', kwargs={ 'coin_symbol': coin_symbol_to_use, 'tx_hash': result['tx']['hash'], }) return HttpResponseRedirect(url) 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, '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, }
def push_tx(request, coin_symbol): """ Push a raw TX to the bitcoin network """ initial = {"coin_symbol": coin_symbol} form = RawTXForm(initial=initial) if request.method == "POST": form = RawTXForm(data=request.POST) if form.is_valid(): # broadcast the transaction tx_hex = form.cleaned_data["tx_hex"] coin_symbol_to_use = form.cleaned_data["coin_symbol"] result = pushtx(tx_hex=tx_hex, coin_symbol=coin_symbol_to_use, api_key=BLOCKCYPHER_API_KEY) # import pprint; pprint.pprint(result, width=1) if result.get("errors"): for error in result.get("errors"): messages.error(request, error["error"]) elif result.get("error"): messages.error(request, result.get("error")) else: success_msg = _("Transaction Successfully Broadcst") messages.success(request, success_msg) url = reverse( "transaction_overview", kwargs={"coin_symbol": coin_symbol_to_use, "tx_hash": result["tx"]["hash"]} ) return HttpResponseRedirect(url) 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}
def push_tx(request, coin_symbol): ''' Push a raw TX to the bitcoin network ''' initial = {'coin_symbol': coin_symbol} form = RawTXForm(initial=initial) if request.method == 'POST': form = RawTXForm(data=request.POST) if form.is_valid(): # broadcast the transaction tx_hex = form.cleaned_data['tx_hex'] coin_symbol_to_use = form.cleaned_data['coin_symbol'] result = pushtx(tx_hex=tx_hex, coin_symbol=coin_symbol_to_use, api_key=BLOCKCYPHER_API_KEY) #import pprint; pprint.pprint(result, width=1) if result.get('errors'): err_msg = _( 'Transaction not broadcast for the following errors') messages.error(request, err_msg) for error in result['errors']: messages.info(request, error['error']) else: success_msg = _('Transaction Successfully Broadcst') messages.success(request, success_msg) url = reverse('transaction_overview', kwargs={ 'coin_symbol': coin_symbol_to_use, 'tx_hash': result['tx']['hash'], }) return HttpResponseRedirect(url) 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, }