Print if nothing. Clean up loop.
This commit is contained in:
parent
db2e1d43d8
commit
6ccdce2c77
25
query.py
25
query.py
@ -3,31 +3,40 @@
|
|||||||
# See the file "LICENSE" for information about the copyright
|
# See the file "LICENSE" for information about the copyright
|
||||||
# and warranty status of this software.
|
# and warranty status of this software.
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from server.env import Env
|
from server.env import Env
|
||||||
from server.server import Server
|
from server.db import DB
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
env = Env()
|
env = Env()
|
||||||
os.chdir(env.db_dir)
|
os.chdir(env.db_dir)
|
||||||
loop = asyncio.get_event_loop()
|
db = DB(env)
|
||||||
server = Server(env, loop)
|
|
||||||
db = server.db
|
|
||||||
coin = db.coin
|
coin = db.coin
|
||||||
for addr in sys.argv[1:]:
|
argc = 1
|
||||||
|
try:
|
||||||
|
limit = int(sys.argv[argc])
|
||||||
|
argc += 1
|
||||||
|
except:
|
||||||
|
limit = 10
|
||||||
|
for addr in sys.argv[argc:]:
|
||||||
print('Address: ', addr)
|
print('Address: ', addr)
|
||||||
hash160 = coin.address_to_hash160(addr)
|
hash160 = coin.address_to_hash160(addr)
|
||||||
for n, (tx_hash, height) in enumerate(db.get_history(hash160)):
|
n = None
|
||||||
|
for n, (tx_hash, height) in enumerate(db.get_history(hash160, limit)):
|
||||||
print('History #{:d}: hash: {} height: {:d}'
|
print('History #{:d}: hash: {} height: {:d}'
|
||||||
.format(n + 1, bytes(reversed(tx_hash)).hex(), height))
|
.format(n + 1, bytes(reversed(tx_hash)).hex(), height))
|
||||||
for n, utxo in enumerate(db.get_utxos(hash160)):
|
if n is None:
|
||||||
|
print('No history')
|
||||||
|
n = None
|
||||||
|
for n, utxo in enumerate(db.get_utxos(hash160, limit)):
|
||||||
print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'
|
print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'
|
||||||
.format(n, bytes(reversed(utxo.tx_hash)).hex(),
|
.format(n, bytes(reversed(utxo.tx_hash)).hex(),
|
||||||
utxo.tx_pos, utxo.height, utxo.value))
|
utxo.tx_pos, utxo.height, utxo.value))
|
||||||
|
if n is None:
|
||||||
|
print('No UTXOs')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -15,11 +15,11 @@ from server.db import DB
|
|||||||
|
|
||||||
class Server(object):
|
class Server(object):
|
||||||
|
|
||||||
def __init__(self, env, loop):
|
def __init__(self, env):
|
||||||
self.env = env
|
self.env = env
|
||||||
self.db = DB(env)
|
self.db = DB(env)
|
||||||
self.rpc = RPC(env)
|
self.rpc = RPC(env)
|
||||||
self.block_cache = BlockCache(env, self.db, self.rpc, loop)
|
self.block_cache = BlockCache(env, self.db, self.rpc)
|
||||||
|
|
||||||
def async_tasks(self):
|
def async_tasks(self):
|
||||||
return [
|
return [
|
||||||
@ -32,7 +32,7 @@ class BlockCache(object):
|
|||||||
'''Requests blocks ahead of time from the daemon. Serves them
|
'''Requests blocks ahead of time from the daemon. Serves them
|
||||||
to the blockchain processor.'''
|
to the blockchain processor.'''
|
||||||
|
|
||||||
def __init__(self, env, db, rpc, loop):
|
def __init__(self, env, db, rpc):
|
||||||
self.logger = logging.getLogger('BlockCache')
|
self.logger = logging.getLogger('BlockCache')
|
||||||
self.logger.setLevel(logging.INFO)
|
self.logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
@ -47,6 +47,8 @@ class BlockCache(object):
|
|||||||
self.blocks = []
|
self.blocks = []
|
||||||
self.recent_sizes = []
|
self.recent_sizes = []
|
||||||
self.ave_size = 0
|
self.ave_size = 0
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
for signame in ('SIGINT', 'SIGTERM'):
|
for signame in ('SIGINT', 'SIGTERM'):
|
||||||
loop.add_signal_handler(getattr(signal, signame),
|
loop.add_signal_handler(getattr(signal, signame),
|
||||||
partial(self.on_signal, signame))
|
partial(self.on_signal, signame))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user