Merge branch 'develop'
This commit is contained in:
commit
f32435d1cb
@ -2,6 +2,7 @@
|
||||
# and warranty status of this software.
|
||||
|
||||
|
||||
from decimal import Decimal
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
@ -20,6 +21,7 @@ class Coin(object):
|
||||
# Not sure if these are coin-specific
|
||||
HEADER_LEN = 80
|
||||
DEFAULT_RPC_PORT = 8332
|
||||
VALUE_PER_COIN = 100000000
|
||||
|
||||
@staticmethod
|
||||
def coins():
|
||||
@ -131,6 +133,10 @@ class Coin(object):
|
||||
d = Deserializer(block[cls.HEADER_LEN:])
|
||||
return d.read_block()
|
||||
|
||||
@classmethod
|
||||
def decimal_value(cls, value):
|
||||
return Decimal(value) / cls.VALUE_PER_COIN
|
||||
|
||||
|
||||
class Bitcoin(Coin):
|
||||
NAME = "Bitcoin"
|
||||
|
||||
3
query.py
3
query.py
@ -37,6 +37,9 @@ def main():
|
||||
utxo.tx_pos, utxo.height, utxo.value))
|
||||
if n is None:
|
||||
print('No UTXOs')
|
||||
balance = db.get_balance(hash160)
|
||||
print('Balance: {} {}'.format(coin.decimal_value(balance),
|
||||
coin.SHORTNAME))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@ -460,7 +460,7 @@ class DB(object):
|
||||
|
||||
def get_balance(self, hash160):
|
||||
'''Returns the confirmed balance of an address.'''
|
||||
return sum(utxo.value for utxo in self.get_utxos(hash_160, limit=None))
|
||||
return sum(utxo.value for utxo in self.get_utxos(hash160, limit=None))
|
||||
|
||||
def get_utxos(self, hash160, limit=1000):
|
||||
'''Generator that yields all UTXOs for an address sorted in no
|
||||
|
||||
@ -22,10 +22,11 @@ def main_loop():
|
||||
logging.info('switching current directory to {}'.format(env.db_dir))
|
||||
os.chdir(env.db_dir)
|
||||
|
||||
server = Server(env)
|
||||
tasks = server.async_tasks()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
try:
|
||||
server = Server(env, loop)
|
||||
tasks = server.async_tasks()
|
||||
loop.run_until_complete(asyncio.gather(*tasks))
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user