You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

#!/usr/bin/env python3
# See the file "LICENSE" for information about the copyright
# and warranty status of this software.
import os
import sys
from server.env import Env
8 years ago
from server.block_processor import BlockProcessor
from lib.hash import hash_to_str
def count_entries(db):
utxos = 0
for key in db.iterator(prefix=b'u', include_value=False):
utxos += 1
print("UTXO count:", utxos)
hash168 = 0
for key in db.iterator(prefix=b'h', include_value=False):
hash168 += 1
print("Hash168 count:", hash168)
hist = 0
for key in db.iterator(prefix=b'H', include_value=False):
hist += 1
print("History addresses:", hist)
def main():
env = Env()
8 years ago
coin = env.coin
os.chdir(env.db_dir)
8 years ago
bp = BlockProcessor(env, None)
if len(sys.argv) == 1:
count_entries(bp.db)
return
argc = 1
try:
limit = int(sys.argv[argc])
argc += 1
except:
limit = 10
for addr in sys.argv[argc:]:
print('Address: ', addr)
hash168 = coin.address_to_hash168(addr)
n = None
8 years ago
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
8 years ago
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')
8 years ago
balance = bp.get_balance(hash168)
print('Balance: {} {}'.format(coin.decimal_value(balance),
coin.SHORTNAME))
if __name__ == '__main__':
main()