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__);
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
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.
std::vector< CTransactionRef > vtx
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/)
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)
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.
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
BaseIndex::DB & GetDB() const override
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
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.
virtual ~TxIndex() override
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.
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
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)
Block data sent with blockConnected, blockDisconnected notifications.
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