def in_mem(in_args): add_dict = dict() for add, val, height in parse_ldb(fin_name=in_args.chainstate, version=in_args.bitcoin_version, types=get_types(in_args)): if add in add_dict: add_dict[add][0] += val add_dict[add][1] = height else: add_dict[add] = [val, height] for key in add_dict: ll = add_dict[key] yield key, ll[0], ll[1]
def get_all_txs(arguments): return parse_ldb(fin_name=arguments.chainstate, version=arguments.bitcoin_version, types={0, 1})
def low_mem(in_args): keep_types = [] if in_args.P2PKH: keep_types.append(0) if in_args.P2SH: keep_types.append(1) if in_args.P2PK: keep_types += [2, 3, 4, 5] if in_args.keep_sqlite: dbfile = in_args.keep_sqlite else: fd, dbfile = tempfile.mkstemp() os.close(fd) with sqlite3.connect(dbfile) as conn: curr = conn.cursor() curr.execute( """ DROP TABLE IF EXISTS balance """ ) curr.execute( """ CREATE TABLE balance ( address TEXT PRIMARY KEY, amount BIGINT NOT NULL, height BIGINT NOT NULL ) """ ) curr.execute('BEGIN TRANSACTION') expinsert = """ INSERT OR IGNORE INTO balance (address, amount, height) VALUES (?, ?, ?)""" expupdate = """ UPDATE balance SET amount = amount + ?, height = ? WHERE address = ? """ for add, val, height in parse_ldb( fin_name=in_args.chainstate, version=in_args.bitcoin_version, types=get_types(in_args)): curr.execute(expinsert, (add, 0, 0)) curr.execute(expupdate, (val, height, add)) if in_args.sort is None: exp = 'SELECT * FROM balance' elif in_args.sort == 'ASC': exp = 'SELECT * FROM balance ORDER BY amount ASC' elif in_args.sort == 'DESC': exp = 'SELECT * FROM balance ORDER BY amount DESC' else: raise Exception curr.execute(exp) for j in curr: yield j[0], j[1], j[2] conn.commit() curr.close() if not in_args.keep_sqlite: os.remove(dbfile)