Skip to content

Commit c1aad1b

Browse files
committed
scripted-diff: rename RetFormat to RESTResponseFormat
As RetFormat is now exposed in a header, it is renamed to the more understandable RESTResponseFormat -BEGIN VERIFY SCRIPT- s() { sed -i 's/RetFormat/RESTResponseFormat/g' $1; } s src/rest.cpp s src/rest.h -END VERIFY SCRIPT-
1 parent 9f1c547 commit c1aad1b

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

src/rest.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints t
4444
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;
4545

4646
static const struct {
47-
RetFormat rf;
47+
RESTResponseFormat rf;
4848
const char* name;
4949
} rf_names[] = {
50-
{RetFormat::UNDEF, ""},
51-
{RetFormat::BINARY, "bin"},
52-
{RetFormat::HEX, "hex"},
53-
{RetFormat::JSON, "json"},
50+
{RESTResponseFormat::UNDEF, ""},
51+
{RESTResponseFormat::BINARY, "bin"},
52+
{RESTResponseFormat::HEX, "hex"},
53+
{RESTResponseFormat::JSON, "json"},
5454
};
5555

5656
struct CCoin {
@@ -133,7 +133,7 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
133133
return node_context->chainman.get();
134134
}
135135

136-
RetFormat ParseDataFormat(std::string& param, const std::string& strReq)
136+
RESTResponseFormat ParseDataFormat(std::string& param, const std::string& strReq)
137137
{
138138
const std::string::size_type pos = strReq.rfind('.');
139139
if (pos == std::string::npos)
@@ -187,7 +187,7 @@ static bool rest_headers(const std::any& context,
187187
if (!CheckWarmup(req))
188188
return false;
189189
std::string param;
190-
const RetFormat rf = ParseDataFormat(param, strURIPart);
190+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
191191
std::vector<std::string> path;
192192
boost::split(path, param, boost::is_any_of("/"));
193193

@@ -225,7 +225,7 @@ static bool rest_headers(const std::any& context,
225225
}
226226

227227
switch (rf) {
228-
case RetFormat::BINARY: {
228+
case RESTResponseFormat::BINARY: {
229229
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
230230
for (const CBlockIndex *pindex : headers) {
231231
ssHeader << pindex->GetBlockHeader();
@@ -237,7 +237,7 @@ static bool rest_headers(const std::any& context,
237237
return true;
238238
}
239239

240-
case RetFormat::HEX: {
240+
case RESTResponseFormat::HEX: {
241241
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
242242
for (const CBlockIndex *pindex : headers) {
243243
ssHeader << pindex->GetBlockHeader();
@@ -248,7 +248,7 @@ static bool rest_headers(const std::any& context,
248248
req->WriteReply(HTTP_OK, strHex);
249249
return true;
250250
}
251-
case RetFormat::JSON: {
251+
case RESTResponseFormat::JSON: {
252252
UniValue jsonHeaders(UniValue::VARR);
253253
for (const CBlockIndex *pindex : headers) {
254254
jsonHeaders.push_back(blockheaderToJSON(tip, pindex));
@@ -272,7 +272,7 @@ static bool rest_block(const std::any& context,
272272
if (!CheckWarmup(req))
273273
return false;
274274
std::string hashStr;
275-
const RetFormat rf = ParseDataFormat(hashStr, strURIPart);
275+
const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
276276

277277
uint256 hash;
278278
if (!ParseHashStr(hashStr, hash))
@@ -300,7 +300,7 @@ static bool rest_block(const std::any& context,
300300
}
301301

302302
switch (rf) {
303-
case RetFormat::BINARY: {
303+
case RESTResponseFormat::BINARY: {
304304
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
305305
ssBlock << block;
306306
std::string binaryBlock = ssBlock.str();
@@ -309,7 +309,7 @@ static bool rest_block(const std::any& context,
309309
return true;
310310
}
311311

312-
case RetFormat::HEX: {
312+
case RESTResponseFormat::HEX: {
313313
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
314314
ssBlock << block;
315315
std::string strHex = HexStr(ssBlock) + "\n";
@@ -318,7 +318,7 @@ static bool rest_block(const std::any& context,
318318
return true;
319319
}
320320

321-
case RetFormat::JSON: {
321+
case RESTResponseFormat::JSON: {
322322
UniValue objBlock = blockToJSON(block, tip, pblockindex, tx_verbosity);
323323
std::string strJSON = objBlock.write() + "\n";
324324
req->WriteHeader("Content-Type", "application/json");
@@ -347,7 +347,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
347347
if (!CheckWarmup(req)) return false;
348348

349349
std::string param;
350-
const RetFormat rf = ParseDataFormat(param, strURIPart);
350+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
351351

352352
std::vector<std::string> uri_parts;
353353
boost::split(uri_parts, param, boost::is_any_of("/"));
@@ -413,7 +413,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
413413
}
414414

415415
switch (rf) {
416-
case RetFormat::BINARY: {
416+
case RESTResponseFormat::BINARY: {
417417
CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION};
418418
for (const uint256& header : filter_headers) {
419419
ssHeader << header;
@@ -424,7 +424,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
424424
req->WriteReply(HTTP_OK, binaryHeader);
425425
return true;
426426
}
427-
case RetFormat::HEX: {
427+
case RESTResponseFormat::HEX: {
428428
CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION};
429429
for (const uint256& header : filter_headers) {
430430
ssHeader << header;
@@ -435,7 +435,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
435435
req->WriteReply(HTTP_OK, strHex);
436436
return true;
437437
}
438-
case RetFormat::JSON: {
438+
case RESTResponseFormat::JSON: {
439439
UniValue jsonHeaders(UniValue::VARR);
440440
for (const uint256& header : filter_headers) {
441441
jsonHeaders.push_back(header.GetHex());
@@ -457,7 +457,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
457457
if (!CheckWarmup(req)) return false;
458458

459459
std::string param;
460-
const RetFormat rf = ParseDataFormat(param, strURIPart);
460+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
461461

462462
// request is sent over URI scheme /rest/blockfilter/filtertype/blockhash
463463
std::vector<std::string> uri_parts;
@@ -513,7 +513,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
513513
}
514514

515515
switch (rf) {
516-
case RetFormat::BINARY: {
516+
case RESTResponseFormat::BINARY: {
517517
CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION};
518518
ssResp << filter;
519519

@@ -522,7 +522,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
522522
req->WriteReply(HTTP_OK, binaryResp);
523523
return true;
524524
}
525-
case RetFormat::HEX: {
525+
case RESTResponseFormat::HEX: {
526526
CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION};
527527
ssResp << filter;
528528

@@ -531,7 +531,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
531531
req->WriteReply(HTTP_OK, strHex);
532532
return true;
533533
}
534-
case RetFormat::JSON: {
534+
case RESTResponseFormat::JSON: {
535535
UniValue ret(UniValue::VOBJ);
536536
ret.pushKV("filter", HexStr(filter.GetEncodedFilter()));
537537
std::string strJSON = ret.write() + "\n";
@@ -553,10 +553,10 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
553553
if (!CheckWarmup(req))
554554
return false;
555555
std::string param;
556-
const RetFormat rf = ParseDataFormat(param, strURIPart);
556+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
557557

558558
switch (rf) {
559-
case RetFormat::JSON: {
559+
case RESTResponseFormat::JSON: {
560560
JSONRPCRequest jsonRequest;
561561
jsonRequest.context = context;
562562
jsonRequest.params = UniValue(UniValue::VARR);
@@ -579,10 +579,10 @@ static bool rest_mempool_info(const std::any& context, HTTPRequest* req, const s
579579
const CTxMemPool* mempool = GetMemPool(context, req);
580580
if (!mempool) return false;
581581
std::string param;
582-
const RetFormat rf = ParseDataFormat(param, strURIPart);
582+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
583583

584584
switch (rf) {
585-
case RetFormat::JSON: {
585+
case RESTResponseFormat::JSON: {
586586
UniValue mempoolInfoObject = MempoolInfoToJSON(*mempool);
587587

588588
std::string strJSON = mempoolInfoObject.write() + "\n";
@@ -602,10 +602,10 @@ static bool rest_mempool_contents(const std::any& context, HTTPRequest* req, con
602602
const CTxMemPool* mempool = GetMemPool(context, req);
603603
if (!mempool) return false;
604604
std::string param;
605-
const RetFormat rf = ParseDataFormat(param, strURIPart);
605+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
606606

607607
switch (rf) {
608-
case RetFormat::JSON: {
608+
case RESTResponseFormat::JSON: {
609609
UniValue mempoolObject = MempoolToJSON(*mempool, true);
610610

611611
std::string strJSON = mempoolObject.write() + "\n";
@@ -624,7 +624,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
624624
if (!CheckWarmup(req))
625625
return false;
626626
std::string hashStr;
627-
const RetFormat rf = ParseDataFormat(hashStr, strURIPart);
627+
const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
628628

629629
uint256 hash;
630630
if (!ParseHashStr(hashStr, hash))
@@ -643,7 +643,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
643643
}
644644

645645
switch (rf) {
646-
case RetFormat::BINARY: {
646+
case RESTResponseFormat::BINARY: {
647647
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
648648
ssTx << tx;
649649

@@ -653,7 +653,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
653653
return true;
654654
}
655655

656-
case RetFormat::HEX: {
656+
case RESTResponseFormat::HEX: {
657657
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
658658
ssTx << tx;
659659

@@ -663,7 +663,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
663663
return true;
664664
}
665665

666-
case RetFormat::JSON: {
666+
case RESTResponseFormat::JSON: {
667667
UniValue objTx(UniValue::VOBJ);
668668
TxToUniv(*tx, hashBlock, objTx);
669669
std::string strJSON = objTx.write() + "\n";
@@ -683,7 +683,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
683683
if (!CheckWarmup(req))
684684
return false;
685685
std::string param;
686-
const RetFormat rf = ParseDataFormat(param, strURIPart);
686+
const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
687687

688688
std::vector<std::string> uriParts;
689689
if (param.length() > 1)
@@ -730,14 +730,14 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
730730
}
731731

732732
switch (rf) {
733-
case RetFormat::HEX: {
733+
case RESTResponseFormat::HEX: {
734734
// convert hex to bin, continue then with bin part
735735
std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
736736
strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
737737
[[fallthrough]];
738738
}
739739

740-
case RetFormat::BINARY: {
740+
case RESTResponseFormat::BINARY: {
741741
try {
742742
//deserialize only if user sent a request
743743
if (strRequestMutable.size() > 0)
@@ -757,7 +757,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
757757
break;
758758
}
759759

760-
case RetFormat::JSON: {
760+
case RESTResponseFormat::JSON: {
761761
if (!fInputParsed)
762762
return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
763763
break;
@@ -811,7 +811,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
811811
}
812812

813813
switch (rf) {
814-
case RetFormat::BINARY: {
814+
case RESTResponseFormat::BINARY: {
815815
// serialize data
816816
// use exact same output as mentioned in Bip64
817817
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
@@ -823,7 +823,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
823823
return true;
824824
}
825825

826-
case RetFormat::HEX: {
826+
case RESTResponseFormat::HEX: {
827827
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
828828
ssGetUTXOResponse << chainman.ActiveChain().Height() << chainman.ActiveChain().Tip()->GetBlockHash() << bitmap << outs;
829829
std::string strHex = HexStr(ssGetUTXOResponse) + "\n";
@@ -833,7 +833,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
833833
return true;
834834
}
835835

836-
case RetFormat::JSON: {
836+
case RESTResponseFormat::JSON: {
837837
UniValue objGetUTXOResponse(UniValue::VOBJ);
838838

839839
// pack in some essentials
@@ -873,7 +873,7 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
873873
{
874874
if (!CheckWarmup(req)) return false;
875875
std::string height_str;
876-
const RetFormat rf = ParseDataFormat(height_str, str_uri_part);
876+
const RESTResponseFormat rf = ParseDataFormat(height_str, str_uri_part);
877877

878878
int32_t blockheight = -1; // Initialization done only to prevent valgrind false positive, see https://github.com/bitcoin/bitcoin/pull/18785
879879
if (!ParseInt32(height_str, &blockheight) || blockheight < 0) {
@@ -893,19 +893,19 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
893893
pblockindex = active_chain[blockheight];
894894
}
895895
switch (rf) {
896-
case RetFormat::BINARY: {
896+
case RESTResponseFormat::BINARY: {
897897
CDataStream ss_blockhash(SER_NETWORK, PROTOCOL_VERSION);
898898
ss_blockhash << pblockindex->GetBlockHash();
899899
req->WriteHeader("Content-Type", "application/octet-stream");
900900
req->WriteReply(HTTP_OK, ss_blockhash.str());
901901
return true;
902902
}
903-
case RetFormat::HEX: {
903+
case RESTResponseFormat::HEX: {
904904
req->WriteHeader("Content-Type", "text/plain");
905905
req->WriteReply(HTTP_OK, pblockindex->GetBlockHash().GetHex() + "\n");
906906
return true;
907907
}
908-
case RetFormat::JSON: {
908+
case RESTResponseFormat::JSON: {
909909
req->WriteHeader("Content-Type", "application/json");
910910
UniValue resp = UniValue(UniValue::VOBJ);
911911
resp.pushKV("blockhash", pblockindex->GetBlockHash().GetHex());

src/rest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
#include <string>
99

10-
enum class RetFormat {
10+
enum class RESTResponseFormat {
1111
UNDEF,
1212
BINARY,
1313
HEX,
1414
JSON,
1515
};
1616

17-
RetFormat ParseDataFormat(std::string& param, const std::string& strReq);
17+
RESTResponseFormat ParseDataFormat(std::string& param, const std::string& strReq);
1818

1919
#endif // BITCOIN_REST_H

0 commit comments

Comments
 (0)