def push_tx(request, coin_symbol): form = PushTXForm(initial={'coin_symbol': coin_symbol}) if request.method == 'POST': form = PushTXForm(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) return { 'coin_symbol': coin_symbol, 'form': form, }
def push_tx(request, coin_symbol): form = PushTXForm(initial={'coin_symbol': coin_symbol}) if request.method == 'POST': form = PushTXForm(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 Succesfully 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) 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'): 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 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 pushtx(tx, coin_symbol=None, api_key=None): if not re.match('^[0-9a-fA-F]*$', tx): tx = tx.encode('hex') return api.pushtx(tx, coin_symbol=coin_symbol, api_key=None)