| 585 | } |
| 586 | |
| 587 | UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempool_sequence) |
| 588 | { |
| 589 | if (verbose) { |
| 590 | if (include_mempool_sequence) { |
| 591 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbose results cannot contain mempool sequence values."); |
| 592 | } |
| 593 | LOCK(pool.cs); |
| 594 | UniValue o(UniValue::VOBJ); |
| 595 | for (const CTxMemPoolEntry& e : pool.entryAll()) { |
| 596 | UniValue info(UniValue::VOBJ); |
| 597 | entryToJSON(pool, info, e); |
| 598 | // Mempool has unique entries so there is no advantage in using |
| 599 | // UniValue::pushKV, which checks if the key already exists in O(N). |
| 600 | // UniValue::pushKVEnd is used instead which currently is O(1). |
| 601 | o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info)); |
| 602 | } |
| 603 | return o; |
| 604 | } else { |
| 605 | UniValue a(UniValue::VARR); |
| 606 | uint64_t mempool_sequence; |
| 607 | { |
| 608 | LOCK(pool.cs); |
| 609 | for (const CTxMemPoolEntry& e : pool.entryAll()) { |
| 610 | a.push_back(e.GetTx().GetHash().ToString()); |
| 611 | } |
| 612 | mempool_sequence = pool.GetSequence(); |
| 613 | } |
| 614 | if (!include_mempool_sequence) { |
| 615 | return a; |
| 616 | } else { |
| 617 | UniValue o(UniValue::VOBJ); |
| 618 | o.pushKV("txids", std::move(a)); |
| 619 | o.pushKV("mempool_sequence", mempool_sequence); |
| 620 | return o; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | static RPCMethod getmempoolfeeratediagram() |
| 626 | { |
no test coverage detected