@@ -52,6 +52,8 @@ class Compiler {
52
52
53
53
this . globalsFile = path . join ( globalsLib , globalsFile )
54
54
55
+ this . protocol = this . options . protocol
56
+
55
57
process . on ( 'uncaughtException' , function ( e ) {
56
58
toolbox . print . error ( `UNCAUGHT EXCEPTION: ${ e } ` )
57
59
} )
@@ -132,9 +134,12 @@ class Compiler {
132
134
files . push ( path . resolve ( subgraph . getIn ( [ 'schema' , 'file' ] ) ) )
133
135
subgraph . get ( 'dataSources' ) . map ( dataSource => {
134
136
files . push ( dataSource . getIn ( [ 'mapping' , 'file' ] ) )
135
- dataSource . getIn ( [ 'mapping' , 'abis' ] ) . map ( abi => {
136
- files . push ( abi . get ( 'file' ) )
137
- } )
137
+ // Only watch ABI related files if the target protocol has support/need for them.
138
+ if ( this . protocol . hasABIs ( ) ) {
139
+ dataSource . getIn ( [ 'mapping' , 'abis' ] ) . map ( abi => {
140
+ files . push ( abi . get ( 'file' ) )
141
+ } )
142
+ }
138
143
} )
139
144
140
145
// Make paths absolute
@@ -403,46 +408,53 @@ class Compiler {
403
408
} )
404
409
405
410
// Copy data source files and update their paths
406
- subgraph = subgraph . update ( 'dataSources' , dataSources => {
407
- return dataSources . map ( dataSource =>
408
- dataSource
409
- // Write data source ABIs to the output directory
410
- . updateIn ( [ 'mapping' , 'abis' ] , abis =>
411
- abis . map ( abi =>
412
- abi . update ( 'file' , abiFile => {
413
- abiFile = path . resolve ( this . sourceDir , abiFile )
414
- let abiData = ABI . load ( abi . get ( 'name' ) , abiFile )
415
- return path . relative (
416
- this . options . outputDir ,
417
- this . _writeSubgraphFile (
418
- abiFile ,
419
- JSON . stringify ( abiData . data . toJS ( ) , null , 2 ) ,
420
- this . sourceDir ,
421
- this . subgraphDir ( this . options . outputDir , dataSource ) ,
422
- spinner ,
423
- ) ,
424
- )
425
- } ) ,
426
- ) ,
427
- )
428
-
429
- // The mapping file is already being written to the output
430
- // directory by the AssemblyScript compiler
431
- . updateIn ( [ 'mapping' , 'file' ] , mappingFile =>
432
- path . relative (
433
- this . options . outputDir ,
434
- path . resolve ( this . sourceDir , mappingFile ) ,
435
- ) ,
411
+ subgraph = subgraph . update ( 'dataSources' , dataSources =>
412
+ dataSources . map ( dataSource => {
413
+ let updatedDataSource = dataSource
414
+
415
+ if ( this . protocol . hasABIs ( ) ) {
416
+ updatedDataSource = updatedDataSource
417
+ // Write data source ABIs to the output directory
418
+ . updateIn ( [ 'mapping' , 'abis' ] , abis =>
419
+ abis . map ( abi =>
420
+ abi . update ( 'file' , abiFile => {
421
+ abiFile = path . resolve ( this . sourceDir , abiFile )
422
+ let abiData = ABI . load ( abi . get ( 'name' ) , abiFile )
423
+ return path . relative (
424
+ this . options . outputDir ,
425
+ this . _writeSubgraphFile (
426
+ abiFile ,
427
+ JSON . stringify ( abiData . data . toJS ( ) , null , 2 ) ,
428
+ this . sourceDir ,
429
+ this . subgraphDir ( this . options . outputDir , dataSource ) ,
430
+ spinner ,
431
+ ) ,
432
+ )
433
+ } ) ,
434
+ ) ,
435
+ )
436
+ }
437
+
438
+ // The mapping file is already being written to the output
439
+ // directory by the AssemblyScript compiler
440
+ return updatedDataSource . updateIn ( [ 'mapping' , 'file' ] , mappingFile =>
441
+ path . relative (
442
+ this . options . outputDir ,
443
+ path . resolve ( this . sourceDir , mappingFile ) ,
436
444
) ,
437
- )
438
- } )
445
+ )
446
+ } )
447
+ )
439
448
440
449
// Copy template files and update their paths
441
- subgraph = subgraph . update ( 'templates' , templates => {
442
- return templates === undefined
450
+ subgraph = subgraph . update ( 'templates' , templates =>
451
+ templates === undefined
443
452
? templates
444
- : templates . map ( template =>
445
- template
453
+ : templates . map ( template => {
454
+ let updatedTemplate = template
455
+
456
+ if ( this . protocol . hasABIs ( ) ) {
457
+ updatedTemplate = updatedTemplate
446
458
// Write template ABIs to the output directory
447
459
. updateIn ( [ 'mapping' , 'abis' ] , abis =>
448
460
abis . map ( abi =>
@@ -462,17 +474,18 @@ class Compiler {
462
474
} ) ,
463
475
) ,
464
476
)
477
+ }
465
478
466
- // The mapping file is already being written to the output
467
- // directory by the AssemblyScript compiler
468
- . updateIn ( [ 'mapping' , 'file' ] , mappingFile =>
469
- path . relative (
470
- this . options . outputDir ,
471
- path . resolve ( this . sourceDir , mappingFile ) ,
472
- ) ,
473
- ) ,
479
+ // The mapping file is already being written to the output
480
+ // directory by the AssemblyScript compiler
481
+ return updatedTemplate . updateIn ( [ 'mapping' , 'file' ] , mappingFile =>
482
+ path . relative (
483
+ this . options . outputDir ,
484
+ path . resolve ( this . sourceDir , mappingFile ) ,
485
+ ) ,
474
486
)
475
- } )
487
+ } )
488
+ )
476
489
477
490
// Write the subgraph manifest itself
478
491
let outputFilename = path . join ( this . options . outputDir , 'subgraph.yaml' )
@@ -506,17 +519,18 @@ class Compiler {
506
519
) ,
507
520
} )
508
521
509
- // Upload the ABIs of all data sources to IPFS
510
- for ( let [ i , dataSource ] of subgraph . get ( 'dataSources' ) . entries ( ) ) {
511
- for ( let [ j , abi ] of dataSource . getIn ( [ 'mapping' , 'abis' ] ) . entries ( ) ) {
512
- updates . push ( {
513
- keyPath : [ 'dataSources' , i , 'mapping' , 'abis' , j , 'file' ] ,
514
- value : await this . _uploadFileToIPFS (
515
- abi . get ( 'file' ) ,
516
- uploadedFiles ,
517
- spinner ,
518
- ) ,
519
- } )
522
+ if ( this . protocol . hasABIs ( ) ) {
523
+ for ( let [ i , dataSource ] of subgraph . get ( 'dataSources' ) . entries ( ) ) {
524
+ for ( let [ j , abi ] of dataSource . getIn ( [ 'mapping' , 'abis' ] ) . entries ( ) ) {
525
+ updates . push ( {
526
+ keyPath : [ 'dataSources' , i , 'mapping' , 'abis' , j , 'file' ] ,
527
+ value : await this . _uploadFileToIPFS (
528
+ abi . get ( 'file' ) ,
529
+ uploadedFiles ,
530
+ spinner ,
531
+ ) ,
532
+ } )
533
+ }
520
534
}
521
535
}
522
536
@@ -532,17 +546,18 @@ class Compiler {
532
546
} )
533
547
}
534
548
535
- // Upload the mapping and ABIs of all data source templates
536
549
for ( let [ i , template ] of subgraph . get ( 'templates' , immutable . List ( ) ) . entries ( ) ) {
537
- for ( let [ j , abi ] of template . getIn ( [ 'mapping' , 'abis' ] ) . entries ( ) ) {
538
- updates . push ( {
539
- keyPath : [ 'templates' , i , 'mapping' , 'abis' , j , 'file' ] ,
540
- value : await this . _uploadFileToIPFS (
541
- abi . get ( 'file' ) ,
542
- uploadedFiles ,
543
- spinner ,
544
- ) ,
545
- } )
550
+ if ( this . protocol . hasABIs ( ) ) {
551
+ for ( let [ j , abi ] of template . getIn ( [ 'mapping' , 'abis' ] ) . entries ( ) ) {
552
+ updates . push ( {
553
+ keyPath : [ 'templates' , i , 'mapping' , 'abis' , j , 'file' ] ,
554
+ value : await this . _uploadFileToIPFS (
555
+ abi . get ( 'file' ) ,
556
+ uploadedFiles ,
557
+ spinner ,
558
+ ) ,
559
+ } )
560
+ }
546
561
}
547
562
548
563
updates . push ( {
0 commit comments