Skip to content

Commit 345e88e

Browse files
committed
wallettool: add param to create descriptors wallet
1 parent 6d3af3a commit 345e88e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
2727
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2828
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
2929
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
30+
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for create", ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
3031
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
3132

3233
argsman.AddArg("info", "Get wallet info", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);

src/wallet/wallettool.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ static void WalletToolReleaseWallet(CWallet* wallet)
2121
delete wallet;
2222
}
2323

24-
static void WalletCreate(CWallet* wallet_instance)
24+
static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flags)
2525
{
2626
LOCK(wallet_instance->cs_wallet);
2727

2828
wallet_instance->SetMinVersion(FEATURE_HD_SPLIT);
29+
wallet_instance->AddWalletFlags(wallet_creation_flags);
2930

30-
// generate a new HD seed
31-
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();
32-
CPubKey seed = spk_man->GenerateNewSeed();
33-
spk_man->SetHDSeed(seed);
31+
if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
32+
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();
33+
spk_man->SetupGeneration(false);
34+
} else {
35+
wallet_instance->SetupDescriptorScriptPubKeyMans();
36+
}
3437

3538
tfm::format(std::cout, "Topping up keypool...\n");
3639
wallet_instance->TopUpKeyPool();
@@ -79,7 +82,7 @@ static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::pa
7982
}
8083
}
8184

82-
if (options.require_create) WalletCreate(wallet_instance.get());
85+
if (options.require_create) WalletCreate(wallet_instance.get(), options.create_flags);
8386

8487
return wallet_instance;
8588
}
@@ -106,6 +109,11 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
106109
if (command == "create") {
107110
DatabaseOptions options;
108111
options.require_create = true;
112+
if (gArgs.GetBoolArg("-descriptors", false)) {
113+
options.create_flags |= WALLET_FLAG_DESCRIPTORS;
114+
options.require_format = DatabaseFormat::SQLITE;
115+
}
116+
109117
std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
110118
if (wallet_instance) {
111119
WalletShowInfo(wallet_instance.get());

0 commit comments

Comments
 (0)