Skip to content

Commit 70cfbfd

Browse files
committed
wallettool: Optionally use BERKELEY_RO as format when dumping BDB wallets
In order to ease the transition to not having BDB, make the dump tool use DatabaseFormmat::BERKELEY_RO when -withinternalbdb is set.
1 parent dd57713 commit 70cfbfd

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
4444
argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4545
argsman.AddArg("-format=<format>", "The format of the wallet file to create. Either \"bdb\" or \"sqlite\". Only used with 'createfromdump'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4646
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
47+
argsman.AddArg("-withinternalbdb", "Use the internal Berkeley DB parser when dumping a Berkeley DB wallet file (default: false)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
4748

4849
argsman.AddCommand("info", "Get wallet info");
4950
argsman.AddCommand("create", "Create new wallet file");

src/wallet/dump.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& erro
6060
hasher << Span{line};
6161

6262
// Write out the file format
63-
line = strprintf("%s,%s\n", "format", db.Format());
63+
std::string format = db.Format();
64+
// BDB files that are opened using BerkeleyRODatabase have it's format as "bdb_ro"
65+
// We want to override that format back to "bdb"
66+
if (format == "bdb_ro") {
67+
format = "bdb";
68+
}
69+
line = strprintf("%s,%s\n", "format", format);
6470
dump_file.write(line.data(), line.size());
6571
hasher << Span{line};
6672

src/wallet/wallettool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
194194
ReadDatabaseArgs(args, options);
195195
options.require_existing = true;
196196
DatabaseStatus status;
197+
198+
if (args.GetBoolArg("-withinternalbdb", false) && IsBDBFile(BDBDataFile(path))) {
199+
options.require_format = DatabaseFormat::BERKELEY_RO;
200+
}
201+
197202
bilingual_str error;
198203
std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error);
199204
if (!database) {

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
'mempool_resurrect.py',
193193
'wallet_txn_doublespend.py --mineblock',
194194
'tool_wallet.py --legacy-wallet',
195+
'tool_wallet.py --legacy-wallet --bdbro',
195196
'tool_wallet.py --descriptors',
196197
'tool_signet_miner.py --legacy-wallet',
197198
'tool_signet_miner.py --descriptors',

test/functional/tool_wallet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class ToolWalletTest(BitcoinTestFramework):
2222
def add_options(self, parser):
2323
self.add_wallet_options(parser)
24+
parser.add_argument("--bdbro", action="store_true", help="Use the BerkeleyRO internal parser when dumping a Berkeley DB wallet file")
2425

2526
def set_test_params(self):
2627
self.num_nodes = 1
@@ -35,6 +36,8 @@ def bitcoin_wallet_process(self, *args):
3536
default_args = ['-datadir={}'.format(self.nodes[0].datadir_path), '-chain=%s' % self.chain]
3637
if not self.options.descriptors and 'create' in args:
3738
default_args.append('-legacy')
39+
if "dump" in args and self.options.bdbro:
40+
default_args.append("-withinternalbdb")
3841

3942
return subprocess.Popen([self.options.bitcoinwallet] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
4043

0 commit comments

Comments
 (0)