@@ -189,6 +189,7 @@ export const main = async (_config, _options, justKill) => {
189
189
const compose = await getCompose ( )
190
190
191
191
try {
192
+ console . log ( 'Starting anvil...' )
192
193
await compose . upOne ( 'anvil' , opts )
193
194
} catch ( e ) {
194
195
console . error ( 'e: ' , e )
@@ -283,17 +284,60 @@ export const main = async (_config, _options, justKill) => {
283
284
284
285
if ( options . graph ) {
285
286
try {
286
- // console.log('Starting postgres...')
287
- // await compose.upOne('postgres', opts)
288
- // console.log('Starting ipfs...')
289
- // await compose.upOne('ipfs', opts)
290
- // console.log('Starting graph-node...')
287
+ console . log ( 'Starting graph-node...' )
291
288
await compose . upOne ( 'graph-node' , opts )
292
- console . log ( 'Starting metadata...' )
293
- // await compose.upOne('metadata', opts)
294
- } catch { }
295
289
296
- await waitOn ( { resources : [ 'http://localhost:8040' ] } )
290
+ await waitOn ( { resources : [ 'http://localhost:8040' ] } )
291
+
292
+ const latestBlock = await rpcFetch ( 'eth_getBlockByNumber' , [ 'latest' , false ] )
293
+ const latestBlockNumber = parseInt ( latestBlock . result . number , 16 )
294
+ if ( Number . isNaN ( latestBlockNumber ) ) {
295
+ console . error ( 'Failed to fetch latest block number' )
296
+ return cleanup ( undefined , 0 )
297
+ }
298
+
299
+ let indexArray = [ ]
300
+ const getCurrentIndex = async ( ) =>
301
+ fetch ( 'http://localhost:8000/subgraphs/name/graphprotocol/ens' , {
302
+ method : 'POST' ,
303
+ headers : {
304
+ 'Content-Type' : 'application/json' ,
305
+ } ,
306
+ body : JSON . stringify ( {
307
+ query : `
308
+ {
309
+ _meta {
310
+ block {
311
+ number
312
+ }
313
+ }
314
+ }
315
+ ` ,
316
+ variables : { } ,
317
+ } ) ,
318
+ } )
319
+ . then ( ( res ) => res . json ( ) )
320
+ . then ( ( res ) => {
321
+ if ( res . errors ) return 0
322
+ return res . data . _meta . block . number
323
+ } )
324
+ . catch ( ( ) => 0 )
325
+ do {
326
+ const index = await getCurrentIndex ( )
327
+ console . log ( 'subgraph index:' , index )
328
+ indexArray . push ( await getCurrentIndex ( ) )
329
+ if ( indexArray . length > 10 ) indexArray . shift ( )
330
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
331
+ if ( indexArray . every ( ( i ) => i === indexArray [ 0 ] ) && indexArray . length === 10 ) {
332
+ console . error ( 'Subgraph failed to launch properly' )
333
+ return cleanup ( undefined , 0 )
334
+ }
335
+ } while (
336
+ indexArray [ indexArray . length - 1 ] < latestBlockNumber
337
+ )
338
+ console . log ( 'Starting remaining docker containers...' )
339
+ await compose . upAll ( opts )
340
+ } catch { }
297
341
298
342
if ( options . save ) {
299
343
const internalHashes = [
@@ -351,55 +395,6 @@ export const main = async (_config, _options, justKill) => {
351
395
}
352
396
353
397
if ( ! options . save && cmdsToRun . length > 0 && options . scripts ) {
354
- if ( options . graph ) {
355
-
356
- const latestBlock = await rpcFetch ( 'eth_getBlockByNumber' , [ 'latest' , false ] )
357
- const latestBlockNumber = parseInt ( latestBlock . result . number , 16 )
358
- if ( Number . isNaN ( latestBlockNumber ) ) {
359
- console . error ( 'Failed to fetch latest block number' )
360
- return cleanup ( undefined , 0 )
361
- }
362
-
363
- let indexArray = [ ]
364
- const getCurrentIndex = async ( ) =>
365
- fetch ( 'http://localhost:8000/subgraphs/name/graphprotocol/ens' , {
366
- method : 'POST' ,
367
- headers : {
368
- 'Content-Type' : 'application/json' ,
369
- } ,
370
- body : JSON . stringify ( {
371
- query : `
372
- {
373
- _meta {
374
- block {
375
- number
376
- }
377
- }
378
- }
379
- ` ,
380
- variables : { } ,
381
- } ) ,
382
- } )
383
- . then ( ( res ) => res . json ( ) )
384
- . then ( ( res ) => {
385
- if ( res . errors ) return 0
386
- return res . data . _meta . block . number
387
- } )
388
- . catch ( ( ) => 0 )
389
- do {
390
- const index = await getCurrentIndex ( )
391
- console . log ( 'current index:' , index )
392
- indexArray . push ( await getCurrentIndex ( ) )
393
- if ( indexArray . length > 10 ) indexArray . shift ( )
394
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
395
- if ( indexArray . every ( ( i ) => i === indexArray [ 0 ] ) && indexArray . length === 10 ) {
396
- console . error ( 'Subgraph failed to launch properly' )
397
- return cleanup ( undefined , 0 )
398
- }
399
- } while (
400
- indexArray [ indexArray . length - 1 ] < latestBlockNumber
401
- )
402
- }
403
398
/**
404
399
* @type {import('concurrently').ConcurrentlyResult['result'] }
405
400
**/
0 commit comments