mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-22 20:58:09 +02:00
Merge bitcoin/bitcoin#34049: rpc: Disallow captures in RPCMethodImpl
5a81d73a81scripted-diff: rpc: Don't pointlessly capture in RPCMethod lambdas (Anthony Towns)4e789299afscripted-diff: rpc: Rename RPCHelpMan to RPCMethod (Anthony Towns) Pull request description: When defining `RPCHelpMan` objects, we usually return a lambda, and mostly we define those via `[&](...) { ... }` which explicitly captures any parameters or local variables by reference. If we were to actually use any of those captures (we don't), we would invoke undefined behaviour. So instead, convert all the `[&]` to `[]` to avoid capturing. While we're at it, rename `RPCHelpMan` to `RPCMethod`, reflecting its greater responsibility since #19386. ACKs for top commit: maflcko: review ACK5a81d73a81🏣 stickies-v: ACK5a81d73a81rkrux: code review ACK5a81d73a81Tree-SHA512: 72e9232857ba5bf4c346fb963a2028047f7c7e9b420ef58b3108669204bfbb6952342cfcfd2e8a06f813a21545abf7fc8b0ad422f00d7ec9c1134626cd1650e6
This commit is contained in:
@@ -36,9 +36,9 @@
|
||||
using interfaces::FoundBlock;
|
||||
|
||||
namespace wallet {
|
||||
RPCHelpMan importprunedfunds()
|
||||
RPCMethod importprunedfunds()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"importprunedfunds",
|
||||
"Imports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n",
|
||||
{
|
||||
@@ -47,7 +47,7 @@ RPCHelpMan importprunedfunds()
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{""},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
||||
if (!pwallet) return UniValue::VNULL;
|
||||
@@ -91,9 +91,9 @@ RPCHelpMan importprunedfunds()
|
||||
};
|
||||
}
|
||||
|
||||
RPCHelpMan removeprunedfunds()
|
||||
RPCMethod removeprunedfunds()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"removeprunedfunds",
|
||||
"Deletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
|
||||
{
|
||||
@@ -105,7 +105,7 @@ RPCHelpMan removeprunedfunds()
|
||||
"\nAs a JSON-RPC call\n"
|
||||
+ HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
||||
if (!pwallet) return UniValue::VNULL;
|
||||
@@ -299,9 +299,9 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
|
||||
return result;
|
||||
}
|
||||
|
||||
RPCHelpMan importdescriptors()
|
||||
RPCMethod importdescriptors()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"importdescriptors",
|
||||
"Import descriptors. This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported. Requires a new wallet backup.\n"
|
||||
"When importing descriptors with multipath key expressions, if the multipath specifier contains exactly two elements, the descriptor produced from the second element will be imported as an internal descriptor.\n"
|
||||
@@ -354,7 +354,7 @@ RPCHelpMan importdescriptors()
|
||||
"{ \"desc\": \"<my descriptor 2>\", \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
|
||||
HelpExampleCli("importdescriptors", "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, \"active\": true, \"range\": [0,100], \"label\": \"<my bech32 wallet>\" }]'")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& main_request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& main_request) -> UniValue
|
||||
{
|
||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(main_request);
|
||||
if (!pwallet) return UniValue::VNULL;
|
||||
@@ -462,9 +462,9 @@ RPCHelpMan importdescriptors()
|
||||
};
|
||||
}
|
||||
|
||||
RPCHelpMan listdescriptors()
|
||||
RPCMethod listdescriptors()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"listdescriptors",
|
||||
"List all descriptors present in a wallet.\n",
|
||||
{
|
||||
@@ -492,7 +492,7 @@ RPCHelpMan listdescriptors()
|
||||
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
|
||||
+ HelpExampleCli("listdescriptors", "true") + HelpExampleRpc("listdescriptors", "true")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
|
||||
if (!wallet) return UniValue::VNULL;
|
||||
@@ -572,9 +572,9 @@ RPCHelpMan listdescriptors()
|
||||
};
|
||||
}
|
||||
|
||||
RPCHelpMan backupwallet()
|
||||
RPCMethod backupwallet()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"backupwallet",
|
||||
"Safely copies the current wallet file to the specified destination, which can either be a directory or a path with a filename.\n",
|
||||
{
|
||||
@@ -585,7 +585,7 @@ RPCHelpMan backupwallet()
|
||||
HelpExampleCli("backupwallet", "\"backup.dat\"")
|
||||
+ HelpExampleRpc("backupwallet", "\"backup.dat\"")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
|
||||
if (!pwallet) return UniValue::VNULL;
|
||||
@@ -607,9 +607,9 @@ RPCHelpMan backupwallet()
|
||||
}
|
||||
|
||||
|
||||
RPCHelpMan restorewallet()
|
||||
RPCMethod restorewallet()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
return RPCMethod{
|
||||
"restorewallet",
|
||||
"Restores and loads a wallet from backup.\n"
|
||||
"\nThe rescan is significantly faster if block filters are available"
|
||||
@@ -635,7 +635,7 @@ RPCHelpMan restorewallet()
|
||||
+ HelpExampleCliNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
|
||||
+ HelpExampleRpcNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
|
||||
WalletContext& context = EnsureWalletContext(request.context);
|
||||
|
||||
Reference in New Issue
Block a user