diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-14 09:08:29 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-14 09:08:29 -0300 |
| commit | 95bd9cbcb1d17f4bc6223e6bfe3a92bfb8c3067d (patch) | |
| tree | 1ca90f11685b47aaa6a36e3677d0a3dfed072136 /src/walletcmd.cpp | |
| parent | cf597ca37aec53b0dd7016399fee73e1959dc604 (diff) | |
wallet: add read-only record scan boundary
Diffstat (limited to 'src/walletcmd.cpp')
| -rw-r--r-- | src/walletcmd.cpp | 63 |
1 files changed, 25 insertions, 38 deletions
diff --git a/src/walletcmd.cpp b/src/walletcmd.cpp index ce0da02..71f1ec3 100644 --- a/src/walletcmd.cpp +++ b/src/walletcmd.cpp | |||
| @@ -553,51 +553,38 @@ static void CountWalletStorageType(const std::string& strType, | |||
| 553 | static bool ReadWalletStorageCounts(WalletStorageAuditCounts& counts, | 553 | static bool ReadWalletStorageCounts(WalletStorageAuditCounts& counts, |
| 554 | std::string& strError) | 554 | std::string& strError) |
| 555 | { | 555 | { |
| 556 | class CWalletAuditDB : public CWalletDB | 556 | class CWalletStorageCountVisitor : public CWalletRecordVisitor |
| 557 | { | 557 | { |
| 558 | public: | 558 | public: |
| 559 | CWalletAuditDB() : CWalletDB("r") { } | 559 | WalletStorageAuditCounts& counts; |
| 560 | using CDB::GetCursor; | ||
| 561 | using CDB::ReadAtCursor; | ||
| 562 | }; | ||
| 563 | |||
| 564 | CWalletAuditDB walletdb; | ||
| 565 | Dbc* pcursor = walletdb.GetCursor(); | ||
| 566 | if (!pcursor) | ||
| 567 | { | ||
| 568 | strError = "cannot open wallet.dat cursor"; | ||
| 569 | return false; | ||
| 570 | } | ||
| 571 | 560 | ||
| 572 | for (;;) | 561 | explicit CWalletStorageCountVisitor(WalletStorageAuditCounts& countsIn) |
| 573 | { | 562 | : counts(countsIn) { } |
| 574 | CDataStream ssKey(SER_DISK); | ||
| 575 | CDataStream ssValue(SER_DISK); | ||
| 576 | int ret = walletdb.ReadAtCursor(pcursor, ssKey, ssValue); | ||
| 577 | if (ret == DB_NOTFOUND) | ||
| 578 | break; | ||
| 579 | if (ret != 0) | ||
| 580 | { | ||
| 581 | pcursor->close(); | ||
| 582 | strError = strprintf("Berkeley DB cursor read failed (%d)", ret); | ||
| 583 | return false; | ||
| 584 | } | ||
| 585 | 563 | ||
| 586 | counts.nTotal++; | 564 | bool VisitWalletRecord(const CDataStream& ssKeyIn, |
| 587 | try | 565 | const CDataStream& ssValue, |
| 566 | std::string& strErrorRet) | ||
| 588 | { | 567 | { |
| 589 | std::string strType; | 568 | (void)ssValue; |
| 590 | ssKey >> strType; | 569 | (void)strErrorRet; |
| 591 | CountWalletStorageType(strType, counts); | 570 | counts.nTotal++; |
| 592 | } | 571 | try |
| 593 | catch (...) | 572 | { |
| 594 | { | 573 | CDataStream ssKey = ssKeyIn; |
| 595 | counts.nMalformed++; | 574 | std::string strType; |
| 575 | ssKey >> strType; | ||
| 576 | CountWalletStorageType(strType, counts); | ||
| 577 | } | ||
| 578 | catch (...) | ||
| 579 | { | ||
| 580 | counts.nMalformed++; | ||
| 581 | } | ||
| 582 | return true; | ||
| 596 | } | 583 | } |
| 597 | } | 584 | }; |
| 598 | 585 | ||
| 599 | pcursor->close(); | 586 | CWalletStorageCountVisitor visitor(counts); |
| 600 | return true; | 587 | return ScanWalletRecords(visitor, strError); |
| 601 | } | 588 | } |
| 602 | 589 | ||
| 603 | static std::string WalletStorageAuditJson(const WalletStorageAuditCounts& counts) | 590 | static std::string WalletStorageAuditJson(const WalletStorageAuditCounts& counts) |