mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
start refactoring deployment steps
This commit is contained in:
parent
a0f4953c17
commit
a2a27bb0c2
@ -108,8 +108,10 @@ ABIGenerator.prototype.generateABI = function(options) {
|
|||||||
|
|
||||||
result += this.generateProvider();
|
result += this.generateProvider();
|
||||||
result += this.generateContracts(options.useEmbarkJS);
|
result += this.generateContracts(options.useEmbarkJS);
|
||||||
result += this.generateStorageInitialization(options.useEmbarkJS);
|
|
||||||
result += this.generateCommunicationInitialization(options.useEmbarkJS);
|
// TODO: disable this for now until refactor is over
|
||||||
|
//result += this.generateStorageInitialization(options.useEmbarkJS);
|
||||||
|
//result += this.generateCommunicationInitialization(options.useEmbarkJS);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
@ -41,14 +41,14 @@ ContractsManager.prototype.build = function(done) {
|
|||||||
function compileContracts(callback) {
|
function compileContracts(callback) {
|
||||||
var compiler = new Compiler({plugins: self.plugins});
|
var compiler = new Compiler({plugins: self.plugins});
|
||||||
// TODO: check if try is still needed
|
// TODO: check if try is still needed
|
||||||
try {
|
//try {
|
||||||
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
|
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
|
||||||
self.compiledContracts = compiledObject;
|
self.compiledContracts = compiledObject;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
} catch(err) {
|
//} catch(err) {
|
||||||
return callback(new Error(err.message));
|
// return callback(new Error(err.message));
|
||||||
}
|
//}
|
||||||
},
|
},
|
||||||
function prepareContractsFromConfig(callback) {
|
function prepareContractsFromConfig(callback) {
|
||||||
var className, contract;
|
var className, contract;
|
||||||
|
83
lib/contracts/deploy_manager.js
Normal file
83
lib/contracts/deploy_manager.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
var async = require('async');
|
||||||
|
var Web3 = require('web3');
|
||||||
|
|
||||||
|
var Deploy = require('./deploy.js');
|
||||||
|
var ContractsManager = require('./contracts.js');
|
||||||
|
var ABIGenerator = require('./abi.js');
|
||||||
|
|
||||||
|
var DeployManager = function(options) {
|
||||||
|
this.config = options.config;
|
||||||
|
this.logger = options.logger;
|
||||||
|
this.plugins = options.plugins;
|
||||||
|
this.events = options.events;
|
||||||
|
};
|
||||||
|
|
||||||
|
DeployManager.prototype.deployContracts = function(done) {
|
||||||
|
var self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function buildContracts(callback) {
|
||||||
|
var contractsManager = new ContractsManager({
|
||||||
|
contractFiles: self.config.contractsFiles,
|
||||||
|
contractsConfig: self.config.contractsConfig,
|
||||||
|
logger: self.logger,
|
||||||
|
plugins: self.plugins
|
||||||
|
});
|
||||||
|
contractsManager.build(callback);
|
||||||
|
},
|
||||||
|
function deployContracts(contractsManager, callback) {
|
||||||
|
|
||||||
|
//TODO: figure out where to put this since the web3 can be passed along if needed
|
||||||
|
// perhaps it should go into the deploy object itself
|
||||||
|
// TODO: should come from the config object
|
||||||
|
var web3 = new Web3();
|
||||||
|
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
|
||||||
|
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
|
||||||
|
|
||||||
|
if (!web3.isConnected()) {
|
||||||
|
console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
|
||||||
|
console.log("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
||||||
|
// ===================================
|
||||||
|
// TODO: should throw exception instead
|
||||||
|
// ===================================
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
web3.eth.getAccounts(function(err, accounts) {
|
||||||
|
if (err) {
|
||||||
|
return callback(new Error(err));
|
||||||
|
}
|
||||||
|
web3.eth.defaultAccount = accounts[0];
|
||||||
|
|
||||||
|
var deploy = new Deploy({
|
||||||
|
web3: web3,
|
||||||
|
contractsManager: contractsManager,
|
||||||
|
logger: self.logger,
|
||||||
|
chainConfig: self.config.chainTracker,
|
||||||
|
env: self.config.env
|
||||||
|
});
|
||||||
|
deploy.deployAll(function() {
|
||||||
|
callback(null, contractsManager);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function generateABI(contractsManager, callback) {
|
||||||
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
|
||||||
|
var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
||||||
|
var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
||||||
|
|
||||||
|
self.events.emit('abi-vanila', vanillaABI);
|
||||||
|
self.events.emit('abi', embarkJSABI);
|
||||||
|
|
||||||
|
callback(null, embarkJSABI);
|
||||||
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
done(err, null);
|
||||||
|
} else {
|
||||||
|
done(null, result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = DeployManager;
|
||||||
|
|
110
lib/index.js
110
lib/index.js
@ -7,9 +7,7 @@ var Blockchain = require('./cmds/blockchain/blockchain.js');
|
|||||||
var Simulator = require('./cmds/simulator.js');
|
var Simulator = require('./cmds/simulator.js');
|
||||||
var TemplateGenerator = require('./cmds/template_generator.js');
|
var TemplateGenerator = require('./cmds/template_generator.js');
|
||||||
|
|
||||||
var Deploy = require('./contracts/deploy.js');
|
var DeployManager = require('./contracts/deploy_manager.js');
|
||||||
var ContractsManager = require('./contracts/contracts.js');
|
|
||||||
var ABIGenerator = require('./contracts/abi.js');
|
|
||||||
|
|
||||||
var Test = require('./core/test.js');
|
var Test = require('./core/test.js');
|
||||||
var Logger = require('./core/logger.js');
|
var Logger = require('./core/logger.js');
|
||||||
@ -138,7 +136,20 @@ var Embark = {
|
|||||||
Embark.servicesMonitor.startMonitor();
|
Embark.servicesMonitor.startMonitor();
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
self.buildDeployGenerate.bind(self),
|
function (callback) {
|
||||||
|
var deployManager = new DeployManager({
|
||||||
|
config: Embark.config,
|
||||||
|
logger: Embark.logger,
|
||||||
|
plugins: self.plugins,
|
||||||
|
events: self.events
|
||||||
|
});
|
||||||
|
deployManager.deployContracts(function(abi) {
|
||||||
|
callback(null, abi);
|
||||||
|
});
|
||||||
|
//if (Embark.dashboard) {
|
||||||
|
// Embark.dashboard.console.runCode(consoleABI);
|
||||||
|
//}
|
||||||
|
},
|
||||||
function buildPipeline(abi, callback) {
|
function buildPipeline(abi, callback) {
|
||||||
self.logger.setStatus("Building Assets");
|
self.logger.setStatus("Building Assets");
|
||||||
var pipeline = new Pipeline({
|
var pipeline = new Pipeline({
|
||||||
@ -148,6 +159,7 @@ var Embark = {
|
|||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
plugins: self.plugins
|
plugins: self.plugins
|
||||||
});
|
});
|
||||||
|
// TODO: do this with event instead
|
||||||
pipeline.build(abi);
|
pipeline.build(abi);
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
@ -158,7 +170,7 @@ var Embark = {
|
|||||||
self.events.on('file-event', function(fileType, path) {
|
self.events.on('file-event', function(fileType, path) {
|
||||||
if (fileType === 'contract' || fileType === 'config') {
|
if (fileType === 'contract' || fileType === 'config') {
|
||||||
self.logger.info("received redeploy event");
|
self.logger.info("received redeploy event");
|
||||||
Embark.redeploy();
|
//Embark.redeploy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.events.on('rebuildAssets', function(fileType, path) {
|
self.events.on('rebuildAssets', function(fileType, path) {
|
||||||
@ -166,7 +178,7 @@ var Embark = {
|
|||||||
self.logger.info("received rebuildAssets event");
|
self.logger.info("received rebuildAssets event");
|
||||||
// TODO: can just rebuild pipeline, no need to deploy contracts
|
// TODO: can just rebuild pipeline, no need to deploy contracts
|
||||||
// again
|
// again
|
||||||
Embark.redeploy();
|
//Embark.redeploy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback();
|
callback();
|
||||||
@ -211,7 +223,9 @@ var Embark = {
|
|||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
plugins: self.plugins
|
plugins: self.plugins
|
||||||
});
|
});
|
||||||
pipeline.build(abi);
|
Embark.events.on('abi', function(abi) {
|
||||||
|
pipeline.build(abi);
|
||||||
|
});
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
@ -223,64 +237,6 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
buildAndDeploy: function(done) {
|
|
||||||
var self = this;
|
|
||||||
async.waterfall([
|
|
||||||
function buildContracts(callback) {
|
|
||||||
var contractsManager = new ContractsManager({
|
|
||||||
contractFiles: self.config.contractsFiles,
|
|
||||||
contractsConfig: self.config.contractsConfig,
|
|
||||||
logger: Embark.logger,
|
|
||||||
plugins: self.plugins
|
|
||||||
});
|
|
||||||
contractsManager.build(callback);
|
|
||||||
},
|
|
||||||
function deployContracts(contractsManager, callback) {
|
|
||||||
|
|
||||||
//TODO: figure out where to put this since the web3 can be passed along if needed
|
|
||||||
// perhaps it should go into the deploy object itself
|
|
||||||
// TODO: should come from the config object
|
|
||||||
var web3 = new Web3();
|
|
||||||
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
|
|
||||||
|
|
||||||
if (!web3.isConnected()) {
|
|
||||||
console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
|
|
||||||
console.log("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
|
||||||
// ===================================
|
|
||||||
// TODO: should throw exception instead
|
|
||||||
// ===================================
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
web3.eth.getAccounts(function(err, accounts) {
|
|
||||||
if (err) {
|
|
||||||
return callback(new Error(err));
|
|
||||||
}
|
|
||||||
web3.eth.defaultAccount = accounts[0];
|
|
||||||
|
|
||||||
var deploy = new Deploy({
|
|
||||||
web3: web3,
|
|
||||||
contractsManager: contractsManager,
|
|
||||||
logger: Embark.logger,
|
|
||||||
chainConfig: self.config.chainTracker,
|
|
||||||
env: self.config.env
|
|
||||||
});
|
|
||||||
deploy.deployAll(function() {
|
|
||||||
callback(null, contractsManager);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
|
||||||
done(err, null);
|
|
||||||
} else {
|
|
||||||
done(null, result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
deploy: function(done) {
|
deploy: function(done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@ -290,8 +246,6 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
|
|
||||||
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -301,38 +255,16 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
buildDeployGenerate: function(done) {
|
buildDeployGenerate: function(done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.config.blockchainConfig.enabled === false) {
|
|
||||||
self.logger.info('== blockchain is disabled in this environment in config/blockchain.json'.underline);
|
|
||||||
return done(null, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
self.logger.setStatus("Deploying...".magenta.underline);
|
self.logger.setStatus("Deploying...".magenta.underline);
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function deployAndBuildContractsManager(callback) {
|
|
||||||
Embark.buildAndDeploy(function(err, contractsManager) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
return callback(null, contractsManager);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function generateConsoleABI(contractsManager, callback) {
|
function generateConsoleABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
|
||||||
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
|
|
||||||
// not good, better generate events when deployment is done and do this
|
|
||||||
// through a listener
|
// through a listener
|
||||||
if (Embark.dashboard) {
|
|
||||||
Embark.dashboard.console.runCode(consoleABI);
|
|
||||||
}
|
|
||||||
callback(null, contractsManager);
|
callback(null, contractsManager);
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
|
||||||
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user