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