Skip to content

Commit 5d7adb4

Browse files
committed
abi: Move to protocol except for 'init'
1 parent 5738d05 commit 5d7adb4

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/commands/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { withSpinner, step } = require('../command-helpers/spinner')
1515
const { fixParameters } = require('../command-helpers/gluegun')
1616
const { chooseNodeUrl } = require('../command-helpers/node')
1717
const { abiEvents, generateScaffold, writeScaffold } = require('../scaffold')
18+
// TODO: Use Protocol class to getABI
1819
const ABI = require('../protocols/ethereum/abi')
1920

2021
const networkChoices = [

src/compiler/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const toolbox = require('gluegun/toolbox')
99
const { step, withSpinner } = require('../command-helpers/spinner')
1010
const Subgraph = require('../subgraph')
1111
const Watcher = require('../watcher')
12-
const ABI = require('../protocols/ethereum/abi')
1312
const { applyMigrations } = require('../migrations')
1413
const asc = require('./asc')
1514

@@ -53,6 +52,7 @@ class Compiler {
5352
this.globalsFile = path.join(globalsLib, globalsFile)
5453

5554
this.protocol = this.options.protocol
55+
this.ABI = this.protocol.getABI()
5656

5757
process.on('uncaughtException', function(e) {
5858
toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`)
@@ -419,7 +419,7 @@ class Compiler {
419419
abis.map(abi =>
420420
abi.update('file', abiFile => {
421421
abiFile = path.resolve(this.sourceDir, abiFile)
422-
let abiData = ABI.load(abi.get('name'), abiFile)
422+
let abiData = this.ABI.load(abi.get('name'), abiFile)
423423
return path.relative(
424424
this.options.outputDir,
425425
this._writeSubgraphFile(
@@ -460,7 +460,7 @@ class Compiler {
460460
abis.map(abi =>
461461
abi.update('file', abiFile => {
462462
abiFile = path.resolve(this.sourceDir, abiFile)
463-
let abiData = ABI.load(abi.get('name'), abiFile)
463+
let abiData = this.ABI.load(abi.get('name'), abiFile)
464464
return path.relative(
465465
this.options.outputDir,
466466
this._writeSubgraphFile(

src/protocols/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const EthereumTypeGenerator = require('./ethereum/type-generator')
22
const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
33
const NearTemplateCodeGen = require('./near/codegen/template')
4+
const EthereumABI = require('./ethereum/abi')
45

56
module.exports = class Protocol {
67
static fromDataSources(dataSourcesAndTemplates) {
@@ -45,4 +46,14 @@ module.exports = class Protocol {
4546
)
4647
}
4748
}
49+
50+
getABI() {
51+
switch (this.name) {
52+
case 'ethereum':
53+
case 'ethereum/contract':
54+
return EthereumABI
55+
case 'near':
56+
return null
57+
}
58+
}
4859
}

src/scaffold.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const pkginfo = require('pkginfo')(module)
66
const { getSubgraphBasename } = require('./command-helpers/subgraph')
77
const { step } = require('./command-helpers/spinner')
88
const { ascTypeForEthereum, valueTypeForAsc } = require('./codegen/types')
9+
// TODO: Use Protocol class to getABI
910
const ABI = require('./protocols/ethereum/abi')
1011
const AbiCodeGenerator = require('./protocols/ethereum/codegen/abi')
1112
const util = require('./codegen/util')

0 commit comments

Comments
 (0)