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

Function rest_mempool

src/rest.cpp:783–837  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

781}
782
783static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
784{
785 if (!CheckWarmup(req))
786 return false;
787
788 std::string param;
789 const RESTResponseFormat rf = ParseDataFormat(param, str_uri_part);
790 if (param != "contents" && param != "info") {
791 return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/mempool/<info|contents>.json");
792 }
793
794 const CTxMemPool* mempool = GetMemPool(context, req);
795 if (!mempool) return false;
796
797 switch (rf) {
798 case RESTResponseFormat::JSON: {
799 std::string str_json;
800 if (param == "contents") {
801 std::string raw_verbose;
802 try {
803 raw_verbose = req->GetQueryParameter("verbose").value_or("true");
804 } catch (const std::runtime_error& e) {
805 return RESTERR(req, HTTP_BAD_REQUEST, e.what());
806 }
807 if (raw_verbose != "true" && raw_verbose != "false") {
808 return RESTERR(req, HTTP_BAD_REQUEST, "The \"verbose\" query parameter must be either \"true\" or \"false\".");
809 }
810 std::string raw_mempool_sequence;
811 try {
812 raw_mempool_sequence = req->GetQueryParameter("mempool_sequence").value_or("false");
813 } catch (const std::runtime_error& e) {
814 return RESTERR(req, HTTP_BAD_REQUEST, e.what());
815 }
816 if (raw_mempool_sequence != "true" && raw_mempool_sequence != "false") {
817 return RESTERR(req, HTTP_BAD_REQUEST, "The \"mempool_sequence\" query parameter must be either \"true\" or \"false\".");
818 }
819 const bool verbose{raw_verbose == "true"};
820 const bool mempool_sequence{raw_mempool_sequence == "true"};
821 if (verbose && mempool_sequence) {
822 return RESTERR(req, HTTP_BAD_REQUEST, "Verbose results cannot contain mempool sequence values. (hint: set \"verbose=false\")");
823 }
824 str_json = MempoolToJSON(*mempool, verbose, mempool_sequence).write() + "\n";
825 } else {
826 str_json = MempoolInfoToJSON(*mempool).write() + "\n";
827 }
828
829 req->WriteHeader("Content-Type", "application/json");
830 req->WriteReply(HTTP_OK, str_json);
831 return true;
832 }
833 default: {
834 return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
835 }
836 }
837}
838
839static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string& uri_part)
840{

Callers

nothing calls this directly

Calls 12

CheckWarmupFunction · 0.85
ParseDataFormatFunction · 0.85
RESTERRFunction · 0.85
GetMemPoolFunction · 0.85
MempoolToJSONFunction · 0.85
MempoolInfoToJSONFunction · 0.85
GetQueryParameterMethod · 0.80
WriteHeaderMethod · 0.80
value_orMethod · 0.45
whatMethod · 0.45
writeMethod · 0.45
WriteReplyMethod · 0.45

Tested by

no test coverage detected