10#include <validation.h>
21 explicit DB(
size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
28 bool WriteTxs(
const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
32 BaseIndex::
DB(
gArgs.GetDataDirNet() /
"indexes" /
"txindex", n_cache_size, f_memory, f_wipe)
37 return Read(std::make_pair(
DB_TXINDEX, txid), pos);
43 for (
const auto& tuple : v_pos) {
46 return WriteBatch(batch);
50 :
m_db(std::make_unique<
TxIndex::
DB>(n_cache_size, f_memory, f_wipe))
58 if (pindex->
nHeight == 0)
return true;
61 std::vector<std::pair<uint256, CDiskTxPos>> vPos;
62 vPos.reserve(block.
vtx.size());
63 for (
const auto& tx : block.
vtx) {
64 vPos.emplace_back(tx->GetHash(), pos);
67 return m_db->WriteTxs(vPos);
75 if (!
m_db->ReadTxPos(tx_hash, postx)) {
81 return error(
"%s: OpenBlockFile failed", __func__);
87 return error(
"%s: fseek(...) failed", __func__);
90 }
catch (
const std::exception& e) {
91 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
93 if (tx->GetHash() != tx_hash) {
94 return error(
"%s: txid mismatch", __func__);
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
The database stores a block locator of the chain the database is synced to so that the index can effi...
Base class for indices of blockchain data.
Non-refcounted RAII wrapper for FILE*.
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
FlatFilePos GetBlockPos() const
int nHeight
height of the entry in the chain. The genesis block has height 0
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
Access to the txindex database (indexes/txindex/)
DB(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
bool WriteTxs(const std::vector< std::pair< uint256, CDiskTxPos > > &v_pos)
Write a batch of transaction positions to the DB.
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given hash.
TxIndex is used to look up transactions included in the blockchain by hash.
TxIndex(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
BaseIndex::DB & GetDB() const override
virtual ~TxIndex() override
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
const std::unique_ptr< DB > m_db
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
std::shared_ptr< const CTransaction > CTransactionRef
unsigned int GetSizeOfCompactSize(uint64_t nSize)
Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 byt...
size_t GetSerializeSize(const T &t, int nVersion=0)
bool error(const char *fmt, const Args &... args)
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
constexpr uint8_t DB_TXINDEX