def load_from_filename(wallet_filename): wallet_filename = os.path.abspath(wallet_filename) import bsddb3.db db_env = bsddb3.db.DBEnv() try: db_env.open(os.path.dirname(wallet_filename), bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL) db = bsddb3.db.DB(db_env) db.open(wallet_filename, b"main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY) except UnicodeEncodeError: error_exit("the entire path and filename of Bitcoin Core wallets should be entirely ASCII") mkey = db.get(b"\x04mkey\x01\x00\x00\x00") db.close() db_env.close() # if not mkey: # raise ValueError("Encrypted master key #1 not found in the Bitcoin Core wallet file.\n"+ # "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)") # This is a little fragile because it assumes the encrypted key and salt sizes are # 48 and 8 bytes long respectively, which although currently true may not always be # (it will loudly fail if this isn't the case; if smarter it could gracefully succeed): # self = cls(loading=True) encrypted_master_key, salt, method, iter_count = struct.unpack_from(b"< 49p 9p I I", mkey) # print encrypted_master_key return encrypted_master_key, salt, method, iter_count
def _read_from_data(self, filename): db_env = bsddb3.db.DBEnv() try: db_env.open(os.path.dirname(filename), bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL) db = bsddb3.db.DB(db_env) db.open(filename, b"main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY) except UnicodeEncodeError: error_exit("the entire path and filename of Bitcoin Core wallets should be entirely ASCII") mkey = db.get(b"\x04mkey\x01\x00\x00\x00") encrypted_master_key, salt, method, iter_count = struct.unpack_from(b"< 49p 9p I I", mkey) db.close() db_env.close() return encrypted_master_key, salt, method, iter_count
def open(filename, mode): db = bsddb3.db.DB(None) if mode == "r": flags = bsddb3.db.DB_RDONLY elif mode == "rw": flags = 0 elif mode == "w": flags = bsddb3.db.DB_CREATE elif mode == "c": flags = bsddb3.db.DB_CREATE elif mode == "n": flags = bsddb3.db.DB_TRUNCATE | bsddb3.db.DB_CREATE else: raise bsddb3.db.DBError( "flags should be one of 'r', 'w', 'c' or 'n' or use the " "bsddb.db.DB_* flags") db.open(filename, None, bsddb3.db.DB_HASH, flags) return db
def open(filename, mode): db = bsddb3.db.DB(None) if mode == 'r': flags = bsddb3.db.DB_RDONLY elif mode == 'rw': flags = 0 elif mode == 'w': flags = bsddb3.db.DB_CREATE elif mode == 'c': flags = bsddb3.db.DB_CREATE elif mode == 'n': flags = bsddb3.db.DB_TRUNCATE | bsddb3.db.DB_CREATE else: raise bsddb3.db.DBError( "flags should be one of 'r', 'w', 'c' or 'n' or use the " "bsddb.db.DB_* flags") db.open(filename, None, bsddb3.db.DB_HASH, flags) return db
globals()[name] = value import_constants(bsddb3.db, '^DB_') HOME = './data' flags = (DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN | DB_THREAD) env = DBEnv() env.set_cachesize(0, 32 * 1024 * 1024, 0) env.open(HOME, flags) db = DB(env) db.set_flags(DB_DUP | DB_DUPSORT) db.open('main', dbname='records', flags=DB_CREATE | DB_AUTO_COMMIT | DB_MULTIVERSION, dbtype=DB_BTREE) def finish(): db.close() env.close() atexit.register(finish) def popuplate(): txn = env.txn_begin(flags=0) for l in string.letters: for i in range(25): db.put(l, '%03d' % i, txn=txn) txn.commit()
import_constants(bsddb3.db, '^DB_') HOME = './data' flags = (DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN | DB_THREAD) env = DBEnv() env.set_cachesize(0, 32 * 1024 * 1024, 0) env.open(HOME, flags) db = DB(env) db.set_flags(DB_DUP | DB_DUPSORT) db.open('main', dbname='records', flags=DB_CREATE | DB_AUTO_COMMIT | DB_MULTIVERSION, dbtype=DB_BTREE) def finish(): db.close() env.close() atexit.register(finish) def popuplate(): txn = env.txn_begin(flags=0) for l in string.letters: for i in range(25):
wallet_filename = os.path.abspath(sys.argv[1]) with open(wallet_filename, "rb") as wallet_file: wallet_file.seek(12) if wallet_file.read( 8) != b"\x62\x31\x05\x00\x09\x00\x00\x00": # BDB magic, Btree v9 print(prog + ": error: file is not a Bitcoin Core wallet", file=sys.stderr) sys.exit(1) db_env = bsddb3.db.DBEnv() db_env.open(os.path.dirname(wallet_filename), bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL) db = bsddb3.db.DB(db_env) db.open(wallet_filename, "main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY) mkey = db.get(b"\x04mkey\x01\x00\x00\x00") db.close() db_env.close() if not mkey: raise ValueError( "Encrypted master key #1 not found in the Bitcoin Core wallet file.\n" + "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)") # This is a little fragile because it assumes the encrypted key and salt sizes are # 48 and 8 bytes long respectively, which although currently true may not always be: # (it will loudly fail if this isn't the case; if smarter it could gracefully succeed): encrypted_master_key, salt, method, iter_count = struct.unpack_from( "< 49p 9p I I", mkey)