Merge branch 'develop' of https://github.com/embark-framework/embark into develop

This commit is contained in:
Jonathan Rainville 2018-05-31 10:38:09 -04:00
commit ac69f2f9fd
24 changed files with 271 additions and 320 deletions

View File

@ -28,8 +28,6 @@ class CodeGenerator {
this.communicationConfig = options.communicationConfig || {}; this.communicationConfig = options.communicationConfig || {};
this.namesystemConfig = options.namesystemConfig || {}; this.namesystemConfig = options.namesystemConfig || {};
this.env = options.env || 'development'; this.env = options.env || 'development';
// TODO: this should also be removed and use events instead
this.contractsManager = options.contractsManager;
this.plugins = options.plugins; this.plugins = options.plugins;
this.events = options.events; this.events = options.events;
} }
@ -43,71 +41,47 @@ class CodeGenerator {
cb(providerCode); cb(providerCode);
}); });
// deprecated events; to remove in embark 2.7.0
this.events.setCommandHandlerOnce('abi-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON();
cb(vanillaABI, contractsJSON);
});
this.events.setCommandHandlerOnce('abi', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON();
cb(embarkJSABI, contractsJSON);
});
this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false);
let contractsJSON = self.generateContractsJSON();
cb(vanillaContractsABI, contractsJSON);
});
this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON();
cb(vanillaABI, contractsJSON);
});
// new events // new events
this.events.setCommandHandlerOnce('code-vanila', function(cb) { this.events.setCommandHandlerOnce('code-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false}); self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(); let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON); cb(vanillaABI, contractsJSON);
});
}); });
this.events.setCommandHandlerOnce('code', function(cb) { this.events.setCommandHandlerOnce('code', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true}); self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(); let embarkJSABI = self.generateABI(contractsList, {useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON(contractsList);
cb(embarkJSABI, contractsJSON); cb(embarkJSABI, contractsJSON);
});
}); });
this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) { this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false); self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(); let vanillaContractsABI = self.generateContracts(contractsList, false, true, false);
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaContractsABI, contractsJSON); cb(vanillaContractsABI, contractsJSON);
});
}); });
this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) { this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(); let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON); cb(vanillaABI, contractsJSON);
});
}); });
this.events.setCommandHandlerOnce('code-generator:web3js', function(cb) { this.events.setCommandHandlerOnce('code-generator:web3js', function(cb) {
self.buildWeb3JS(cb); self.buildWeb3JS(cb);
}); });
this.events.setCommandHandler('code-generator:contract', (contractName, cb) => { self.events.setCommandHandler('code-generator:contract', (contractName, cb) => {
let contract = self.contractsManager.contracts[contractName]; self.events.request('contracts:contract', contractName, (contract) => {
self.buildContractJS(contractName, self.generateContractJSON(contractName, contract), cb); self.buildContractJS(contractName, self.generateContractJSON(contract, contract), cb);
});
}); });
self.events.setCommandHandler('code-generator:contract:vanilla', (contract, gasLimit, cb) => { self.events.setCommandHandler('code-generator:contract:vanilla', (contract, gasLimit, cb) => {
@ -115,7 +89,7 @@ class CodeGenerator {
}); });
this.events.setCommandHandler('embark-building-placeholder', (cb) => { this.events.setCommandHandler('embark-building-placeholder', (cb) => {
this.buildPlaceholderPage(cb); self.buildPlaceholderPage(cb);
}); });
} }
@ -173,16 +147,15 @@ class CodeGenerator {
return result; return result;
} }
generateContracts(useEmbarkJS, isDeployment, useLoader) { generateContracts(contractsList, useEmbarkJS, isDeployment, useLoader) {
let self = this; let self = this;
let result = "\n"; let result = "\n";
let contractsPlugins; let contractsPlugins;
if (useLoader === false) { if (useLoader === false) {
for (let className in this.contractsManager.contracts) { for (let contract of contractsList) {
let contract = this.contractsManager.contracts[className];
let abi = JSON.stringify(contract.abiDefinition); let abi = JSON.stringify(contract.abiDefinition);
result += Templates.vanilla_contract({className: className, abi: abi, contract: contract, gasLimit: 6000000}); result += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: 6000000});
} }
return result; return result;
} }
@ -197,12 +170,10 @@ class CodeGenerator {
if (this.plugins && contractsPlugins.length > 0) { if (this.plugins && contractsPlugins.length > 0) {
contractsPlugins.forEach(function (plugin) { contractsPlugins.forEach(function (plugin) {
result += plugin.generateContracts({contracts: self.contractsManager.contracts}); result += plugin.generateContracts({contracts: contractsList});
}); });
} else { } else {
for (let className in this.contractsManager.contracts) { for (let contract of contractsList) {
let contract = this.contractsManager.contracts[className];
let abi = JSON.stringify(contract.abiDefinition); let abi = JSON.stringify(contract.abiDefinition);
let gasEstimates = JSON.stringify(contract.gasEstimates); let gasEstimates = JSON.stringify(contract.gasEstimates);
@ -210,9 +181,9 @@ class CodeGenerator {
if (useEmbarkJS) { if (useEmbarkJS) {
let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined"; let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined";
block += Templates.embarkjs_contract({className: className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates}); block += Templates.embarkjs_contract({className: contract.className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates});
} else { } else {
block += Templates.vanilla_contract({className: className, abi: abi, contract: contract, gasLimit: (isDeployment ? 6000000 : false)}); block += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: (isDeployment ? 6000000 : false)});
} }
result += Templates.exec_when_ready({block: block}); result += Templates.exec_when_ready({block: block});
@ -276,11 +247,11 @@ class CodeGenerator {
return result; return result;
} }
generateABI(options) { generateABI(contractsList, options) {
let result = ""; let result = "";
result += this.generateProvider(options.deployment); result += this.generateProvider(options.deployment);
result += this.generateContracts(options.useEmbarkJS, options.deployment, true); result += this.generateContracts(contractsList, options.useEmbarkJS, options.deployment, true);
result += this.generateStorageInitialization(options.useEmbarkJS); result += this.generateStorageInitialization(options.useEmbarkJS);
result += this.generateCommunicationInitialization(options.useEmbarkJS); result += this.generateCommunicationInitialization(options.useEmbarkJS);
result += this.generateNamesInitialization(options.useEmbarkJS); result += this.generateNamesInitialization(options.useEmbarkJS);
@ -304,12 +275,11 @@ class CodeGenerator {
return contractJSON; return contractJSON;
} }
generateContractsJSON() { generateContractsJSON(contractsList) {
let contracts = {}; let contracts = {};
for (let className in this.contractsManager.contracts) { for (let contract of contractsList) {
let contract = this.contractsManager.contracts[className]; contracts[contract.className] = this.generateContractJSON(contract.className, contract);
contracts[className] = this.generateContractJSON(className, contract);
} }
return contracts; return contracts;

View File

@ -2,13 +2,19 @@ let async = require('async');
//require("../utils/debug_util.js")(__filename, async); //require("../utils/debug_util.js")(__filename, async);
let utils = require('../utils/utils.js'); let utils = require('../utils/utils.js');
class Deploy { class ContractDeployer {
constructor(options) { constructor(options) {
const self = this;
this.blockchain = options.blockchain; this.blockchain = options.blockchain;
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.plugins = options.plugins; this.plugins = options.plugins;
this.gasLimit = options.gasLimit; this.gasLimit = options.gasLimit;
self.events.setCommandHandler('deploy:contract', (contract, cb) => {
self.checkAndDeployContract(contract, null, cb);
});
} }
// TODO: determining the arguments could also be in a module since it's not // TODO: determining the arguments could also be in a module since it's not
@ -30,40 +36,30 @@ class Deploy {
} }
} }
let realArgs = []; async.map(args, (arg, nextEachCb) => {
async.eachLimit(args, 1, (arg, nextEachCb) => {
if (arg[0] === "$") { if (arg[0] === "$") {
let contractName = arg.substr(1); let contractName = arg.substr(1);
self.events.request('contracts:contract', contractName, (referedContract) => { self.events.request('contracts:contract', contractName, (referedContract) => {
realArgs.push(referedContract.deployedAddress); nextEachCb(null, referedContract.deployedAddress);
nextEachCb();
}); });
} else if (Array.isArray(arg)) { } else if (Array.isArray(arg)) {
let subRealArgs = []; async.map(arg, (sub_arg, nextSubEachCb) => {
async.eachLimit(arg, 1, (sub_arg, nextSubEachCb) => {
if (sub_arg[0] === "$") { if (sub_arg[0] === "$") {
let contractName = sub_arg.substr(1); let contractName = sub_arg.substr(1);
self.events.request('contracts:contract', contractName, (referedContract) => { self.events.request('contracts:contract', contractName, (referedContract) => {
subRealArgs.push(referedContract.deployedAddress); nextSubEachCb(null, referedContract.deployedAddress);
nextSubEachCb();
}); });
} else { } else {
subRealArgs.push(sub_arg); nextSubEachCb(null, sub_arg);
nextSubEachCb();
} }
}, () => { }, (err, subRealArgs) => {
realArgs.push(subRealArgs); nextEachCb(null, subRealArgs);
nextEachCb();
}); });
} else { } else {
realArgs.push(arg); nextEachCb(null, arg);
nextEachCb();
} }
}, () => { }, callback);
callback(realArgs);
});
} }
checkAndDeployContract(contract, params, callback) { checkAndDeployContract(contract, params, callback) {
@ -77,7 +73,10 @@ class Deploy {
async.waterfall([ async.waterfall([
function _determineArguments(next) { function _determineArguments(next) {
self.determineArguments(params || contract.args, contract, (realArgs) => { self.determineArguments(params || contract.args, contract, (err, realArgs) => {
if (err) {
return next(err);
}
contract.realArgs = realArgs; contract.realArgs = realArgs;
next(); next();
}); });
@ -102,14 +101,14 @@ class Deploy {
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract // TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) { self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
if (!trackedContract) { if (!trackedContract) {
return self.contractToDeploy(contract, params, next); return self.deployContract(contract, next);
} }
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) { self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
if (codeInChain !== "0x") { if (codeInChain !== "0x") {
self.contractAlreadyDeployed(contract, trackedContract, next); self.contractAlreadyDeployed(contract, trackedContract, next);
} else { } else {
self.contractToDeploy(contract, params, next); self.deployContract(contract, next);
} }
}); });
}); });
@ -125,49 +124,16 @@ class Deploy {
// TODO: can be moved into a afterDeploy event // TODO: can be moved into a afterDeploy event
// just need to figure out the gasLimit coupling issue // just need to figure out the gasLimit coupling issue
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit, (contractCode) => {
self.events.request('runcode:eval', contractCode); self.events.request('runcode:eval', contractCode);
return callback(); return callback();
}); });
} }
contractToDeploy(contract, params, callback) { deployContract(contract, callback) {
const self = this;
// TODO: refactor to async
self.determineArguments(params || contract.args, contract, (realArgs) => {
contract.realArgs = realArgs;
this.deployContract(contract, contract.realArgs, function (err, address) {
if (err) {
self.events.emit("deploy:contract:error", contract);
return callback(new Error(err));
}
contract.address = address;
self.events.emit("deploy:contract:deployed", contract);
// TODO: can be moved into a afterDeploy event
// just need to figure out the gasLimit coupling issue
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
self.events.request('runcode:eval', contractCode);
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) {
plugin.call(plugin, contract, nextEach);
}, () => {
callback();
});
});
});
});
}
deployContract(contract, params, callback) {
let self = this; let self = this;
let accounts = []; let accounts = [];
let contractParams = (params || contract.args).slice(); let contractParams = (contract.realArgs || contract.args).slice();
let contractCode = contract.code; let contractCode = contract.code;
let deploymentAccount = self.blockchain.defaultAccount(); let deploymentAccount = self.blockchain.defaultAccount();
let deployObject; let deployObject;
@ -227,34 +193,7 @@ class Deploy {
}); });
}, },
function applyBeforeDeploy(next) { function applyBeforeDeploy(next) {
let beforeDeployPlugins = self.plugins.getPluginsFor('beforeDeploy'); self.plugins.emitAndRunActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next);
//self.logger.info("applying beforeDeploy plugins...", beforeDeployPlugins.length);
async.eachSeries(beforeDeployPlugins, (plugin, eachPluginCb) => {
self.logger.info(__("running beforeDeploy plugin %s .", plugin.name));
// calling each beforeDeploy handler declared by the plugin
async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => {
function beforeDeployCb(resObj){
contract.code = resObj.contractCode;
eachCb();
}
beforeDeployFn({
embarkDeploy: self,
pluginConfig: plugin.pluginConfig,
deploymentAccount: deploymentAccount,
contract: contract,
callback: beforeDeployCb
}, beforeDeployCb);
}, () => {
//self.logger.info('All beforeDeploy handlers of the plugin has processed.');
eachPluginCb();
});
}, () => {
//self.logger.info('All beforeDeploy plugins has been processed.');
contractCode = contract.code;
next();
});
}, },
function createDeployObject(next) { function createDeployObject(next) {
let contractObject = self.blockchain.ContractObject({abi: contract.abiDefinition}); let contractObject = self.blockchain.ContractObject({abi: contract.abiDefinition});
@ -289,46 +228,29 @@ class Deploy {
gasPrice: contract.gasPrice gasPrice: contract.gasPrice
}, function(error, receipt) { }, function(error, receipt) {
if (error) { if (error) {
contract.error = error.message;
self.events.emit("deploy:contract:error", contract);
return next(new Error("error deploying =" + contract.className + "= due to error: " + error.message)); return next(new Error("error deploying =" + contract.className + "= due to error: " + error.message));
} }
self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan); self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan);
contract.deployedAddress = receipt.contractAddress; contract.deployedAddress = receipt.contractAddress;
contract.transactionHash = receipt.transactionHash; contract.transactionHash = receipt.transactionHash;
return next(null, receipt.contractAddress); self.events.emit("deploy:contract:receipt", receipt);
self.events.emit("deploy:contract:deployed", contract);
// TODO: can be moved into a afterDeploy event
// just need to figure out the gasLimit coupling issue
self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit, (contractCode) => {
self.events.request('runcode:eval', contractCode);
self.plugins.runActionsForEvent('deploy:contract:deployed', {contract: contract}, () => {
return next(null, receipt);
});
});
}); });
} }
], callback); ], callback);
} }
deployAll(done) {
let self = this;
this.logger.info(__("deploying contracts"));
this.events.emit("deploy:beforeAll");
self.events.request('contracts:list', (contracts) => {
async.eachOfSeries(contracts,
function (contract, key, callback) {
self.logger.trace(arguments);
self.checkAndDeployContract(contract, null, callback);
},
function (err, _results) {
if (err) {
self.logger.error(__("error deploying contracts"));
self.logger.error(err.message);
self.logger.debug(err.stack);
}
if (contracts.length === 0) {
self.logger.info(__("no contracts found"));
return done();
}
self.logger.info(__("finished deploying contracts"));
self.logger.trace(arguments);
done(err);
}
);
});
}
} }
module.exports = Deploy; module.exports = ContractDeployer;

View File

@ -34,6 +34,13 @@ class ContractsManager {
cb(self.getContract(contractName)); cb(self.getContract(contractName));
}); });
self.events.setCommandHandler("contracts:build", (configOnly, cb) => {
self.deployOnlyOnConfig = configOnly; // temporary, should refactor
self.build(() => {
cb();
});
});
self.events.on("deploy:contract:error", (_contract) => { self.events.on("deploy:contract:error", (_contract) => {
self.events.emit('contractsState', self.contractsState()); self.events.emit('contractsState', self.contractsState());
}); });
@ -45,6 +52,7 @@ class ContractsManager {
self.events.on("deploy:contract:undeployed", (_contract) => { self.events.on("deploy:contract:undeployed", (_contract) => {
self.events.emit('contractsState', self.contractsState()); self.events.emit('contractsState', self.contractsState());
}); });
} }
build(done) { build(done) {

View File

@ -1,9 +1,8 @@
let async = require('async'); let async = require('async');
//require("../utils/debug_util.js")(__filename, async);
let Deploy = require('./deploy.js');
class DeployManager { class DeployManager {
constructor(options) { constructor(options) {
const self = this;
this.config = options.config; this.config = options.config;
this.logger = options.logger; this.logger = options.logger;
this.blockchainConfig = this.config.blockchainConfig; this.blockchainConfig = this.config.blockchainConfig;
@ -11,12 +10,44 @@ class DeployManager {
this.events = options.events; this.events = options.events;
this.plugins = options.plugins; this.plugins = options.plugins;
this.blockchain = options.blockchain; this.blockchain = options.blockchain;
this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false;
this.contractsManager = options.contractsManager;
this.gasLimit = false; this.gasLimit = false;
this.fatalErrors = false; this.fatalErrors = false;
this.deployOnlyOnConfig = false; this.deployOnlyOnConfig = false;
this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false; this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false;
this.events.setCommandHandler('deploy:contracts', (cb) => {
self.deployContracts(cb);
});
}
deployAll(done) {
let self = this;
this.logger.info(__("deploying contracts"));
this.events.emit("deploy:beforeAll");
self.events.request('contracts:list', (contracts) => {
async.eachOfSeries(contracts,
function (contract, key, callback) {
contract._gasLimit = self.gasLimit;
self.events.request('deploy:contract', contract, () => {
callback();
});
},
function (err, _results) {
if (err) {
self.logger.error(__("error deploying contracts"));
self.logger.error(err.message);
self.logger.debug(err.stack);
}
if (contracts.length === 0) {
self.logger.info(__("no contracts found"));
return done();
}
self.logger.info(__("finished deploying contracts"));
done(err);
}
);
});
} }
deployContracts(done) { deployContracts(done) {
@ -30,8 +61,7 @@ class DeployManager {
async.waterfall([ async.waterfall([
function buildContracts(callback) { function buildContracts(callback) {
self.contractsManager.deployOnlyOnConfig = self.deployOnlyOnConfig; // temporary, should refactor self.events.request("contracts:build", self.deployOnlyOnConfig, () => {
self.contractsManager.build(() => {
callback(); callback();
}); });
}, },
@ -39,7 +69,7 @@ class DeployManager {
// TODO: shouldn't be necessary // TODO: shouldn't be necessary
function checkCompileOnly(callback){ function checkCompileOnly(callback){
if(self.onlyCompile){ if(self.onlyCompile){
self.events.emit('contractsDeployed', self.contractsManager); self.events.emit('contractsDeployed');
return done(); return done();
} }
return callback(); return callback();
@ -62,20 +92,9 @@ class DeployManager {
}, },
function deployAllContracts(callback) { function deployAllContracts(callback) {
let deploy = new Deploy({ self.deployAll(function (err) {
blockchain: self.blockchain,
contractsManager: self.contractsManager,
logger: self.logger,
events: self.events,
chainConfig: self.chainConfig,
env: self.config.env,
plugins: self.plugins,
gasLimit: self.gasLimit
});
deploy.deployAll(function (err) {
if (!err) { if (!err) {
self.events.emit('contractsDeployed', self.contractsManager); self.events.emit('contractsDeployed');
} }
if (err && self.fatalErrors) { if (err && self.fatalErrors) {
return callback(err); return callback(err);
@ -84,13 +103,7 @@ class DeployManager {
}); });
}, },
function runAfterDeploy(callback) { function runAfterDeploy(callback) {
let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions'); self.plugins.emitAndRunActionsForEvent('contracts:deploy:afterAll', callback);
async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) {
plugin.call(plugin, nextEach);
}, () => {
callback();
});
} }
], function (err, _result) { ], function (err, _result) {
done(err); done(err);

View File

@ -6,6 +6,7 @@ const Config = require('./config.js');
const Blockchain = require('../contracts/blockchain.js'); const Blockchain = require('../contracts/blockchain.js');
const Compiler = require('../contracts/compiler.js'); const Compiler = require('../contracts/compiler.js');
const ContractsManager = require('../contracts/contracts.js'); const ContractsManager = require('../contracts/contracts.js');
const ContractDeployer = require('../contracts/contract_deployer.js');
const DeployManager = require('../contracts/deploy_manager.js'); const DeployManager = require('../contracts/deploy_manager.js');
const CodeGenerator = require('../contracts/code_generator.js'); const CodeGenerator = require('../contracts/code_generator.js');
const ServicesMonitor = require('./services_monitor.js'); const ServicesMonitor = require('./services_monitor.js');
@ -92,7 +93,7 @@ class Engine {
} }
registerModule(moduleName, options) { registerModule(moduleName, options) {
this.plugins.loadInternalPlugin(moduleName, options); this.plugins.loadInternalPlugin(moduleName, options || {});
} }
startService(serviceName, _options) { startService(serviceName, _options) {
@ -148,12 +149,7 @@ class Engine {
} }
namingSystem(_options) { namingSystem(_options) {
this.registerModule('ens', { this.registerModule('ens');
logger: this.logger,
events: this.events,
web3: this.blockchain.web3,
namesConfig: this.config.namesystemConfig
});
} }
codeRunnerService(_options) { codeRunnerService(_options) {
@ -170,7 +166,6 @@ class Engine {
this.codeGenerator = new CodeGenerator({ this.codeGenerator = new CodeGenerator({
blockchainConfig: self.config.blockchainConfig, blockchainConfig: self.config.blockchainConfig,
contractsConfig: self.config.contractsConfig, contractsConfig: self.config.contractsConfig,
contractsManager: this.contractsManager,
plugins: self.plugins, plugins: self.plugins,
storageConfig: self.config.storageConfig, storageConfig: self.config.storageConfig,
namesystemConfig: self.config.namesystemConfig, namesystemConfig: self.config.namesystemConfig,
@ -185,12 +180,12 @@ class Engine {
self.events.emit('code-generator-ready'); self.events.emit('code-generator-ready');
}); });
}; };
const cargo = async.cargo((tasks, callback) => { const cargo = async.cargo((_tasks, callback) => {
generateCode(tasks[tasks.length - 1].contractsManager); generateCode();
self.events.once('outputDone', callback); self.events.once('outputDone', callback);
}); });
const addToCargo = function (contractsManager) { const addToCargo = function () {
cargo.push({contractsManager}); cargo.push({});
}; };
this.events.on('contractsDeployed', addToCargo); this.events.on('contractsDeployed', addToCargo);
@ -206,22 +201,11 @@ class Engine {
compiler.compile_contracts(contractFiles, cb); compiler.compile_contracts(contractFiles, cb);
}); });
this.registerModule('solidity', { this.registerModule('solidity');
contractDirectories: self.config.contractDirectories this.registerModule('vyper');
}); this.registerModule('profiler');
this.registerModule('vyper', { this.registerModule('deploytracker');
contractDirectories: self.config.contractDirectories this.registerModule('specialconfigs');
});
this.registerModule('profiler', {
events: this.events,
logger: this.logger
});
this.registerModule('deploytracker', {
});
this.registerModule('specialconfigs', {
});
this.contractsManager = new ContractsManager({ this.contractsManager = new ContractsManager({
contractFiles: this.config.contractsFiles, contractFiles: this.config.contractsFiles,
@ -234,15 +218,20 @@ class Engine {
this.deployManager = new DeployManager({ this.deployManager = new DeployManager({
blockchain: this.blockchain, blockchain: this.blockchain,
trackContracts: options.trackContracts,
config: this.config, config: this.config,
logger: this.logger, logger: this.logger,
plugins: this.plugins, plugins: this.plugins,
events: this.events, events: this.events,
contractsManager: this.contractsManager,
onlyCompile: options.onlyCompile onlyCompile: options.onlyCompile
}); });
this.contractDeployer = new ContractDeployer({
blockchain: this.blockchain,
logger: this.logger,
events: this.events,
plugins: this.plugins
});
this.events.on('file-event', function (fileType) { this.events.on('file-event', function (fileType) {
clearTimeout(self.fileTimeout); clearTimeout(self.fileTimeout);
self.fileTimeout = setTimeout(() => { self.fileTimeout = setTimeout(() => {
@ -256,8 +245,8 @@ class Engine {
// because the contractsManager config is corrupted after a deploy // because the contractsManager config is corrupted after a deploy
if (fileType === 'contract' || fileType === 'config') { if (fileType === 'contract' || fileType === 'config') {
self.config.reloadConfig(); self.config.reloadConfig();
self.deployManager.deployContracts(function () {
}); self.events.request('deploy:contracts', () => {});
} }
}, 50); }, 50);
}); });
@ -278,7 +267,6 @@ class Engine {
ipfsService(_options) { ipfsService(_options) {
this.registerModule('ipfs', { this.registerModule('ipfs', {
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
storageConfig: this.config.storageConfig,
host: _options.host, host: _options.host,
port: _options.port port: _options.port
}); });
@ -287,7 +275,6 @@ class Engine {
swarmService(_options) { swarmService(_options) {
this.registerModule('swarm', { this.registerModule('swarm', {
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
storageConfig: this.config.storageConfig,
// TODO: this should not be needed and should be deducted from the config instead // TODO: this should not be needed and should be deducted from the config instead
// the eth provider is not necessary the same as the swarm one // the eth provider is not necessary the same as the swarm one
bzz: this.blockchain.web3.bzz bzz: this.blockchain.web3.bzz
@ -308,7 +295,6 @@ class Engine {
this.registerModule('whisper', { this.registerModule('whisper', {
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
communicationConfig: this.config.communicationConfig,
// TODO: this should not be needed and should be deducted from the config instead // TODO: this should not be needed and should be deducted from the config instead
// the eth provider is not necessary the same as the whisper one // the eth provider is not necessary the same as the whisper one
web3: this.blockchain.web3 web3: this.blockchain.web3

View File

@ -1,7 +1,7 @@
var EventEmitter = require('events'); var EventEmitter = require('events');
function warnIfLegacy(eventName) { function warnIfLegacy(eventName) {
const legacyEvents = ['abi-vanila', 'abi', 'abi-contracts-vanila', 'abi-vanila-deployment']; const legacyEvents = [];
if (legacyEvents.indexOf(eventName) >= 0) { if (legacyEvents.indexOf(eventName) >= 0) {
console.info(__("this event is deprecated and will be removed in future versions %s", eventName)); console.info(__("this event is deprecated and will be removed in future versions %s", eventName));
} }

View File

@ -1,6 +1,7 @@
const fs = require('./fs.js'); const fs = require('./fs.js');
const utils = require('../utils/utils.js'); const utils = require('../utils/utils.js');
const constants = require('../constants'); const constants = require('../constants');
const _ = require('underscore');
// TODO: pass other params like blockchainConfig, contract files, etc.. // TODO: pass other params like blockchainConfig, contract files, etc..
var Plugin = function(options) { var Plugin = function(options) {
@ -27,6 +28,7 @@ var Plugin = function(options) {
this.embarkjs_init_code = {}; this.embarkjs_init_code = {};
this.afterContractsDeployActions = []; this.afterContractsDeployActions = [];
this.onDeployActions = []; this.onDeployActions = [];
this.eventActions = {};
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.config = options.config; this.config = options.config;
@ -119,43 +121,45 @@ Plugin.prototype.interceptLogs = function(context) {
Plugin.prototype.registerClientWeb3Provider = function(cb) { Plugin.prototype.registerClientWeb3Provider = function(cb) {
this.clientWeb3Providers.push(cb); this.clientWeb3Providers.push(cb);
this.pluginTypes.push('clientWeb3Provider'); this.pluginTypes.push('clientWeb3Provider');
}; this.pluginTypes = _.uniq(this.pluginTypes);
Plugin.prototype.registerBeforeDeploy = function(cb) {
this.beforeDeploy.push(cb);
this.pluginTypes.push('beforeDeploy');
}; };
Plugin.prototype.registerContractsGeneration = function(cb) { Plugin.prototype.registerContractsGeneration = function(cb) {
this.contractsGenerators.push(cb); this.contractsGenerators.push(cb);
this.pluginTypes.push('contractGeneration'); this.pluginTypes.push('contractGeneration');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerPipeline = function(matcthingFiles, cb) { Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
// TODO: generate error for more than one pipeline per plugin // TODO: generate error for more than one pipeline per plugin
this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb}); this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb});
this.pluginTypes.push('pipeline'); this.pluginTypes.push('pipeline');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options}); this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
this.pluginTypes.push('pipelineFiles'); this.pluginTypes.push('pipelineFiles');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.addContractFile = function(file) { Plugin.prototype.addContractFile = function(file) {
this.contractsFiles.push(file); this.contractsFiles.push(file);
this.pluginTypes.push('contractFiles'); this.pluginTypes.push('contractFiles');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerConsoleCommand = function(cb) { Plugin.prototype.registerConsoleCommand = function(cb) {
this.console.push(cb); this.console.push(cb);
this.pluginTypes.push('console'); this.pluginTypes.push('console');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
// TODO: this only works for services done on startup // TODO: this only works for services done on startup
Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) { Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) {
this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time}); this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time});
this.pluginTypes.push('serviceChecks'); this.pluginTypes.push('serviceChecks');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.has = function(pluginType) { Plugin.prototype.has = function(pluginType) {
@ -177,42 +181,47 @@ Plugin.prototype.generateContracts = function(args) {
Plugin.prototype.registerContractConfiguration = function(config) { Plugin.prototype.registerContractConfiguration = function(config) {
this.contractsConfigs.push(config); this.contractsConfigs.push(config);
this.pluginTypes.push('contractsConfig'); this.pluginTypes.push('contractsConfig');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerCompiler = function(extension, cb) { Plugin.prototype.registerCompiler = function(extension, cb) {
this.compilers.push({extension: extension, cb: cb}); this.compilers.push({extension: extension, cb: cb});
this.pluginTypes.push('compilers'); this.pluginTypes.push('compilers');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerUploadCommand = function(cmd, cb) { Plugin.prototype.registerUploadCommand = function(cmd, cb) {
this.uploadCmds.push({cmd: cmd, cb: cb}); this.uploadCmds.push({cmd: cmd, cb: cb});
this.pluginTypes.push('uploadCmds'); this.pluginTypes.push('uploadCmds');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.addCodeToEmbarkJS = function(code) { Plugin.prototype.addCodeToEmbarkJS = function(code) {
this.embarkjs_code.push(code); this.embarkjs_code.push(code);
this.pluginTypes.push('embarkjsCode'); this.pluginTypes.push('embarkjsCode');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { Plugin.prototype.addProviderInit = function(providerType, code, initCondition) {
this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || []; this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || [];
this.embarkjs_init_code[providerType].push([code, initCondition]); this.embarkjs_init_code[providerType].push([code, initCondition]);
this.pluginTypes.push('initCode'); this.pluginTypes.push('initCode');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerImportFile = function(importName, importLocation) { Plugin.prototype.registerImportFile = function(importName, importLocation) {
this.imports.push([importName, importLocation]); this.imports.push([importName, importLocation]);
this.pluginTypes.push('imports'); this.pluginTypes.push('imports');
this.pluginTypes = _.uniq(this.pluginTypes);
}; };
Plugin.prototype.registerAfterAllContractsDeploy = function(cb) { Plugin.prototype.registerActionForEvent = function(eventName, cb) {
this.afterContractsDeployActions.push(cb); if (!this.eventActions[eventName]) {
this.pluginTypes.push('afterContractsDeployActions'); this.eventActions[eventName] = [];
}; }
this.eventActions[eventName].push(cb);
Plugin.prototype.registerOnDeployContracts = function(cb) { this.pluginTypes.push('eventActions');
this.onDeployActions.push(cb); this.pluginTypes = _.uniq(this.pluginTypes);
this.pluginTypes.push('onDeployActions');
}; };
Plugin.prototype.runFilePipeline = function() { Plugin.prototype.runFilePipeline = function() {

View File

@ -1,3 +1,4 @@
const async = require('async');
var Plugin = require('./plugin.js'); var Plugin = require('./plugin.js');
var utils = require('../utils/utils.js'); var utils = require('../utils/utils.js');
@ -58,7 +59,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) {
var pluginWrapper = new Plugin({ var pluginWrapper = new Plugin({
name: pluginName, name: pluginName,
pluginModule: plugin, pluginModule: plugin,
pluginConfig: pluginConfig, pluginConfig: pluginConfig || {},
logger: this.logger, logger: this.logger,
pluginPath: pluginPath, pluginPath: pluginPath,
interceptLogs: this.interceptLogs, interceptLogs: this.interceptLogs,
@ -98,18 +99,48 @@ Plugins.prototype.getPluginsFor = function(pluginType) {
}); });
}; };
Plugins.prototype.getPluginsProperty = function(pluginType, property) { Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_property) {
let matchingPlugins = this.plugins.filter(function(plugin) { let matchingPlugins = this.plugins.filter(function(plugin) {
return plugin.has(pluginType); return plugin.has(pluginType);
}); });
let matchingProperties = matchingPlugins.map((plugin) => { let matchingProperties = matchingPlugins.map((plugin) => {
if (sub_property) {
return plugin[property][sub_property];
}
return plugin[property]; return plugin[property];
}); });
matchingProperties = matchingProperties.filter((property) => property);
//return flattened list //return flattened list
if (matchingProperties.length === 0) return []; if (matchingProperties.length === 0) return [];
return matchingProperties.reduce((a,b) => { return a.concat(b); }); return matchingProperties.reduce((a,b) => { return a.concat(b); }) || [];
};
Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
if (typeof (args) === 'function') {
cb = args;
}
let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName);
if (actionPlugins.length === 0) {
return cb();
}
async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
if (typeof (args) === 'function') {
plugin.call(plugin, nextEach);
} else {
//plugin.call(plugin, ...args, nextEach);
plugin.call(plugin, args, nextEach);
}
}, cb);
};
Plugins.prototype.emitAndRunActionsForEvent = function(eventName, args, cb) {
this.events.emit(eventName);
return this.runActionsForEvent(eventName, args, cb);
}; };
module.exports = Plugins; module.exports = Plugins;

View File

@ -167,7 +167,7 @@ class Embark {
engine.events.on('check:backOnline:Ethereum', function () { engine.events.on('check:backOnline:Ethereum', function () {
engine.logger.info(__('Ethereum node detected') + '..'); engine.logger.info(__('Ethereum node detected') + '..');
engine.config.reloadConfig(); engine.config.reloadConfig();
engine.deployManager.deployContracts(function () { engine.events.request('deploy:contracts', function() {
engine.logger.info(__('Deployment Done')); engine.logger.info(__('Deployment Done'));
}); });
}); });
@ -191,6 +191,7 @@ class Embark {
engine.logger.info(__("Ready").underline); engine.logger.info(__("Ready").underline);
engine.events.emit("status", __("Ready").green); engine.events.emit("status", __("Ready").green);
}); });
if (options.runWebserver) { if (options.runWebserver) {
engine.startService("webServer", { engine.startService("webServer", {
host: options.serverHost, host: options.serverHost,
@ -255,7 +256,7 @@ class Embark {
callback(); callback();
}, },
function deploy(callback) { function deploy(callback) {
engine.deployManager.deployContracts(function (err) { engine.events.request('deploy:contracts', function(err) {
callback(err); callback(err);
}); });
} }
@ -306,7 +307,7 @@ class Embark {
engine.startService("deployment", {onlyCompile: true}); engine.startService("deployment", {onlyCompile: true});
engine.startService("codeGenerator"); engine.startService("codeGenerator");
engine.deployManager.deployContracts(function (err) { engine.events.request('deploy:contracts', function(err) {
callback(err); callback(err);
}); });
} }
@ -418,7 +419,6 @@ class Embark {
callback(); callback();
}, },
function deploy(callback) { function deploy(callback) {
// 2. upload to storage (outputDone event triggered after webpack finished)
engine.events.on('outputDone', function () { engine.events.on('outputDone', function () {
cmdPlugin.uploadCmds[0].cb() cmdPlugin.uploadCmds[0].cb()
.then((success) => { .then((success) => {
@ -427,8 +427,7 @@ class Embark {
.catch(callback); .catch(callback);
}); });
// 1. build the contracts and dapp webpack engine.events.request('deploy:contracts', function(err) {
engine.deployManager.deployContracts(function (err) {
engine.logger.info(__("finished deploying").underline); engine.logger.info(__("finished deploying").underline);
if(err){ if(err){
callback(err); callback(err);

View File

@ -2,11 +2,10 @@ const fs = require('../../core/fs.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
class ENS { class ENS {
constructor(embark, options) { constructor(embark, _options) {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.web3 = options.web3; this.namesConfig = embark.config.namesystemConfig;
this.namesConfig = options.namesConfig;
this.embark = embark; this.embark = embark;
this.addENSToEmbarkJS(); this.addENSToEmbarkJS();

View File

@ -9,7 +9,7 @@ class IPFS {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.buildDir = options.buildDir; this.buildDir = options.buildDir;
this.storageConfig = options.storageConfig; this.storageConfig = embark.config.storageConfig;
this.host = options.host || this.storageConfig.host; this.host = options.host || this.storageConfig.host;
this.port = options.port || this.storageConfig.port; this.port = options.port || this.storageConfig.port;
this.addCheck = options.addCheck; this.addCheck = options.addCheck;

View File

@ -5,7 +5,6 @@ class Profiler {
this.embark = embark; this.embark = embark;
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.plugins = embark.plugins;
this.registerConsoleCommand(); this.registerConsoleCommand();
} }

View File

@ -3,10 +3,10 @@ let SolcW = require('./solcW.js');
class Solidity { class Solidity {
constructor(embark, options) { constructor(embark, _options) {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.contractDirectories = options.contractDirectories; this.contractDirectories = embark.config.contractDirectories;
this.solcAlreadyLoaded = false; this.solcAlreadyLoaded = false;
this.solcW = null; this.solcW = null;

View File

@ -48,7 +48,7 @@ class SpecialConfigs {
registerAfterDeployAction() { registerAfterDeployAction() {
const self = this; const self = this;
this.embark.registerAfterAllContractsDeploy((cb) => { this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
let afterDeployCmds = self.contractsConfig.afterDeploy || []; let afterDeployCmds = self.contractsConfig.afterDeploy || [];
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => { async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
@ -79,7 +79,9 @@ class SpecialConfigs {
registerOnDeployAction() { registerOnDeployAction() {
const self = this; const self = this;
this.embark.registerOnDeployContracts((contract, cb) => { this.embark.registerActionForEvent("deploy:contract:deployed", (params, cb) => {
let contract = params.contract;
if (!contract.onDeploy) { if (!contract.onDeploy) {
return cb(); return cb();
} }

View File

@ -8,7 +8,7 @@ class Swarm {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.buildDir = options.buildDir; this.buildDir = options.buildDir;
this.storageConfig = options.storageConfig; this.storageConfig = embark.config.storageConfig;
this.host = options.host || this.storageConfig.host; this.host = options.host || this.storageConfig.host;
this.port = options.port || this.storageConfig.port; this.port = options.port || this.storageConfig.port;
this.addCheck = options.addCheck; this.addCheck = options.addCheck;

View File

@ -4,10 +4,10 @@ const path = require('path');
class Vyper { class Vyper {
constructor(embark, options) { constructor(embark, _options) {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.contractDirectories = options.contractDirectories; this.contractDirectories = embark.config.contractDirectories;
// FIXME: Use array of extensions instead of duplicatiing // FIXME: Use array of extensions instead of duplicatiing
embark.registerCompiler(".py", this.compile_vyper.bind(this)); embark.registerCompiler(".py", this.compile_vyper.bind(this));

View File

@ -6,7 +6,7 @@ class Whisper {
constructor(embark, options) { constructor(embark, options) {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.communicationConfig = options.communicationConfig; this.communicationConfig = embark.config.communicationConfig;
this.addCheck = options.addCheck; this.addCheck = options.addCheck;
// TODO: this should not be needed and should be deducted from the config instead // TODO: this should not be needed and should be deducted from the config instead
this.web3 = options.web3; this.web3 = options.web3;

View File

@ -88,7 +88,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
self.engine.contractsManager.gasLimit = 6000000; self.engine.contractsManager.gasLimit = 6000000;
self.engine.deployManager.fatalErrors = true; self.engine.deployManager.fatalErrors = true;
self.engine.deployManager.deployOnlyOnConfig = true; self.engine.deployManager.deployOnlyOnConfig = true;
self.engine.deployManager.deployContracts(function(err, _result) { self.engine.events.request('deploy:contracts', function(err) {
if (err) { if (err) {
callback(err); callback(err);
} }

View File

@ -12,29 +12,31 @@ describe('embark.CodeGenerator', function() {
this.timeout(0); this.timeout(0);
describe('#generateContracts', function() { describe('#generateContracts', function() {
let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: { let contracts = [
contracts: { {
SimpleStorage: { className: '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"}],
gasEstimates: 12000, gasEstimates: 12000,
deployedAddress: "0x123", deployedAddress: "0x123",
code: '12345' code: '12345'
}, },
Foo: { {
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"}], className: 'Foo',
gasEstimates: 12000, 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"}],
deployedAddress: "0x124", gasEstimates: 12000,
code: '123456' deployedAddress: "0x124",
} code: '123456'
} }
}}); ]
let generator = new CodeGenerator({blockchainConfig: {}});
describe('with EmbarkJS', function() { describe('with EmbarkJS', function() {
let withEmbarkJS = true; let withEmbarkJS = true;
it('should generate contract code', function() { it('should generate contract code', function() {
var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.SimpleStorage = new EmbarkJS.Contract({abi: [{\"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\"}], address: '0x123', code: '12345', gasEstimates: 12000});\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.Foo = new EmbarkJS.Contract({abi: [{\"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\"}], address: '0x124', code: '123456', gasEstimates: 12000});\n\n});\n"; var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.SimpleStorage = new EmbarkJS.Contract({abi: [{\"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\"}], address: '0x123', code: '12345', gasEstimates: 12000});\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.Foo = new EmbarkJS.Contract({abi: [{\"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\"}], address: '0x124', code: '123456', gasEstimates: 12000});\n\n});\n";
assert.strictEqual(replaceCRLF(generator.generateContracts(withEmbarkJS)), contractCode); assert.strictEqual(replaceCRLF(generator.generateContracts(contracts, withEmbarkJS)), contractCode);
}); });
}); });
@ -43,7 +45,7 @@ describe('embark.CodeGenerator', function() {
it('should generate contract code', function() { it('should generate contract code', function() {
var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n SimpleStorageAbi = [{\"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\"}];\nSimpleStorage = new web3.eth.Contract(SimpleStorageAbi);\nSimpleStorage.options.address = '0x123';\nSimpleStorage.address = '0x123';\nSimpleStorage.options.from = web3.eth.defaultAccount;\n\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n FooAbi = [{\"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\"}];\nFoo = new web3.eth.Contract(FooAbi);\nFoo.options.address = '0x124';\nFoo.address = '0x124';\nFoo.options.from = web3.eth.defaultAccount;\n\n\n});\n"; var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n SimpleStorageAbi = [{\"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\"}];\nSimpleStorage = new web3.eth.Contract(SimpleStorageAbi);\nSimpleStorage.options.address = '0x123';\nSimpleStorage.address = '0x123';\nSimpleStorage.options.from = web3.eth.defaultAccount;\n\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n FooAbi = [{\"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\"}];\nFoo = new web3.eth.Contract(FooAbi);\nFoo.options.address = '0x124';\nFoo.address = '0x124';\nFoo.options.from = web3.eth.defaultAccount;\n\n\n});\n";
assert.strictEqual(replaceCRLF(generator.generateContracts(withEmbarkJS)), contractCode); assert.strictEqual(replaceCRLF(generator.generateContracts(contracts, withEmbarkJS)), contractCode);
}); });
}); });

File diff suppressed because one or more lines are too long

View File

@ -26,9 +26,12 @@ describe('embark.Contracts', function() {
describe('simple', function() { describe('simple', function() {
let plugins = new Plugins({ let plugins = new Plugins({
logger: new TestLogger({}), logger: new TestLogger({}),
events: TestEvents events: TestEvents,
config: {
contractDirectories: ['app/contracts/']
}
}); });
plugins.loadInternalPlugin('solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']}); plugins.loadInternalPlugin('solidity');
let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let compiler = new Compiler({plugins: plugins, logger: plugins.logger});
let events = new Events(); let events = new Events();
@ -115,9 +118,12 @@ describe('embark.Contracts', function() {
describe('config with contract instances', function() { describe('config with contract instances', function() {
let plugins = new Plugins({ let plugins = new Plugins({
logger: new TestLogger({}), logger: new TestLogger({}),
events: TestEvents events: TestEvents,
config: {
contractDirectories: ['app/contracts/']
}
}); });
plugins.loadInternalPlugin('solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']}); plugins.loadInternalPlugin('solidity');
let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let compiler = new Compiler({plugins: plugins, logger: plugins.logger});
let events = new Events(); let events = new Events();

View File

@ -23,9 +23,12 @@ module.exports = function (embark) {
embark.addFileToPipeline('./fileInPipeline.js'); embark.addFileToPipeline('./fileInPipeline.js');
embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js'); embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js');
embark.registerBeforeDeploy(function (options, callback) { embark.registerActionForEvent("deploy:contract:beforeDeploy", (params, cb) => {
// Just calling register to prove it works. We don't actually want to change the contracts embark.logger.info("applying beforeDeploy plugin...");
callback({contractCode: options.contract.code}); //console.dir(params);
//console.dir(cb);
//console.dir('------------------');
cb();
}); });
// NOTE: uncommenting this will make dappConnection stop working // NOTE: uncommenting this will make dappConnection stop working

View File

@ -89,7 +89,7 @@
"dom-helpers": { "dom-helpers": {
"version": "3.3.1", "version": "3.3.1",
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz", "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz",
"integrity": "sha1-/BpOFf/fYN3eA6SAqcD+zoId1KY=" "integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg=="
}, },
"dotenv": { "dotenv": {
"version": "4.0.0", "version": "4.0.0",
@ -229,7 +229,7 @@
"node-fetch": { "node-fetch": {
"version": "1.7.3", "version": "1.7.3",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
"integrity": "sha1-mA9vcthSEaU0fGsrwYxbhMPrR+8=", "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
"requires": { "requires": {
"encoding": "0.1.12", "encoding": "0.1.12",
"is-stream": "1.1.0" "is-stream": "1.1.0"
@ -252,7 +252,7 @@
"promise": { "promise": {
"version": "7.3.1", "version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
"integrity": "sha1-BktyYCsY+Q8pGSuLG8QY/9Hr078=", "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
"requires": { "requires": {
"asap": "2.0.6" "asap": "2.0.6"
} }
@ -289,7 +289,7 @@
"react-bootstrap": { "react-bootstrap": {
"version": "0.32.1", "version": "0.32.1",
"resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-0.32.1.tgz", "resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-0.32.1.tgz",
"integrity": "sha1-YGJMG0ijnXc+9szmQhpPM+zBZrs=", "integrity": "sha512-RbfzKUbsukWsToWqGHfCCyMFq9QQI0TznutdyxyJw6dih2NvIne25Mrssg8LZsprqtPpyQi8bN0L0Fx3fUsL8Q==",
"requires": { "requires": {
"babel-runtime": "6.26.0", "babel-runtime": "6.26.0",
"classnames": "2.2.5", "classnames": "2.2.5",
@ -319,7 +319,7 @@
"react-overlays": { "react-overlays": {
"version": "0.8.3", "version": "0.8.3",
"resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-0.8.3.tgz", "resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-0.8.3.tgz",
"integrity": "sha1-+tZe6lskMBzKGSoWn13dsLINOsU=", "integrity": "sha512-h6GT3jgy90PgctleP39Yu3eK1v9vaJAW73GOA/UbN9dJ7aAN4BTZD6793eI1D5U+ukMk17qiqN/wl3diK1Z5LA==",
"requires": { "requires": {
"classnames": "2.2.5", "classnames": "2.2.5",
"dom-helpers": "3.3.1", "dom-helpers": "3.3.1",
@ -353,7 +353,7 @@
"regenerator-runtime": { "regenerator-runtime": {
"version": "0.11.1", "version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=" "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
}, },
"setimmediate": { "setimmediate": {
"version": "1.0.5", "version": "1.0.5",
@ -412,7 +412,7 @@
"zeppelin-solidity": { "zeppelin-solidity": {
"version": "1.8.0", "version": "1.8.0",
"resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz", "resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz",
"integrity": "sha1-BJ/N59rqn8hSEPjG25+M0auKhTo=", "integrity": "sha512-7Mxq6Y7EES0PSLrRF6v0EVYqBVRRo8hFrr7m3jEs69VbbQ5kpANzizeEdbP1/PWKSOmBOg208qP2vSA0FlzFLA==",
"requires": { "requires": {
"dotenv": "4.0.0", "dotenv": "4.0.0",
"ethjs-abi": "0.2.1" "ethjs-abi": "0.2.1"