Advertisement
Guest User

Untitled

a guest
Aug 26th, 2011
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import decimal.Decimal
  2.  
  3. def q_getreceivedbyaddress(abe, page, chain):
  4. """getreceivedbyaddress"""
  5. if chain is None:
  6. return 'returns amount of money received by given address (not balance, sends are not subtracted)\n' \
  7. '/chain/CHAIN/q/getreceivedbyaddress/ADDRESS*\n'
  8. addr = wsgiref.util.shift_path_info(page['env'])
  9.  
  10. if ADDRESS_RE.match(addr):
  11. version, hash = decode_address(addr)
  12. sql = """
  13. select
  14. ifnull(sum(txout.txout_value),0) from pubkey
  15. join txout on txout.pubkey_id=pubkey.pubkey_id
  16. join block_tx on block_tx.tx_id=txout.tx_id
  17. join block b on b.block_id=block_tx.block_id
  18. join chain_candidate cc on cc.block_id=b.block_id
  19. where
  20. pubkey_hash='%s' and
  21. cc.chain_id=%s and
  22. cc.in_longest=1
  23. ;""" % (binascii.hexlify(hash), chain['id'])
  24. #ret = NETHASH_HEADER + '\n' + sql + '\n\n' # debugging
  25. rows = abe.store.selectall(sql)
  26. ret = (rows[0][0] / decimal.Decimal('1E8')).to_eng_string()
  27. else:
  28. ret = 'address invalid'
  29.  
  30. return ret
  31.  
  32. def q_getsentbyaddress(abe, page, chain):
  33. """getsentbyaddress"""
  34. if chain is None:
  35. return 'returns amount of money sent from given address\n' \
  36. '/chain/CHAIN/q/getsentbyaddress/ADDRESS\n'
  37. addr = wsgiref.util.shift_path_info(page['env'])
  38.  
  39. if ADDRESS_RE.match(addr):
  40. version, hash = decode_address(addr)
  41. sql = """
  42. select
  43. ifnull(sum(txout.txout_value),0) from pubkey
  44. join txout txout on txout.pubkey_id=pubkey.pubkey_id
  45. join txin on txin.txout_id=txout.txout_id
  46. join block_tx on block_tx.tx_id=txout.tx_id
  47. join block b on b.block_id=block_tx.block_id
  48. join chain_candidate cc on cc.block_id=b.block_id
  49. where
  50. pubkey_hash='%s' and
  51. cc.chain_id=%s and
  52. cc.in_longest=1
  53. ;""" % (binascii.hexlify(hash), chain['id'])
  54. #ret = NETHASH_HEADER + '\n' + sql + '\n\n' # debugging
  55. rows = abe.store.selectall(sql)
  56. ret = (rows[0][0] / decimal.Decimal('1E8')).to_eng_string()
  57. else:
  58. ret = 'address invalid'
  59.  
  60. return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement