@@ -217,9 +217,10 @@ static bool rest_headers(const std::any& context,
217217 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));
218218 }
219219
220- uint256 hash;
221- if (!ParseHashStr (hashStr, hash))
220+ auto hash{ uint256::FromHex (hashStr)} ;
221+ if (!hash) {
222222 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
223+ }
223224
224225 const CBlockIndex* tip = nullptr ;
225226 std::vector<const CBlockIndex*> headers;
@@ -231,7 +232,7 @@ static bool rest_headers(const std::any& context,
231232 LOCK (cs_main);
232233 CChain& active_chain = chainman.ActiveChain ();
233234 tip = active_chain.Tip ();
234- const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (hash);
235+ const CBlockIndex* pindex{ chainman.m_blockman .LookupBlockIndex (* hash)} ;
235236 while (pindex != nullptr && active_chain.Contains (pindex)) {
236237 headers.push_back (pindex);
237238 if (headers.size () == *parsed_count) {
@@ -290,9 +291,10 @@ static bool rest_block(const std::any& context,
290291 std::string hashStr;
291292 const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
292293
293- uint256 hash;
294- if (!ParseHashStr (hashStr, hash))
294+ auto hash{ uint256::FromHex (hashStr)} ;
295+ if (!hash) {
295296 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
297+ }
296298
297299 FlatFilePos pos{};
298300 const CBlockIndex* pblockindex = nullptr ;
@@ -303,7 +305,7 @@ static bool rest_block(const std::any& context,
303305 {
304306 LOCK (cs_main);
305307 tip = chainman.ActiveChain ().Tip ();
306- pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
308+ pblockindex = chainman.m_blockman .LookupBlockIndex (* hash);
307309 if (!pblockindex) {
308310 return RESTERR (req, HTTP_NOT_FOUND, hashStr + " not found" );
309311 }
@@ -390,8 +392,8 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
390392 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));
391393 }
392394
393- uint256 block_hash;
394- if (!ParseHashStr (raw_blockhash, block_hash) ) {
395+ auto block_hash{ uint256::FromHex (raw_blockhash)} ;
396+ if (!block_hash) {
395397 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + raw_blockhash);
396398 }
397399
@@ -413,7 +415,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
413415 ChainstateManager& chainman = *maybe_chainman;
414416 LOCK (cs_main);
415417 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)} ;
417419 while (pindex != nullptr && active_chain.Contains (pindex)) {
418420 headers.push_back (pindex);
419421 if (headers.size () == *parsed_count)
@@ -494,8 +496,8 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
494496 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid URI format. Expected /rest/blockfilter/<filtertype>/<blockhash>" );
495497 }
496498
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) {
499501 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + uri_parts[1 ]);
500502 }
501503
@@ -516,7 +518,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
516518 if (!maybe_chainman) return false ;
517519 ChainstateManager& chainman = *maybe_chainman;
518520 LOCK (cs_main);
519- block_index = chainman.m_blockman .LookupBlockIndex (block_hash);
521+ block_index = chainman.m_blockman .LookupBlockIndex (* block_hash);
520522 if (!block_index) {
521523 return RESTERR (req, HTTP_NOT_FOUND, uri_parts[1 ] + " not found" );
522524 }
@@ -616,14 +618,14 @@ static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const
616618 jsonRequest.params = UniValue (UniValue::VARR);
617619
618620 if (!hash_str.empty ()) {
619- uint256 hash;
620- if (!ParseHashStr (hash_str, hash) ) {
621+ auto hash{ uint256::FromHex (hash_str)} ;
622+ if (!hash) {
621623 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hash_str);
622624 }
623625
624626 const ChainstateManager* chainman = GetChainman (context, req);
625627 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 ))) {
627629 return RESTERR (req, HTTP_BAD_REQUEST, " Block not found" );
628630 }
629631
@@ -704,9 +706,10 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
704706 std::string hashStr;
705707 const RESTResponseFormat rf = ParseDataFormat (hashStr, strURIPart);
706708
707- uint256 hash;
708- if (!ParseHashStr (hashStr, hash))
709+ auto hash{ uint256::FromHex (hashStr)} ;
710+ if (!hash) {
709711 return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
712+ }
710713
711714 if (g_txindex) {
712715 g_txindex->BlockUntilSyncedToCurrentChain ();
@@ -715,7 +718,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
715718 const NodeContext* const node = GetNodeContext (context, req);
716719 if (!node) return false ;
717720 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 )} ;
719722 if (!tx) {
720723 return RESTERR (req, HTTP_NOT_FOUND, hashStr + " not found" );
721724 }
@@ -792,13 +795,14 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
792795 if (txid_out.size () != 2 ) {
793796 return RESTERR (req, HTTP_BAD_REQUEST, " Parse error" );
794797 }
798+ auto txid{Txid::FromHex (txid_out.at (0 ))};
795799 auto output{ToIntegral<uint32_t >(txid_out.at (1 ))};
796800
797- if (!output || !IsHex (txid_out. at ( 0 )) ) {
801+ if (!txid || !output ) {
798802 return RESTERR (req, HTTP_BAD_REQUEST, " Parse error" );
799803 }
800804
801- vOutPoints.emplace_back (TxidFromString (txid_out. at ( 0 )) , *output);
805+ vOutPoints.emplace_back (*txid , *output);
802806 }
803807
804808 if (vOutPoints.size () > 0 )
0 commit comments