| 711 | } |
| 712 | |
| 713 | static RPCHelpMan getmempoolancestors() |
| 714 | { |
| 715 | return RPCHelpMan{"getmempoolancestors", |
| 716 | "\nIf txid is in the mempool, returns all in-mempool ancestors.\n", |
| 717 | { |
| 718 | {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, |
| 719 | {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"}, |
| 720 | }, |
| 721 | { |
| 722 | RPCResult{"for verbose = false", |
| 723 | RPCResult::Type::ARR, "", "", |
| 724 | {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}}, |
| 725 | RPCResult{"for verbose = true", |
| 726 | RPCResult::Type::OBJ_DYN, "", "", |
| 727 | { |
| 728 | {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()}, |
| 729 | }}, |
| 730 | }, |
| 731 | RPCExamples{ |
| 732 | HelpExampleCli("getmempoolancestors", "\"mytxid\"") |
| 733 | + HelpExampleRpc("getmempoolancestors", "\"mytxid\"") |
| 734 | }, |
| 735 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 736 | { |
| 737 | bool fVerbose = false; |
| 738 | if (!request.params[1].isNull()) |
| 739 | fVerbose = request.params[1].get_bool(); |
| 740 | |
| 741 | uint256 hash = ParseHashV(request.params[0], "parameter 1"); |
| 742 | |
| 743 | const CTxMemPool& mempool = EnsureAnyMemPool(request.context); |
| 744 | LOCK(mempool.cs); |
| 745 | |
| 746 | CTxMemPool::txiter it = mempool.mapTx.find(hash); |
| 747 | if (it == mempool.mapTx.end()) { |
| 748 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool"); |
| 749 | } |
| 750 | |
| 751 | CTxMemPool::setEntries setAncestors; |
| 752 | uint64_t noLimit = std::numeric_limits<uint64_t>::max(); |
| 753 | std::string dummy; |
| 754 | mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false); |
| 755 | |
| 756 | if (!fVerbose) { |
| 757 | UniValue o(UniValue::VARR); |
| 758 | for (CTxMemPool::txiter ancestorIt : setAncestors) { |
| 759 | o.push_back(ancestorIt->GetTx().GetHash().ToString()); |
| 760 | } |
| 761 | return o; |
| 762 | } else { |
| 763 | UniValue o(UniValue::VOBJ); |
| 764 | for (CTxMemPool::txiter ancestorIt : setAncestors) { |
| 765 | const CTxMemPoolEntry &e = *ancestorIt; |
| 766 | const uint256& _hash = e.GetTx().GetHash(); |
| 767 | UniValue info(UniValue::VOBJ); |
| 768 | entryToJSON(mempool, info, e); |
| 769 | o.pushKV(_hash.ToString(), info); |
| 770 | } |
nothing calls this directly
no test coverage detected