10 #include <validation.h> 23 explicit DB(
size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
30 bool WriteTxs(
const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
34 BaseIndex::
DB(
gArgs.GetDataDirNet() /
"indexes" /
"txindex", n_cache_size, f_memory, f_wipe)
39 return Read(std::make_pair(
DB_TXINDEX, txid), pos);
45 for (
const auto& tuple : v_pos) {
48 return WriteBatch(batch);
51 TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain,
size_t n_cache_size,
bool f_memory,
bool f_wipe)
60 if (block.
height == 0)
return true;
64 std::vector<std::pair<uint256, CDiskTxPos>> vPos;
65 vPos.reserve(block.
data->
vtx.size());
66 for (
const auto& tx : block.
data->
vtx) {
67 vPos.emplace_back(tx->GetHash(), pos);
70 return m_db->WriteTxs(vPos);
78 if (!
m_db->ReadTxPos(tx_hash, postx)) {
84 return error(
"%s: OpenBlockFile failed", __func__);
90 return error(
"%s: fseek(...) failed", __func__);
93 }
catch (
const std::exception& e) {
94 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
96 if (tx->GetHash() != tx_hash) {
97 return error(
"%s: txid mismatch", __func__);
std::shared_ptr< const CTransaction > CTransactionRef
constexpr uint8_t DB_TXINDEX
Batch of changes queued to be written to a CDBWrapper.
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
unsigned int GetSizeOfCompactSize(uint64_t nSize)
Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 ...
const std::unique_ptr< DB > m_db
Access to the txindex database (indexes/txindex/)
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given hash.
size_t GetSerializeSize(const T &t, int nVersion=0)
The database stores a block locator of the chain the database is synced to so that the index can effi...
Block data sent with blockConnected, blockDisconnected notifications.
Base class for indices of blockchain data.
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
void Write(const K &key, const V &value)
BaseIndex::DB & GetDB() const override
virtual ~TxIndex() override
std::vector< CTransactionRef > vtx
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
bool WriteTxs(const std::vector< std::pair< uint256, CDiskTxPos >> &v_pos)
Write a batch of transaction positions to the DB.
DB(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
TxIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
bool error(const char *fmt, const Args &... args)
TxIndex is used to look up transactions included in the blockchain by hash.
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.