| 461 | } |
| 462 | |
| 463 | std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetCandidateScriptPubKeys() const |
| 464 | { |
| 465 | LOCK(cs_KeyStore); |
| 466 | std::unordered_set<CScript, SaltedSipHasher> candidate_spks; |
| 467 | |
| 468 | // For every private key in the wallet, there should be a P2PK, P2PKH, P2WPKH, and P2SH-P2WPKH |
| 469 | const auto& add_pubkey = [&candidate_spks](const CPubKey& pub) -> void { |
| 470 | candidate_spks.insert(GetScriptForRawPubKey(pub)); |
| 471 | candidate_spks.insert(GetScriptForDestination(PKHash(pub))); |
| 472 | |
| 473 | CScript wpkh = GetScriptForDestination(WitnessV0KeyHash(pub)); |
| 474 | candidate_spks.insert(wpkh); |
| 475 | candidate_spks.insert(GetScriptForDestination(ScriptHash(wpkh))); |
| 476 | }; |
| 477 | for (const auto& [_, key] : mapKeys) { |
| 478 | add_pubkey(key.GetPubKey()); |
| 479 | } |
| 480 | for (const auto& [_, ckeypair] : mapCryptedKeys) { |
| 481 | add_pubkey(ckeypair.first); |
| 482 | } |
| 483 | |
| 484 | // mapScripts contains all redeemScripts and witnessScripts. Therefore each script in it has |
| 485 | // itself, P2SH, P2WSH, and P2SH-P2WSH as a candidate. |
| 486 | // Invalid scripts such as P2SH-P2SH and P2WSH-P2SH, among others, will be added as candidates. |
| 487 | // Callers of this function will need to remove such scripts. |
| 488 | const auto& add_script = [&candidate_spks](const CScript& script) -> void { |
| 489 | candidate_spks.insert(script); |
| 490 | candidate_spks.insert(GetScriptForDestination(ScriptHash(script))); |
| 491 | |
| 492 | CScript wsh = GetScriptForDestination(WitnessV0ScriptHash(script)); |
| 493 | candidate_spks.insert(wsh); |
| 494 | candidate_spks.insert(GetScriptForDestination(ScriptHash(wsh))); |
| 495 | }; |
| 496 | for (const auto& [_, script] : mapScripts) { |
| 497 | add_script(script); |
| 498 | } |
| 499 | |
| 500 | // Although setWatchOnly should only contain output scripts, we will also include each script's |
| 501 | // P2SH, P2WSH, and P2SH-P2WSH as a precaution. |
| 502 | for (const auto& script : setWatchOnly) { |
| 503 | add_script(script); |
| 504 | } |
| 505 | |
| 506 | return candidate_spks; |
| 507 | } |
| 508 | |
| 509 | std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetScriptPubKeys() const |
| 510 | { |
nothing calls this directly
no test coverage detected