| 689 | } |
| 690 | |
| 691 | static 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 | } |
nothing calls this directly
no test coverage detected