MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / getmempoolancestors

Function getmempoolancestors

src/rpc/blockchain.cpp:515–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

513}
514
515static UniValue getmempoolancestors(const JSONRPCRequest& request)
516{
517 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
518 throw std::runtime_error(
519 "getmempoolancestors txid (verbose)\n"
520 "\nIf txid is in the mempool, returns all in-mempool ancestors.\n"
521 "\nArguments:\n"
522 "1. \"txid\" (string, required) The transaction id (must be in mempool)\n"
523 "2. verbose (boolean, optional, default=false) True for a json object, false for array of transaction ids\n"
524 "\nResult (for verbose=false):\n"
525 "[ (json array of strings)\n"
526 " \"transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n"
527 " ,...\n"
528 "]\n"
529 "\nResult (for verbose=true):\n"
530 "{ (json object)\n"
531 " \"transactionid\" : { (json object)\n"
532 + EntryDescriptionString()
533 + " }, ...\n"
534 "}\n"
535 "\nExamples:\n"
536 + HelpExampleCli("getmempoolancestors", "\"mytxid\"")
537 + HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
538 );
539 }
540
541 bool fVerbose = false;
542 if (!request.params[1].isNull())
543 fVerbose = request.params[1].get_bool();
544
545 uint256 hash = ParseHashV(request.params[0], "parameter 1");
546
547 LOCK(mempool.cs);
548
549 CTxMemPool::txiter it = mempool.mapTx.find(hash);
550 if (it == mempool.mapTx.end()) {
551 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
552 }
553
554 CTxMemPool::setEntries setAncestors;
555 uint64_t noLimit = std::numeric_limits<uint64_t>::max();
556 std::string dummy;
557 mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false);
558
559 if (!fVerbose) {
560 UniValue o(UniValue::VARR);
561 for (CTxMemPool::txiter ancestorIt : setAncestors) {
562 o.push_back(ancestorIt->GetTx().GetHash().ToString());
563 }
564
565 return o;
566 } else {
567 UniValue o(UniValue::VOBJ);
568 for (CTxMemPool::txiter ancestorIt : setAncestors) {
569 const CTxMemPoolEntry &e = *ancestorIt;
570 const uint256& _hash = e.GetTx().GetHash();
571 UniValue info(UniValue::VOBJ);
572 entryToJSON(info, e);

Callers

nothing calls this directly

Calls 15

EntryDescriptionStringFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHashVFunction · 0.85
JSONRPCErrorFunction · 0.85
maxFunction · 0.85
isNullMethod · 0.80
get_boolMethod · 0.80
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected