From 76748d26732cf43e5f6713cf9e3fc323d484505e Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 22 Oct 2016 14:19:51 +0900 Subject: [PATCH] Fix query.py --- query.py | 12 ++++++------ server/block_processor.py | 5 ++++- server/cache.py | 2 -- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/query.py b/query.py index dc771e0..60f3380 100755 --- a/query.py +++ b/query.py @@ -7,15 +7,15 @@ import os import sys from server.env import Env -from server.block_processor import DB +from server.block_processor import BlockProcessor from lib.hash import hash_to_str def main(): env = Env() + coin = env.coin os.chdir(env.db_dir) - db = DB(env) - coin = db.coin + bp = BlockProcessor(env, None) argc = 1 try: limit = int(sys.argv[argc]) @@ -26,19 +26,19 @@ def main(): print('Address: ', addr) hash168 = coin.address_to_hash168(addr) n = None - for n, (tx_hash, height) in enumerate(db.get_history(hash168, limit)): + for n, (tx_hash, height) in enumerate(bp.get_history(hash168, limit)): print('History #{:d}: hash: {} height: {:d}' .format(n + 1, hash_to_str(tx_hash), height)) if n is None: print('No history') n = None - for n, utxo in enumerate(db.get_utxos(hash168, limit)): + for n, utxo in enumerate(bp.get_utxos(hash168, limit)): print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}' .format(n + 1, hash_to_str(utxo.tx_hash), utxo.tx_pos, utxo.height, utxo.value)) if n is None: print('No UTXOs') - balance = db.get_balance(hash168) + balance = bp.get_balance(hash168) print('Balance: {} {}'.format(coin.decimal_value(balance), coin.SHORTNAME)) diff --git a/server/block_processor.py b/server/block_processor.py index 35a7f2f..d2852d5 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -6,7 +6,7 @@ import ast import asyncio import struct import time -from collections import defaultdict +from collections import defaultdict, namedtuple from functools import partial import plyvel @@ -25,6 +25,9 @@ def formatted_time(t): t // 86400, (t % 86400) // 3600, (t % 3600) // 60, t % 60) +UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value") + + class ChainError(Exception): pass diff --git a/server/cache.py b/server/cache.py index 7cf8978..adefc02 100644 --- a/server/cache.py +++ b/server/cache.py @@ -6,7 +6,6 @@ import itertools import os import struct from bisect import bisect_right -from collections import namedtuple from lib.script import ScriptPubKey from lib.util import chunks, LoggedClass @@ -18,7 +17,6 @@ HIST_ENTRIES_PER_KEY = 1024 HIST_VALUE_BYTES = HIST_ENTRIES_PER_KEY * 4 ADDR_TX_HASH_LEN = 4 UTXO_TX_HASH_LEN = 4 -UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value") class UTXOCache(LoggedClass):