Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
Show First 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static bool rest_tx(Config &config, HTTPRequest *req, | static bool rest_tx(Config &config, HTTPRequest *req, | ||||
const std::string &strURIPart) { | const std::string &strURIPart) { | ||||
if (!CheckWarmup(req)) return false; | if (!CheckWarmup(req)) return false; | ||||
std::string hashStr; | std::string hashStr; | ||||
const RetFormat rf = ParseDataFormat(hashStr, strURIPart); | const RetFormat rf = ParseDataFormat(hashStr, strURIPart); | ||||
uint256 hash; | txhash_t hash; | ||||
if (!ParseHashStr(hashStr, hash)) | if (!ParseHashStr(hashStr, hash)) | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
uint256 hashBlock = uint256(); | uint256 hashBlock = uint256(); | ||||
if (!GetTransaction(config, hash, tx, hashBlock)) { | if (!GetTransaction(config, hash, tx, hashBlock)) { | ||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | static bool rest_getutxos(Config &config, HTTPRequest *req, | ||||
// parse/deserialize input | // parse/deserialize input | ||||
// input-format = output-format, rest/getutxos/bin requires binary input, | // input-format = output-format, rest/getutxos/bin requires binary input, | ||||
// gives binary output, ... | // gives binary output, ... | ||||
if (uriParts.size() > 0) { | if (uriParts.size() > 0) { | ||||
// inputs is sent over URI scheme | // inputs is sent over URI scheme | ||||
// (/rest/getutxos/checkmempool/txid1-n/txid2-n/...) | // (/rest/getutxos/checkmempool/unspentid1-n/unspentid2-n/...) | ||||
if (uriParts.size() > 0 && uriParts[0] == "checkmempool") | if (uriParts.size() > 0 && uriParts[0] == "checkmempool") | ||||
fCheckMemPool = true; | fCheckMemPool = true; | ||||
for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++) { | for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++) { | ||||
uint256 txid; | unspentid_t unspentid; | ||||
int32_t nOutput; | int32_t nOutput; | ||||
std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-")); | std::string strunspentid = | ||||
uriParts[i].substr(0, uriParts[i].find("-")); | |||||
std::string strOutput = | std::string strOutput = | ||||
uriParts[i].substr(uriParts[i].find("-") + 1); | uriParts[i].substr(uriParts[i].find("-") + 1); | ||||
if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid)) | if (!ParseInt32(strOutput, &nOutput) || !IsHex(strunspentid)) | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error"); | return RESTERR(req, HTTP_BAD_REQUEST, "Parse error"); | ||||
txid.SetHex(strTxid); | unspentid.SetHex(strunspentid); | ||||
vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput)); | vOutPoints.push_back(COutPoint(unspentid, (uint32_t)nOutput)); | ||||
} | } | ||||
if (vOutPoints.size() > 0) { | if (vOutPoints.size() > 0) { | ||||
fInputParsed = true; | fInputParsed = true; | ||||
} else { | } else { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request"); | return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request"); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |