make abi generation independent of deployment

This commit is contained in:
Iuri Matias 2017-02-28 23:29:16 -05:00
parent 1674adee4a
commit b7cd296716
8 changed files with 60 additions and 30 deletions

View File

@ -28,7 +28,8 @@ $(document).ready(function() {
// Storage (IPFS) example
// ===========================
$(document).ready(function() {
EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
$("#storage .error").hide();
EmbarkJS.Storage.ipfsConnection.ping()

View File

@ -189,8 +189,6 @@ var EmbarkJS =
EmbarkJS.Storage = {
};
// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
EmbarkJS.Storage.setProvider = function(provider, options) {
if (provider === 'ipfs') {
this.currentStorage = EmbarkJS.Storage.IPFS;
@ -283,7 +281,7 @@ var EmbarkJS =
var ipfs;
if (provider === 'whisper') {
this.currentMessages = EmbarkJS.Messages.Whisper;
if (web3 === undefined) {
if (typeof variable === 'undefined') {
if (options === undefined) {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
} else {

View File

@ -142,8 +142,6 @@ EmbarkJS.IPFS = 'ipfs';
EmbarkJS.Storage = {
};
// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
EmbarkJS.Storage.setProvider = function(provider, options) {
if (provider === 'ipfs') {
this.currentStorage = EmbarkJS.Storage.IPFS;
@ -236,7 +234,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
var ipfs;
if (provider === 'whisper') {
this.currentMessages = EmbarkJS.Messages.Whisper;
if (web3 === undefined) {
if (typeof variable === 'undefined') {
if (options === undefined) {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
} else {

View File

@ -94,10 +94,10 @@ ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJ
if (!useEmbarkJS || self.communicationConfig === {}) return "";
if (self.communicationConfig.provider === 'ipfs' && self.communicationConfig.enabled === true) {
result += "\nEmbarkJS.Storage.setProvider('" + self.communicationConfig.provider + "');";
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
result += "\nEmbarkJS.Storage.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
}
return result;

View File

@ -3,7 +3,6 @@ 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;
@ -18,6 +17,7 @@ DeployManager.prototype.deployContracts = function(done) {
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
self.logger.info("Blockchain component is disabled in the config".underline);
self.events.emit('blockchainDisabled', {});
return done();
}
@ -61,19 +61,9 @@ DeployManager.prototype.deployContracts = function(done) {
});
deploy.deployAll(function() {
callback(null, contractsManager);
self.events.emit('contractsDeployed');
self.events.emit('contractsDeployed', 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) {

20
lib/core/debug_util.js Normal file
View File

@ -0,0 +1,20 @@
// util to map async method names
function extend(filename, async) {
if (async._waterfall !== undefined) {
return;
}
async._waterfall = async.waterfall;
async.waterfall = function(_tasks, callback) {
var tasks = _tasks.map(function(t) {
var fn = function() {
console.log("async " + filename + ": " + t.name);
t.apply(t, arguments);
};
return fn;
});
async._waterfall(tasks, callback);
};
}
module.exports = extend;

View File

@ -1,5 +1,7 @@
/*jshint esversion: 6 */
var async = require('async');
//require("./core/debug_util.js")(__filename, async);
var Web3 = require('web3');
var colors = require('colors');
@ -8,6 +10,7 @@ var Simulator = require('./cmds/simulator.js');
var TemplateGenerator = require('./cmds/template_generator.js');
var DeployManager = require('./contracts/deploy_manager.js');
var ABIGenerator = require('./contracts/abi.js');
var Test = require('./core/test.js');
var Logger = require('./core/logger.js');
@ -148,6 +151,26 @@ var Embark = {
callback();
},
function generateABI(callback) {
var generateABICode = function(contractsManager) {
var abiGenerator = new ABIGenerator({
blockchainConfig: self.config.blockchainConfig,
contractsManager: contractsManager,
plugins: self.plugins,
storageConfig: self.config.storageConfig,
communicationConfig: self.config.communicationConfig
});
var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
self.events.emit('abi-vanila', vanillaABI);
self.events.emit('abi', embarkJSABI);
};
self.events.on('contractsDeployed', generateABICode);
self.events.on('blockchainDisabled', generateABICode);
callback();
},
function deploy(callback) {
var deployManager = new DeployManager({
config: Embark.config,

View File

@ -28,7 +28,7 @@ $(document).ready(function() {
// Storage (IPFS) example
// ===========================
$(document).ready(function() {
EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
$("#storage button.setIpfsText").click(function() {
var value = $("#storage input.ipfsText").val();
@ -73,13 +73,13 @@ $(document).ready(function() {
$(document).ready(function() {
$("#communication .error").hide();
web3.version.getWhisper(function(err, res) {
if (err) {
$("#communication .error").show();
} else {
EmbarkJS.Messages.setProvider('whisper');
}
});
//web3.version.getWhisper(function(err, res) {
// if (err) {
// $("#communication .error").show();
// } else {
// EmbarkJS.Messages.setProvider('whisper');
// }
//});
$("#communication button.listenToChannel").click(function() {
var channel = $("#communication .listen input.channel").val();