From 1e97686c5f96394d63dbc002186dc5f3057324df Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 9 Oct 2016 08:26:46 +0900 Subject: [PATCH] Add a simple query for debugging --- query.py | 33 +++++++++++++++++++++++++++++++++ server/server.py | 29 ----------------------------- 2 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 query.py diff --git a/query.py b/query.py new file mode 100644 index 0000000..f445d06 --- /dev/null +++ b/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() diff --git a/server/server.py b/server/server.py index 2618d2b..e6a7bbc 100644 --- a/server/server.py +++ b/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))