示例#1
0
async def query(args):
    env = Env()
    db = DB(env)
    coin = env.coin

    await db._open_dbs(False)

    if not args.scripts:
        await print_stats(db.hist_db, db.utxo_db)
        return
    limit = args.limit
    for arg in args.scripts:
        hashX = arg_to_hashX(coin, arg)
        if not hashX:
            continue
        n = None
        for n, (tx_hash, height) in enumerate(db.get_history(hashX, limit),
                                              start=1):
            print(f'History #{n:,d}: height {height:,d} '
                  f'tx_hash {hash_to_hex_str(tx_hash)}')
        if n is None:
            print('No history found')
        n = None
        for n, utxo in enumerate(db.get_utxos(hashX, limit), start=1):
            print(f'UTXO #{n:,d}: tx_hash {hash_to_hex_str(utxo.tx_hash)} '
                  f'tx_pos {utxo.tx_pos:,d} height {utxo.height:,d} '
                  f'value {utxo.value:,d}')
        if n is None:
            print('No UTXOs found')
        balance = db.get_balance(hashX)
        print(f'Balance: {coin.decimal_value(balance):,f} {coin.SHORTNAME}')
示例#2
0
def main():
    env = Env()
    bp = DB(env)
    coin = env.coin
    if len(sys.argv) == 1:
        count_entries(bp.hist_db, bp.utxo_db)
        return
    argc = 1
    try:
        limit = int(sys.argv[argc])
        argc += 1
    except Exception:
        limit = 10
    for addr in sys.argv[argc:]:
        print('Address: ', addr)
        hashX = coin.address_to_hashX(addr)

        for n, (tx_hash, height) in enumerate(bp.get_history(hashX, limit)):
            print('History #{:d}: hash: {} height: {:d}'.format(
                n + 1, hash_to_hex_str(tx_hash), height))
        n = None
        for n, utxo in enumerate(bp.get_utxos(hashX, limit)):
            print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'.
                  format(n + 1, hash_to_hex_str(utxo.tx_hash), utxo.tx_pos,
                         utxo.height, utxo.value))
        if n is None:
            print('No UTXOs')
        balance = bp.get_balance(hashX)
        print('Balance: {} {}'.format(coin.decimal_value(balance),
                                      coin.SHORTNAME))