7 #include <chainparams.h> 18 #include <validation.h> 25 "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 26 "\nNOTE: By default this function only works sometimes. This is when there is an\n" 27 "unspent output in the utxo for this transaction. To make it always work,\n" 28 "you need to maintain a transaction index, using the -txindex command line option or\n" 29 "specify the block in which the transaction is included manually (by blockhash).\n",
44 std::set<uint256> setTxids;
49 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
59 if (!request.params[1].isNull()) {
61 hashBlock =
ParseHashV(request.params[1],
"blockhash");
71 for (
const auto& tx : setTxids) {
83 g_txindex->BlockUntilSyncedToCurrentChain();
86 if (pblockindex ==
nullptr) {
88 if (!tx || hashBlock.
IsNull()) {
104 unsigned int ntxFound = 0;
105 for (
const auto& tx : block.
vtx) {
106 if (setTxids.count(tx->GetHash())) {
110 if (ntxFound != setTxids.size()) {
117 std::string strHex =
HexStr(ssMB);
126 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 127 "and throwing an RPC error if the block is not in our best chain\n",
134 {
RPCResult::Type::STR_HEX,
"txid",
"The txid(s) which the proof commits to, or empty array if the proof cannot be validated."},
146 std::vector<uint256> vMatch;
147 std::vector<unsigned int> vIndex;
148 if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
160 if (pindex->
nTx == merkleBlock.txn.GetNumTransactions()) {
161 for (
const uint256& hash : vMatch) {
177 for (
const auto& c : commands) {
178 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()
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())
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.
void RegisterTxoutProofRPCCommands(CRPCTable &t)
const UniValue & get_array() const
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
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.
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.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
constexpr bool IsNull() const
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
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 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...
unsigned int nTx
Number of transactions in this block.
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...