rename ABIGenerator (very old legacy reasons) to more apropriate CodeGenerator

This commit is contained in:
Iuri Matias 2017-08-03 19:29:09 -04:00
parent 42aa072811
commit 2dc1941e48
6 changed files with 20 additions and 22 deletions

View File

@ -1,4 +1,4 @@
class ABIGenerator { class CodeGenerator {
constructor(options) { constructor(options) {
this.blockchainConfig = options.blockchainConfig || {}; this.blockchainConfig = options.blockchainConfig || {};
this.contractsConfig = options.contractsConfig || {}; this.contractsConfig = options.contractsConfig || {};
@ -245,4 +245,4 @@ class ABIGenerator {
} }
} }
module.exports = ABIGenerator; module.exports = CodeGenerator;

View File

@ -3,7 +3,7 @@ let async = require('async');
let RunCode = require('../core/runCode.js'); let RunCode = require('../core/runCode.js');
let DeployTracker = require('./deploy_tracker.js'); let DeployTracker = require('./deploy_tracker.js');
let ABIGenerator = require('./abi.js'); let CodeGenerator = require('./code_generator.js');
class Deploy { class Deploy {
constructor(options) { constructor(options) {
@ -81,11 +81,11 @@ class Deploy {
if (contract.onDeploy !== undefined) { if (contract.onDeploy !== undefined) {
self.logger.info('executing onDeploy commands'); self.logger.info('executing onDeploy commands');
let abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
let abi = abiGenerator.generateContracts(false); let code = codeGenerator.generateContracts(false);
let cmds = contract.onDeploy.join(';\n'); let cmds = contract.onDeploy.join(';\n');
RunCode.doEval(abi + "\n" + cmds, self.web3); RunCode.doEval(code + "\n" + cmds, self.web3);
} }
callback(); callback();

View File

@ -4,7 +4,7 @@ let Events = require('./events.js');
let Logger = require('./logger.js'); let Logger = require('./logger.js');
let Config = require('./config.js'); let Config = require('./config.js');
let DeployManager = require('../contracts/deploy_manager.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 ServicesMonitor = require('./services_monitor.js');
let Pipeline = require('../pipeline/pipeline.js'); let Pipeline = require('../pipeline/pipeline.js');
let Server = require('../pipeline/server.js'); let Server = require('../pipeline/server.js');
@ -51,7 +51,7 @@ class Engine {
let services = { let services = {
"pipeline": this.pipelineService, "pipeline": this.pipelineService,
"abi": this.abiService, "codeGenerator": this.codeGeneratorService,
"deployment": this.deploymentService, "deployment": this.deploymentService,
"fileWatcher": this.fileWatchService, "fileWatcher": this.fileWatchService,
"webServer": this.webServerService, "webServer": this.webServerService,
@ -100,10 +100,10 @@ class Engine {
//}); //});
} }
abiService(options) { codeGeneratorService(options) {
let self = this; let self = this;
let generateABICode = function (contractsManager) { let generateCode = function (contractsManager) {
let abiGenerator = new ABIGenerator({ let codeGenerator = new CodeGenerator({
blockchainConfig: self.config.blockchainConfig, blockchainConfig: self.config.blockchainConfig,
contractsConfig: self.config.contractsConfig, contractsConfig: self.config.contractsConfig,
contractsManager: contractsManager, contractsManager: contractsManager,
@ -112,12 +112,12 @@ class Engine {
communicationConfig: self.config.communicationConfig, communicationConfig: self.config.communicationConfig,
events: self.events events: self.events
}); });
abiGenerator.listenToCommands(); codeGenerator.listenToCommands();
self.events.emit('code-generator-ready'); self.events.emit('code-generator-ready');
}; };
this.events.on('contractsDeployed', generateABICode); this.events.on('contractsDeployed', generateCode);
this.events.on('blockchainDisabled', generateABICode); this.events.on('blockchainDisabled', generateCode);
} }
deploymentService(options) { deploymentService(options) {

View File

@ -5,8 +5,6 @@ var Embark = require('../index.js');
var Engine = require('./engine.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 Deploy = require('../contracts/deploy.js');
var Config = require('./config.js'); var Config = require('./config.js');

View File

@ -103,7 +103,7 @@ class Embark {
engine.startMonitor(); engine.startMonitor();
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("abi"); engine.startService("codeGenerator");
engine.startService("deployment"); engine.startService("deployment");
engine.startService("ipfs"); engine.startService("ipfs");
@ -158,7 +158,7 @@ class Embark {
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("abi"); engine.startService("codeGenerator");
engine.startService("deployment"); engine.startService("deployment");
callback(); callback();
}, },

View File

@ -1,13 +1,13 @@
/*globals describe, it*/ /*globals describe, it*/
let ABIGenerator = require('../lib/contracts/abi.js'); let CodeGenerator = require('../lib/contracts/code_generator.js');
let assert = require('assert'); let assert = require('assert');
// TODO: instead 'eval' the code with a fake web3 object // TODO: instead 'eval' the code with a fake web3 object
// and check the generate code interacts as expected // and check the generate code interacts as expected
describe('embark.ABIGenerator', function() { describe('embark.CodeGenerator', function() {
this.timeout(0); this.timeout(0);
describe('#generateProvider', function() { 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() { 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})"; 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() { describe('#generateContracts', function() {
let generator = new ABIGenerator({blockchainConfig: {}, contractsManager: { let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: {
contracts: { contracts: {
SimpleStorage: { 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"}], 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"}],