Browse Source

Fix query.py

master
Neil Booth 8 years ago
parent
commit
76748d2673
  1. 12
      query.py
  2. 5
      server/block_processor.py
  3. 2
      server/cache.py

12
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))

5
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

2
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):

Loading…
Cancel
Save