@@ -217,9 +217,10 @@ static bool rest_headers(const std::any& context,
217
217
return RESTERR (req, HTTP_BAD_REQUEST, strprintf (" Header count is invalid or out of acceptable range (1-%u): %s" , MAX_REST_HEADERS_RESULTS, raw_count));
218
218
}
219
219
220
- uint256 hash;
221
- if (!ParseHashStr (hashStr, hash))
220
+ auto hash{ uint256::FromHex (hashStr)} ;
221
+ if (!hash) {
222
222
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
223
+ }
223
224
224
225
const CBlockIndex* tip = nullptr ;
225
226
std::vector<const CBlockIndex*> headers;
@@ -231,7 +232,7 @@ static bool rest_headers(const std::any& context,
231
232
LOCK (cs_main);
232
233
CChain& active_chain = chainman.ActiveChain ();
233
234
tip = active_chain.Tip ();
234
- const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (hash);
235
+ const CBlockIndex* pindex{ chainman.m_blockman .LookupBlockIndex (* hash)} ;
235
236
while (pindex != nullptr && active_chain.Contains (pindex)) {
236
237
headers.push_back (pindex);
237
238
if (headers.size () == *parsed_count) {
@@ -290,9 +291,10 @@ static bool rest_block(const std::any& context,
290
291
std::string hashStr;
291
292
const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
292
293
293
- uint256 hash;
294
- if (!ParseHashStr (hashStr, hash))
294
+ auto hash{ uint256::FromHex (hashStr)} ;
295
+ if (!hash) {
295
296
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
297
+ }
296
298
297
299
FlatFilePos pos{};
298
300
const CBlockIndex* pblockindex = nullptr ;
@@ -303,7 +305,7 @@ static bool rest_block(const std::any& context,
303
305
{
304
306
LOCK (cs_main);
305
307
tip = chainman.ActiveChain ().Tip ();
306
- pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
308
+ pblockindex = chainman.m_blockman .LookupBlockIndex (* hash);
307
309
if (!pblockindex) {
308
310
return RESTERR (req, HTTP_NOT_FOUND, hashStr + " not found" );
309
311
}
@@ -390,8 +392,8 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
390
392
return RESTERR (req, HTTP_BAD_REQUEST, strprintf (" Header count is invalid or out of acceptable range (1-%u): %s" , MAX_REST_HEADERS_RESULTS, raw_count));
391
393
}
392
394
393
- uint256 block_hash;
394
- if (!ParseHashStr (raw_blockhash, block_hash) ) {
395
+ auto block_hash{ uint256::FromHex (raw_blockhash)} ;
396
+ if (!block_hash) {
395
397
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + raw_blockhash);
396
398
}
397
399
@@ -413,7 +415,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
413
415
ChainstateManager& chainman = *maybe_chainman;
414
416
LOCK (cs_main);
415
417
CChain& active_chain = chainman.ActiveChain ();
416
- const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (block_hash);
418
+ const CBlockIndex* pindex{ chainman.m_blockman .LookupBlockIndex (* block_hash)} ;
417
419
while (pindex != nullptr && active_chain.Contains (pindex)) {
418
420
headers.push_back (pindex);
419
421
if (headers.size () == *parsed_count)
@@ -494,8 +496,8 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
494
496
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid URI format. Expected /rest/blockfilter/<filtertype>/<blockhash>" );
495
497
}
496
498
497
- uint256 block_hash;
498
- if (!ParseHashStr (uri_parts[ 1 ], block_hash) ) {
499
+ auto block_hash{ uint256::FromHex (uri_parts[ 1 ])} ;
500
+ if (!block_hash) {
499
501
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + uri_parts[1 ]);
500
502
}
501
503
@@ -516,7 +518,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
516
518
if (!maybe_chainman) return false ;
517
519
ChainstateManager& chainman = *maybe_chainman;
518
520
LOCK (cs_main);
519
- block_index = chainman.m_blockman .LookupBlockIndex (block_hash);
521
+ block_index = chainman.m_blockman .LookupBlockIndex (* block_hash);
520
522
if (!block_index) {
521
523
return RESTERR (req, HTTP_NOT_FOUND, uri_parts[1 ] + " not found" );
522
524
}
@@ -616,14 +618,14 @@ static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const
616
618
jsonRequest.params = UniValue (UniValue::VARR);
617
619
618
620
if (!hash_str.empty ()) {
619
- uint256 hash;
620
- if (!ParseHashStr (hash_str, hash) ) {
621
+ auto hash{ uint256::FromHex (hash_str)} ;
622
+ if (!hash) {
621
623
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hash_str);
622
624
}
623
625
624
626
const ChainstateManager* chainman = GetChainman (context, req);
625
627
if (!chainman) return false ;
626
- if (!WITH_LOCK (::cs_main, return chainman->m_blockman .LookupBlockIndex (ParseHashV (hash_str, " blockhash " ) ))) {
628
+ if (!WITH_LOCK (::cs_main, return chainman->m_blockman .LookupBlockIndex (*hash ))) {
627
629
return RESTERR (req, HTTP_BAD_REQUEST, " Block not found" );
628
630
}
629
631
@@ -704,9 +706,10 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
704
706
std::string hashStr;
705
707
const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
706
708
707
- uint256 hash;
708
- if (!ParseHashStr (hashStr, hash))
709
+ auto hash{ uint256::FromHex (hashStr)} ;
710
+ if (!hash) {
709
711
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
712
+ }
710
713
711
714
if (g_txindex) {
712
715
g_txindex->BlockUntilSyncedToCurrentChain ();
@@ -715,7 +718,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
715
718
const NodeContext* const node = GetNodeContext (context, req);
716
719
if (!node) return false ;
717
720
uint256 hashBlock = uint256 ();
718
- const CTransactionRef tx = GetTransaction (/* block_index=*/ nullptr , node->mempool .get (), hash, hashBlock, node->chainman ->m_blockman );
721
+ const CTransactionRef tx{ GetTransaction (/* block_index=*/ nullptr , node->mempool .get (), * hash, hashBlock, node->chainman ->m_blockman )} ;
719
722
if (!tx) {
720
723
return RESTERR (req, HTTP_NOT_FOUND, hashStr + " not found" );
721
724
}
0 commit comments