MCPcopy Create free account
hub / github.com/ElementsProject/elements / rest_getutxos

Function rest_getutxos

src/rest.cpp:691–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

689}
690
691static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
692{
693 if (!CheckWarmup(req))
694 return false;
695 std::string param;
696 const RetFormat rf = ParseDataFormat(param, strURIPart);
697
698 std::vector<std::string> uriParts;
699 if (param.length() > 1)
700 {
701 std::string strUriParams = param.substr(1);
702 boost::split(uriParts, strUriParams, boost::is_any_of("/"));
703 }
704
705 // throw exception in case of an empty request
706 std::string strRequestMutable = req->ReadBody();
707 if (strRequestMutable.length() == 0 && uriParts.size() == 0)
708 return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
709
710 bool fInputParsed = false;
711 bool fCheckMemPool = false;
712 std::vector<COutPoint> vOutPoints;
713
714 // parse/deserialize input
715 // input-format = output-format, rest/getutxos/bin requires binary input, gives binary output, ...
716
717 if (uriParts.size() > 0)
718 {
719 //inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...)
720 if (uriParts[0] == "checkmempool") fCheckMemPool = true;
721
722 for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
723 {
724 uint256 txid;
725 int32_t nOutput;
726 std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
727 std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
728
729 if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
730 return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
731
732 txid.SetHex(strTxid);
733 vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput));
734 }
735
736 if (vOutPoints.size() > 0)
737 fInputParsed = true;
738 else
739 return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
740 }
741
742 switch (rf) {
743 case RetFormat::HEX: {
744 // convert hex to bin, continue then with bin part
745 std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
746 strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
747 [[fallthrough]];
748 }

Callers

nothing calls this directly

Calls 15

CheckWarmupFunction · 0.85
ParseDataFormatFunction · 0.85
RESTERRFunction · 0.85
IsHexFunction · 0.85
ParseHexFunction · 0.85
GetChainmanFunction · 0.85
GetMemPoolFunction · 0.85
ValueFromAmountFunction · 0.85
ScriptPubKeyToUnivFunction · 0.85
ReadBodyMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected