Skip to content

Commit 7fe537f

Browse files
committed
Implement CCoinsViewErrorCatcher::HaveCoin
1 parent a52ff61 commit 7fe537f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/coins.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
292292
return coinEmpty;
293293
}
294294

295-
bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
295+
template <typename Func>
296+
static bool ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
297+
{
296298
try {
297-
return CCoinsViewBacked::GetCoin(outpoint, coin);
299+
return func();
298300
} catch(const std::runtime_error& e) {
299-
for (const auto& f : m_err_callbacks) {
301+
for (const auto& f : err_callbacks) {
300302
f();
301303
}
302304
LogPrintf("Error reading from database: %s\n", e.what());
@@ -307,3 +309,11 @@ bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) cons
307309
std::abort();
308310
}
309311
}
312+
313+
bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
314+
return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::GetCoin(outpoint, coin); }, m_err_callbacks);
315+
}
316+
317+
bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint &outpoint) const {
318+
return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
319+
}

src/coins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class CCoinsViewErrorCatcher final : public CCoinsViewBacked
349349
}
350350

351351
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
352+
bool HaveCoin(const COutPoint &outpoint) const override;
352353

353354
private:
354355
/** A list of callbacks to execute upon leveldb read error. */

0 commit comments

Comments
 (0)