MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MempoolToJSON

Function MempoolToJSON

src/rpc/mempool.cpp:587–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

585}
586
587UniValue 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
625static RPCMethod getmempoolfeeratediagram()
626{

Callers 3

rest_mempoolFunction · 0.85
getrawmempoolFunction · 0.85
RpcMempoolFunction · 0.85

Calls 9

JSONRPCErrorFunction · 0.85
entryAllMethod · 0.80
pushKVEndMethod · 0.80
GetTxMethod · 0.80
pushKVMethod · 0.80
ToStringMethod · 0.45
GetHashMethod · 0.45
push_backMethod · 0.45
GetSequenceMethod · 0.45

Tested by

no test coverage detected