From 2dc1941e4827dc5564764fde5ca37f456475df3e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 3 Aug 2017 19:29:09 -0400 Subject: [PATCH] rename ABIGenerator (very old legacy reasons) to more apropriate CodeGenerator --- lib/contracts/{abi.js => code_generator.js} | 4 ++-- lib/contracts/deploy.js | 8 ++++---- lib/core/engine.js | 16 ++++++++-------- lib/core/test.js | 2 -- lib/index.js | 4 ++-- test/{abi.js => code_generator.js} | 8 ++++---- 6 files changed, 20 insertions(+), 22 deletions(-) rename lib/contracts/{abi.js => code_generator.js} (99%) rename test/{abi.js => code_generator.js} (95%) diff --git a/lib/contracts/abi.js b/lib/contracts/code_generator.js similarity index 99% rename from lib/contracts/abi.js rename to lib/contracts/code_generator.js index caf6a6e6f..d4ef7e038 100644 --- a/lib/contracts/abi.js +++ b/lib/contracts/code_generator.js @@ -1,4 +1,4 @@ -class ABIGenerator { +class CodeGenerator { constructor(options) { this.blockchainConfig = options.blockchainConfig || {}; this.contractsConfig = options.contractsConfig || {}; @@ -245,4 +245,4 @@ class ABIGenerator { } } -module.exports = ABIGenerator; +module.exports = CodeGenerator; diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 8af0a1703..5ed3b833b 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -3,7 +3,7 @@ let async = require('async'); let RunCode = require('../core/runCode.js'); let DeployTracker = require('./deploy_tracker.js'); -let ABIGenerator = require('./abi.js'); +let CodeGenerator = require('./code_generator.js'); class Deploy { constructor(options) { @@ -81,11 +81,11 @@ class Deploy { if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); - let abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); - let abi = abiGenerator.generateContracts(false); + let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); + let code = codeGenerator.generateContracts(false); let cmds = contract.onDeploy.join(';\n'); - RunCode.doEval(abi + "\n" + cmds, self.web3); + RunCode.doEval(code + "\n" + cmds, self.web3); } callback(); diff --git a/lib/core/engine.js b/lib/core/engine.js index cad71fe83..181b129d3 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -4,7 +4,7 @@ let Events = require('./events.js'); let Logger = require('./logger.js'); let Config = require('./config.js'); let DeployManager = require('../contracts/deploy_manager.js'); -let ABIGenerator = require('../contracts/abi.js'); +let CodeGenerator = require('../contracts/code_generator.js'); let ServicesMonitor = require('./services_monitor.js'); let Pipeline = require('../pipeline/pipeline.js'); let Server = require('../pipeline/server.js'); @@ -51,7 +51,7 @@ class Engine { let services = { "pipeline": this.pipelineService, - "abi": this.abiService, + "codeGenerator": this.codeGeneratorService, "deployment": this.deploymentService, "fileWatcher": this.fileWatchService, "webServer": this.webServerService, @@ -100,10 +100,10 @@ class Engine { //}); } - abiService(options) { + codeGeneratorService(options) { let self = this; - let generateABICode = function (contractsManager) { - let abiGenerator = new ABIGenerator({ + let generateCode = function (contractsManager) { + let codeGenerator = new CodeGenerator({ blockchainConfig: self.config.blockchainConfig, contractsConfig: self.config.contractsConfig, contractsManager: contractsManager, @@ -112,12 +112,12 @@ class Engine { communicationConfig: self.config.communicationConfig, events: self.events }); - abiGenerator.listenToCommands(); + codeGenerator.listenToCommands(); self.events.emit('code-generator-ready'); }; - this.events.on('contractsDeployed', generateABICode); - this.events.on('blockchainDisabled', generateABICode); + this.events.on('contractsDeployed', generateCode); + this.events.on('blockchainDisabled', generateCode); } deploymentService(options) { diff --git a/lib/core/test.js b/lib/core/test.js index 593f3c4e6..22e05abe1 100644 --- a/lib/core/test.js +++ b/lib/core/test.js @@ -5,8 +5,6 @@ var Embark = require('../index.js'); var Engine = require('./engine.js'); -var ABIGenerator = require('../contracts/abi.js'); -var ContractsManager = require('../contracts/contracts.js'); var Deploy = require('../contracts/deploy.js'); var Config = require('./config.js'); diff --git a/lib/index.js b/lib/index.js index 9e931ac1c..88498f09d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,7 +103,7 @@ class Embark { engine.startMonitor(); engine.startService("web3"); engine.startService("pipeline"); - engine.startService("abi"); + engine.startService("codeGenerator"); engine.startService("deployment"); engine.startService("ipfs"); @@ -158,7 +158,7 @@ class Embark { engine.startService("web3"); engine.startService("pipeline"); - engine.startService("abi"); + engine.startService("codeGenerator"); engine.startService("deployment"); callback(); }, diff --git a/test/abi.js b/test/code_generator.js similarity index 95% rename from test/abi.js rename to test/code_generator.js index 04a506ed6..4ea42f9b6 100644 --- a/test/abi.js +++ b/test/code_generator.js @@ -1,13 +1,13 @@ /*globals describe, it*/ -let ABIGenerator = require('../lib/contracts/abi.js'); +let CodeGenerator = require('../lib/contracts/code_generator.js'); let assert = require('assert'); // TODO: instead 'eval' the code with a fake web3 object // and check the generate code interacts as expected -describe('embark.ABIGenerator', function() { +describe('embark.CodeGenerator', function() { this.timeout(0); describe('#generateProvider', function() { - let generator = new ABIGenerator({contractsConfig: {"dappConnection": [ "$WEB3", "http://somehost:1234" ] }, contractsManager: {}}); + let generator = new CodeGenerator({contractsConfig: {"dappConnection": [ "$WEB3", "http://somehost:1234" ] }, contractsManager: {}}); it('should generate code to connect to a provider', function() { var providerCode = "\nvar whenEnvIsLoaded = function(cb) {\n if (typeof document !== 'undefined' && document !== null) {\n document.addEventListener('DOMContentLoaded', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} if (typeof Web3 !== 'undefined' && ((typeof web3 === 'undefined') || (typeof web3 !== 'undefined' && !web3.isConnected()))) {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];\n})"; @@ -17,7 +17,7 @@ describe('embark.ABIGenerator', function() { }); describe('#generateContracts', function() { - let generator = new ABIGenerator({blockchainConfig: {}, contractsManager: { + let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: { contracts: { SimpleStorage: { abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}],