MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / rest_tx

Function rest_tx

src/rest.cpp:364–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
365{
366 if (!CheckWarmup(req))
367 return false;
368 std::string hashStr;
369 const RetFormat rf = ParseDataFormat(hashStr, strURIPart);
370
371 uint256 hash;
372 if (!ParseHashStr(hashStr, hash))
373 return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
374
375 if (g_txindex) {
376 g_txindex->BlockUntilSyncedToCurrentChain();
377 }
378
379 CTransactionRef tx;
380 uint256 hashBlock = uint256();
381 if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
382 return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
383
384 CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
385 ssTx << tx;
386
387 switch (rf) {
388 case RetFormat::BINARY: {
389 std::string binaryTx = ssTx.str();
390 req->WriteHeader("Content-Type", "application/octet-stream");
391 req->WriteReply(HTTP_OK, binaryTx);
392 return true;
393 }
394
395 case RetFormat::HEX: {
396 std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
397 req->WriteHeader("Content-Type", "text/plain");
398 req->WriteReply(HTTP_OK, strHex);
399 return true;
400 }
401
402 case RetFormat::JSON: {
403 UniValue objTx(UniValue::VOBJ);
404 TxToUniv(*tx, hashBlock, objTx);
405 std::string strJSON = objTx.write() + "\n";
406 req->WriteHeader("Content-Type", "application/json");
407 req->WriteReply(HTTP_OK, strJSON);
408 return true;
409 }
410
411 default: {
412 return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
413 }
414 }
415}
416
417static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
418{

Callers

nothing calls this directly

Calls 15

CheckWarmupFunction · 0.85
ParseDataFormatFunction · 0.85
RESTERRFunction · 0.85
GetTransactionFunction · 0.85
RPCSerializationFlagsFunction · 0.85
HexStrFunction · 0.85
TxToUnivFunction · 0.85
strMethod · 0.80
WriteHeaderMethod · 0.80
WriteReplyMethod · 0.80
ParseHashStrFunction · 0.70

Tested by

no test coverage detected