mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
feat: add option -usehd to wallettool to let create non-hd wallets
This commit is contained in:
parent
456e34c991
commit
31ffb78ced
@ -25,6 +25,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
|
||||
SetupChainParamsBaseOptions(argsman);
|
||||
|
||||
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-usehd", strprintf("Create HD (hierarchical deterministic) wallet (default: %d)", true), 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, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-dumpfile=<file name>", "When used with 'dump', writes out the records to this file. When used with 'createfromdump', loads the records into a new wallet.", ArgsManager::ALLOW_STRING, OptionsCategory::OPTIONS);
|
||||
|
@ -22,10 +22,16 @@ static void WalletToolReleaseWallet(CWallet* wallet)
|
||||
delete wallet;
|
||||
}
|
||||
|
||||
static const bool DEFAULT_USE_HD_WALLET{true};
|
||||
|
||||
static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flags)
|
||||
{
|
||||
LOCK(wallet_instance->cs_wallet);
|
||||
wallet_instance->SetMinVersion(FEATURE_LATEST);
|
||||
if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET)) {
|
||||
wallet_instance->SetMinVersion(FEATURE_LATEST);
|
||||
} else {
|
||||
wallet_instance->SetMinVersion(FEATURE_COMPRPUBKEY);
|
||||
}
|
||||
wallet_instance->SetWalletFlag(wallet_creation_flags);
|
||||
|
||||
if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
|
||||
@ -33,7 +39,9 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
|
||||
// SetupGeneration is not backported yet
|
||||
wallet_instance->SetupLegacyScriptPubKeyMan();
|
||||
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();
|
||||
spk_man->GenerateNewHDChain(/*secureMnemonic=*/"", /*secureMnemonicPassphrase=*/"");
|
||||
if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET)) {
|
||||
spk_man->GenerateNewHDChain(/*secureMnemonic=*/"", /*secureMnemonicPassphrase=*/"");
|
||||
}
|
||||
} else {
|
||||
wallet_instance->SetupDescriptorScriptPubKeyMans();
|
||||
}
|
||||
|
@ -400,6 +400,16 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload"))
|
||||
|
||||
|
||||
def test_nonhd(self):
|
||||
self.log.info('Check non-hd wallet')
|
||||
self.start_node(0, ['-usehd=0', '-nowallet'])
|
||||
self.nodes[0].createwallet("nohd")
|
||||
assert_equal(False, 'hdchainid' in self.nodes[0].get_wallet_rpc('nohd').getwalletinfo())
|
||||
self.restart_node(0, ['-usehd=1', '-nowallet'])
|
||||
self.nodes[0].createwallet("hd")
|
||||
assert_equal(True, 'hdchainid' in self.nodes[0].get_wallet_rpc('hd').getwalletinfo())
|
||||
self.stop_node(0)
|
||||
|
||||
def run_test(self):
|
||||
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
|
||||
self.test_invalid_tool_commands_and_args()
|
||||
@ -412,6 +422,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||
# Salvage is a legacy wallet only thing
|
||||
self.test_salvage()
|
||||
self.test_wipe()
|
||||
self.test_nonhd()
|
||||
self.test_dump_createfromdump()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user