Branch data Line data Source code
1 : : // Copyright (c) 2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-present The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : #include <bitcoin-build-config.h> // IWYU pragma: keep
7 : :
8 : : #include <wallet/rpc/wallet.h>
9 : :
10 : : #include <coins.h>
11 : : #include <core_io.h>
12 : : #include <key.h>
13 : : #include <key_io.h>
14 : : #include <rpc/server.h>
15 : : #include <rpc/util.h>
16 : : #include <univalue.h>
17 : : #include <util/bip32.h>
18 : : #include <util/translation.h>
19 : : #include <wallet/context.h>
20 : : #include <wallet/export.h>
21 : : #include <wallet/receive.h>
22 : : #include <wallet/rpc/util.h>
23 : : #include <wallet/wallet.h>
24 : : #include <wallet/walletutil.h>
25 : :
26 : : #include <algorithm>
27 : : #include <optional>
28 : : #include <string_view>
29 : :
30 : :
31 : : namespace wallet {
32 : :
33 : : using HDPubKeyMap = CWallet::HDPubKeyMap;
34 : : using HDKeyFilter = CWallet::HDKeyFilter;
35 : :
36 : : static const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS{
37 : : {WALLET_FLAG_AVOID_REUSE,
38 : : "You need to rescan the blockchain in order to correctly mark used "
39 : : "destinations in the past. Until this is done, some destinations may "
40 : : "be considered unused, even if the opposite is the case."},
41 : : };
42 : :
43 : 14 : static RPCMethod getwalletinfo()
44 : : {
45 : 14 : return RPCMethod{"getwalletinfo",
46 [ + - ]: 28 : "Returns an object containing various wallet state info.\n",
47 : : {},
48 [ + - ]: 28 : RPCResult{
49 [ + - ]: 28 : RPCResult::Type::OBJ, "", "",
50 : : {
51 : : {
52 [ + - + - ]: 28 : {RPCResult::Type::STR, "walletname", "the wallet name"},
53 [ + - + - ]: 28 : {RPCResult::Type::NUM, "walletversion", "(DEPRECATED) only related to unsupported legacy wallet, returns the latest version 169900 for backwards compatibility"},
54 [ + - + - ]: 28 : {RPCResult::Type::STR, "format", "the database format (only sqlite)"},
55 [ + - + - ]: 28 : {RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"},
56 [ + - + - ]: 28 : {RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"},
57 [ + - + - ]: 28 : {RPCResult::Type::NUM, "keypoolsize_hd_internal", /*optional=*/true, "how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)"},
58 [ + - + - ]: 28 : {RPCResult::Type::NUM_TIME, "unlocked_until", /*optional=*/true, "the " + UNIX_EPOCH_TIME + " until which the wallet is unlocked for transfers, or 0 if the wallet is locked (only present for passphrase-encrypted wallets)"},
59 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "private_keys_enabled", "false if privatekeys are disabled for this wallet (enforced watch-only wallet)"},
60 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "avoid_reuse", "whether this wallet tracks clean/dirty coins in terms of reuse"},
61 [ + - + - ]: 28 : {RPCResult::Type::OBJ, "scanning", "current scanning details, or false if no scan is in progress",
62 : : {
63 [ + - + - ]: 28 : {RPCResult::Type::NUM, "duration", "elapsed seconds since scan start"},
64 [ + - + - ]: 28 : {RPCResult::Type::NUM, "progress", "scanning progress percentage [0.0, 1.0]"},
65 : : }, {.skip_type_check=true}, },
66 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "descriptors", "whether this wallet uses descriptors for output script management"},
67 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "external_signer", "whether this wallet is configured to use an external signer such as a hardware wallet"},
68 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "blank", "Whether this wallet intentionally does not contain any keys, scripts, or descriptors"},
69 [ + - + - ]: 28 : {RPCResult::Type::NUM_TIME, "birthtime", /*optional=*/true, "The start time for blocks scanning. It could be modified by (re)importing any descriptor with an earlier timestamp."},
70 [ + - + - ]: 28 : {RPCResult::Type::ARR, "flags", "The flags currently set on the wallet",
71 : : {
72 [ + - + - ]: 28 : {RPCResult::Type::STR, "flag", "The name of the flag"},
73 : : }},
74 : : RESULT_LAST_PROCESSED_BLOCK,
75 : : }},
76 [ + - + - : 574 : },
+ - + - +
+ + + + +
- - - - -
- ]
77 : 14 : RPCExamples{
78 [ + - + - : 28 : HelpExampleCli("getwalletinfo", "")
+ - ]
79 [ + - + - : 56 : + HelpExampleRpc("getwalletinfo", "")
+ - + - ]
80 [ + - ]: 14 : },
81 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
82 : : {
83 [ # # ]: 0 : const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
84 [ # # ]: 0 : if (!pwallet) return UniValue::VNULL;
85 : :
86 : : // Make sure the results are valid at least up to the most recent block
87 : : // the user could have gotten from another RPC command prior to now
88 [ # # ]: 0 : pwallet->BlockUntilSyncedToCurrentChain();
89 : :
90 [ # # ]: 0 : LOCK(pwallet->cs_wallet);
91 : :
92 : 0 : UniValue obj(UniValue::VOBJ);
93 : :
94 : 0 : const int latest_legacy_wallet_minversion{169900};
95 : :
96 [ # # ]: 0 : size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
97 [ # # # # : 0 : obj.pushKV("walletname", pwallet->GetName());
# # ]
98 [ # # # # : 0 : obj.pushKV("walletversion", latest_legacy_wallet_minversion);
# # ]
99 [ # # # # : 0 : obj.pushKV("format", pwallet->GetDatabase().Format());
# # # # ]
100 [ # # # # : 0 : obj.pushKV("txcount", pwallet->mapWallet.size());
# # ]
101 [ # # # # : 0 : obj.pushKV("keypoolsize", kpExternalSize);
# # ]
102 [ # # # # : 0 : obj.pushKV("keypoolsize_hd_internal", pwallet->GetKeyPoolSize() - kpExternalSize);
# # # # ]
103 : :
104 [ # # # # ]: 0 : if (pwallet->HasEncryptionKeys()) {
105 [ # # # # : 0 : obj.pushKV("unlocked_until", pwallet->nRelockTime);
# # ]
106 : : }
107 [ # # # # : 0 : obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
# # # # ]
108 [ # # # # : 0 : obj.pushKV("avoid_reuse", pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE));
# # # # ]
109 [ # # ]: 0 : if (pwallet->IsScanning()) {
110 : 0 : UniValue scanning(UniValue::VOBJ);
111 [ # # # # : 0 : scanning.pushKV("duration", Ticks<std::chrono::seconds>(pwallet->ScanningDuration()));
# # ]
112 [ # # # # : 0 : scanning.pushKV("progress", pwallet->ScanningProgress());
# # ]
113 [ # # # # ]: 0 : obj.pushKV("scanning", std::move(scanning));
114 : 0 : } else {
115 [ # # # # : 0 : obj.pushKV("scanning", false);
# # ]
116 : : }
117 [ # # # # : 0 : obj.pushKV("descriptors", pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
# # # # ]
118 [ # # # # : 0 : obj.pushKV("external_signer", pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER));
# # # # ]
119 [ # # # # : 0 : obj.pushKV("blank", pwallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET));
# # # # ]
120 [ # # ]: 0 : if (int64_t birthtime = pwallet->GetBirthTime(); birthtime != UNKNOWN_TIME) {
121 [ # # # # : 0 : obj.pushKV("birthtime", birthtime);
# # ]
122 : : }
123 : :
124 : : // Push known flags
125 : 0 : UniValue flags(UniValue::VARR);
126 [ # # ]: 0 : uint64_t wallet_flags = pwallet->GetWalletFlags();
127 [ # # ]: 0 : for (uint64_t i = 0; i < 64; ++i) {
128 : 0 : uint64_t flag = uint64_t{1} << i;
129 [ # # ]: 0 : if (flag & wallet_flags) {
130 [ # # ]: 0 : if (flag & KNOWN_WALLET_FLAGS) {
131 [ # # # # : 0 : flags.push_back(WALLET_FLAG_TO_STRING.at(WalletFlags{flag}));
# # ]
132 : : } else {
133 [ # # # # : 0 : flags.push_back(strprintf("unknown_flag_%u", i));
# # ]
134 : : }
135 : : }
136 : : }
137 [ # # # # : 0 : obj.pushKV("flags", flags);
# # ]
138 : :
139 [ # # ]: 0 : AppendLastProcessedBlock(obj, *pwallet);
140 : 0 : return obj;
141 [ # # ]: 0 : },
142 [ + - + - ]: 56 : };
143 [ + - + - : 504 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
- - - ]
144 : :
145 : 14 : static RPCMethod listwalletdir()
146 : : {
147 : 14 : return RPCMethod{"listwalletdir",
148 [ + - ]: 28 : "Returns a list of wallets in the wallet directory.\n",
149 : : {},
150 [ + - ]: 28 : RPCResult{
151 [ + - ]: 28 : RPCResult::Type::OBJ, "", "",
152 : : {
153 [ + - + - ]: 28 : {RPCResult::Type::ARR, "wallets", "",
154 : : {
155 [ + - + - ]: 28 : {RPCResult::Type::OBJ, "", "",
156 : : {
157 [ + - + - ]: 28 : {RPCResult::Type::STR, "name", "The wallet name"},
158 [ + - + - ]: 28 : {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
159 : : {
160 [ + - + - ]: 28 : {RPCResult::Type::STR, "", ""},
161 : : }},
162 : : }},
163 : : }},
164 : : }
165 [ + - + - : 210 : },
+ - + - +
- + + + +
+ + + + -
- - - - -
- - ]
166 : 14 : RPCExamples{
167 [ + - + - : 28 : HelpExampleCli("listwalletdir", "")
+ - ]
168 [ + - + - : 56 : + HelpExampleRpc("listwalletdir", "")
+ - + - ]
169 [ + - ]: 14 : },
170 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
171 : : {
172 : 0 : UniValue wallets(UniValue::VARR);
173 [ # # # # : 0 : for (const auto& [path, db_type] : ListDatabases(GetWalletDir())) {
# # ]
174 : 0 : UniValue wallet(UniValue::VOBJ);
175 [ # # # # : 0 : wallet.pushKV("name", path.utf8string());
# # # # ]
176 : 0 : UniValue warnings(UniValue::VARR);
177 [ # # ]: 0 : if (db_type == "bdb") {
178 [ # # # # ]: 0 : warnings.push_back("This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded");
179 : : }
180 [ # # # # : 0 : wallet.pushKV("warnings", warnings);
# # ]
181 [ # # ]: 0 : wallets.push_back(std::move(wallet));
182 : 0 : }
183 : :
184 : 0 : UniValue result(UniValue::VOBJ);
185 [ # # # # ]: 0 : result.pushKV("wallets", std::move(wallets));
186 : 0 : return result;
187 : 0 : },
188 [ + - + - ]: 56 : };
189 [ + - + - : 140 : }
+ - + - +
- - - ]
190 : :
191 : 14 : static RPCMethod listwallets()
192 : : {
193 : 14 : return RPCMethod{"listwallets",
194 [ + - ]: 28 : "Returns a list of currently loaded wallets.\n"
195 : : "For full information on the wallet, use \"getwalletinfo\"\n",
196 : : {},
197 [ + - ]: 28 : RPCResult{
198 [ + - ]: 28 : RPCResult::Type::ARR, "", "",
199 : : {
200 [ + - + - ]: 28 : {RPCResult::Type::STR, "walletname", "the wallet name"},
201 : : }
202 [ + - + - : 56 : },
+ + - - ]
203 : 14 : RPCExamples{
204 [ + - + - : 28 : HelpExampleCli("listwallets", "")
+ - ]
205 [ + - + - : 56 : + HelpExampleRpc("listwallets", "")
+ - + - ]
206 [ + - ]: 14 : },
207 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
208 : : {
209 : 0 : UniValue obj(UniValue::VARR);
210 : :
211 [ # # ]: 0 : WalletContext& context = EnsureWalletContext(request.context);
212 [ # # # # ]: 0 : for (const std::shared_ptr<CWallet>& wallet : GetWallets(context)) {
213 [ # # ]: 0 : LOCK(wallet->cs_wallet);
214 [ # # # # : 0 : obj.push_back(wallet->GetName());
# # ]
215 : 0 : }
216 : :
217 : 0 : return obj;
218 : 0 : },
219 [ + - + - ]: 56 : };
220 [ + - ]: 28 : }
221 : :
222 : 14 : static RPCMethod loadwallet()
223 : : {
224 : 14 : return RPCMethod{
225 : 14 : "loadwallet",
226 [ + - ]: 28 : "Loads a wallet from a wallet file or directory."
227 : : "\nNote that all wallet command-line options used when starting bitcoind will be"
228 : : "\napplied to the new wallet.\n",
229 : : {
230 [ + - + - ]: 28 : {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The path to the directory of the wallet to be loaded, either absolute or relative to the \"wallets\" directory. The \"wallets\" directory is set by the -walletdir option and defaults to the \"wallets\" folder within the data directory."},
231 [ + - + - ]: 28 : {"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."},
232 : : },
233 [ + - ]: 28 : RPCResult{
234 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
235 : : {
236 [ + - + - ]: 28 : {RPCResult::Type::STR, "name", "The wallet name if loaded successfully."},
237 [ + - + - ]: 28 : {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
238 : : {
239 [ + - + - ]: 28 : {RPCResult::Type::STR, "", ""},
240 : : }},
241 : : }
242 [ + - + - : 126 : },
+ - + + +
+ - - -
- ]
243 : 14 : RPCExamples{
244 : : "\nLoad wallet from the wallet dir:\n"
245 [ + - + - : 28 : + HelpExampleCli("loadwallet", "\"walletname\"")
+ - + - ]
246 [ + - + - : 56 : + HelpExampleRpc("loadwallet", "\"walletname\"")
+ - + - ]
247 : 14 : + "\nLoad wallet using absolute path (Unix):\n"
248 [ + - + - : 56 : + HelpExampleCli("loadwallet", "\"/path/to/walletname/\"")
+ - + - ]
249 [ + - + - : 56 : + HelpExampleRpc("loadwallet", "\"/path/to/walletname/\"")
+ - + - ]
250 : 14 : + "\nLoad wallet using absolute path (Windows):\n"
251 [ + - + - : 56 : + HelpExampleCli("loadwallet", "\"DriveLetter:\\path\\to\\walletname\\\"")
+ - + - ]
252 [ + - + - : 56 : + HelpExampleRpc("loadwallet", "\"DriveLetter:\\path\\to\\walletname\\\"")
+ - + - ]
253 [ + - ]: 14 : },
254 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
255 : : {
256 : 0 : WalletContext& context = EnsureWalletContext(request.context);
257 [ # # ]: 0 : const std::string name(request.params[0].get_str());
258 : :
259 [ # # ]: 0 : DatabaseOptions options;
260 : 0 : DatabaseStatus status;
261 [ # # ]: 0 : ReadDatabaseArgs(*context.args, options);
262 : 0 : options.require_existing = true;
263 [ # # ]: 0 : bilingual_str error;
264 : 0 : std::vector<bilingual_str> warnings;
265 [ # # # # : 0 : std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
# # # # ]
266 : :
267 : 0 : {
268 [ # # ]: 0 : LOCK(context.wallets_mutex);
269 [ # # # # ]: 0 : if (std::any_of(context.wallets.begin(), context.wallets.end(), [&name](const auto& wallet) { return wallet->GetName() == name; })) {
270 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ALREADY_LOADED, "Wallet \"" + name + "\" is already loaded.");
271 : : }
272 : 0 : }
273 : :
274 [ # # ]: 0 : std::shared_ptr<CWallet> const wallet = LoadWallet(context, name, load_on_start, options, status, error, warnings);
275 : :
276 [ # # ]: 0 : HandleWalletError(wallet, status, error);
277 : :
278 : 0 : UniValue obj(UniValue::VOBJ);
279 [ # # # # : 0 : obj.pushKV("name", wallet->GetName());
# # ]
280 [ # # ]: 0 : PushWarnings(warnings, obj);
281 : :
282 [ # # ]: 0 : return obj;
283 : 0 : },
284 [ + - + - : 84 : };
+ + - - ]
285 [ + - + - : 140 : }
+ - + - +
- - - -
- ]
286 : :
287 : 14 : static RPCMethod setwalletflag()
288 : : {
289 : 14 : std::string flags;
290 [ + + ]: 112 : for (auto& it : STRING_TO_WALLET_FLAG)
291 [ + + ]: 98 : if (it.second & MUTABLE_WALLET_FLAGS)
292 [ - + + - ]: 28 : flags += (flags == "" ? "" : ", ") + it.first;
293 : :
294 : 14 : return RPCMethod{
295 [ + - ]: 28 : "setwalletflag",
296 [ + - ]: 28 : "Change the state of the given wallet flag for a wallet.\n",
297 : : {
298 [ + - + - ]: 28 : {"flag", RPCArg::Type::STR, RPCArg::Optional::NO, "The name of the flag to change. Current available flags: " + flags},
299 [ + - + - : 42 : {"value", RPCArg::Type::BOOL, RPCArg::Default{true}, "The new state."},
+ - ]
300 : : },
301 [ + - ]: 28 : RPCResult{
302 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
303 : : {
304 [ + - + - ]: 28 : {RPCResult::Type::STR, "flag_name", "The name of the flag that was modified"},
305 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "flag_state", "The new state of the flag"},
306 [ + - + - ]: 28 : {RPCResult::Type::STR, "warnings", /*optional=*/true, "Any warnings associated with the change"},
307 : : }
308 [ + - + - : 112 : },
+ + - - ]
309 : 14 : RPCExamples{
310 [ + - + - : 28 : HelpExampleCli("setwalletflag", "avoid_reuse")
+ - ]
311 [ + - + - : 56 : + HelpExampleRpc("setwalletflag", "\"avoid_reuse\"")
+ - + - ]
312 [ + - ]: 14 : },
313 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
314 : : {
315 : 0 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
316 [ # # ]: 0 : if (!pwallet) return UniValue::VNULL;
317 : :
318 [ # # # # : 0 : std::string flag_str = request.params[0].get_str();
# # ]
319 [ # # # # : 0 : bool value = request.params[1].isNull() || request.params[1].get_bool();
# # # # #
# ]
320 : :
321 [ # # ]: 0 : if (!STRING_TO_WALLET_FLAG.contains(flag_str)) {
322 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unknown wallet flag: %s", flag_str));
323 : : }
324 : :
325 [ # # ]: 0 : auto flag = STRING_TO_WALLET_FLAG.at(flag_str);
326 : :
327 [ # # ]: 0 : if (!(flag & MUTABLE_WALLET_FLAGS)) {
328 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is immutable: %s", flag_str));
329 : : }
330 : :
331 : 0 : UniValue res(UniValue::VOBJ);
332 : :
333 [ # # # # ]: 0 : if (pwallet->IsWalletFlagSet(flag) == value) {
334 [ # # # # : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is already set to %s: %s", value ? "true" : "false", flag_str));
# # ]
335 : : }
336 : :
337 [ # # # # : 0 : res.pushKV("flag_name", flag_str);
# # ]
338 [ # # # # : 0 : res.pushKV("flag_state", value);
# # ]
339 : :
340 [ # # ]: 0 : if (value) {
341 [ # # ]: 0 : pwallet->SetWalletFlag(flag);
342 : : } else {
343 [ # # ]: 0 : pwallet->UnsetWalletFlag(flag);
344 : : }
345 : :
346 [ # # # # : 0 : if (flag && value && WALLET_FLAG_CAVEATS.contains(flag)) {
# # ]
347 [ # # # # : 0 : res.pushKV("warnings", WALLET_FLAG_CAVEATS.at(flag));
# # # # ]
348 : : }
349 : :
350 : 0 : return res;
351 : 0 : },
352 [ + - + - : 70 : };
+ + - - ]
353 [ + - + - : 154 : }
+ - + - +
- - - -
- ]
354 : :
355 : 14 : static RPCMethod createwallet()
356 : : {
357 : 14 : return RPCMethod{
358 : 14 : "createwallet",
359 [ + - ]: 28 : "Creates and loads a new wallet.\n",
360 : : {
361 [ + - + - ]: 28 : {"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, "The name for the new wallet. If this is a path, the wallet will be created at the path location."},
362 [ + - + - : 42 : {"disable_private_keys", RPCArg::Type::BOOL, RPCArg::Default{false}, "Disable the possibility of private keys (only watchonlys are possible in this mode)."},
+ - ]
363 [ + - + - : 42 : {"blank", RPCArg::Type::BOOL, RPCArg::Default{false}, "Create a blank wallet. A blank wallet has no keys."},
+ - ]
364 [ + - + - ]: 28 : {"passphrase", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Encrypt the wallet with this passphrase."},
365 [ + - + - : 42 : {"avoid_reuse", RPCArg::Type::BOOL, RPCArg::Default{false}, "Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind."},
+ - ]
366 [ + - + - : 42 : {"descriptors", RPCArg::Type::BOOL, RPCArg::Default{true}, "If set, must be \"true\""},
+ - ]
367 [ + - + - ]: 28 : {"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."},
368 [ + - + - : 42 : {"external_signer", RPCArg::Type::BOOL, RPCArg::Default{false}, "Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true."},
+ - ]
369 : : },
370 [ + - ]: 28 : RPCResult{
371 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
372 : : {
373 [ + - + - ]: 28 : {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."},
374 [ + - + - ]: 28 : {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to creating and loading the wallet.",
375 : : {
376 [ + - + - ]: 28 : {RPCResult::Type::STR, "", ""},
377 : : }},
378 : : }
379 [ + - + - : 126 : },
+ - + + +
+ - - -
- ]
380 : 14 : RPCExamples{
381 [ + - + - : 28 : HelpExampleCli("createwallet", "\"testwallet\"")
+ - ]
382 [ + - + - : 56 : + HelpExampleRpc("createwallet", "\"testwallet\"")
+ - + - ]
383 [ + - + - : 98 : + HelpExampleCliNamed("createwallet", {{"wallet_name", "descriptors"}, {"avoid_reuse", true}, {"load_on_startup", true}})
+ - + - +
+ - - ]
384 [ + - + - : 98 : + HelpExampleRpcNamed("createwallet", {{"wallet_name", "descriptors"}, {"avoid_reuse", true}, {"load_on_startup", true}})
+ - + - +
+ - - ]
385 [ + - ]: 14 : },
386 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
387 : : {
388 : 0 : WalletContext& context = EnsureWalletContext(request.context);
389 : 0 : uint64_t flags = 0;
390 [ # # # # ]: 0 : if (!request.params[1].isNull() && request.params[1].get_bool()) {
391 : : flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
392 : : }
393 : :
394 [ # # # # ]: 0 : if (!request.params[2].isNull() && request.params[2].get_bool()) {
395 : 0 : flags |= WALLET_FLAG_BLANK_WALLET;
396 : : }
397 [ # # ]: 0 : SecureString passphrase;
398 [ # # ]: 0 : passphrase.reserve(100);
399 : 0 : std::vector<bilingual_str> warnings;
400 [ # # # # ]: 0 : if (!request.params[3].isNull()) {
401 [ # # # # : 0 : passphrase = std::string_view{request.params[3].get_str()};
# # # # ]
402 [ # # ]: 0 : if (passphrase.empty()) {
403 : : // Empty string means unencrypted
404 [ # # # # : 0 : warnings.emplace_back(Untranslated("Empty string given as passphrase, wallet will not be encrypted."));
# # ]
405 : : }
406 : : }
407 : :
408 [ # # # # : 0 : if (!request.params[4].isNull() && request.params[4].get_bool()) {
# # # # #
# ]
409 : 0 : flags |= WALLET_FLAG_AVOID_REUSE;
410 : : }
411 : 0 : flags |= WALLET_FLAG_DESCRIPTORS;
412 [ # # # # ]: 0 : if (!self.Arg<bool>("descriptors")) {
413 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "descriptors argument must be set to \"true\"; it is no longer possible to create a legacy wallet.");
414 : : }
415 [ # # # # : 0 : if (!request.params[7].isNull() && request.params[7].get_bool()) {
# # # # #
# ]
416 : : #ifdef ENABLE_EXTERNAL_SIGNER
417 : 0 : flags |= WALLET_FLAG_EXTERNAL_SIGNER;
418 : : #else
419 : : throw JSONRPCError(RPC_WALLET_ERROR, "Compiled without external signing support (required for external signing)");
420 : : #endif
421 : : }
422 : :
423 [ # # ]: 0 : DatabaseOptions options;
424 : 0 : DatabaseStatus status;
425 [ # # ]: 0 : ReadDatabaseArgs(*context.args, options);
426 : 0 : options.require_create = true;
427 : 0 : options.create_flags = flags;
428 [ # # ]: 0 : options.create_passphrase = passphrase;
429 [ # # ]: 0 : bilingual_str error;
430 [ # # # # : 0 : std::optional<bool> load_on_start = request.params[6].isNull() ? std::nullopt : std::optional<bool>(request.params[6].get_bool());
# # # # ]
431 [ # # # # : 0 : const std::shared_ptr<CWallet> wallet = CreateWallet(context, request.params[0].get_str(), load_on_start, options, status, error, warnings);
# # ]
432 [ # # ]: 0 : HandleWalletError(wallet, status, error);
433 : :
434 : 0 : UniValue obj(UniValue::VOBJ);
435 [ # # # # : 0 : obj.pushKV("name", wallet->GetName());
# # ]
436 [ # # ]: 0 : PushWarnings(warnings, obj);
437 : :
438 [ # # ]: 0 : return obj;
439 : 0 : },
440 [ + - + - : 168 : };
+ + - - ]
441 [ + - + - : 336 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
- - - - -
- - - ]
442 : :
443 : 14 : static RPCMethod unloadwallet()
444 : : {
445 : 14 : return RPCMethod{"unloadwallet",
446 [ + - ]: 28 : "Unloads the wallet referenced by the request endpoint or the wallet_name argument.\n"
447 : : "If both are specified, they must be identical.",
448 : : {
449 [ + - + - : 42 : {"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."},
+ - ]
450 [ + - + - ]: 28 : {"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."},
451 : : },
452 [ + - + - : 56 : RPCResult{RPCResult::Type::OBJ, "", "", {
+ - ]
453 [ + - + - ]: 28 : {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to unloading the wallet.",
454 : : {
455 [ + - + - ]: 28 : {RPCResult::Type::STR, "", ""},
456 : : }},
457 [ + - + - : 98 : }},
+ - + + +
+ - - -
- ]
458 : 14 : RPCExamples{
459 [ + - + - : 28 : HelpExampleCli("unloadwallet", "wallet_name")
+ - ]
460 [ + - + - : 56 : + HelpExampleRpc("unloadwallet", "wallet_name")
+ - + - ]
461 [ + - ]: 14 : },
462 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
463 : : {
464 : 0 : const std::string wallet_name{EnsureUniqueWalletName(request, self.MaybeArg<std::string_view>("wallet_name"))};
465 : :
466 [ # # ]: 0 : WalletContext& context = EnsureWalletContext(request.context);
467 [ # # ]: 0 : std::shared_ptr<CWallet> wallet = GetWallet(context, wallet_name);
468 [ # # ]: 0 : if (!wallet) {
469 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
470 : : }
471 : :
472 : 0 : std::vector<bilingual_str> warnings;
473 : 0 : {
474 : 0 : WalletRescanReserver reserver(*wallet);
475 [ # # ]: 0 : if (!reserver.reserve()) {
476 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
477 : : }
478 : :
479 : : // Release the "main" shared pointer and prevent further notifications.
480 : : // Note that any attempt to load the same wallet would fail until the wallet
481 : : // is destroyed (see CheckUniqueFileid).
482 [ # # ]: 0 : std::optional<bool> load_on_start{self.MaybeArg<bool>("load_on_startup")};
483 [ # # # # ]: 0 : if (!RemoveWallet(context, wallet, load_on_start, warnings)) {
484 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
485 : : }
486 : 0 : }
487 : :
488 [ # # ]: 0 : WaitForDeleteWallet(std::move(wallet));
489 : :
490 : 0 : UniValue result(UniValue::VOBJ);
491 [ # # ]: 0 : PushWarnings(warnings, result);
492 : :
493 : 0 : return result;
494 [ # # ]: 0 : },
495 [ + - + - : 84 : };
+ + - - ]
496 [ + - + - : 112 : }
+ - + - -
- ]
497 : :
498 : 14 : RPCMethod simulaterawtransaction()
499 : : {
500 : 14 : return RPCMethod{
501 : 14 : "simulaterawtransaction",
502 [ + - ]: 28 : "Calculate the balance change resulting in the signing and broadcasting of the given transaction(s).\n",
503 : : {
504 [ + - + - ]: 28 : {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "An array of hex strings of raw transactions.\n",
505 : : {
506 [ + - + - ]: 28 : {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
507 : : },
508 : : },
509 [ + - + - ]: 28 : {"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "",
510 : : {
511 [ + - + - : 42 : {"include_watchonly", RPCArg::Type::BOOL, RPCArg::Default{false}, "(DEPRECATED) No longer used"},
+ - ]
512 : : },
513 : : },
514 : : },
515 [ + - ]: 28 : RPCResult{
516 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
517 : : {
518 [ + - + - ]: 28 : {RPCResult::Type::STR_AMOUNT, "balance_change", "The wallet balance change (negative means decrease)."},
519 : : }
520 [ + - + - : 56 : },
+ + - - ]
521 : 14 : RPCExamples{
522 [ + - + - : 28 : HelpExampleCli("simulaterawtransaction", "[\"myhex\"]")
+ - ]
523 [ + - + - : 56 : + HelpExampleRpc("simulaterawtransaction", "[\"myhex\"]")
+ - + - ]
524 [ + - ]: 14 : },
525 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
526 : : {
527 [ # # ]: 0 : const std::shared_ptr<const CWallet> rpc_wallet = GetWalletForJSONRPCRequest(request);
528 [ # # ]: 0 : if (!rpc_wallet) return UniValue::VNULL;
529 [ # # ]: 0 : const CWallet& wallet = *rpc_wallet;
530 : :
531 [ # # ]: 0 : LOCK(wallet.cs_wallet);
532 : :
533 [ # # # # ]: 0 : const auto& txs = request.params[0].get_array();
534 : 0 : CAmount changes{0};
535 : 0 : std::map<COutPoint, CAmount> new_utxos; // UTXO:s that were made available in transaction array
536 : 0 : std::set<COutPoint> spent;
537 : :
538 [ # # # # ]: 0 : for (size_t i = 0; i < txs.size(); ++i) {
539 [ # # ]: 0 : CMutableTransaction mtx;
540 [ # # # # : 0 : if (!DecodeHexTx(mtx, txs[i].get_str(), /*try_no_witness=*/ true, /*try_witness=*/ true)) {
# # # # ]
541 [ # # # # ]: 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Transaction hex string decoding failure.");
542 : : }
543 : :
544 : : // Fetch previous transactions (inputs)
545 : 0 : std::map<COutPoint, Coin> coins;
546 [ # # ]: 0 : for (const CTxIn& txin : mtx.vin) {
547 [ # # ]: 0 : coins[txin.prevout]; // Create empty map entry keyed by prevout.
548 : : }
549 [ # # ]: 0 : wallet.chain().findCoins(coins);
550 : :
551 : : // Fetch debit; we are *spending* these; if the transaction is signed and
552 : : // broadcast, we will lose everything in these
553 [ # # ]: 0 : for (const auto& txin : mtx.vin) {
554 : 0 : const auto& outpoint = txin.prevout;
555 [ # # ]: 0 : if (spent.contains(outpoint)) {
556 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Transaction(s) are spending the same output more than once");
557 : : }
558 [ # # ]: 0 : if (new_utxos.contains(outpoint)) {
559 [ # # ]: 0 : changes -= new_utxos.at(outpoint);
560 : 0 : new_utxos.erase(outpoint);
561 : : } else {
562 [ # # # # ]: 0 : if (coins.at(outpoint).IsSpent()) {
563 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "One or more transaction inputs are missing or have been spent already");
564 : : }
565 [ # # ]: 0 : changes -= wallet.GetDebit(txin);
566 : : }
567 [ # # ]: 0 : spent.insert(outpoint);
568 : : }
569 : :
570 : : // Iterate over outputs; we are *receiving* these, if the wallet considers
571 : : // them "mine"; if the transaction is signed and broadcast, we will receive
572 : : // everything in these
573 : : // Also populate new_utxos in case these are spent in later transactions
574 : :
575 [ # # ]: 0 : const auto& hash = mtx.GetHash();
576 [ # # # # ]: 0 : for (size_t i = 0; i < mtx.vout.size(); ++i) {
577 [ # # ]: 0 : const auto& txout = mtx.vout[i];
578 [ # # ]: 0 : bool is_mine = wallet.IsMine(txout);
579 [ # # # # ]: 0 : changes += new_utxos[COutPoint(hash, i)] = is_mine ? txout.nValue : 0;
580 : : }
581 : 0 : }
582 : :
583 : 0 : UniValue result(UniValue::VOBJ);
584 [ # # # # : 0 : result.pushKV("balance_change", ValueFromAmount(changes));
# # ]
585 : :
586 : 0 : return result;
587 [ # # ]: 0 : }
588 [ + - + - : 168 : };
+ - + - +
+ + + + +
- - - - -
- ]
589 [ + - + - : 140 : }
+ - + - +
- - - ]
590 : :
591 : 14 : static RPCMethod migratewallet()
592 : : {
593 : 14 : return RPCMethod{
594 : 14 : "migratewallet",
595 [ + - ]: 28 : "Migrate the wallet to a descriptor wallet.\n"
596 : : "A new wallet backup will need to be made.\n"
597 : : "\nThe migration process will create a backup of the wallet before migrating. This backup\n"
598 : : "file will be named <wallet name>-<timestamp>.legacy.bak and can be found in the directory\n"
599 : : "for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet."
600 : : "\nEncrypted wallets must have the passphrase provided as an argument to this call.\n"
601 : : "\nThis RPC may take a long time to complete. Increasing the RPC client timeout is recommended.",
602 : : {
603 [ + - + - : 42 : {"wallet_name", RPCArg::Type::STR, RPCArg::DefaultHint{"the wallet name from the RPC endpoint"}, "The name of the wallet to migrate. If provided both here and in the RPC endpoint, the two must be identical."},
+ - ]
604 [ + - + - ]: 28 : {"passphrase", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The wallet passphrase"},
605 [ + - + - : 42 : {"load_wallet", RPCArg::Type::BOOL, RPCArg::Default{true}, "Load the wallet after migration."},
+ - ]
606 : : },
607 [ + - ]: 28 : RPCResult{
608 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
609 : : {
610 [ + - + - ]: 28 : {RPCResult::Type::STR, "wallet_name", "The name of the primary migrated wallet"},
611 [ + - + - ]: 28 : {RPCResult::Type::STR, "watchonly_name", /*optional=*/true, "The name of the migrated wallet containing the watchonly scripts"},
612 [ + - + - ]: 28 : {RPCResult::Type::STR, "solvables_name", /*optional=*/true, "The name of the migrated wallet containing solvable but not watched scripts"},
613 [ + - + - ]: 28 : {RPCResult::Type::STR, "backup_path", "The location of the backup of the original wallet"},
614 : : }
615 [ + - + - : 140 : },
+ + - - ]
616 : 14 : RPCExamples{
617 [ + - + - : 28 : HelpExampleCli("migratewallet", "")
+ - ]
618 [ + - + - : 56 : + HelpExampleRpc("migratewallet", "")
+ - + - ]
619 [ + - ]: 14 : },
620 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
621 : : {
622 : 0 : const std::string wallet_name{EnsureUniqueWalletName(request, self.MaybeArg<std::string_view>("wallet_name"))};
623 : :
624 [ # # ]: 0 : SecureString wallet_pass;
625 [ # # ]: 0 : wallet_pass.reserve(100);
626 [ # # # # ]: 0 : if (!request.params[1].isNull()) {
627 [ # # # # : 0 : wallet_pass = std::string_view{request.params[1].get_str()};
# # # # ]
628 : : }
629 : :
630 [ # # ]: 0 : const bool loadwallet = self.Arg<bool>("load_wallet");
631 : :
632 [ # # ]: 0 : WalletContext& context = EnsureWalletContext(request.context);
633 [ # # ]: 0 : util::Result<MigrationResult> res = MigrateLegacyToDescriptor(wallet_name, wallet_pass, context, loadwallet);
634 [ # # ]: 0 : if (!res) {
635 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(res).original);
636 : : }
637 : :
638 : 0 : UniValue r{UniValue::VOBJ};
639 [ # # # # : 0 : r.pushKV("wallet_name", res->wallet_name);
# # ]
640 [ # # ]: 0 : if (res->watchonly_wallet_name.has_value()) {
641 [ # # # # : 0 : r.pushKV("watchonly_name", res->watchonly_wallet_name.value());
# # ]
642 : : }
643 [ # # ]: 0 : if (res->solvables_wallet_name.has_value()) {
644 [ # # # # : 0 : r.pushKV("solvables_name", res->solvables_wallet_name.value());
# # ]
645 : : }
646 [ # # # # : 0 : r.pushKV("backup_path", res->backup_path.utf8string());
# # # # ]
647 : :
648 : 0 : return r;
649 : 0 : },
650 [ + - + - : 98 : };
+ + - - ]
651 [ + - + - : 196 : }
+ - + - +
- + - + -
- - - - ]
652 : :
653 : 14 : RPCMethod gethdkeys()
654 : : {
655 : 14 : return RPCMethod{
656 : 14 : "gethdkeys",
657 [ + - ]: 28 : "List all BIP 32 HD keys in the wallet and which descriptors use them.\n",
658 : : {
659 [ + - + - ]: 28 : {"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", {
660 [ + - + - : 42 : {"active_only", RPCArg::Type::BOOL, RPCArg::Default{false}, "Show the keys for only active descriptors"},
+ - ]
661 [ + - + - : 42 : {"private", RPCArg::Type::BOOL, RPCArg::Default{false}, "Show private keys"}
+ - ]
662 : : }},
663 : : },
664 [ + - + - : 56 : RPCResult{RPCResult::Type::ARR, "", "", {
+ - ]
665 : : {
666 [ + - + - ]: 28 : {RPCResult::Type::OBJ, "", "", {
667 [ + - + - ]: 28 : {RPCResult::Type::STR, "xpub", "The extended public key"},
668 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "has_private", "Whether the wallet has the private key for this xpub"},
669 [ + - + - ]: 28 : {RPCResult::Type::STR, "xprv", /*optional=*/true, "The extended private key if \"private\" is true"},
670 [ + - + - ]: 28 : {RPCResult::Type::ARR, "descriptors", "Array of descriptor objects that use this HD key",
671 : : {
672 [ + - + - ]: 28 : {RPCResult::Type::OBJ, "", "", {
673 [ + - + - ]: 28 : {RPCResult::Type::STR, "desc", "Descriptor string public representation"},
674 [ + - + - ]: 28 : {RPCResult::Type::BOOL, "active", "Whether this descriptor is currently used to generate new addresses"},
675 : : }},
676 : : }},
677 : : }},
678 : : }
679 [ + - + - : 294 : }},
+ - + - +
- + + + +
+ + + + -
- - - - -
- - ]
680 : 14 : RPCExamples{
681 [ + - + - : 28 : HelpExampleCli("gethdkeys", "") + HelpExampleRpc("gethdkeys", "")
+ - + - +
- + - +
- ]
682 [ + - + - : 140 : + HelpExampleCliNamed("gethdkeys", {{"active_only", "true"}, {"private", "true"}}) + HelpExampleRpcNamed("gethdkeys", {{"active_only", "true"}, {"private", "true"}})
+ - + - +
- + - + -
+ - + + +
+ - - -
- ]
683 [ + - ]: 14 : },
684 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
685 : : {
686 [ # # ]: 0 : const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
687 [ # # ]: 0 : if (!wallet) return UniValue::VNULL;
688 : :
689 [ # # ]: 0 : LOCK(wallet->cs_wallet);
690 : :
691 [ # # # # : 0 : UniValue options{request.params[0].isNull() ? UniValue::VOBJ : request.params[0]};
# # # # ]
692 [ # # # # : 0 : const bool active_only{options.exists("active_only") ? options["active_only"].get_bool() : false};
# # # # #
# ]
693 [ # # # # : 0 : const bool priv{options.exists("private") ? options["private"].get_bool() : false};
# # # # #
# ]
694 [ # # ]: 0 : if (priv) {
695 [ # # ]: 0 : EnsureWalletIsUnlocked(*wallet);
696 : : }
697 : :
698 [ # # ]: 0 : std::map<CExtPubKey, std::set<std::tuple<std::string, bool, bool>>> wallet_xpubs;
699 : 0 : std::map<CExtPubKey, CExtKey> wallet_xprvs;
700 [ # # # # : 0 : for (const auto& [xpub, spkms] : wallet->GetHDPubKeys(active_only ? HDKeyFilter::Active : HDKeyFilter::All)) {
# # ]
701 [ # # ]: 0 : for (auto* desc_spkm : spkms) {
702 [ # # ]: 0 : LOCK(desc_spkm->cs_desc_man);
703 [ # # ]: 0 : std::string desc_str;
704 [ # # ]: 0 : bool ok = desc_spkm->GetDescriptorString(desc_str, /*priv=*/false);
705 [ # # ]: 0 : CHECK_NONFATAL(ok);
706 [ # # # # : 0 : wallet_xpubs[xpub].emplace(desc_str, wallet->IsActiveScriptPubKeyMan(*desc_spkm), desc_spkm->HasPrivKey(xpub.pubkey.GetID()));
# # # # #
# ]
707 [ # # # # : 0 : if (std::optional<CKey> key = priv ? desc_spkm->GetKey(xpub.pubkey.GetID()) : std::nullopt) {
# # # # ]
708 [ # # # # ]: 0 : wallet_xprvs[xpub] = CExtKey(xpub, *key);
709 : 0 : }
710 [ # # ]: 0 : }
711 : 0 : }
712 : :
713 : 0 : UniValue response(UniValue::VARR);
714 [ # # ]: 0 : for (const auto& [xpub, descs] : wallet_xpubs) {
715 : 0 : bool has_xprv = false;
716 : 0 : UniValue descriptors(UniValue::VARR);
717 [ # # ]: 0 : for (const auto& [desc, active, has_priv] : descs) {
718 : 0 : UniValue d(UniValue::VOBJ);
719 [ # # # # : 0 : d.pushKV("desc", desc);
# # ]
720 [ # # # # : 0 : d.pushKV("active", active);
# # ]
721 : 0 : has_xprv |= has_priv;
722 : :
723 [ # # ]: 0 : descriptors.push_back(std::move(d));
724 : 0 : }
725 : 0 : UniValue xpub_info(UniValue::VOBJ);
726 [ # # # # : 0 : xpub_info.pushKV("xpub", EncodeExtPubKey(xpub));
# # # # ]
727 [ # # # # : 0 : xpub_info.pushKV("has_private", has_xprv);
# # ]
728 [ # # # # ]: 0 : if (priv && has_xprv) {
729 [ # # # # : 0 : xpub_info.pushKV("xprv", EncodeExtKey(wallet_xprvs.at(xpub)));
# # # # #
# ]
730 : : }
731 [ # # # # ]: 0 : xpub_info.pushKV("descriptors", std::move(descriptors));
732 : :
733 [ # # ]: 0 : response.push_back(std::move(xpub_info));
734 : 0 : }
735 : :
736 : 0 : return response;
737 [ # # ]: 0 : },
738 [ + - + - : 126 : };
+ - + + +
+ - - -
- ]
739 [ + - + - : 336 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- - - - -
- - - - -
- ]
740 : :
741 : 14 : static RPCMethod createwalletdescriptor()
742 : : {
743 : 14 : return RPCMethod{"createwalletdescriptor",
744 : : "Creates the wallet's descriptor for the given address type. "
745 : : "The address type must be one that the wallet does not already have a descriptor for."
746 [ + - ]: 28 : + HELP_REQUIRING_PASSPHRASE,
747 : : {
748 [ + - + - : 28 : {"type", RPCArg::Type::STR, RPCArg::Optional::NO, "The address type the descriptor will produce. Options are " + FormatAllOutputTypes() + "."},
+ - ]
749 [ + - + - ]: 28 : {"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", {
750 [ + - + - : 42 : {"internal", RPCArg::Type::BOOL, RPCArg::DefaultHint{"Both external and internal will be generated unless this parameter is specified"}, "Whether to only make one descriptor that is internal (if parameter is true) or external (if parameter is false)"},
+ - ]
751 [ + - + - : 42 : {"hdkey", RPCArg::Type::STR, RPCArg::DefaultHint{"The HD key used by all other active descriptors"}, "The HD key that the wallet knows the private key of, listed using 'gethdkeys', to use for this descriptor's key"},
+ - ]
752 : : }},
753 : : },
754 [ + - ]: 28 : RPCResult{
755 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
756 : : {
757 [ + - + - ]: 28 : {RPCResult::Type::ARR, "descs", "The public descriptors that were added to the wallet",
758 [ + - + - ]: 28 : {{RPCResult::Type::STR, "", ""}}
759 : : }
760 : : },
761 [ + - + - : 98 : },
+ - + + +
+ - - -
- ]
762 : 14 : RPCExamples{
763 [ + - + - : 28 : HelpExampleCli("createwalletdescriptor", "bech32m")
+ - ]
764 [ + - + - : 56 : + HelpExampleRpc("createwalletdescriptor", "bech32m")
+ - + - ]
765 [ + - ]: 14 : },
766 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
767 : : {
768 : 0 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
769 [ # # ]: 0 : if (!pwallet) return UniValue::VNULL;
770 : :
771 [ # # # # : 0 : std::optional<OutputType> output_type = ParseOutputType(request.params[0].get_str());
# # # # ]
772 [ # # ]: 0 : if (!output_type) {
773 [ # # # # : 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));
# # # # ]
774 : : }
775 : :
776 [ # # # # : 0 : UniValue options{request.params[1].isNull() ? UniValue::VOBJ : request.params[1]};
# # # # ]
777 [ # # # # : 0 : UniValue internal_only{options["internal"]};
# # ]
778 [ # # # # : 0 : UniValue hdkey{options["hdkey"]};
# # ]
779 : :
780 : 0 : std::vector<bool> internals;
781 [ # # ]: 0 : if (internal_only.isNull()) {
782 [ # # ]: 0 : internals.push_back(false);
783 [ # # ]: 0 : internals.push_back(true);
784 : : } else {
785 [ # # # # ]: 0 : internals.push_back(internal_only.get_bool());
786 : : }
787 : :
788 [ # # ]: 0 : LOCK(pwallet->cs_wallet);
789 [ # # ]: 0 : EnsureWalletIsUnlocked(*pwallet);
790 : :
791 [ # # ]: 0 : CExtPubKey xpub;
792 [ # # ]: 0 : if (hdkey.isNull()) {
793 [ # # ]: 0 : HDPubKeyMap active_xpubs = pwallet->GetHDPubKeys(HDKeyFilter::Active);
794 [ # # ]: 0 : if (active_xpubs.size() != 1) {
795 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to determine which HD key to use from active descriptors. Please specify with 'hdkey'");
796 : : }
797 : 0 : xpub = active_xpubs.begin()->first;
798 : 0 : } else {
799 [ # # # # ]: 0 : xpub = DecodeExtPubKey(hdkey.get_str());
800 [ # # ]: 0 : if (!xpub.pubkey.IsValid()) {
801 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to parse HD key. Please provide a valid xpub");
802 : : }
803 : : }
804 : :
805 [ # # # # ]: 0 : std::optional<CKey> key = pwallet->GetKey(xpub.pubkey.GetID());
806 [ # # ]: 0 : if (!key) {
807 [ # # # # : 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Private key for %s is not known", EncodeExtPubKey(xpub)));
# # ]
808 : : }
809 [ # # ]: 0 : CExtKey active_hdkey(xpub, *key);
810 : :
811 : 0 : std::vector<std::reference_wrapper<DescriptorScriptPubKeyMan>> spkms;
812 [ # # ]: 0 : WalletBatch batch{pwallet->GetDatabase()};
813 [ # # # # : 0 : for (bool internal : internals) {
# # ]
814 [ # # ]: 0 : WalletDescriptor w_desc = GenerateWalletDescriptor(xpub, *output_type, internal);
815 [ # # ]: 0 : uint256 w_id = DescriptorID(*w_desc.descriptor);
816 [ # # # # ]: 0 : if (!pwallet->GetScriptPubKeyMan(w_id)) {
817 [ # # # # ]: 0 : spkms.emplace_back(pwallet->SetupDescriptorScriptPubKeyMan(batch, active_hdkey, *output_type, internal));
818 : : }
819 : 0 : }
820 [ # # ]: 0 : if (spkms.empty()) {
821 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "Descriptor already exists");
822 : : }
823 : :
824 : : // Fetch each descspkm from the wallet in order to get the descriptor strings
825 : 0 : UniValue descs{UniValue::VARR};
826 [ # # ]: 0 : for (const auto& spkm : spkms) {
827 [ # # ]: 0 : std::string desc_str;
828 [ # # ]: 0 : bool ok = spkm.get().GetDescriptorString(desc_str, false);
829 [ # # ]: 0 : CHECK_NONFATAL(ok);
830 [ # # # # ]: 0 : descs.push_back(desc_str);
831 : 0 : }
832 : 0 : UniValue out{UniValue::VOBJ};
833 [ # # # # ]: 0 : out.pushKV("descs", std::move(descs));
834 : 0 : return out;
835 [ # # ]: 0 : }
836 [ + - + - : 140 : };
+ - + + +
+ - - -
- ]
837 [ + - + - : 168 : }
+ - + - +
- + - - -
- - ]
838 : :
839 : 14 : RPCMethod addhdkey()
840 : : {
841 : 14 : return RPCMethod{
842 : 14 : "addhdkey",
843 [ + - ]: 28 : "Add a BIP 32 HD key to the wallet that can be used with 'createwalletdescriptor'\n",
844 : : {
845 [ + - + - : 42 : {"hdkey", RPCArg::Type::STR, RPCArg::DefaultHint{"Automatically generated new key"}, "The BIP 32 extended private key to add. If none is provided, a randomly generated one will be added."},
+ - ]
846 : : },
847 [ + - ]: 28 : RPCResult{
848 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
849 : : {
850 [ + - + - ]: 28 : {RPCResult::Type::STR, "xpub", "The xpub of the HD key that was added to the wallet"}
851 : : },
852 [ + - + - : 56 : },
+ + - - ]
853 : 14 : RPCExamples{
854 [ + - + - : 28 : HelpExampleCli("addhdkey", "xprv") + HelpExampleRpc("addhdkey", "xprv")
+ - + - +
- + - +
- ]
855 [ + - ]: 14 : },
856 : 14 : [&](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
857 : : {
858 : 0 : std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
859 [ # # ]: 0 : if (!wallet) return UniValue::VNULL;
860 : :
861 [ # # # # ]: 0 : if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
862 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "addhdkey is not available for wallets without private keys");
863 : : }
864 : :
865 [ # # ]: 0 : EnsureWalletIsUnlocked(*wallet);
866 : :
867 [ # # ]: 0 : CExtKey hdkey;
868 [ # # # # ]: 0 : if (request.params[0].isNull()) {
869 : 0 : CKey seed_key = GenerateRandomKey();
870 [ # # # # ]: 0 : hdkey.SetSeed(seed_key);
871 : 0 : } else {
872 [ # # # # : 0 : hdkey = DecodeExtKey(request.params[0].get_str());
# # ]
873 [ # # ]: 0 : if (!hdkey.key.IsValid()) {
874 : : // Check if the user gave us an xpub and give a more descriptive error if so
875 [ # # # # : 0 : CExtPubKey xpub = DecodeExtPubKey(request.params[0].get_str());
# # ]
876 [ # # ]: 0 : if (xpub.pubkey.IsValid()) {
877 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Extended public key (xpub) provided, but extended private key (xprv) is required");
878 : : } else {
879 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Could not parse HD key");
880 : : }
881 : 0 : }
882 : : }
883 : :
884 [ # # ]: 0 : LOCK(wallet->cs_wallet);
885 [ # # # # ]: 0 : std::string desc_str = "unused(" + EncodeExtKey(hdkey) + ")";
886 : 0 : FlatSigningProvider keys;
887 [ # # ]: 0 : std::string error;
888 [ # # # # ]: 0 : std::vector<std::unique_ptr<Descriptor>> descs = Parse(desc_str, keys, error, false);
889 [ # # ]: 0 : CHECK_NONFATAL(!descs.empty());
890 [ # # # # : 0 : WalletDescriptor w_desc(std::move(descs.at(0)), GetTime(), 0, 0, 0);
# # # # ]
891 [ # # # # ]: 0 : if (wallet->GetDescriptorScriptPubKeyMan(w_desc) != nullptr) {
892 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "HD key already exists");
893 : : }
894 : :
895 [ # # # # ]: 0 : auto spkm = wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", /*internal=*/false);
896 [ # # ]: 0 : if (!spkm) {
897 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(spkm).original);
898 : : }
899 : :
900 : 0 : UniValue response(UniValue::VOBJ);
901 [ # # ]: 0 : const DescriptorScriptPubKeyMan& desc_spkm = spkm->get();
902 [ # # ]: 0 : LOCK(desc_spkm.cs_desc_man);
903 [ # # ]: 0 : std::set<CPubKey> pubkeys;
904 : 0 : std::set<CExtPubKey> extpubs;
905 [ # # # # ]: 0 : desc_spkm.GetWalletDescriptor().descriptor->GetPubKeys(pubkeys, extpubs);
906 [ # # ]: 0 : CHECK_NONFATAL(pubkeys.size() == 0);
907 [ # # ]: 0 : CHECK_NONFATAL(extpubs.size() == 1);
908 [ # # # # : 0 : response.pushKV("xpub", EncodeExtPubKey(*extpubs.begin()));
# # # # ]
909 : :
910 : 0 : return response;
911 [ # # # # ]: 0 : },
912 [ + - + - : 70 : };
+ + - - ]
913 [ + - + - ]: 56 : }
914 : :
915 : 14 : static RPCMethod exportwatchonlywallet()
916 : : {
917 : 14 : return RPCMethod{"exportwatchonlywallet",
918 [ + - ]: 28 : "Creates a wallet file at the specified destination containing a watchonly version "
919 : : "of the current wallet. This watchonly wallet contains the wallet's public descriptors, "
920 : : "its transactions, and address book data. Descriptors that use hardened derivation will "
921 : : "only have a limited number of derived keys included in the export due to hardened "
922 : : "derivation requiring private keys. Descriptors with unhardened derivation do not have "
923 : : "this limitation. The watchonly wallet can be imported into another node using 'restorewallet'.",
924 : : {
925 [ + - + - ]: 28 : {"destination", RPCArg::Type::STR, RPCArg::Optional::NO, "The path to the filename the exported watchonly wallet will be saved to"},
926 : : },
927 [ + - ]: 28 : RPCResult{
928 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "",
929 : : {
930 [ + - + - ]: 28 : {RPCResult::Type::STR, "exported_file", "The full path that the file has been exported to"},
931 : : },
932 [ + - + - : 56 : },
+ + - - ]
933 : 14 : RPCExamples{
934 [ + - + - : 28 : HelpExampleCli("exportwatchonlywallet", "\"/path/to/export.dat\"")
+ - ]
935 [ + - + - : 56 : + HelpExampleRpc("exportwatchonlywallet", "\"/path/to/export.dat\"")
+ - + - ]
936 [ + - ]: 14 : },
937 : 14 : [&](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
938 : : {
939 : 0 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
940 [ # # ]: 0 : if (!pwallet) return UniValue::VNULL;
941 [ # # ]: 0 : WalletContext& context = EnsureWalletContext(request.context);
942 : :
943 [ # # # # : 0 : std::string dest = request.params[0].get_str();
# # ]
944 : :
945 [ # # ]: 0 : LOCK(pwallet->cs_wallet);
946 [ # # ]: 0 : pwallet->TopUpKeyPool();
947 [ # # # # ]: 0 : util::Result<std::string> exported = ExportWatchOnlyWallet(*pwallet, fs::PathFromString(dest), context);
948 [ # # ]: 0 : if (!exported) {
949 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(exported).original);
950 : : }
951 : 0 : UniValue out{UniValue::VOBJ};
952 [ # # # # : 0 : out.pushKV("exported_file", *exported);
# # ]
953 : 0 : return out;
954 [ # # ]: 0 : }
955 [ + - + - : 70 : };
+ + - - ]
956 [ + - + - ]: 56 : }
957 : :
958 : 14 : RPCMethod derivehdkey()
959 : : {
960 : 14 : return RPCMethod{
961 : 14 : "derivehdkey",
962 : : "Derive extended public or private key from HD key in the wallet at a given path.\n"
963 : : "Derivation uses wallet private key material.\n"
964 [ + - ]: 28 : + HELP_REQUIRING_PASSPHRASE,
965 : : {
966 [ + - + - ]: 28 : {"path", RPCArg::Type::STR, RPCArg::Optional::NO, "BIP 32 derivation path with at least one hardened step."},
967 [ + - + - ]: 28 : {"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", {
968 [ + - + - : 42 : {"private", RPCArg::Type::BOOL, RPCArg::Default{false}, "Show private key"},
+ - ]
969 [ + - + - : 42 : {"hdkey", RPCArg::Type::STR, RPCArg::DefaultHint{"Either the HD key of an unused(KEY) descriptor, or any other active descriptor."}, "The HD key that the wallet knows the private key of, listed using 'gethdkeys', to use for derivation"},
+ - ]
970 : : }},
971 : : },
972 [ + - ]: 28 : RPCResult{
973 [ + - + - ]: 28 : RPCResult::Type::OBJ, "", "", {
974 [ + - + - ]: 28 : {RPCResult::Type::STR, "origin", "Fingerprint and path for use in descriptors"},
975 [ + - + - ]: 28 : {RPCResult::Type::STR, "xpub", "The extended public key"},
976 [ + - + - ]: 28 : {RPCResult::Type::STR, "xprv", /*optional=*/true, "The extended private key if \"private\" is true"},
977 : : },
978 [ + - + - : 112 : },
+ + - - ]
979 : 14 : RPCExamples{
980 [ + - + - : 28 : HelpExampleCli("derivehdkey", "m/87h/0h/0h") + HelpExampleRpc("derivehdkey", "\"m/87h/0h/0h\"")
+ - + - +
- + - +
- ]
981 [ + - + - : 84 : + HelpExampleCliNamed("derivehdkey", {{"path", "m/87h/0h/0h"}, {"private", "true"}})
+ - + - +
+ - - ]
982 [ + - + - : 84 : + HelpExampleRpcNamed("derivehdkey", {{"path", "m/87h/0h/0h"}, {"private", "true"}})
+ - + - +
+ - - ]
983 [ + - ]: 14 : },
984 : 14 : [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
985 : : {
986 [ # # ]: 0 : const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
987 [ # # ]: 0 : if (!wallet) return UniValue::VNULL;
988 : :
989 [ # # # # ]: 0 : if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
990 : : // Watch-only wallets can't contain unused(KEY) descriptors
991 [ # # # # ]: 0 : throw JSONRPCError(RPC_WALLET_ERROR, "derivehdkey is not available for watch-only wallets");
992 : : }
993 : :
994 [ # # # # : 0 : std::vector<uint32_t> path = ParsePathBIP32(request.params[0].get_str());
# # ]
995 [ # # # # : 0 : UniValue options{request.params[1].isNull() ? UniValue::VOBJ : request.params[1]};
# # # # ]
996 [ # # # # : 0 : const bool priv{options.exists("private") ? options["private"].get_bool() : false};
# # # # #
# ]
997 [ # # # # : 0 : UniValue hdkey{options["hdkey"]};
# # ]
998 [ # # # # : 0 : if (!HasHardenedDerivation(path)) {
# # ]
999 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Derivation path requires at least one hardened step");
1000 : : }
1001 : :
1002 [ # # ]: 0 : LOCK(wallet->cs_wallet);
1003 : :
1004 : : // The RPC requires a hardened derivation step, so always unlock
1005 : : // the wallet.
1006 [ # # ]: 0 : EnsureWalletIsUnlocked(*wallet);
1007 : :
1008 [ # # ]: 0 : CExtPubKey xpub;
1009 [ # # ]: 0 : if (!hdkey.isNull()) {
1010 [ # # # # ]: 0 : xpub = DecodeExtPubKey(hdkey.get_str());
1011 [ # # ]: 0 : if (!xpub.pubkey.IsValid()) {
1012 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to parse HD key. Please provide a valid xpub");
1013 : : }
1014 : :
1015 : : // Accept an xpub from an active or unused(KEY) descriptor, but
1016 : : // not from a (used) inactive one.
1017 [ # # ]: 0 : std::set<CExtPubKey> xpub_candidates;
1018 [ # # # # ]: 0 : for (const auto& candidate : wallet->GetHDPubKeys(HDKeyFilter::UnusedKey)) {
1019 [ # # ]: 0 : xpub_candidates.insert(candidate.first);
1020 : 0 : }
1021 [ # # # # ]: 0 : for (const auto& candidate : wallet->GetHDPubKeys(HDKeyFilter::Active)) {
1022 [ # # ]: 0 : xpub_candidates.insert(candidate.first);
1023 : 0 : }
1024 [ # # ]: 0 : if (!xpub_candidates.contains(xpub)) {
1025 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "HD key is not used by an active or unused(KEY) descriptor");
1026 : : }
1027 : 0 : }
1028 : :
1029 : : // If hdkey was not specified, try to look it up. First consider
1030 : : // unused(KEY) descriptors. Otherwise look for active descriptors.
1031 [ # # ]: 0 : if (hdkey.isNull()) {
1032 [ # # ]: 0 : HDPubKeyMap wallet_xpubs{wallet->GetHDPubKeys(HDKeyFilter::UnusedKey)};
1033 : :
1034 [ # # ]: 0 : if (wallet_xpubs.size() > 1) {
1035 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to determine which HD key to use. Please specify with 'hdkey'");
1036 [ # # ]: 0 : } else if (wallet_xpubs.size() == 1) {
1037 : 0 : xpub = wallet_xpubs.begin()->first;
1038 : : } else {
1039 [ # # ]: 0 : HDPubKeyMap active_xpubs = wallet->GetHDPubKeys(HDKeyFilter::Active);
1040 [ # # ]: 0 : if (active_xpubs.empty()) {
1041 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No active or unused(KEY) descriptor found");
1042 : : }
1043 : :
1044 [ # # ]: 0 : if (active_xpubs.size() > 1) {
1045 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to determine which HD key to use from active descriptors. Please specify with 'hdkey'");
1046 : : }
1047 : :
1048 : 0 : xpub = active_xpubs.begin()->first;
1049 : 0 : }
1050 : 0 : }
1051 : :
1052 [ # # ]: 0 : std::optional<CExtKey> xprv{wallet->GetExtKey(xpub)};
1053 [ # # ]: 0 : if (!xprv) {
1054 [ # # # # : 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Private key for %s is not known", EncodeExtPubKey(xpub)));
# # ]
1055 : : }
1056 : :
1057 [ # # ]: 0 : std::optional<std::pair<CExtKey, KeyOriginInfo>> child{DeriveExtKey(*xprv, path)};
1058 [ # # ]: 0 : if (!child) {
1059 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Unable to derive HD key at the requested path");
1060 : : }
1061 : :
1062 : 0 : UniValue res{UniValue::VOBJ};
1063 : :
1064 [ # # ]: 0 : const std::string fingerprint{HexStr(child->second.fingerprint)};
1065 : :
1066 [ # # # # : 0 : res.pushKV("origin", strprintf("[%s%s]", fingerprint, FormatHDKeypath(child->second.path)));
# # # # #
# ]
1067 [ # # # # : 0 : res.pushKV("xpub", EncodeExtPubKey(child->first.Neuter()));
# # # # #
# ]
1068 [ # # ]: 0 : if (priv) {
1069 [ # # # # : 0 : res.pushKV("xprv", EncodeExtKey(child->first));
# # # # ]
1070 : : }
1071 : 0 : return res;
1072 [ # # # # ]: 0 : },
1073 [ + - + - : 140 : };
+ - + + +
+ - - -
- ]
1074 [ + - + - : 224 : }
+ - + - +
- + - + -
+ - + - +
- + - - -
- - - - -
- - - ]
1075 : :
1076 : : // addresses
1077 : : RPCMethod getaddressinfo();
1078 : : RPCMethod getnewaddress();
1079 : : RPCMethod getrawchangeaddress();
1080 : : RPCMethod setlabel();
1081 : : RPCMethod listaddressgroupings();
1082 : : RPCMethod keypoolrefill();
1083 : : RPCMethod getaddressesbylabel();
1084 : : RPCMethod listlabels();
1085 : : #ifdef ENABLE_EXTERNAL_SIGNER
1086 : : RPCMethod walletdisplayaddress();
1087 : : #endif // ENABLE_EXTERNAL_SIGNER
1088 : :
1089 : : // backup
1090 : : RPCMethod importprunedfunds();
1091 : : RPCMethod removeprunedfunds();
1092 : : RPCMethod importdescriptors();
1093 : : RPCMethod listdescriptors();
1094 : : RPCMethod backupwallet();
1095 : : RPCMethod restorewallet();
1096 : :
1097 : : // coins
1098 : : RPCMethod getreceivedbyaddress();
1099 : : RPCMethod getreceivedbylabel();
1100 : : RPCMethod getbalance();
1101 : : RPCMethod lockunspent();
1102 : : RPCMethod listlockunspent();
1103 : : RPCMethod getbalances();
1104 : : RPCMethod listunspent();
1105 : :
1106 : : // encryption
1107 : : RPCMethod walletpassphrase();
1108 : : RPCMethod walletpassphrasechange();
1109 : : RPCMethod walletlock();
1110 : : RPCMethod encryptwallet();
1111 : :
1112 : : // spend
1113 : : RPCMethod sendtoaddress();
1114 : : RPCMethod sendmany();
1115 : : RPCMethod fundrawtransaction();
1116 : : RPCMethod bumpfee();
1117 : : RPCMethod psbtbumpfee();
1118 : : RPCMethod send();
1119 : : RPCMethod sendall();
1120 : : RPCMethod walletprocesspsbt();
1121 : : RPCMethod walletcreatefundedpsbt();
1122 : : RPCMethod signrawtransactionwithwallet();
1123 : :
1124 : : // signmessage
1125 : : RPCMethod signmessage();
1126 : :
1127 : : // transactions
1128 : : RPCMethod listreceivedbyaddress();
1129 : : RPCMethod listreceivedbylabel();
1130 : : RPCMethod listtransactions();
1131 : : RPCMethod listsinceblock();
1132 : : RPCMethod gettransaction();
1133 : : RPCMethod abandontransaction();
1134 : : RPCMethod rescanblockchain();
1135 : : RPCMethod abortrescan();
1136 : :
1137 : 18 : std::span<const CRPCCommand> GetWalletRPCCommands()
1138 : : {
1139 : 18 : static const CRPCCommand commands[]{
1140 [ + - ]: 14 : {"rawtransactions", &fundrawtransaction},
1141 [ + - ]: 14 : {"wallet", &abandontransaction},
1142 [ + - ]: 14 : {"wallet", &abortrescan},
1143 [ + - ]: 14 : {"wallet", &addhdkey},
1144 [ + - ]: 14 : {"wallet", &backupwallet},
1145 [ + - ]: 14 : {"wallet", &bumpfee},
1146 [ + - ]: 14 : {"wallet", &psbtbumpfee},
1147 [ + - ]: 14 : {"wallet", &createwallet},
1148 [ + - ]: 14 : {"wallet", &createwalletdescriptor},
1149 [ + - ]: 14 : {"wallet", &derivehdkey},
1150 [ + - ]: 14 : {"wallet", &restorewallet},
1151 [ + - ]: 14 : {"wallet", &encryptwallet},
1152 [ + - ]: 14 : {"wallet", &exportwatchonlywallet},
1153 [ + - ]: 14 : {"wallet", &getaddressesbylabel},
1154 [ + - ]: 14 : {"wallet", &getaddressinfo},
1155 [ + - ]: 14 : {"wallet", &getbalance},
1156 [ + - ]: 14 : {"wallet", &gethdkeys},
1157 [ + - ]: 14 : {"wallet", &getnewaddress},
1158 [ + - ]: 14 : {"wallet", &getrawchangeaddress},
1159 [ + - ]: 14 : {"wallet", &getreceivedbyaddress},
1160 [ + - ]: 14 : {"wallet", &getreceivedbylabel},
1161 [ + - ]: 14 : {"wallet", &gettransaction},
1162 [ + - ]: 14 : {"wallet", &getbalances},
1163 [ + - ]: 14 : {"wallet", &getwalletinfo},
1164 [ + - ]: 14 : {"wallet", &importdescriptors},
1165 [ + - ]: 14 : {"wallet", &importprunedfunds},
1166 [ + - ]: 14 : {"wallet", &keypoolrefill},
1167 [ + - ]: 14 : {"wallet", &listaddressgroupings},
1168 [ + - ]: 14 : {"wallet", &listdescriptors},
1169 [ + - ]: 14 : {"wallet", &listlabels},
1170 [ + - ]: 14 : {"wallet", &listlockunspent},
1171 [ + - ]: 14 : {"wallet", &listreceivedbyaddress},
1172 [ + - ]: 14 : {"wallet", &listreceivedbylabel},
1173 [ + - ]: 14 : {"wallet", &listsinceblock},
1174 [ + - ]: 14 : {"wallet", &listtransactions},
1175 [ + - ]: 14 : {"wallet", &listunspent},
1176 [ + - ]: 14 : {"wallet", &listwalletdir},
1177 [ + - ]: 14 : {"wallet", &listwallets},
1178 [ + - ]: 14 : {"wallet", &loadwallet},
1179 [ + - ]: 14 : {"wallet", &lockunspent},
1180 [ + - ]: 14 : {"wallet", &migratewallet},
1181 [ + - ]: 14 : {"wallet", &removeprunedfunds},
1182 [ + - ]: 14 : {"wallet", &rescanblockchain},
1183 [ + - ]: 14 : {"wallet", &send},
1184 [ + - ]: 14 : {"wallet", &sendmany},
1185 [ + - ]: 14 : {"wallet", &sendtoaddress},
1186 [ + - ]: 14 : {"wallet", &setlabel},
1187 [ + - ]: 14 : {"wallet", &setwalletflag},
1188 [ + - ]: 14 : {"wallet", &signmessage},
1189 [ + - ]: 14 : {"wallet", &signrawtransactionwithwallet},
1190 [ + - ]: 14 : {"wallet", &simulaterawtransaction},
1191 [ + - ]: 14 : {"wallet", &sendall},
1192 [ + - ]: 14 : {"wallet", &unloadwallet},
1193 [ + - ]: 14 : {"wallet", &walletcreatefundedpsbt},
1194 : : #ifdef ENABLE_EXTERNAL_SIGNER
1195 [ + - ]: 14 : {"wallet", &walletdisplayaddress},
1196 : : #endif // ENABLE_EXTERNAL_SIGNER
1197 [ + - ]: 14 : {"wallet", &walletlock},
1198 [ + - ]: 14 : {"wallet", &walletpassphrase},
1199 [ + - ]: 14 : {"wallet", &walletpassphrasechange},
1200 [ + - ]: 14 : {"wallet", &walletprocesspsbt},
1201 [ + + + - : 431 : };
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - -
- ]
1202 : 18 : return commands;
1203 : : }
1204 : : } // namespace wallet
|