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");
68 Chainstate& active_chainstate = chainman.ActiveChainstate();
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;
161 for (
const uint256& hash : vMatch) {
177 for (
const auto& c : commands) {
178 t.appendCommand(c.name, &c);
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.
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
CBlockHeader header
Public only for unit testing.
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
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...
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...
bool IsSpent() const
Either this coin never existed (see e.g.
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Double ended buffer combining vector and stream-like interfaces.
void push_back(UniValue val)
const UniValue & get_array() const
constexpr bool IsNull() const
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &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 uint256 &hash, uint256 &hashBlock, const BlockManager &blockman)
Return transaction with a given hash.
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< unsigned char > 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)
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ STR_HEX
Special string with only hex chars.
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.