Bitcoin Core 30.99.0
P2P Digital Currency
txospenderindex.h
Go to the documentation of this file.
1
2// Copyright (c) The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_INDEX_TXOSPENDERINDEX_H
7#define BITCOIN_INDEX_TXOSPENDERINDEX_H
8
9#include <index/base.h>
10#include <interfaces/chain.h>
12#include <uint256.h>
13#include <util/expected.h>
14
15#include <cstddef>
16#include <cstdint>
17#include <memory>
18#include <optional>
19#include <string>
20#include <utility>
21#include <vector>
22
23struct CDiskTxPos;
24
25static constexpr bool DEFAULT_TXOSPENDERINDEX{false};
26
27struct TxoSpender {
30};
31
37class TxoSpenderIndex final : public BaseIndex
38{
39private:
40 std::unique_ptr<BaseIndex::DB> m_db;
41 std::pair<uint64_t, uint64_t> m_siphash_key;
42 bool AllowPrune() const override { return false; }
43 void WriteSpenderInfos(const std::vector<std::pair<COutPoint, CDiskTxPos>>& items);
44 void EraseSpenderInfos(const std::vector<std::pair<COutPoint, CDiskTxPos>>& items);
46
47protected:
49
50 bool CustomAppend(const interfaces::BlockInfo& block) override;
51
52 bool CustomRemove(const interfaces::BlockInfo& block) override;
53
54 BaseIndex::DB& GetDB() const override;
55
56public:
57 explicit TxoSpenderIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
58
60};
61
63extern std::unique_ptr<TxoSpenderIndex> g_txospenderindex;
64
65
66#endif // BITCOIN_INDEX_TXOSPENDERINDEX_H
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:65
Base class for indices of blockchain data.
Definition: base.h:55
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
TxoSpenderIndex is used to look up which transaction spent a given output.
void EraseSpenderInfos(const std::vector< std::pair< COutPoint, CDiskTxPos > > &items)
std::pair< uint64_t, uint64_t > m_siphash_key
TxoSpenderIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
bool AllowPrune() const override
std::unique_ptr< BaseIndex::DB > m_db
bool CustomRemove(const interfaces::BlockInfo &block) override
Rewind index by one block during a chain reorg.
util::Expected< TxoSpender, std::string > ReadTransaction(const CDiskTxPos &pos) const
util::Expected< std::optional< TxoSpender >, std::string > FindSpender(const COutPoint &txo) const
interfaces::Chain::NotifyOptions CustomOptions() override
Return custom notification options for index.
void WriteSpenderInfos(const std::vector< std::pair< COutPoint, CDiskTxPos > > &items)
BaseIndex::DB & GetDB() const override
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
256-bit opaque blob.
Definition: uint256.h:195
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition: expected.h:45
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
uint256 block_hash
CTransactionRef tx
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:19
Options specifying which chain notifications are required.
Definition: chain.h:319
static constexpr bool DEFAULT_TXOSPENDERINDEX
std::unique_ptr< TxoSpenderIndex > g_txospenderindex
The global txo spender index. May be null.