7#include <chainparams.h>
19#include <validation.h>
26 "Returns a hex-encoded proof that \"txid\" was included in a block.\n"
27 "\nNOTE: By default this function only works sometimes. "
28 "This is when there is an\n"
29 "unspent output in the utxo for this transaction. To make it always "
31 "you need to maintain a transaction index, using the -txindex command "
33 "specify the block in which the transaction is included manually (by "
40 "The txids to filter",
43 "A transaction hash"},
48 "If specified, looks for txid in the block with this hash"},
52 "A string that is a serialized, hex-encoded data for the proof."},
56 std::set<TxId> setTxIds;
59 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
62 if (setTxIds.count(txid)) {
65 std::string(
"Invalid parameter, duplicated txid: ") +
69 setTxIds.insert(txid);
77 if (!request.params[1].isNull()) {
91 for (
const auto &txid : setTxIds) {
105 g_txindex->BlockUntilSyncedToCurrentChain();
108 if (pblockindex ==
nullptr) {
111 nullptr, oneTxId, hashBlock,
113 if (!tx || hashBlock.
IsNull()) {
115 "Transaction not yet in block");
122 "Transaction index corrupt");
129 "Can't read block from disk");
132 unsigned int ntxFound = 0;
133 for (
const auto &tx : block.
vtx) {
134 if (setTxIds.count(tx->GetId())) {
139 if (ntxFound != setTxIds.size()) {
141 "Not all transactions found in specified or "
148 std::string strHex =
HexStr(ssMB);
157 "Verifies that a proof points to a transaction in a block, returning "
158 "the transaction it commits to\n"
159 "and throwing an RPC error if the block is not in our best chain\n",
162 "The hex-encoded proof generated by gettxoutproof"},
169 "The txid(s) which the proof commits to, or empty array "
170 "if the proof can not be validated."},
182 std::vector<uint256> vMatch;
183 std::vector<size_t> vIndex;
197 "Block not found in chain");
202 for (
const uint256 &hash : vMatch) {
219 for (
const auto &c : commands) {
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.
Double ended buffer combining vector and stream-like interfaces.
Used to create a Merkle proof (usually from a subset of transactions), which consists of a block head...
CBlockHeader header
Public only for unit testing.
uint32_t GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< size_t > &vnIndex)
Extract the matching txid's represented by this partial merkle tree and their respective indices with...
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
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(std::function< void(bilingual_str)> shutdown_fnc=[](bilingual_str msg) { AbortNode(msg.original, msg);}) 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...
uint32_t GetHeight() const
void push_back(UniValue val)
const std::string & get_str() const
const UniValue & get_array() const
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
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.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const TxId &txid, BlockHash &hashBlock, const BlockManager &blockman)
Return transaction with a given txid.
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< uint8_t > ParseHexV(const UniValue &v, std::string strName)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
ChainstateManager & EnsureAnyChainman(const std::any &context)
A BlockHash is a unqiue identifier for a block.
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED
The arg is optional for one of two reasons:
@ STR_HEX
Special string with only hex chars.
A TxId is the identifier of a transaction.
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()
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static const int PROTOCOL_VERSION
network protocol versioning