Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import decimal.Decimal
- def q_getreceivedbyaddress(abe, page, chain):
- """getreceivedbyaddress"""
- if chain is None:
- return 'returns amount of money received by given address (not balance, sends are not subtracted)\n' \
- '/chain/CHAIN/q/getreceivedbyaddress/ADDRESS*\n'
- addr = wsgiref.util.shift_path_info(page['env'])
- if ADDRESS_RE.match(addr):
- version, hash = decode_address(addr)
- sql = """
- select
- ifnull(sum(txout.txout_value),0) from pubkey
- join txout on txout.pubkey_id=pubkey.pubkey_id
- join block_tx on block_tx.tx_id=txout.tx_id
- join block b on b.block_id=block_tx.block_id
- join chain_candidate cc on cc.block_id=b.block_id
- where
- pubkey_hash='%s' and
- cc.chain_id=%s and
- cc.in_longest=1
- ;""" % (binascii.hexlify(hash), chain['id'])
- #ret = NETHASH_HEADER + '\n' + sql + '\n\n' # debugging
- rows = abe.store.selectall(sql)
- ret = (rows[0][0] / decimal.Decimal('1E8')).to_eng_string()
- else:
- ret = 'address invalid'
- return ret
- def q_getsentbyaddress(abe, page, chain):
- """getsentbyaddress"""
- if chain is None:
- return 'returns amount of money sent from given address\n' \
- '/chain/CHAIN/q/getsentbyaddress/ADDRESS\n'
- addr = wsgiref.util.shift_path_info(page['env'])
- if ADDRESS_RE.match(addr):
- version, hash = decode_address(addr)
- sql = """
- select
- ifnull(sum(txout.txout_value),0) from pubkey
- join txout txout on txout.pubkey_id=pubkey.pubkey_id
- join txin on txin.txout_id=txout.txout_id
- join block_tx on block_tx.tx_id=txout.tx_id
- join block b on b.block_id=block_tx.block_id
- join chain_candidate cc on cc.block_id=b.block_id
- where
- pubkey_hash='%s' and
- cc.chain_id=%s and
- cc.in_longest=1
- ;""" % (binascii.hexlify(hash), chain['id'])
- #ret = NETHASH_HEADER + '\n' + sql + '\n\n' # debugging
- rows = abe.store.selectall(sql)
- ret = (rows[0][0] / decimal.Decimal('1E8')).to_eng_string()
- else:
- ret = 'address invalid'
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement