MCPcopy Create free account
hub / github.com/ElementsProject/elements / importaddress

Function importaddress

src/wallet/rpc/backup.cpp:216–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216RPCHelpMan importaddress()
217{
218 return RPCHelpMan{"importaddress",
219 "\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
220 "\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
221 "may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
222 "If you have the full public key, you should call importpubkey instead of this.\n"
223 "Hint: use importmulti to import more than one address.\n"
224 "\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
225 "as change, and not show up in many RPCs.\n"
226 "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
227 {
228 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The Bitcoin address (or hex-encoded script)"},
229 {"label", RPCArg::Type::STR, RPCArg::Default{""}, "An optional label"},
230 {"rescan", RPCArg::Type::BOOL, RPCArg::Default{true}, "Rescan the wallet for transactions"},
231 {"p2sh", RPCArg::Type::BOOL, RPCArg::Default{false}, "Add the P2SH version of the script as well"},
232 },
233 RPCResult{RPCResult::Type::NONE, "", ""},
234 RPCExamples{
235 "\nImport an address with rescan\n"
236 + HelpExampleCli("importaddress", "\"myaddress\"") +
237 "\nImport using a label without rescan\n"
238 + HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
239 "\nAs a JSON-RPC call\n"
240 + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
241 },
242 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
243{
244 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
245 if (!pwallet) return NullUniValue;
246
247 EnsureLegacyScriptPubKeyMan(*pwallet, true);
248
249 std::string strLabel;
250 if (!request.params[1].isNull())
251 strLabel = request.params[1].get_str();
252
253 // Whether to perform rescan after import
254 bool fRescan = true;
255 if (!request.params[2].isNull())
256 fRescan = request.params[2].get_bool();
257
258 if (fRescan && pwallet->chain().havePruned()) {
259 // Exit early and print an error.
260 // If a block is pruned after this check, we will import the key(s),
261 // but fail the rescan with a generic error.
262 throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled when blocks are pruned");
263 }
264
265 WalletRescanReserver reserver(*pwallet);
266 if (fRescan && !reserver.reserve()) {
267 throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
268 }
269
270 // Whether to import a p2sh version, too
271 bool fP2SH = false;
272 if (!request.params[3].isNull())
273 fP2SH = request.params[3].get_bool();

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
GetScriptForDestinationFunction · 0.85
IsHexFunction · 0.85
ParseHexFunction · 0.85
ScriptHashClass · 0.85
RescanWalletFunction · 0.85

Tested by

no test coverage detected