@@ -44,13 +44,13 @@ static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints t
44
44
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000 ;
45
45
46
46
static const struct {
47
- RetFormat rf;
47
+ RESTResponseFormat rf;
48
48
const char * name;
49
49
} 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" },
54
54
};
55
55
56
56
struct CCoin {
@@ -133,7 +133,7 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
133
133
return node_context->chainman .get ();
134
134
}
135
135
136
- RetFormat ParseDataFormat (std::string& param, const std::string& strReq)
136
+ RESTResponseFormat ParseDataFormat (std::string& param, const std::string& strReq)
137
137
{
138
138
const std::string::size_type pos = strReq.rfind (' .' );
139
139
if (pos == std::string::npos)
@@ -187,7 +187,7 @@ static bool rest_headers(const std::any& context,
187
187
if (!CheckWarmup (req))
188
188
return false ;
189
189
std::string param;
190
- const RetFormat rf = ParseDataFormat (param, strURIPart);
190
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
191
191
std::vector<std::string> path;
192
192
boost::split (path, param, boost::is_any_of (" /" ));
193
193
@@ -225,7 +225,7 @@ static bool rest_headers(const std::any& context,
225
225
}
226
226
227
227
switch (rf) {
228
- case RetFormat ::BINARY: {
228
+ case RESTResponseFormat ::BINARY: {
229
229
CDataStream ssHeader (SER_NETWORK, PROTOCOL_VERSION);
230
230
for (const CBlockIndex *pindex : headers) {
231
231
ssHeader << pindex->GetBlockHeader ();
@@ -237,7 +237,7 @@ static bool rest_headers(const std::any& context,
237
237
return true ;
238
238
}
239
239
240
- case RetFormat ::HEX: {
240
+ case RESTResponseFormat ::HEX: {
241
241
CDataStream ssHeader (SER_NETWORK, PROTOCOL_VERSION);
242
242
for (const CBlockIndex *pindex : headers) {
243
243
ssHeader << pindex->GetBlockHeader ();
@@ -248,7 +248,7 @@ static bool rest_headers(const std::any& context,
248
248
req->WriteReply (HTTP_OK, strHex);
249
249
return true ;
250
250
}
251
- case RetFormat ::JSON: {
251
+ case RESTResponseFormat ::JSON: {
252
252
UniValue jsonHeaders (UniValue::VARR);
253
253
for (const CBlockIndex *pindex : headers) {
254
254
jsonHeaders.push_back (blockheaderToJSON (tip, pindex));
@@ -272,7 +272,7 @@ static bool rest_block(const std::any& context,
272
272
if (!CheckWarmup (req))
273
273
return false ;
274
274
std::string hashStr;
275
- const RetFormat rf = ParseDataFormat (hashStr, strURIPart);
275
+ const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
276
276
277
277
uint256 hash;
278
278
if (!ParseHashStr (hashStr, hash))
@@ -300,7 +300,7 @@ static bool rest_block(const std::any& context,
300
300
}
301
301
302
302
switch (rf) {
303
- case RetFormat ::BINARY: {
303
+ case RESTResponseFormat ::BINARY: {
304
304
CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
305
305
ssBlock << block;
306
306
std::string binaryBlock = ssBlock.str ();
@@ -309,7 +309,7 @@ static bool rest_block(const std::any& context,
309
309
return true ;
310
310
}
311
311
312
- case RetFormat ::HEX: {
312
+ case RESTResponseFormat ::HEX: {
313
313
CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
314
314
ssBlock << block;
315
315
std::string strHex = HexStr (ssBlock) + " \n " ;
@@ -318,7 +318,7 @@ static bool rest_block(const std::any& context,
318
318
return true ;
319
319
}
320
320
321
- case RetFormat ::JSON: {
321
+ case RESTResponseFormat ::JSON: {
322
322
UniValue objBlock = blockToJSON (block, tip, pblockindex, tx_verbosity);
323
323
std::string strJSON = objBlock.write () + " \n " ;
324
324
req->WriteHeader (" Content-Type" , " application/json" );
@@ -347,7 +347,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
347
347
if (!CheckWarmup (req)) return false ;
348
348
349
349
std::string param;
350
- const RetFormat rf = ParseDataFormat (param, strURIPart);
350
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
351
351
352
352
std::vector<std::string> uri_parts;
353
353
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
413
413
}
414
414
415
415
switch (rf) {
416
- case RetFormat ::BINARY: {
416
+ case RESTResponseFormat ::BINARY: {
417
417
CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION};
418
418
for (const uint256& header : filter_headers) {
419
419
ssHeader << header;
@@ -424,7 +424,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
424
424
req->WriteReply (HTTP_OK, binaryHeader);
425
425
return true ;
426
426
}
427
- case RetFormat ::HEX: {
427
+ case RESTResponseFormat ::HEX: {
428
428
CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION};
429
429
for (const uint256& header : filter_headers) {
430
430
ssHeader << header;
@@ -435,7 +435,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
435
435
req->WriteReply (HTTP_OK, strHex);
436
436
return true ;
437
437
}
438
- case RetFormat ::JSON: {
438
+ case RESTResponseFormat ::JSON: {
439
439
UniValue jsonHeaders (UniValue::VARR);
440
440
for (const uint256& header : filter_headers) {
441
441
jsonHeaders.push_back (header.GetHex ());
@@ -457,7 +457,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
457
457
if (!CheckWarmup (req)) return false ;
458
458
459
459
std::string param;
460
- const RetFormat rf = ParseDataFormat (param, strURIPart);
460
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
461
461
462
462
// request is sent over URI scheme /rest/blockfilter/filtertype/blockhash
463
463
std::vector<std::string> uri_parts;
@@ -513,7 +513,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
513
513
}
514
514
515
515
switch (rf) {
516
- case RetFormat ::BINARY: {
516
+ case RESTResponseFormat ::BINARY: {
517
517
CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION};
518
518
ssResp << filter;
519
519
@@ -522,7 +522,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
522
522
req->WriteReply (HTTP_OK, binaryResp);
523
523
return true ;
524
524
}
525
- case RetFormat ::HEX: {
525
+ case RESTResponseFormat ::HEX: {
526
526
CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION};
527
527
ssResp << filter;
528
528
@@ -531,7 +531,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
531
531
req->WriteReply (HTTP_OK, strHex);
532
532
return true ;
533
533
}
534
- case RetFormat ::JSON: {
534
+ case RESTResponseFormat ::JSON: {
535
535
UniValue ret (UniValue::VOBJ);
536
536
ret.pushKV (" filter" , HexStr (filter.GetEncodedFilter ()));
537
537
std::string strJSON = ret.write () + " \n " ;
@@ -553,10 +553,10 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
553
553
if (!CheckWarmup (req))
554
554
return false ;
555
555
std::string param;
556
- const RetFormat rf = ParseDataFormat (param, strURIPart);
556
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
557
557
558
558
switch (rf) {
559
- case RetFormat ::JSON: {
559
+ case RESTResponseFormat ::JSON: {
560
560
JSONRPCRequest jsonRequest;
561
561
jsonRequest.context = context;
562
562
jsonRequest.params = UniValue (UniValue::VARR);
@@ -579,10 +579,10 @@ static bool rest_mempool_info(const std::any& context, HTTPRequest* req, const s
579
579
const CTxMemPool* mempool = GetMemPool (context, req);
580
580
if (!mempool) return false ;
581
581
std::string param;
582
- const RetFormat rf = ParseDataFormat (param, strURIPart);
582
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
583
583
584
584
switch (rf) {
585
- case RetFormat ::JSON: {
585
+ case RESTResponseFormat ::JSON: {
586
586
UniValue mempoolInfoObject = MempoolInfoToJSON (*mempool);
587
587
588
588
std::string strJSON = mempoolInfoObject.write () + " \n " ;
@@ -602,10 +602,10 @@ static bool rest_mempool_contents(const std::any& context, HTTPRequest* req, con
602
602
const CTxMemPool* mempool = GetMemPool (context, req);
603
603
if (!mempool) return false ;
604
604
std::string param;
605
- const RetFormat rf = ParseDataFormat (param, strURIPart);
605
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
606
606
607
607
switch (rf) {
608
- case RetFormat ::JSON: {
608
+ case RESTResponseFormat ::JSON: {
609
609
UniValue mempoolObject = MempoolToJSON (*mempool, true );
610
610
611
611
std::string strJSON = mempoolObject.write () + " \n " ;
@@ -624,7 +624,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
624
624
if (!CheckWarmup (req))
625
625
return false ;
626
626
std::string hashStr;
627
- const RetFormat rf = ParseDataFormat (hashStr, strURIPart);
627
+ const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
628
628
629
629
uint256 hash;
630
630
if (!ParseHashStr (hashStr, hash))
@@ -643,7 +643,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
643
643
}
644
644
645
645
switch (rf) {
646
- case RetFormat ::BINARY: {
646
+ case RESTResponseFormat ::BINARY: {
647
647
CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
648
648
ssTx << tx;
649
649
@@ -653,7 +653,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
653
653
return true ;
654
654
}
655
655
656
- case RetFormat ::HEX: {
656
+ case RESTResponseFormat ::HEX: {
657
657
CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
658
658
ssTx << tx;
659
659
@@ -663,7 +663,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
663
663
return true ;
664
664
}
665
665
666
- case RetFormat ::JSON: {
666
+ case RESTResponseFormat ::JSON: {
667
667
UniValue objTx (UniValue::VOBJ);
668
668
TxToUniv (*tx, hashBlock, objTx);
669
669
std::string strJSON = objTx.write () + " \n " ;
@@ -683,7 +683,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
683
683
if (!CheckWarmup (req))
684
684
return false ;
685
685
std::string param;
686
- const RetFormat rf = ParseDataFormat (param, strURIPart);
686
+ const RESTResponseFormat rf = ParseDataFormat (param, strURIPart);
687
687
688
688
std::vector<std::string> uriParts;
689
689
if (param.length () > 1 )
@@ -730,14 +730,14 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
730
730
}
731
731
732
732
switch (rf) {
733
- case RetFormat ::HEX: {
733
+ case RESTResponseFormat ::HEX: {
734
734
// convert hex to bin, continue then with bin part
735
735
std::vector<unsigned char > strRequestV = ParseHex (strRequestMutable);
736
736
strRequestMutable.assign (strRequestV.begin (), strRequestV.end ());
737
737
[[fallthrough]];
738
738
}
739
739
740
- case RetFormat ::BINARY: {
740
+ case RESTResponseFormat ::BINARY: {
741
741
try {
742
742
// deserialize only if user sent a request
743
743
if (strRequestMutable.size () > 0 )
@@ -757,7 +757,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
757
757
break ;
758
758
}
759
759
760
- case RetFormat ::JSON: {
760
+ case RESTResponseFormat ::JSON: {
761
761
if (!fInputParsed )
762
762
return RESTERR (req, HTTP_BAD_REQUEST, " Error: empty request" );
763
763
break ;
@@ -811,7 +811,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
811
811
}
812
812
813
813
switch (rf) {
814
- case RetFormat ::BINARY: {
814
+ case RESTResponseFormat ::BINARY: {
815
815
// serialize data
816
816
// use exact same output as mentioned in Bip64
817
817
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
@@ -823,7 +823,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
823
823
return true ;
824
824
}
825
825
826
- case RetFormat ::HEX: {
826
+ case RESTResponseFormat ::HEX: {
827
827
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
828
828
ssGetUTXOResponse << chainman.ActiveChain ().Height () << chainman.ActiveChain ().Tip ()->GetBlockHash () << bitmap << outs;
829
829
std::string strHex = HexStr (ssGetUTXOResponse) + " \n " ;
@@ -833,7 +833,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
833
833
return true ;
834
834
}
835
835
836
- case RetFormat ::JSON: {
836
+ case RESTResponseFormat ::JSON: {
837
837
UniValue objGetUTXOResponse (UniValue::VOBJ);
838
838
839
839
// pack in some essentials
@@ -873,7 +873,7 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
873
873
{
874
874
if (!CheckWarmup (req)) return false ;
875
875
std::string height_str;
876
- const RetFormat rf = ParseDataFormat (height_str, str_uri_part);
876
+ const RESTResponseFormat rf = ParseDataFormat (height_str, str_uri_part);
877
877
878
878
int32_t blockheight = -1 ; // Initialization done only to prevent valgrind false positive, see https://github.com/bitcoin/bitcoin/pull/18785
879
879
if (!ParseInt32 (height_str, &blockheight) || blockheight < 0 ) {
@@ -893,19 +893,19 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
893
893
pblockindex = active_chain[blockheight];
894
894
}
895
895
switch (rf) {
896
- case RetFormat ::BINARY: {
896
+ case RESTResponseFormat ::BINARY: {
897
897
CDataStream ss_blockhash (SER_NETWORK, PROTOCOL_VERSION);
898
898
ss_blockhash << pblockindex->GetBlockHash ();
899
899
req->WriteHeader (" Content-Type" , " application/octet-stream" );
900
900
req->WriteReply (HTTP_OK, ss_blockhash.str ());
901
901
return true ;
902
902
}
903
- case RetFormat ::HEX: {
903
+ case RESTResponseFormat ::HEX: {
904
904
req->WriteHeader (" Content-Type" , " text/plain" );
905
905
req->WriteReply (HTTP_OK, pblockindex->GetBlockHash ().GetHex () + " \n " );
906
906
return true ;
907
907
}
908
- case RetFormat ::JSON: {
908
+ case RESTResponseFormat ::JSON: {
909
909
req->WriteHeader (" Content-Type" , " application/json" );
910
910
UniValue resp = UniValue (UniValue::VOBJ);
911
911
resp.pushKV (" blockhash" , pblockindex->GetBlockHash ().GetHex ());
0 commit comments