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. "
29 "This is when there is an\n"
30 "unspent output in the utxo for this transaction. To make it always "
32 "you need to maintain a transaction index, using the -txindex command "
34 "specify the block in which the transaction is included manually (by "
41 "The txids to filter",
44 "A transaction hash"},
49 "If specified, looks for txid in the block with this hash"},
53 "A string that is a serialized, hex-encoded data for the proof."},
57 std::set<TxId> setTxIds;
60 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
63 if (setTxIds.count(txid)) {
66 std::string(
"Invalid parameter, duplicated txid: ") +
70 setTxIds.insert(txid);
78 if (!request.params[1].isNull()) {
92 for (
const auto &txid : setTxIds) {
106 g_txindex->BlockUntilSyncedToCurrentChain();
110 config.GetChainParams().GetConsensus();
112 if (pblockindex ==
nullptr) {
115 nullptr, oneTxId,
Params().GetConsensus(),
117 if (!tx || hashBlock.
IsNull()) {
119 "Transaction not yet in block");
126 "Transaction index corrupt");
133 "Can't read block from disk");
136 unsigned int ntxFound = 0;
137 for (
const auto &tx : block.
vtx) {
138 if (setTxIds.count(tx->GetId())) {
143 if (ntxFound != setTxIds.size()) {
145 "Not all transactions found in specified or "
152 std::string strHex =
HexStr(ssMB);
161 "Verifies that a proof points to a transaction in a block, returning "
162 "the transaction it commits to\n"
163 "and throwing an RPC error if the block is not in our best chain\n",
166 "The hex-encoded proof generated by gettxoutproof"},
173 "The txid(s) which the proof commits to, or empty array "
174 "if the proof can not be validated."},
186 std::vector<uint256> vMatch;
187 std::vector<size_t> vIndex;
201 "Block not found in chain");
206 for (
const uint256 &hash : vMatch) {
223 for (
const auto &c : commands) {
RecursiveMutex cs_main
Global state.
const CChainParams & Params()
Return the currently selected parameters.
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...
Chainstate & ActiveChainstate() const
The most-work chain.
CChain & ActiveChain() const
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
uint32_t GetHeight() const
const std::string & get_str() const
bool push_back(const UniValue &val)
const UniValue & get_array() const
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.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const TxId &txid, const Consensus::Params &consensusParams, BlockHash &hashBlock)
Return transaction with a given txid.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params ¶ms)
Functions for disk access for blocks.
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)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
A BlockHash is a unqiue identifier for a block.
Parameters that influence chain consensus.
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
@ 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()
static const int PROTOCOL_VERSION
network protocol versioning