示例#1
0
def summarize(conn: leveldb.LevelDB):
    counts = defaultdict(int)
    for k, v in conn.RangeIter():
        assert isinstance(k, bytearray)
        kind = chr(k[0])
        counts[kind] += 1

    code_to_name = {t.value: t.name for t in RowType}
示例#2
0
def dump_csv(conn: leveldb.LevelDB) -> None:
    """Dump the data from a given connection."""
    writer = csv.writer(sys.stdout)
    secret = get_obfuscate_key(conn)
    writer.writerow(['txid', 'vout', 'height', 'coinbase', 'amount'])
    for k, v in conn.RangeIter(b'C', b'D', include_value=True):
        txid, vout = decode_key(k)
        decrypt(v, secret)
        height, coinbase, amount = decode_val(v)
        writer.writerow([txid, vout, height, coinbase, amount])
示例#3
0
def dump_chainstate_csv(conn: leveldb.LevelDB):
    secret = get_obfuscate_key(conn)
    writer = csv.writer(sys.stdout)
    writer.writerow(
        ['txid', 'vout', 'height', 'coinbase', 'amount', 'scriptsize'])
    for k, v in conn.RangeIter(b'C', b'D', include_value=True):
        txid, vout = decode_key(k)
        decrypt(v, secret)
        height, coinbase, amount, sz = decode_val(v)
        writer.writerow([txid, vout, height, coinbase, amount, sz])
示例#4
0
def summarize(conn: leveldb.LevelDB):
    counts = defaultdict(int)
    for k, v in conn.RangeIter():
        assert isinstance(k, bytearray)
        kind = chr(k[0])
        counts[kind] += 1

    code_to_name = {t.value: t.name for t in RowType}
    for k, v in sorted(
            counts.items(), key=operator.itemgetter(1), reverse=True):
        print('{:15s} {}'.format(code_to_name[k], v))
示例#5
0
文件: dbmgr.py 项目: bwlang/fatools
def do_viewpeakcachedb(args, dbh):

    from leveldb import LevelDB
    from collections import defaultdict

    ldb = LevelDB(args.peakcachedb, create_if_missing=False)

    batches = defaultdict(int)

    for key in ldb.RangeIter(include_value=False):
        batch_code = bytes(key.split(b'|', 1)[0])
        batches[batch_code] += 1

    cout('Peakcache DB: %s' % args.peakcachedb)
    for (k, v) in batches.items():
        cout('\t%s\t%4d' % (k.decode(), v))