wallettool: add param to create descriptors wallet

This commit is contained in:
Ivan Metlushko
2020-11-11 11:41:53 +07:00
parent 6d3af3ab62
commit 345e88eecf
2 changed files with 15 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS); argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for create", ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("info", "Get wallet info", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS); argsman.AddArg("info", "Get wallet info", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);

View File

@@ -21,16 +21,19 @@ static void WalletToolReleaseWallet(CWallet* wallet)
delete wallet; delete wallet;
} }
static void WalletCreate(CWallet* wallet_instance) static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flags)
{ {
LOCK(wallet_instance->cs_wallet); LOCK(wallet_instance->cs_wallet);
wallet_instance->SetMinVersion(FEATURE_HD_SPLIT); wallet_instance->SetMinVersion(FEATURE_HD_SPLIT);
wallet_instance->AddWalletFlags(wallet_creation_flags);
// generate a new HD seed if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan(); auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();
CPubKey seed = spk_man->GenerateNewSeed(); spk_man->SetupGeneration(false);
spk_man->SetHDSeed(seed); } else {
wallet_instance->SetupDescriptorScriptPubKeyMans();
}
tfm::format(std::cout, "Topping up keypool...\n"); tfm::format(std::cout, "Topping up keypool...\n");
wallet_instance->TopUpKeyPool(); wallet_instance->TopUpKeyPool();
@@ -79,7 +82,7 @@ static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::pa
} }
} }
if (options.require_create) WalletCreate(wallet_instance.get()); if (options.require_create) WalletCreate(wallet_instance.get(), options.create_flags);
return wallet_instance; return wallet_instance;
} }
@@ -106,6 +109,11 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
if (command == "create") { if (command == "create") {
DatabaseOptions options; DatabaseOptions options;
options.require_create = true; options.require_create = true;
if (gArgs.GetBoolArg("-descriptors", false)) {
options.create_flags |= WALLET_FLAG_DESCRIPTORS;
options.require_format = DatabaseFormat::SQLITE;
}
std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options); std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
if (wallet_instance) { if (wallet_instance) {
WalletShowInfo(wallet_instance.get()); WalletShowInfo(wallet_instance.get());