12#include <validation.h>
29 bool WriteTxs(
const std::vector<std::pair<TxId, CDiskTxPos>> &
v_pos);
37 return Read(std::make_pair(
DB_TXINDEX, txid), pos);
41 const std::vector<std::pair<TxId, CDiskTxPos>> &
v_pos) {
46 return WriteBatch(batch);
62 std::vector<std::pair<TxId, CDiskTxPos>>
vPos;
64 for (
const auto &tx : block.
vtx) {
65 vPos.emplace_back(tx->GetId(), pos);
94 }
catch (
const std::exception &
e) {
95 return error(
"%s: Deserialize or I/O error - %s",
__func__,
e.what());
97 if (tx->GetId() != txid) {
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 TxIndex can ef...
Base class for indices of blockchain data.
Chainstate * m_chainstate
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
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< TxId, CDiskTxPos > > &v_pos)
Write a batch of transaction positions to the DB.
bool ReadTxPos(const TxId &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given ID.
TxIndex is used to look up transactions included in the blockchain by ID.
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 TxId &txid, BlockHash &block_hash, CTransactionRef &tx) const
Look up a transaction by identifier.
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
bool IsBlockPruned(const CBlockIndex *pblockindex) EXCLUSIVE_LOCKS_REQUIRED(void UpdatePruneLock(const std::string &name, const PruneLockInfo &lock_info) EXCLUSIVE_LOCKS_REQUIRED(FILE OpenBlockFile)(const FlatFilePos &pos, bool fReadOnly=false) const
Check whether the block associated with this index entry is pruned or not.
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
bool error(const char *fmt, const Args &...args)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
uint32_t 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)
A BlockHash is a unqiue identifier for a block.
A TxId is the identifier of a transaction.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
constexpr uint8_t DB_TXINDEX