diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-12 14:44:43 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-12 14:44:43 -0300 |
| commit | a109dcd23fd387324e63f265a237723ba1d6c4fa (patch) | |
| tree | badb646bd1113bc21f2078dd7c427dae06ffa992 /src/selftest.cpp | |
| parent | bc3de301d9ed0e5fb5e2034be2e066d77cf23804 (diff) | |
wallet: collapse restored legacy hdnext
Diffstat (limited to 'src/selftest.cpp')
| -rw-r--r-- | src/selftest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp index cca5335..bcbf9d3 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp | |||
| @@ -586,6 +586,34 @@ static int RunWalletHDSelfTest() | |||
| 586 | "the recovery audit finds wallet.dat-only immature mining rewards") ? 0 : 1; | 586 | "the recovery audit finds wallet.dat-only immature mining rewards") ? 0 : 1; |
| 587 | nFail += Check(audit.nLegacyImmatureTx == 1, | 587 | nFail += Check(audit.nLegacyImmatureTx == 1, |
| 588 | "the recovery audit counts wallet.dat-only immature mining rewards") ? 0 : 1; | 588 | "the recovery audit counts wallet.dat-only immature mining rewards") ? 0 : 1; |
| 589 | |||
| 590 | CKey keyLegacyHD11; | ||
| 591 | nSchemaForLegacyAudit = nHDKeySchema; | ||
| 592 | nHDKeySchema = HD_SCHEMA_LEGACY; | ||
| 593 | if (!DeriveHDKey(11, keyLegacyHD11, strError)) | ||
| 594 | throw std::runtime_error("legacy compatibility index 11 derivation failed: " + strError); | ||
| 595 | nHDKeySchema = nSchemaForLegacyAudit; | ||
| 596 | if (!AddKey(keyLegacyHD11)) | ||
| 597 | throw std::runtime_error("could not store the legacy compatibility index 11 key"); | ||
| 598 | |||
| 599 | std::map<unsigned int, std::vector<unsigned char> > mapLegacyProbe; | ||
| 600 | mapLegacyProbe[0] = keyAuditLegacyHD.GetPubKey(); | ||
| 601 | mapLegacyProbe[11] = keyLegacyHD11.GetPubKey(); | ||
| 602 | |||
| 603 | CWalletTx wtxLegacyHD11; | ||
| 604 | wtxLegacyHD11.vout.push_back(CTxOut(19 * COIN, CScript() << keyLegacyHD11.GetPubKey() << OP_CHECKSIG)); | ||
| 605 | CRITICAL_BLOCK(cs_mapWallet) | ||
| 606 | { | ||
| 607 | mapWallet.clear(); | ||
| 608 | mapWallet[wtxLegacyHD11.GetHash()] = wtxLegacyHD11; | ||
| 609 | } | ||
| 610 | nFail += Check(WalletLastUsedPubKeyIndexNext(mapLegacyProbe) == 12, | ||
| 611 | "restore collapses legacy hdnext to the last used compatibility index plus one") ? 0 : 1; | ||
| 612 | |||
| 613 | CRITICAL_BLOCK(cs_mapWallet) | ||
| 614 | mapWallet.clear(); | ||
| 615 | nFail += Check(WalletLastUsedPubKeyIndexNext(mapLegacyProbe) == 0, | ||
| 616 | "restore does not persist legacy hdnext at the scan depth when no compatibility key was used") ? 0 : 1; | ||
| 589 | } | 617 | } |
| 590 | catch (const std::exception& e) | 618 | catch (const std::exception& e) |
| 591 | { | 619 | { |