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

Method UpgradeKeyMetadata

src/wallet/scriptpubkeyman.cpp:406–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

404}
405
406void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
407{
408 LOCK(cs_KeyStore);
409 if (m_storage.IsLocked() || m_storage.IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA)) {
410 return;
411 }
412
413 std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(m_storage.GetDatabase());
414 for (auto& meta_pair : mapKeyMetadata) {
415 CKeyMetadata& meta = meta_pair.second;
416 if (!meta.hd_seed_id.IsNull() && !meta.has_key_origin && meta.hdKeypath != "s") { // If the hdKeypath is "s", that's the seed and it doesn't have a key origin
417 CKey key;
418 GetKey(meta.hd_seed_id, key);
419 CExtKey masterKey;
420 masterKey.SetSeed(key);
421 // Add to map
422 CKeyID master_id = masterKey.key.GetPubKey().GetID();
423 std::copy(master_id.begin(), master_id.begin() + 4, meta.key_origin.fingerprint);
424 if (!ParseHDKeypath(meta.hdKeypath, meta.key_origin.path)) {
425 throw std::runtime_error("Invalid stored hdKeypath");
426 }
427 meta.has_key_origin = true;
428 if (meta.nVersion < CKeyMetadata::VERSION_WITH_KEY_ORIGIN) {
429 meta.nVersion = CKeyMetadata::VERSION_WITH_KEY_ORIGIN;
430 }
431
432 // Write meta to wallet
433 CPubKey pubkey;
434 if (GetPubKey(meta_pair.first, pubkey)) {
435 batch->WriteKeyMetadata(meta, pubkey, true);
436 }
437 }
438 }
439}
440
441bool LegacyScriptPubKeyMan::SetupGeneration(bool force)
442{

Callers

nothing calls this directly

Calls 10

ParseHDKeypathFunction · 0.85
GetPubKeyFunction · 0.85
IsLockedMethod · 0.80
IsWalletFlagSetMethod · 0.80
WriteKeyMetadataMethod · 0.80
IsNullMethod · 0.45
SetSeedMethod · 0.45
GetIDMethod · 0.45
GetPubKeyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected