MCPcopy Create free account
hub / github.com/ElementsProject/elements / verifytxoutproof

Function verifytxoutproof

src/rpc/rawtransaction.cpp:412–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412static RPCHelpMan verifytxoutproof()
413{
414 return RPCHelpMan{"verifytxoutproof",
415 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n"
416 "and throwing an RPC error if the block is not in our best chain\n",
417 {
418 {"proof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded proof generated by gettxoutproof"},
419 },
420 RPCResult{
421 RPCResult::Type::ARR, "", "",
422 {
423 {RPCResult::Type::STR_HEX, "txid", "The txid(s) which the proof commits to, or empty array if the proof cannot be validated."},
424 }
425 },
426 RPCExamples{""},
427 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
428{
429 CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
430 CMerkleBlock merkleBlock;
431 ssMB >> merkleBlock;
432
433 UniValue res(UniValue::VARR);
434
435 std::vector<uint256> vMatch;
436 std::vector<unsigned int> vIndex;
437 if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
438 return res;
439
440 ChainstateManager& chainman = EnsureAnyChainman(request.context);
441 LOCK(cs_main);
442
443 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(merkleBlock.header.GetHash());
444 if (!pindex || !chainman.ActiveChain().Contains(pindex) || pindex->nTx == 0) {
445 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
446 }
447
448 // Check if proof is valid, only add results if so
449 if (pindex->nTx == merkleBlock.txn.GetNumTransactions()) {
450 for (const uint256& hash : vMatch) {
451 res.push_back(hash.GetHex());
452 }
453 }
454
455 return res;
456},
457 };
458}
459
460static RPCHelpMan createrawtransaction()
461{

Callers

nothing calls this directly

Calls 9

ParseHexVFunction · 0.85
JSONRPCErrorFunction · 0.85
LookupBlockIndexMethod · 0.80
ExtractMatchesMethod · 0.45
GetHashMethod · 0.45
ContainsMethod · 0.45
GetNumTransactionsMethod · 0.45
push_backMethod · 0.45
GetHexMethod · 0.45

Tested by

no test coverage detected