| 513 | } |
| 514 | |
| 515 | static 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); |
nothing calls this directly
no test coverage detected