7#include <chainparams.h>
19#include <validation.h>
26 "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n"
27 "\nNOTE: By default this function only works sometimes. This is when there is an\n"
28 "unspent output in the utxo for this transaction. To make it always work,\n"
29 "you need to maintain a transaction index, using the -txindex command line option or\n"
30 "specify the block in which the transaction is included manually (by blockhash).\n",
45 std::set<Txid> setTxids;
50 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
60 if (!request.params[1].isNull()) {
62 hashBlock =
ParseHashV(request.params[1],
"blockhash");
72 for (
const auto& tx : setTxids) {
74 if (!coin.IsSpent()) {
75 pblockindex = active_chainstate.
m_chain[coin.nHeight];
84 g_txindex->BlockUntilSyncedToCurrentChain();
87 if (pblockindex ==
nullptr) {
89 if (!tx || hashBlock.
IsNull()) {
109 unsigned int ntxFound = 0;
110 for (
const auto& tx : block.
vtx) {
111 if (setTxids.count(tx->GetHash())) {
115 if (ntxFound != setTxids.size()) {
122 std::string strHex =
HexStr(ssMB);
131 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n"
132 "and throwing an RPC error if the block is not in our best chain\n",
139 {
RPCResult::Type::STR_HEX,
"txid",
"The txid(s) which the proof commits to, or empty array if the proof cannot be validated."},
151 std::vector<uint256> vMatch;
152 std::vector<unsigned int> vIndex;
166 for (
const uint256& hash : vMatch) {
182 for (
const auto& c : commands) {
183 t.appendCommand(c.name, &c);
void CheckBlockDataAvailability(BlockManager &blockman, const CBlockIndex &blockindex, bool check_for_undo)
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
unsigned int nTx
Number of transactions in this block.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
CBlockHeader header
Public only for unit testing.
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
Chainstate stores and provides an API to update our local knowledge of the current best chain.
CChain m_chain
The current chain of blockheaders we consult and build on.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(Chainstate ActiveChainstate)() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Double ended buffer combining vector and stream-like interfaces.
void push_back(UniValue val)
const UniValue & get_array() const
constexpr bool IsNull() const
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static transaction_identifier FromUint256(const uint256 &id)
const Coin & AccessByTxid(const CCoinsViewCache &view, const Txid &txid)
Utility function to find any unspent output with a given txid.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, uint256 &hashBlock, const BlockManager &blockman)
Return transaction with a given hash.
std::shared_ptr< const CTransaction > CTransactionRef
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
ChainstateManager & EnsureAnyChainman(const std::any &context)
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ STR_HEX
Special string with only hex chars.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
void RegisterTxoutProofRPCCommands(CRPCTable &t)
static RPCHelpMan gettxoutproof()
static RPCHelpMan verifytxoutproof()