Changeset View
Changeset View
Standalone View
Standalone View
src/coins.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_COINS_H | #ifndef BITCOIN_COINS_H | ||||
#define BITCOIN_COINS_H | #define BITCOIN_COINS_H | ||||
#include <compressor.h> | #include <compressor.h> | ||||
#include <crypto/siphash.h> | #include <crypto/siphash.h> | ||||
#include <memusage.h> | #include <memusage.h> | ||||
#include <primitives/blockhash.h> | #include <primitives/blockhash.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | |||||
#include <unordered_map> | #include <unordered_map> | ||||
/** | /** | ||||
* A UTXO entry. | * A UTXO entry. | ||||
* | * | ||||
* Serialized format: | * Serialized format: | ||||
* - VARINT((coinbase ? 1 : 0) | (height << 1)) | * - VARINT((coinbase ? 1 : 0) | (height << 1)) | ||||
* - the non-spent CTxOut (via CTxOutCompressor) | * - the non-spent CTxOut (via CTxOutCompressor) | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, | ||||
bool check = false); | bool check = false); | ||||
//! Utility function to find any unspent output with a given txid. | //! Utility function to find any unspent output with a given txid. | ||||
//! This function can be quite expensive because in the event of a transaction | //! This function can be quite expensive because in the event of a transaction | ||||
//! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK | //! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK | ||||
//! lookups to database, so it should be used with care. | //! lookups to database, so it should be used with care. | ||||
const Coin &AccessByTxid(const CCoinsViewCache &cache, const TxId &txid); | const Coin &AccessByTxid(const CCoinsViewCache &cache, const TxId &txid); | ||||
/** | |||||
* This is a minimally invasive approach to shutdown on LevelDB read errors from | |||||
* the chainstate, while keeping user interface out of the common library, which | |||||
* is shared between bitcoind, and bitcoin-qt and non-server tools. | |||||
* | |||||
* Writes do not need similar protection, as failure to write is handled by the | |||||
* caller. | |||||
*/ | |||||
class CCoinsViewErrorCatcher final : public CCoinsViewBacked { | |||||
public: | |||||
explicit CCoinsViewErrorCatcher(CCoinsView *view) | |||||
: CCoinsViewBacked(view) {} | |||||
void AddReadErrCallback(std::function<void()> f) { | |||||
m_err_callbacks.emplace_back(std::move(f)); | |||||
} | |||||
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override; | |||||
private: | |||||
/** | |||||
* A list of callbacks to execute upon leveldb read error. | |||||
*/ | |||||
std::vector<std::function<void()>> m_err_callbacks; | |||||
}; | |||||
#endif // BITCOIN_COINS_H | #endif // BITCOIN_COINS_H |