@@ -84,37 +84,7 @@ function waitForTransaction(tx, signer, txName, txMode = TX_MODE_IN_BLOCK) {
8484export async function fetchCid ( httpIpfsApi , cid , maxRetries = 10 , initialDelay = 2000 ) {
8585 const contentUrl = `${ httpIpfsApi } /ipfs/${ cid . toString ( ) } ` ;
8686 console . log ( '⬇️ Downloading the full content (no chunking) by cid from url: ' , contentUrl ) ;
87-
88- let lastError ;
89- for ( let attempt = 0 ; attempt < maxRetries ; attempt ++ ) {
90- try {
91- const res = await fetch ( contentUrl ) ;
92- if ( res . ok ) {
93- console . log ( `✅ Content fetched successfully on attempt ${ attempt + 1 } ` ) ;
94- return Buffer . from ( await res . arrayBuffer ( ) ) ;
95- }
96-
97- // If we get a 404 or 504, retry (content might not be available yet)
98- if ( res . status === 404 || res . status === 504 || res . status === 502 ) {
99- lastError = new Error ( `HTTP error ${ res . status } ` ) ;
100- const delay = initialDelay * Math . pow ( 1.5 , attempt ) ;
101- console . log ( `⏳ Attempt ${ attempt + 1 } /${ maxRetries } failed with status ${ res . status } , retrying in ${ delay } ms...` ) ;
102- await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
103- continue ;
104- }
105-
106- // For other errors, throw immediately
107- throw new Error ( `HTTP error ${ res . status } ` ) ;
108- } catch ( error ) {
109- // Network errors, timeouts, etc.
110- lastError = error ;
111- if ( attempt < maxRetries - 1 ) {
112- const delay = initialDelay * Math . pow ( 1.5 , attempt ) ;
113- console . log ( `⏳ Attempt ${ attempt + 1 } /${ maxRetries } failed with error: ${ error . message } , retrying in ${ delay } ms...` ) ;
114- await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
115- }
116- }
117- }
118-
119- throw new Error ( `Failed to fetch CID after ${ maxRetries } attempts. Last error: ${ lastError ?. message } ` ) ;
87+ const res = await fetch ( contentUrl ) ;
88+ if ( ! res . ok ) throw new Error ( `HTTP error ${ res . status } ` ) ;
89+ return Buffer . from ( await res . arrayBuffer ( ) )
12090}
0 commit comments