7 #include <chainparams.h> 19 #include <validation.h> 27 "Returns a hex-encoded proof that \"txid\" was included in a block.\n" 28 "\nNOTE: By default this function only works sometimes. This is when there is an\n" 29 "unspent output in the utxo for this transaction. To make it always work,\n" 30 "you need to maintain a transaction index, using the -txindex command line option or\n" 31 "specify the block in which the transaction is included manually (by blockhash).\n",
46 std::set<Txid> setTxids;
51 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
61 if (!request.params[1].isNull()) {
63 hashBlock =
ParseHashV(request.params[1],
"blockhash");
73 for (
const auto& tx : setTxids) {
75 if (!coin.IsSpent()) {
76 pblockindex = active_chainstate.
m_chain[coin.nHeight];
85 g_txindex->BlockUntilSyncedToCurrentChain();
88 if (pblockindex ==
nullptr) {
90 if (!tx || hashBlock.
IsNull()) {
110 unsigned int ntxFound = 0;
111 for (
const auto& tx : block.
vtx) {
112 if (setTxids.contains(tx->GetHash())) {
116 if (ntxFound != setTxids.size()) {
123 std::string strHex =
HexStr(ssMB);
133 "Verifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 134 "and throwing an RPC error if the block is not in our best chain\n",
141 {
RPCResult::Type::STR_HEX,
"txid",
"The txid(s) which the proof commits to, or empty array if the proof cannot be validated."},
152 std::vector<Txid> vMatch;
153 std::vector<unsigned int> vIndex;
167 for (
const auto& txid : vMatch) {
183 for (
const auto& c : commands) {
184 t.appendCommand(c.name, &c);
std::shared_ptr< const CTransaction > CTransactionRef
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
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()
CBlockHeader header
Public only for unit testing.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
void RegisterTxoutProofRPCCommands(CRPCTable &t)
const UniValue & get_array() const
CChain m_chain
The current chain of blockheaders we consult and build on.
Invalid, missing or duplicate parameter.
const Coin & AccessByTxid(const CCoinsViewCache &view, const Txid &txid)
Utility function to find any unspent output with a given txid.
Minimal stream for reading from an existing byte array by std::span.
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...
Double ended buffer combining vector and stream-like interfaces.
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.
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
constexpr bool IsNull() const
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const Txid &hash, const BlockManager &blockman, uint256 &hashBlock)
Return transaction with a given hash.
Optional argument for which the default value is omitted from help text for one of two reasons: ...
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root...
static transaction_identifier FromUint256(const uint256 &id)
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
uint256 ExtractMatches(std::vector< Txid > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
bool ReadBlock(CBlock &block, const FlatFilePos &pos, const std::optional< uint256 > &expected_hash) const
Functions for disk access for blocks.
void CheckBlockDataAvailability(BlockManager &blockman, const CBlockIndex &blockindex, bool check_for_undo)
Chainstate & ActiveChainstate() const
Alternatives to CurrentChainstate() used by older code to query latest chainstate information without...
static RPCHelpMan verifytxoutproof()
ChainstateManager & EnsureAnyChainman(const std::any &context)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
unsigned int nTx
Number of transactions in this block.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)