Skip to content

Commit b6bd77a

Browse files
achow101Claude Code
authored andcommitted
Merge bitcoin#27757: rpc: remove deprecated "warning" field from {create,load,restore,unload}wallet
5524fa0 doc: add release note about removal of `deprecatedrpc=walletwarningfield` flag (Sebastian Falbesoner) 5c77db7 Restorewallet/createwallet help documentation fixups/improvements (Jon Atack) a00ae31 rpc: remove deprecated "warning" field from {create,load,restore,unload}wallet (Sebastian Falbesoner) Pull request description: The "warning" string field for wallet creating/loading RPCs (`createwallet`, `loadwallet`, `unloadwallet` and `restorewallet`) has been deprecated with the configuration option `-deprecatedrpc=walletwarningfield` in PR bitcoin#27279 (released in v25.0). For the next release v26.0, the field and the configuration option can be removed. ACKs for top commit: achow101: ACK 5524fa0 jonatack: ACK 5524fa0 Tree-SHA512: 8212f72067d08095304018b8a95d2ebef630004b65123483fbbfb078cc5709c2d825bbc35b16ea5f6b28ae7377347382d7e9afaf7bdbf0575d2c229d970784de
1 parent e7f515c commit b6bd77a

File tree

4 files changed

+89
-48
lines changed

4 files changed

+89
-48
lines changed

doc/release-notes-27757.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Wallet
2+
------
3+
4+
- The `deprecatedrpc=walletwarningfield` configuration option has been removed.
5+
The `createwallet`, `loadwallet`, `restorewallet` and `unloadwallet` RPCs no
6+
longer return the "warning" string field. The same information is provided
7+
through the "warnings" field added in v25.0, which returns a JSON array of
8+
strings. The "warning" string field was deprecated also in v25.0. (#27757)

src/wallet/rpc/backup.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,15 +2059,15 @@ RPCHelpMan listdescriptors()
20592059
RPCHelpMan backupwallet()
20602060
{
20612061
return RPCHelpMan{"backupwallet",
2062-
"\nSafely copies current wallet file to destination, which can be a directory or a path with filename.\n",
2063-
{
2064-
{"destination", RPCArg::Type::STR, RPCArg::Optional::NO, "The destination directory or file"},
2065-
},
2066-
RPCResult{RPCResult::Type::NONE, "", ""},
2067-
RPCExamples{
2068-
HelpExampleCli("backupwallet", "\"backup.dat\"")
2069-
+ HelpExampleRpc("backupwallet", "\"backup.dat\"")
2070-
},
2062+
"\nSafely copies the current wallet file to the specified destination, which can either be a directory or a path with a filename.\n",
2063+
{
2064+
{"destination", RPCArg::Type::STR, RPCArg::Optional::NO, "The destination directory or file"},
2065+
},
2066+
RPCResult{RPCResult::Type::NONE, "", ""},
2067+
RPCExamples{
2068+
HelpExampleCli("backupwallet", "\"backup.dat\"")
2069+
+ HelpExampleRpc("backupwallet", "\"backup.dat\"")
2070+
},
20712071
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
20722072
{
20732073
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
@@ -2093,7 +2093,9 @@ RPCHelpMan restorewallet()
20932093
{
20942094
return RPCHelpMan{
20952095
"restorewallet",
2096-
"\nRestore and loads a wallet from backup.\n",
2096+
"\nRestores and loads a wallet from backup.\n"
2097+
"\nThe rescan is significantly faster if a descriptor wallet is restored"
2098+
"\nand block filters are available (using startup option \"-blockfilterindex=1\").\n",
20972099
{
20982100
{"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, "The name that will be applied to the restored wallet"},
20992101
{"backup_file", RPCArg::Type::STR, RPCArg::Optional::NO, "The backup file that will be used to restore the wallet."},
@@ -2103,7 +2105,10 @@ RPCHelpMan restorewallet()
21032105
RPCResult::Type::OBJ, "", "",
21042106
{
21052107
{RPCResult::Type::STR, "name", "The wallet name if restored successfully."},
2106-
{RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."},
2108+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to restoring and loading the wallet.",
2109+
{
2110+
{RPCResult::Type::STR, "", ""},
2111+
}},
21072112
}
21082113
},
21092114
RPCExamples{
@@ -2133,7 +2138,7 @@ RPCHelpMan restorewallet()
21332138

21342139
UniValue obj(UniValue::VOBJ);
21352140
obj.pushKV("name", wallet->GetName());
2136-
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
2141+
PushWarnings(warnings, obj);
21372142

21382143
return obj;
21392144

src/wallet/rpc/wallet.cpp

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -444,24 +444,28 @@ static RPCHelpMan upgradetohd()
444444
static RPCHelpMan loadwallet()
445445
{
446446
return RPCHelpMan{"loadwallet",
447-
"\nLoads a wallet from a wallet file or directory."
448-
"\nNote that all wallet command-line options used when starting dashd will be"
449-
"\napplied to the new wallet (eg, rescan, etc).\n",
450-
{
451-
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet directory or .dat file."},
452-
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
453-
},
454-
RPCResult{
455-
RPCResult::Type::OBJ, "", "",
456-
{
457-
{RPCResult::Type::STR, "name", "The wallet name if loaded successfully."},
458-
{RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."},
459-
}
460-
},
461-
RPCExamples{
462-
HelpExampleCli("loadwallet", "\"test.dat\"")
463-
+ HelpExampleRpc("loadwallet", "\"test.dat\"")
464-
},
447+
"\nLoads a wallet from a wallet file or directory."
448+
"\nNote that all wallet command-line options used when starting dashd will be"
449+
"\napplied to the new wallet.\n",
450+
{
451+
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet directory or .dat file."},
452+
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
453+
},
454+
RPCResult{
455+
RPCResult::Type::OBJ, "", "",
456+
{
457+
{RPCResult::Type::STR, "name", "The wallet name if loaded successfully."},
458+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
459+
{
460+
{RPCResult::Type::STR, "", ""},
461+
}},
462+
}
463+
},
464+
RPCExamples{
465+
HelpExampleCli("loadwallet", "\"test.dat\"")
466+
+ HelpExampleRpc("loadwallet", "\"test.dat\"")
467+
},
468+
>>>>>>> f0758d8a66 (Merge bitcoin/bitcoin#27757: rpc: remove deprecated "warning" field from {create,load,restore,unload}wallet)
465469
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
466470
{
467471
WalletContext& context = EnsureWalletContext(request.context);
@@ -480,7 +484,7 @@ static RPCHelpMan loadwallet()
480484

481485
UniValue obj(UniValue::VOBJ);
482486
obj.pushKV("name", wallet->GetName());
483-
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
487+
PushWarnings(warnings, obj);
484488

485489
return obj;
486490
},
@@ -573,7 +577,10 @@ static RPCHelpMan createwallet()
573577
RPCResult::Type::OBJ, "", "",
574578
{
575579
{RPCResult::Type::STR, "name", "The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path."},
576-
{RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."},
580+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to creating and loading the wallet.",
581+
{
582+
{RPCResult::Type::STR, "", ""},
583+
}},
577584
}
578585
},
579586
RPCExamples{
@@ -640,7 +647,7 @@ static RPCHelpMan createwallet()
640647

641648
UniValue obj(UniValue::VOBJ);
642649
obj.pushKV("name", wallet->GetName());
643-
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
650+
PushWarnings(warnings, obj);
644651

645652
return obj;
646653
},
@@ -650,19 +657,22 @@ static RPCHelpMan createwallet()
650657
static RPCHelpMan unloadwallet()
651658
{
652659
return RPCHelpMan{"unloadwallet",
653-
"Unloads the wallet referenced by the request endpoint otherwise unloads the wallet specified in the argument.\n"
654-
"Specifying the wallet name on a wallet endpoint is invalid.",
655-
{
656-
{"wallet_name", RPCArg::Type::STR, RPCArg::DefaultHint{"the wallet name from the RPC endpoint"}, "The name of the wallet to unload. If provided both here and in the RPC endpoint, the two must be identical."},
657-
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
658-
},
659-
RPCResult{RPCResult::Type::OBJ, "", "", {
660-
{RPCResult::Type::STR, "warning", "Warning message if wallet was not unloaded cleanly."},
661-
}},
662-
RPCExamples{
663-
HelpExampleCli("unloadwallet", "wallet_name")
664-
+ HelpExampleRpc("unloadwallet", "wallet_name")
665-
},
660+
"Unloads the wallet referenced by the request endpoint, otherwise unloads the wallet specified in the argument.\n"
661+
"Specifying the wallet name on a wallet endpoint is invalid.",
662+
{
663+
{"wallet_name", RPCArg::Type::STR, RPCArg::DefaultHint{"the wallet name from the RPC endpoint"}, "The name of the wallet to unload. If provided both here and in the RPC endpoint, the two must be identical."},
664+
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
665+
},
666+
RPCResult{RPCResult::Type::OBJ, "", "", {
667+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to unloading the wallet.",
668+
{
669+
{RPCResult::Type::STR, "", ""},
670+
}},
671+
}},
672+
RPCExamples{
673+
HelpExampleCli("unloadwallet", "wallet_name")
674+
+ HelpExampleRpc("unloadwallet", "wallet_name")
675+
},
666676
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
667677
{
668678
std::string wallet_name;
@@ -699,7 +709,8 @@ static RPCHelpMan unloadwallet()
699709
UnloadWallet(std::move(wallet));
700710

701711
UniValue result(UniValue::VOBJ);
702-
result.pushKV("warning", Join(warnings, Untranslated("\n")).original);
712+
PushWarnings(warnings, result);
713+
703714
return result;
704715
},
705716
};

test/functional/wallet_createwallet.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
)
1616
from test_framework.wallet_util import bytes_to_wif, generate_wif_key
1717

18+
EMPTY_PASSPHRASE_MSG = "Empty string given as passphrase, wallet will not be encrypted."
19+
LEGACY_WALLET_MSG = "Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future."
20+
1821
class CreateWalletTest(BitcoinTestFramework):
1922
def set_test_params(self):
2023
self.num_nodes = 1
@@ -157,7 +160,7 @@ def run_test(self):
157160
assert_equal(walletinfo['keypoolsize_hd_internal'], keys)
158161
# Allow empty passphrase, but there should be a warning
159162
resp = self.nodes[0].createwallet(wallet_name='w7', disable_private_keys=False, blank=False, passphrase='')
160-
assert 'Empty string given as passphrase, wallet will not be encrypted.' in resp['warning']
163+
assert_equal(resp["warnings"], [EMPTY_PASSPHRASE_MSG] if self.options.descriptors else [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG])
161164
w7 = node.get_wallet_rpc('w7')
162165
assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
163166

@@ -170,5 +173,19 @@ def run_test(self):
170173
self.log.info('Using a passphrase with private keys disabled returns error')
171174
assert_raises_rpc_error(-4, 'Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.', self.nodes[0].createwallet, wallet_name='w9', disable_private_keys=True, passphrase='thisisapassphrase')
172175

176+
if self.is_bdb_compiled():
177+
self.log.info("Test legacy wallet deprecation")
178+
result = self.nodes[0].createwallet(wallet_name="legacy_w0", descriptors=False, passphrase=None)
179+
assert_equal(result, {
180+
"name": "legacy_w0",
181+
"warnings": [LEGACY_WALLET_MSG],
182+
})
183+
result = self.nodes[0].createwallet(wallet_name="legacy_w1", descriptors=False, passphrase="")
184+
assert_equal(result, {
185+
"name": "legacy_w1",
186+
"warnings": [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG],
187+
})
188+
189+
173190
if __name__ == '__main__':
174191
CreateWalletTest().main()

0 commit comments

Comments
 (0)