@@ -55,9 +55,13 @@ export async function checkBlock(query: string): Promise<{
5555 return { found : false }
5656 }
5757
58- const data = await response . json ( )
58+ const json = await response . json ( )
59+ // Unwrap ResultDto if present
60+ const data = ( json && typeof json === 'object' && 'isSuccess' in json && 'data' in json )
61+ ? json . data
62+ : json
5963
60- if ( ! data . found ) {
64+ if ( ! data || ! data . found ) {
6165 return { found : false }
6266 }
6367
@@ -143,9 +147,13 @@ export async function checkTransaction(query: string): Promise<{
143147 return { found : false }
144148 }
145149
146- const responseData = await response . json ( )
150+ const json = await response . json ( )
151+ // Unwrap ResultDto if present
152+ const responseData = ( json && typeof json === 'object' && 'isSuccess' in json && 'data' in json )
153+ ? json . data
154+ : json
147155
148- if ( responseData . data && Array . isArray ( responseData . data ) && responseData . data . length > 0 ) {
156+ if ( responseData && responseData . data && Array . isArray ( responseData . data ) && responseData . data . length > 0 ) {
149157 const transactions = responseData . data . map (
150158 ( tx : { hash : string ; blockHeight ?: number ; status ?: string } ) => ( {
151159 hash : tx . hash || query ,
@@ -247,15 +255,19 @@ export async function checkContract(query: string): Promise<{
247255 return { found : false }
248256 }
249257
250- const data = await response . json ( )
258+ const json = await response . json ( )
259+ // Unwrap ResultDto if present
260+ const data = ( json && typeof json === 'object' && 'isSuccess' in json && 'data' in json )
261+ ? json . data
262+ : json
251263
252- if ( data . contract || data . address ) {
264+ if ( data && ( data . contract || data . address ) ) {
253265 return {
254266 found : true ,
255267 data : {
256268 address : data . contract ?. address ?? data . address ?? query ,
257269 variant : data . contract ?. variant ?? data . variant ,
258- id : data . contract ?. id ?? data . id ?? null
270+ id : data . contract ?. id ?? data . id ?? null
259271 }
260272 }
261273 }
@@ -270,11 +282,14 @@ export async function checkContract(query: string): Promise<{
270282}
271283
272284/**
273- * Helper function to determine if a string is a contract address (64 hex chars without 0x, or 66 with 0x)
285+ * Helper function to determine if a string is a contract address
286+ * Midnight contract addresses can be 64, 66, or 70 hex characters
274287 */
275288export function isContractAddress ( query : string ) : boolean {
276289 const cleanHash = query . startsWith ( "0x" ) ? query . slice ( 2 ) : query
277- return / ^ [ a - f A - F 0 - 9 ] { 64 } $ / . test ( cleanHash )
290+ return / ^ [ a - f A - F 0 - 9 ] { 64 } $ / . test ( cleanHash ) ||
291+ / ^ [ a - f A - F 0 - 9 ] { 66 } $ / . test ( cleanHash ) ||
292+ / ^ [ a - f A - F 0 - 9 ] { 70 } $ / . test ( cleanHash )
278293}
279294
280295/**
@@ -283,12 +298,16 @@ export function isContractAddress(query: string): boolean {
283298 * Block/Pool hash: 64 hex chars
284299 */
285300export function isHexHash ( query : string ) : boolean {
286- // With 0x prefix: total length should be 66 (block) or 68 (tx identifier)
301+ // With 0x prefix: total length should be 66, 68, or 72 chars
287302 if ( query . startsWith ( "0x" ) || query . startsWith ( "0X" ) ) {
288- return / ^ 0 [ x X ] [ a - f A - F 0 - 9 ] { 64 } $ / . test ( query ) || / ^ 0 [ x X ] [ a - f A - F 0 - 9 ] { 66 } $ / . test ( query )
303+ return / ^ 0 [ x X ] [ a - f A - F 0 - 9 ] { 64 } $ / . test ( query ) ||
304+ / ^ 0 [ x X ] [ a - f A - F 0 - 9 ] { 66 } $ / . test ( query ) ||
305+ / ^ 0 [ x X ] [ a - f A - F 0 - 9 ] { 70 } $ / . test ( query )
289306 }
290- // Without prefix: should be 64 chars (block/pool) or 66 chars (tx identifier)
291- return / ^ [ a - f A - F 0 - 9 ] { 64 } $ / . test ( query ) || / ^ [ a - f A - F 0 - 9 ] { 66 } $ / . test ( query )
307+ // Without prefix: should be 64, 66, or 70 chars
308+ return / ^ [ a - f A - F 0 - 9 ] { 64 } $ / . test ( query ) ||
309+ / ^ [ a - f A - F 0 - 9 ] { 66 } $ / . test ( query ) ||
310+ / ^ [ a - f A - F 0 - 9 ] { 70 } $ / . test ( query )
292311}
293312
294313/**
0 commit comments