18 #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<uint256> 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) {
84 g_txindex->BlockUntilSyncedToCurrentChain();
89 if (pblockindex ==
nullptr) {
91 if (!tx || hashBlock.
IsNull()) {
105 unsigned int ntxFound = 0;
106 for (
const auto& tx : block.
vtx) {
107 if (setTxids.count(tx->GetHash())) {
111 if (ntxFound != setTxids.size()) {
118 std::string strHex =
HexStr(ssMB);
127 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 128 "and throwing an RPC error if the block is not in our best chain\n",
135 {
RPCResult::Type::STR_HEX,
"txid",
"The txid(s) which the proof commits to, or empty array if the proof cannot be validated."},
147 std::vector<uint256> vMatch;
148 std::vector<unsigned int> vIndex;
149 if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
161 if (pindex->
nTx == merkleBlock.txn.GetNumTransactions()) {
162 for (
const uint256& hash : vMatch) {
178 for (
const auto& c : commands) {
179 t.appendCommand(c.name, &c);
std::shared_ptr< const CTransaction > CTransactionRef
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
bool IsSpent() const
Either this coin never existed (see e.g.
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
void push_back(UniValue val)
static RPCHelpMan gettxoutproof()
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
void RegisterTxoutProofRPCCommands(CRPCTable &t)
const UniValue & get_array() const
Double ended buffer combining vector and stream-like interfaces.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, const Consensus::Params &consensusParams, uint256 &hashBlock)
Return transaction with a given hash.
CChain m_chain
The current chain of blockheaders we consult and build on.
Invalid, missing or duplicate parameter.
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Special type that is a STR with only hex chars.
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
UniValue JSONRPCError(int code, const std::string &message)
Special string with only hex chars.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
const Consensus::Params & GetConsensus() const
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Optional arg that is a named argument and has a default value of null.
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Optional argument with default value omitted because they are implicitly clear.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root...
static const int PROTOCOL_VERSION
network protocol versioning
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Chainstate & ActiveChainstate() const
The most-work chain.
static RPCHelpMan verifytxoutproof()
ChainstateManager & EnsureAnyChainman(const std::any &context)
unsigned int nTx
Number of transactions in this block.