Browse Source

Add a simple query for debugging

master
Neil Booth 8 years ago
parent
commit
1e97686c5f
  1. 33
      query.py
  2. 29
      server/server.py

33
query.py

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# See the file "LICENSE" for information about the copyright
# and warranty status of this software.
import asyncio
import os
import sys
from server.env import Env
from server.server import Server
def main():
env = Env()
os.chdir(env.db_dir)
loop = asyncio.get_event_loop()
server = Server(env, loop)
db = server.db
coin = db.coin
for addr in sys.argv[1:]:
print('Address: ', addr)
hash160 = coin.address_to_hash160(addr)
for n, (tx_hash, height) in enumerate(db.get_history(hash160)):
print('History #{:d}: hash: {} height: {:d}'
.format(n + 1, bytes(reversed(tx_hash)).hex(), height))
for n, utxo in enumerate(db.get_utxos(hash160)):
print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'
.format(n, bytes(reversed(utxo.tx_hash)).hex(),
utxo.tx_pos, utxo.height, utxo.value))
if __name__ == '__main__':
main()

29
server/server.py

@ -201,32 +201,3 @@ class RPC(object):
self.logger.info('sleeping 1 second and trying again...')
await asyncio.sleep(1)
# for addr in [
# # '1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp',
# # '1HYBcza9tVquCCvCN1hUZkYT9RcM6GfLot',
# # '1BNwxHGaFbeUBitpjy2AsKpJ29Ybxntqvb',
# # '1ARanTkswPiVM6tUEYvbskyqDsZpweiciu',
# # '1VayNert3x1KzbpzMGt2qdqrAThiRovi8',
# # '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
# # '1XPTgDRhN8RFnzniWCddobD9iKZatrvH4',
# # '153h6eE6xRhXuN3pE53gWVfXacAtfyBF8g',
# ]:
# print('Address: ', addr)
# hash160 = coin.address_to_hash160(addr)
# utxos = self.db.get_utxos(hash160)
# for n, utxo in enumerate(utxos):
# print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'
# .format(n, bytes(reversed(utxo.tx_hash)).hex(),
# utxo.tx_pos, utxo.height, utxo.value))
# for addr in [
# '19k8nToWwMGuF4HkNpzgoVAYk4viBnEs5D',
# '1HaHTfmvoUW6i6nhJf8jJs6tU4cHNmBQHQ',
# '1XPTgDRhN8RFnzniWCddobD9iKZatrvH4',
# ]:
# print('Address: ', addr)
# hash160 = coin.address_to_hash160(addr)
# for n, (tx_hash, height) in enumerate(self.db.get_history(hash160)):
# print('History #{:d}: hash: {} height: {:d}'
# .format(n + 1, bytes(reversed(tx_hash)).hex(), height))

Loading…
Cancel
Save