@@ -369,7 +369,7 @@ export const fetchBlockDetails = async (hashOrHeight: string): Promise<BlockInfo
369369 }
370370
371371 const data = response . data ;
372- console . log ( 'Block data received :' , data ) ; // Debug log
372+ console . log ( 'Raw block data :' , data ) ; // Debug log
373373
374374 // Process the block data according to blockchain.info API format
375375 const processedData : BlockInfo = {
@@ -386,10 +386,23 @@ export const fetchBlockDetails = async (hashOrHeight: string): Promise<BlockInfo
386386 nonce : data . nonce || 0 ,
387387 weight : data . weight || 0 ,
388388 difficulty : data . difficulty || 0 ,
389- transactions : Array . isArray ( data . tx ) ? data . tx : [ ] ,
390- reward : calculateBlockReward ( data . height || 0 )
389+ transactions : Array . isArray ( data . tx ) ? data . tx . map ( ( tx : any ) => ( {
390+ hash : tx . hash || '' ,
391+ size : tx . size || 0 ,
392+ fee : tx . fee || 0 ,
393+ time : tx . time || data . time || Math . floor ( Date . now ( ) / 1000 ) ,
394+ inputs : tx . inputs || [ ] ,
395+ out : tx . out || [ ]
396+ } ) ) : [ ] ,
397+ reward : calculateBlockReward ( data . height || 0 ) ,
398+ miner : extractMinerFromCoinbase ( data . tx ?. [ 0 ] ?. inputs ?. [ 0 ] ?. script || '' )
391399 } ;
392400
401+ // Validate the processed data
402+ if ( ! isBlockHash ( processedData . hash ) ) {
403+ throw new Error ( 'Invalid block data: hash is not in correct format' ) ;
404+ }
405+
393406 return processedData ;
394407 } catch ( error ) {
395408 console . error ( 'Error fetching block details:' , error ) ;
0 commit comments