rename ABIGenerator (very old legacy reasons) to more apropriate CodeGenerator
This commit is contained in:
parent
42aa072811
commit
2dc1941e48
|
@ -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;
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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();
|
||||
},
|
||||
|
|
|
@ -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"}],
|
Loading…
Reference in New Issue