MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MigrateToDescriptor

Method MigrateToDescriptor

src/wallet/scriptpubkeyman.cpp:534–824  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
535{
536 LOCK(cs_KeyStore);
537 if (m_storage.IsLocked()) {
538 return std::nullopt;
539 }
540
541 MigrationData out;
542
543 std::unordered_set<CScript, SaltedSipHasher> spks{GetScriptPubKeys()};
544
545 // Get all key ids
546 std::set<CKeyID> keyids;
547 for (const auto& key_pair : mapKeys) {
548 keyids.insert(key_pair.first);
549 }
550 for (const auto& key_pair : mapCryptedKeys) {
551 keyids.insert(key_pair.first);
552 }
553
554 // Get key metadata and figure out which keys don't have a seed
555 // Note that we do not ignore the seeds themselves because they are considered IsMine!
556 for (auto keyid_it = keyids.begin(); keyid_it != keyids.end();) {
557 const CKeyID& keyid = *keyid_it;
558 const auto& it = mapKeyMetadata.find(keyid);
559 if (it != mapKeyMetadata.end()) {
560 const CKeyMetadata& meta = it->second;
561 if (meta.hdKeypath == "s" || meta.hdKeypath == "m") {
562 keyid_it++;
563 continue;
564 }
565 if (!meta.hd_seed_id.IsNull() && (m_hd_chain.seed_id == meta.hd_seed_id || m_inactive_hd_chains.contains(meta.hd_seed_id))) {
566 keyid_it = keyids.erase(keyid_it);
567 continue;
568 }
569 }
570 keyid_it++;
571 }
572
573 WalletBatch batch(m_storage.GetDatabase());
574 if (!batch.TxnBegin()) {
575 LogWarning("Error generating descriptors for migration, cannot initialize db transaction");
576 return std::nullopt;
577 }
578
579 // keyids is now all non-HD keys. Each key will have its own combo descriptor
580 for (const CKeyID& keyid : keyids) {
581 CKey key;
582 if (!GetKey(keyid, key)) {
583 assert(false);
584 }
585
586 // Get birthdate from key meta
587 uint64_t creation_time = 0;
588 const auto& it = mapKeyMetadata.find(keyid);
589 if (it != mapKeyMetadata.end()) {
590 creation_time = it->second.nCreateTime;
591 }

Callers 2

Calls 15

FormatHDKeypathFunction · 0.85
EncodeExtPubKeyFunction · 0.85
CScriptIDClass · 0.85
InferDescriptorFunction · 0.85
IsLockedMethod · 0.80
findMethod · 0.80
emplaceMethod · 0.80
NeuterMethod · 0.80
IsWalletFlagSetMethod · 0.80
IsPayToScriptHashMethod · 0.80
HexStrFunction · 0.50

Tested by

no test coverage detected