Skip to content

Commit

Permalink
Added Native Currency detail in Address detail page, fix MultiChain#5
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Cardoso committed Oct 14, 2016
1 parent 8a3414a commit 1d3b88c
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions Mce/abe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,18 +1399,18 @@ def row_to_html(row, this_ch, other_ch, no_link_text):
body += [
'<a href="', prefix, txid, '#', other_ch, row['vout'],
'">', txid[:10], '...:', row['vout'], '</a>']

body += ['</td>']

# Decode earlier as we need to use script type
novalidaddress=False

the_script = None
if this_ch is 'i':
the_script = row['scriptSig']['hex']
else:
the_script = row['scriptPubKey']['hex']

binscript = None

if the_script is not None:
Expand All @@ -1421,14 +1421,14 @@ def row_to_html(row, this_ch, other_ch, no_link_text):

addressLabel = 'None'
value = 0

if novalidaddress is False:
if this_ch is 'i':
try:
resp = util.jsonrpc(chain_name, chain_url, "getrawtransaction", txid, 1)
n = int(row['vout'])
addressLabel = resp['vout'][n]['scriptPubKey']['addresses'][0]
value = resp['vout'][n]['value']
value = resp['vout'][n]['value']
except Exception as e:
pass
else:
Expand All @@ -1444,12 +1444,12 @@ def row_to_html(row, this_ch, other_ch, no_link_text):
if version is chain.script_addr_vers:
p2sh_flag = True
addressLabel = '<a href="../address/' + addressLabel + '">' + addressLabel + '</a>'

body += [
'</td>\n',
'<td>', format_satoshis(value, chain), '</td>\n',
'<td>', addressLabel]

if p2sh_flag is True:
body += ['<div><span class="label label-info">P2SH</span></div>']
body += [ '</td>\n']
Expand Down Expand Up @@ -1604,7 +1604,7 @@ def row_to_html(row, this_ch, other_ch, no_link_text):
body += ['<table class="table table-bordered table-condensed">']
body += html_keyvalue_tablerow('Hash', tx['txid'])
chain = page['chain']

chain_name = abe.store.get_multichain_name_by_id(chain.id)
chain_url = abe.store.get_url_by_chain(chain)

Expand Down Expand Up @@ -1636,7 +1636,7 @@ def row_to_html(row, this_ch, other_ch, no_link_text):
'<a name="outputs"><h3>Outputs</h3></a>\n<table class="table table-striped">\n',
'<tr><th>Index</th><th>Redeemed at input</th><th>Native</th>',
'<th>To address</th><th>ScriptPubKey</th></tr>\n']

pos = 0
for txout in tx['vout']:
txout['pos'] = pos
Expand Down Expand Up @@ -1697,6 +1697,27 @@ def handle_address(abe, page):
body += ['<div class="alert alert-danger" role="alert">', msg, '</div>']
return

body += ['<h3>Native Balance</h3>']
try:
resp = util.jsonrpc(multichain_name, url, "getaddressbalances", address)
if len(resp) is 0:
body += ['None']
else:
body += ['<ul>']
for balance in resp:
if str(balance['assetref']) is '':
body += ['<li>', str(balance['qty']), '</li>']
body += ['</ul>']
except util.JsonrpcException as e:
msg= "Failed to get balancefor address: JSON-RPC error({0}): {1}".format(e.code, e.message)
body += ['<div class="alert alert-danger" role="warning">', msg ,'</div>']
return
except IOError as e:
msg= "Failed to get balance for address: I/O error({0}): {1}".format(e.errno, e.strerror)
body += ['<div class="alert alert-danger" role="alert">', msg, '</div>']
return


body += ['<h3>Asset Balances</h3>']
try:
row = abe.store.selectrow("""select pubkey_id from pubkey where pubkey_hash = ?""",
Expand Down Expand Up @@ -2285,7 +2306,7 @@ def handle_mempooltx(abe, page):
return s

return abe.show_mempool_tx_json(page, resp)

# MULTICHAIN END

def do_rawtx(abe, page, chain):
Expand Down

0 comments on commit 1d3b88c

Please sign in to comment.