diff options
| author | Andrew Chow <[email protected]> | 2020-08-25 13:10:32 -0400 |
|---|---|---|
| committer | Andrew Chow <[email protected]> | 2020-08-25 13:23:40 -0400 |
| commit | 544e12a4e81633d222574eec253a1ff292d3c4a5 (patch) | |
| tree | d19b99594f9609df1370bdd95941f8d2a1d2a54d /src/wallet/walletdb.cpp | |
| parent | Merge #19601: Refactoring CHashWriter & Get{Prevouts,Sequence,Outputs}Hash to... (diff) | |
| download | discoin-544e12a4e81633d222574eec253a1ff292d3c4a5.tar.xz discoin-544e12a4e81633d222574eec253a1ff292d3c4a5.zip | |
walletdb: Add KeyFilterFn to ReadKeyValue
Add a KeyFilterFn callback to ReadKeyValue which allows the caller to
specify which types to actually deserialize. A KeyFilterFn takes the
type as the parameter and returns a bool indicating whether
deserialization should continue.
Diffstat (limited to 'src/wallet/walletdb.cpp')
| -rw-r--r-- | src/wallet/walletdb.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index fa6814d0d..4635c19b3 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -263,13 +263,17 @@ public: static bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, - CWalletScanState &wss, std::string& strType, std::string& strErr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) + CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { try { // Unserialize // Taking advantage of the fact that pair serialization // is just the two items serialized one after the other ssKey >> strType; + // If we have a filter, check if this matches the filter + if (filter_fn && !filter_fn(strType)) { + return true; + } if (strType == DBKeys::NAME) { std::string strAddress; ssKey >> strAddress; @@ -668,11 +672,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, return true; } -bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr) +bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn) { CWalletScanState dummy_wss; LOCK(pwallet->cs_wallet); - return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr); + return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr, filter_fn); } bool WalletBatch::IsKeyType(const std::string& strType) |