Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115625
D9455.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
43 KB
Subscribers
None
D9455.diff
View Options
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -98,12 +98,6 @@
}
UniValue importprivkey(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importprivkey",
"Adds a private key (as returned by dumpprivkey) to your wallet. "
@@ -139,6 +133,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
throw JSONRPCError(RPC_WALLET_ERROR,
"Cannot import private keys to a wallet with "
@@ -216,12 +216,6 @@
}
UniValue abortrescan(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"abortrescan",
"Stops current wallet rescan triggered by an RPC call, e.g. by an "
@@ -239,6 +233,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) {
return false;
}
@@ -247,12 +247,6 @@
}
UniValue importaddress(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importaddress",
"Adds an address or script (in hex) that can be watched as if it "
@@ -292,6 +286,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
EnsureLegacyScriptPubKeyMan(*pwallet, true);
std::string strLabel;
@@ -377,12 +377,6 @@
UniValue importprunedfunds(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importprunedfunds",
"Imports funds without rescan. Corresponding address or script must "
@@ -402,6 +396,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
CMutableTransaction tx;
if (!DecodeHexTx(tx, request.params[0].get_str())) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
@@ -456,12 +456,6 @@
UniValue removeprunedfunds(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"removeprunedfunds",
"Deletes the specified transaction from the wallet. Meant for use "
@@ -482,6 +476,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
TxId txid(ParseHashV(request.params[0], "txid"));
@@ -503,12 +503,6 @@
}
UniValue importpubkey(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importpubkey",
"Adds a public key (in hex) that can be watched as if it were in "
@@ -540,6 +534,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
EnsureLegacyScriptPubKeyMan(*wallet, true);
std::string strLabel;
@@ -609,12 +609,6 @@
}
UniValue importwallet(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importwallet",
"Imports keys from a wallet dump file (see dumpwallet). Requires a "
@@ -634,6 +628,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
EnsureLegacyScriptPubKeyMan(*wallet, true);
if (pwallet->chain().havePruned()) {
@@ -812,12 +812,6 @@
}
UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"dumpprivkey",
"Reveals the private key corresponding to 'address'.\n"
@@ -833,6 +827,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
@@ -859,12 +859,6 @@
}
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const pwallet =
- GetWalletForJSONRPCRequest(request);
- if (!pwallet) {
- return NullUniValue;
- }
-
RPCHelpMan{
"dumpwallet",
"Dumps all wallet keys in a human-readable format to a server-side "
@@ -891,6 +885,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const pwallet =
+ GetWalletForJSONRPCRequest(request);
+ if (!pwallet) {
+ return NullUniValue;
+ }
+
CWallet &wallet = *pwallet;
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(wallet);
@@ -1020,12 +1020,6 @@
}
static UniValue dumpcoins(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const pwallet =
- GetWalletForJSONRPCRequest(request);
- if (!pwallet) {
- return NullUniValue;
- }
-
RPCHelpMan{
"dumpcoins",
"dump all the UTXO tracked by the wallet.\n",
@@ -1058,6 +1052,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const pwallet =
+ GetWalletForJSONRPCRequest(request);
+ if (!pwallet) {
+ return NullUniValue;
+ }
+
CWallet &wallet = *pwallet;
// Make sure the results are valid at least up to the most recent block
@@ -1590,13 +1590,6 @@
}
UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) {
- std::shared_ptr<CWallet> const wallet =
- GetWalletForJSONRPCRequest(mainRequest);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importmulti",
"\nImport addresses/scripts (with private or public keys, redeem "
@@ -1774,6 +1767,13 @@
}
.Check(mainRequest);
+ std::shared_ptr<CWallet> const wallet =
+ GetWalletForJSONRPCRequest(mainRequest);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
EnsureLegacyScriptPubKeyMan(*wallet, true);
@@ -2077,14 +2077,6 @@
UniValue importdescriptors(const Config &config,
const JSONRPCRequest &main_request) {
- // Acquire the wallet
- std::shared_ptr<CWallet> const wallet =
- GetWalletForJSONRPCRequest(main_request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"importdescriptors",
"\nImport descriptors. This will trigger a rescan of the blockchain "
@@ -2195,6 +2187,13 @@
}
.Check(main_request);
+ std::shared_ptr<CWallet> const wallet =
+ GetWalletForJSONRPCRequest(main_request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure wallet is a descriptor wallet
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
throw JSONRPCError(
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -205,12 +205,6 @@
static UniValue getnewaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getnewaddress",
"Returns a new Bitcoin address for receiving payments.\n"
@@ -234,6 +228,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
if (!pwallet->CanGetAddresses()) {
@@ -267,12 +267,6 @@
static UniValue getrawchangeaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getrawchangeaddress",
"Returns a new Bitcoin address, for receiving change.\n"
@@ -284,6 +278,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
if (!pwallet->CanGetAddresses(true)) {
@@ -312,12 +312,6 @@
}
static UniValue setlabel(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"setlabel",
"Sets the label associated with the given address.\n",
@@ -337,6 +331,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
CTxDestination dest = DecodeDestination(request.params[0].get_str(),
@@ -402,12 +402,6 @@
static UniValue sendtoaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"sendtoaddress",
"Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE,
@@ -454,6 +448,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -502,12 +502,6 @@
static UniValue listaddressgroupings(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listaddressgroupings",
"Lists groups of addresses which have had their common ownership\n"
@@ -540,6 +534,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -571,12 +571,6 @@
static UniValue signmessage(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"signmessage",
"Sign a message with the private key of an address" +
@@ -606,6 +600,11 @@
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")},
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
LOCK(pwallet->cs_wallet);
@@ -693,12 +692,6 @@
static UniValue getreceivedbyaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getreceivedbyaddress",
"Returns the total amount received by the given address in "
@@ -729,6 +722,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -741,12 +740,6 @@
static UniValue getreceivedbylabel(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getreceivedbylabel",
"Returns the total amount received by addresses with <label> in "
@@ -773,6 +766,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -785,12 +784,6 @@
static UniValue getbalance(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getbalance",
"Returns the total available balance.\n"
@@ -826,6 +819,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -857,12 +856,6 @@
static UniValue getunconfirmedbalance(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getunconfirmedbalance",
"DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n",
@@ -872,6 +865,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -882,12 +881,6 @@
}
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"sendmany",
"Send multiple times. Amounts are double-precision "
@@ -974,6 +967,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -1056,12 +1055,6 @@
static UniValue addmultisigaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"addmultisigaddress",
"Add an nrequired-to-sign multisignature address to the wallet. "
@@ -1113,6 +1106,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*pwallet);
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
@@ -1324,12 +1323,6 @@
static UniValue listreceivedbyaddress(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listreceivedbyaddress",
"List balances by receiving address.\n",
@@ -1388,6 +1381,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -1399,12 +1398,6 @@
static UniValue listreceivedbylabel(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listreceivedbylabel",
"List received transactions by label.\n",
@@ -1446,6 +1439,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -1591,12 +1590,6 @@
}
UniValue listtransactions(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listtransactions",
"If a label name is provided, this will return only incoming "
@@ -1673,6 +1666,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -1744,13 +1743,6 @@
static UniValue listsinceblock(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const pwallet =
- GetWalletForJSONRPCRequest(request);
-
- if (!pwallet) {
- return NullUniValue;
- }
-
RPCHelpMan{
"listsinceblock",
"Get all transactions in blocks since block [blockhash], or all "
@@ -1867,6 +1859,13 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const pwallet =
+ GetWalletForJSONRPCRequest(request);
+
+ if (!pwallet) {
+ return NullUniValue;
+ }
+
const CWallet &wallet = *pwallet;
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
@@ -1966,12 +1965,6 @@
static UniValue gettransaction(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"gettransaction",
"Get detailed information about in-wallet transaction <txid>\n",
@@ -2071,6 +2064,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -2128,12 +2127,6 @@
static UniValue abandontransaction(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"abandontransaction",
"Mark in-wallet transaction <txid> as abandoned\n"
@@ -2158,6 +2151,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -2181,12 +2180,6 @@
static UniValue backupwallet(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"backupwallet",
"Safely copies current wallet file to destination, which can be a "
@@ -2201,6 +2194,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -2217,12 +2216,6 @@
static UniValue keypoolrefill(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"keypoolrefill",
"Fills the keypool." + HELP_REQUIRING_PASSPHRASE,
@@ -2236,6 +2229,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
if (pwallet->IsLegacy() &&
pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
throw JSONRPCError(RPC_WALLET_ERROR,
@@ -2267,12 +2266,6 @@
static UniValue walletpassphrase(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"walletpassphrase",
"Stores the wallet decryption key in memory for 'timeout' seconds.\n"
@@ -2299,6 +2292,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
int64_t nSleepTime;
int64_t relock_time;
// Prevent concurrent calls to walletpassphrase with the same wallet.
@@ -2382,12 +2381,6 @@
static UniValue walletpassphrasechange(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"walletpassphrasechange",
"Changes the wallet passphrase from 'oldpassphrase' to "
@@ -2406,6 +2399,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
if (!pwallet->IsCrypted()) {
@@ -2442,12 +2441,6 @@
static UniValue walletlock(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"walletlock",
"Removes the wallet encryption key from memory, locking the wallet.\n"
@@ -2470,6 +2463,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
if (!pwallet->IsCrypted()) {
@@ -2486,12 +2485,6 @@
static UniValue encryptwallet(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"encryptwallet",
"Encrypts the wallet with 'passphrase'. This is for first time "
@@ -2523,6 +2516,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
@@ -2562,12 +2561,6 @@
static UniValue lockunspent(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"lockunspent",
"Updates list of temporarily unspendable outputs.\n"
@@ -2636,6 +2629,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -2723,12 +2722,6 @@
static UniValue listlockunspent(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listlockunspent",
"Returns list of temporarily unspendable outputs.\n"
@@ -2769,6 +2762,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
std::vector<COutPoint> vOutpts;
@@ -2788,12 +2787,6 @@
}
static UniValue settxfee(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"settxfee",
"Set the transaction fee per kB for this wallet. Overrides the "
@@ -2810,6 +2803,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
Amount nAmount = AmountFromValue(request.params[0]);
@@ -2840,13 +2839,6 @@
static UniValue getbalances(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const rpc_wallet =
- GetWalletForJSONRPCRequest(request);
- if (!rpc_wallet) {
- return NullUniValue;
- }
- CWallet &wallet = *rpc_wallet;
-
RPCHelpMan{
"getbalances",
"Returns an object with all balances in " + CURRENCY_UNIT + ".\n",
@@ -2892,6 +2884,13 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const rpc_wallet =
+ GetWalletForJSONRPCRequest(request);
+ if (!rpc_wallet) {
+ return NullUniValue;
+ }
+ CWallet &wallet = *rpc_wallet;
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
wallet.BlockUntilSyncedToCurrentChain();
@@ -2936,12 +2935,6 @@
static UniValue getwalletinfo(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getwalletinfo",
"Returns an object containing various wallet state info.\n",
@@ -3008,6 +3001,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
@@ -3194,12 +3193,6 @@
static UniValue setwalletflag(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
std::string flags = "";
for (auto &it : WALLET_FLAG_MAP) {
if (it.second & MUTABLE_WALLET_FLAGS) {
@@ -3232,6 +3225,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
std::string flag_str = request.params[0].get_str();
bool value = request.params[1].isNull() || request.params[1].get_bool();
@@ -3413,12 +3412,6 @@
static UniValue listunspent(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listunspent",
"Returns array of unspent transaction outputs\n"
@@ -3522,6 +3515,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
int nMinDepth = 1;
if (!request.params[0].isNull()) {
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
@@ -3791,12 +3790,6 @@
static UniValue fundrawtransaction(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"fundrawtransaction",
"If the transaction has no inputs, they will be automatically selected "
@@ -3896,6 +3889,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()});
// parse hex string from parameter
@@ -3923,12 +3922,6 @@
UniValue signrawtransactionwithwallet(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"signrawtransactionwithwallet",
"Sign inputs for raw transaction (serialized, hex-encoded).\n"
@@ -4012,6 +4005,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(request.params,
{UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true);
@@ -4052,12 +4051,6 @@
}
UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"rescanblockchain",
"Rescan the local blockchain for wallet related transactions.\n"
@@ -4087,6 +4080,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
WalletRescanReserver reserver(*pwallet);
if (!reserver.reserve()) {
throw JSONRPCError(
@@ -4254,12 +4253,6 @@
}
UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getaddressinfo",
"\nReturn information about the given bitcoin address.\n"
@@ -4368,6 +4361,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
UniValue ret(UniValue::VOBJ);
@@ -4449,12 +4448,6 @@
UniValue getaddressesbylabel(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"getaddressesbylabel",
"Returns the list of addresses assigned the specified label.\n",
@@ -4479,6 +4472,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
std::string label = LabelFromValue(request.params[0]);
@@ -4515,12 +4514,6 @@
}
UniValue listlabels(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"listlabels",
"Returns the list of all labels, or labels that are assigned to "
@@ -4546,6 +4539,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
LOCK(pwallet->cs_wallet);
std::string purpose;
@@ -4574,12 +4573,6 @@
}
static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"sethdseed",
"Set or generate a new HD wallet seed. Non-HD wallets will not be "
@@ -4615,6 +4608,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
LegacyScriptPubKeyMan &spk_man =
EnsureLegacyScriptPubKeyMan(*pwallet, true);
@@ -4670,12 +4669,6 @@
static UniValue walletprocesspsbt(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- const CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"walletprocesspsbt",
"Update a PSBT with input information from our wallet and then sign "
@@ -4712,6 +4705,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ const CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(request.params,
{UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR});
@@ -4753,12 +4752,6 @@
static UniValue walletcreatefundedpsbt(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{
"walletcreatefundedpsbt",
"Creates and funds a transaction in the Partially Signed Transaction "
@@ -4899,6 +4892,12 @@
}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(request.params,
{UniValue::VARR,
UniValueType(), // ARR or OBJ, checked later
@@ -4943,12 +4942,6 @@
static UniValue upgradewallet(const Config &config,
const JSONRPCRequest &request) {
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) {
- return NullUniValue;
- }
- CWallet *const pwallet = wallet.get();
-
RPCHelpMan{"upgradewallet",
"\nUpgrade the wallet. Upgrades to the latest version if no "
"version number is specified\n"
@@ -4963,6 +4956,12 @@
HelpExampleRpc("upgradewallet", "200300")}}
.Check(request);
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
+ if (!wallet) {
+ return NullUniValue;
+ }
+ CWallet *const pwallet = wallet.get();
+
RPCTypeCheck(request.params, {UniValue::VNUM}, true);
EnsureWalletIsUnlocked(pwallet);
diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py
--- a/test/functional/rpc_help.py
+++ b/test/functional/rpc_help.py
@@ -18,6 +18,8 @@
def run_test(self):
self.test_categories()
self.dump_help()
+ if self.is_wallet_compiled():
+ self.wallet_help()
def test_categories(self):
node = self.nodes[0]
@@ -57,6 +59,13 @@
# crashing
f.write(self.nodes[0].help(call))
+ def wallet_help(self):
+ assert ('getnewaddress ( "label" "address_type" )' in
+ self.nodes[0].help('getnewaddress'))
+ self.restart_node(0, extra_args=['-nowallet=1'])
+ assert ('getnewaddress ( "label" "address_type" )' in
+ self.nodes[0].help('getnewaddress'))
+
if __name__ == '__main__':
HelpRpcTest().main()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:34 (2 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187637
Default Alt Text
D9455.diff (43 KB)
Attached To
D9455: wallet: Make RPC help compile-time static
Event Timeline
Log In to Comment