Skip to content

Commit

Permalink
better handling of decoding raw transction
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Flaxman committed Oct 23, 2015
1 parent 349293d commit 9379bcb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
18 changes: 13 additions & 5 deletions templates/decodetx.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ <h1>

{% if tx_in_json_str %}
<h2>Decoded Transaction</h2>

<pre><small>{{ tx_in_json_str|safe }}</small></pre>

{% if tx_uri %}
(This transaction was previously broadcast,
<a href="{{ tx_uri }}">see it on the blockchain</a>)
{% endif %}

<br />
<h2>Input New Transaction Hex</h2>
{% endif %}
Expand All @@ -44,11 +50,13 @@ <h2>Input New Transaction Hex</h2>
</p>
</form>

<p class="text-center">
Ready to broadcast?
<a href="{% url 'push_tx' coin_symbol %}">Click here</a>
to broadcast a raw transaction without decoding it first.
</p>
{% if not tx_uri %}
<p class="text-center">
Ready to broadcast?
<a href="{% url 'push_tx' coin_symbol %}?t={{ tx_hex }}">Click here</a>
to broadcast a raw transaction hex.
</p>
{% endif %}

</div>
</div>
Expand Down
26 changes: 22 additions & 4 deletions transactions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def scale_confidence(confidence):
assert confidence <= 1

confidence_scaled = min(1, max(0, confidence-.05))
#confidence_scaled = confidence_scaled**2 # arbitrary fudge factor
# confidence_scaled = confidence_scaled**2 # arbitrary fudge factor
return confidence_scaled * 100


Expand Down Expand Up @@ -208,7 +208,7 @@ def decode_tx(request, coin_symbol):
'''
initial = {'coin_symbol': coin_symbol}
form = RawTXForm(initial=initial)
tx_in_json_str = ''
tx_in_json_str, tx_uri, tx_hex = '', '', ''
if request.method == 'POST':
form = RawTXForm(data=request.POST)
if form.is_valid():
Expand All @@ -217,8 +217,24 @@ def decode_tx(request, coin_symbol):
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)
# 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
Expand All @@ -230,6 +246,8 @@ def decode_tx(request, coin_symbol):
'coin_symbol': coin_symbol,
'form': form,
'tx_in_json_str': tx_in_json_str,
'tx_uri': tx_uri,
'tx_hex': tx_hex,
}


Expand Down

0 comments on commit 9379bcb

Please sign in to comment.