MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / importaddress

Function importaddress

src/wallet/rpcdump.cpp:254–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254UniValue importaddress(const JSONRPCRequest& request)
255{
256 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
257 CWallet* const pwallet = wallet.get();
258 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
259 return NullUniValue;
260 }
261
262 if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
263 throw std::runtime_error(
264 "importaddress \"address\" ( \"label\" rescan p2sh )\n"
265 "\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"
266 "\nArguments:\n"
267 "1. \"address\" (string, required) The Bitcoin address (or hex-encoded script)\n"
268 "2. \"label\" (string, optional, default=\"\") An optional label\n"
269 "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
270 "4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well\n"
271 "\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
272 "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"
273 "If you have the full public key, you should call importpubkey instead of this.\n"
274 "\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
275 "as change, and not show up in many RPCs.\n"
276 "\nExamples:\n"
277 "\nImport an address with rescan\n"
278 + HelpExampleCli("importaddress", "\"myaddress\"") +
279 "\nImport using a label without rescan\n"
280 + HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
281 "\nAs a JSON-RPC call\n"
282 + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
283 );
284
285
286 std::string strLabel;
287 if (!request.params[1].isNull())
288 strLabel = request.params[1].get_str();
289
290 // Whether to perform rescan after import
291 bool fRescan = true;
292 if (!request.params[2].isNull())
293 fRescan = request.params[2].get_bool();
294
295 if (fRescan && fPruneMode)
296 throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled in pruned mode");
297
298 WalletRescanReserver reserver(pwallet);
299 if (fRescan && !reserver.reserve()) {
300 throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
301 }
302
303 // Whether to import a p2sh version, too
304 bool fP2SH = false;
305 if (!request.params[3].isNull())
306 fP2SH = request.params[3].get_bool();
307
308 {
309 LOCK2(cs_main, pwallet->cs_wallet);
310
311 CTxDestination dest = DecodeDestination(request.params[0].get_str());

Callers

nothing calls this directly

Calls 15

EnsureWalletIsAvailableFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
IsHexFunction · 0.85
ParseHexFunction · 0.85
RescanWalletFunction · 0.85
getMethod · 0.80
isNullMethod · 0.80

Tested by

no test coverage detected