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

Method MarkUnusedAddresses

src/wallet/scriptpubkeyman.cpp:350–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350std::vector<WalletDestination> LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
351{
352 LOCK(cs_KeyStore);
353 std::vector<WalletDestination> result;
354 // extract addresses and check if they match with an unused keypool key
355 for (const auto& keyid : GetAffectedKeys(script, *this)) {
356 std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
357 if (mi != m_pool_key_to_index.end()) {
358 WalletLogPrintf("%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__);
359 for (const auto& keypool : MarkReserveKeysAsUsed(mi->second)) {
360 // derive all possible destinations as any of them could have been used
361 for (const auto& type : LEGACY_OUTPUT_TYPES) {
362 const auto& dest = GetDestinationForKey(keypool.vchPubKey, type);
363 result.push_back({dest, keypool.fInternal});
364 }
365 }
366
367 if (!TopUp()) {
368 WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__);
369 }
370 }
371
372 // Find the key's metadata and check if it's seed id (if it has one) is inactive, i.e. it is not the current m_hd_chain seed id.
373 // If so, TopUp the inactive hd chain
374 auto it = mapKeyMetadata.find(keyid);
375 if (it != mapKeyMetadata.end()){
376 CKeyMetadata meta = it->second;
377 if (!meta.hd_seed_id.IsNull() && meta.hd_seed_id != m_hd_chain.seed_id) {
378 std::vector<uint32_t> path;
379 if (meta.has_key_origin) {
380 path = meta.key_origin.path;
381 } else if (!ParseHDKeypath(meta.hdKeypath, path)) {
382 WalletLogPrintf("%s: Adding inactive seed keys failed, invalid hdKeypath: %s\n",
383 __func__,
384 meta.hdKeypath);
385 }
386 if (path.size() != 3) {
387 WalletLogPrintf("%s: Adding inactive seed keys failed, invalid path size: %d, has_key_origin: %s\n",
388 __func__,
389 path.size(),
390 meta.has_key_origin);
391 } else {
392 bool internal = (path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
393 int64_t index = path[2] & ~BIP32_HARDENED_KEY_LIMIT;
394
395 if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) {
396 WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__);
397 }
398 }
399 }
400 }
401 }
402
403 return result;
404}
405
406void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
407{

Callers 1

Calls 10

GetAffectedKeysFunction · 0.85
GetDestinationForKeyFunction · 0.85
ParseHDKeypathFunction · 0.85
ExtractDestinationFunction · 0.85
findMethod · 0.80
ExpandFromCacheMethod · 0.80
endMethod · 0.45
push_backMethod · 0.45
IsNullMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected