diff options
| author | Bitflash <admin@bitflash.network> | 2026-08-14 09:39:24 -0300 |
|---|---|---|
| committer | Bitflash <admin@bitflash.network> | 2026-08-14 09:39:24 -0300 |
| commit | 636644d0102689f61ec488dde62cd53e4835b8f1 (patch) | |
| tree | 1ca90f11685b47aaa6a36e3677d0a3dfed072136 /src/db.cpp | |
| parent | cf597ca37aec53b0dd7016399fee73e1959dc604 (diff) | |
| parent | 95bd9cbcb1d17f4bc6223e6bfe3a92bfb8c3067d (diff) | |
Merge pull request 'wallet: add read-only record scan boundary' (#40) from wallet-store-read-abstraction into main
Diffstat (limited to 'src/db.cpp')
| -rw-r--r-- | src/db.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
| @@ -932,6 +932,45 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet) | |||
| 932 | return true; | 932 | return true; |
| 933 | } | 933 | } |
| 934 | 934 | ||
| 935 | bool ScanWalletRecords(CWalletRecordVisitor& visitor, string& strErrorRet) | ||
| 936 | { | ||
| 937 | class CWalletScanDB : public CWalletDB | ||
| 938 | { | ||
| 939 | public: | ||
| 940 | CWalletScanDB() : CWalletDB("r") { } | ||
| 941 | using CDB::GetCursor; | ||
| 942 | using CDB::ReadAtCursor; | ||
| 943 | }; | ||
| 944 | |||
| 945 | strErrorRet.clear(); | ||
| 946 | CWalletScanDB dbWallet; | ||
| 947 | Dbc* pcursor = dbWallet.GetCursor(); | ||
| 948 | if (!pcursor) | ||
| 949 | { | ||
| 950 | strErrorRet = "could not open a wallet cursor"; | ||
| 951 | return false; | ||
| 952 | } | ||
| 953 | CAutoCursor cursorGuard(pcursor); | ||
| 954 | |||
| 955 | loop | ||
| 956 | { | ||
| 957 | CDataStream ssKey(SER_DISK); | ||
| 958 | CDataStream ssValue(SER_DISK); | ||
| 959 | int ret = dbWallet.ReadAtCursor(pcursor, ssKey, ssValue); | ||
| 960 | if (ret == DB_NOTFOUND) | ||
| 961 | break; | ||
| 962 | if (ret != 0) | ||
| 963 | { | ||
| 964 | strErrorRet = strprintf("could not read wallet record: Berkeley DB error %d", ret); | ||
| 965 | return false; | ||
| 966 | } | ||
| 967 | if (!visitor.VisitWalletRecord(ssKey, ssValue, strErrorRet)) | ||
| 968 | return false; | ||
| 969 | } | ||
| 970 | |||
| 971 | return true; | ||
| 972 | } | ||
| 973 | |||
| 935 | bool LoadWallet() | 974 | bool LoadWallet() |
| 936 | { | 975 | { |
| 937 | vector<unsigned char> vchDefaultKey; | 976 | vector<unsigned char> vchDefaultKey; |