 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
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);
60 if (pindex->
nHeight == 0)
return true;
65 std::vector<std::pair<uint256, CDiskTxPos>> vPos;
66 vPos.reserve(block.
vtx.size());
67 for (
const auto& tx : block.
vtx) {
68 vPos.emplace_back(tx->GetHash(), pos);
71 return m_db->WriteTxs(vPos);
79 if (!
m_db->ReadTxPos(tx_hash, postx)) {
85 return error(
"%s: OpenBlockFile failed", __func__);
91 return error(
"%s: fseek(...) failed", __func__);
94 }
catch (
const std::exception& e) {
95 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
97 if (tx->GetHash() != tx_hash) {
98 return error(
"%s: txid mismatch", __func__);
size_t GetSerializeSize(const T &t, int nVersion=0)
Access to the txindex database (indexes/txindex/)
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Batch of changes queued to be written to a CDBWrapper.
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
const std::unique_ptr< DB > m_db
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::shared_ptr< const CTransaction > CTransactionRef
Base class for indices of blockchain data.
void Write(const K &key, const V &value)
Non-refcounted RAII wrapper for FILE*.
virtual ~TxIndex() override
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given hash.
constexpr uint8_t DB_TXINDEX
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...
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
BaseIndex::DB & GetDB() const override
bool WriteTxs(const std::vector< std::pair< uint256, CDiskTxPos >> &v_pos)
Write a batch of transaction positions to the DB.
std::vector< CTransactionRef > vtx
DB(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
TxIndex is used to look up transactions included in the blockchain by hash.
The database stores a block locator of the chain the database is synced to so that the index can effi...
bool error(const char *fmt, const Args &... args)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
The block chain is a tree shaped structure starting with the genesis block at the root,...
TxIndex(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.