mirror of https://github.com/embarklabs/embark.git
make abi generation independent of deployment
This commit is contained in:
parent
1674adee4a
commit
b7cd296716
|
@ -28,7 +28,8 @@ $(document).ready(function() {
|
||||||
// Storage (IPFS) example
|
// Storage (IPFS) example
|
||||||
// ===========================
|
// ===========================
|
||||||
$(document).ready(function() {
|
$(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();
|
$("#storage .error").hide();
|
||||||
EmbarkJS.Storage.ipfsConnection.ping()
|
EmbarkJS.Storage.ipfsConnection.ping()
|
||||||
|
|
|
@ -189,8 +189,6 @@ var EmbarkJS =
|
||||||
EmbarkJS.Storage = {
|
EmbarkJS.Storage = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
|
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
if (provider === 'ipfs') {
|
if (provider === 'ipfs') {
|
||||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
|
@ -283,7 +281,7 @@ var EmbarkJS =
|
||||||
var ipfs;
|
var ipfs;
|
||||||
if (provider === 'whisper') {
|
if (provider === 'whisper') {
|
||||||
this.currentMessages = EmbarkJS.Messages.Whisper;
|
this.currentMessages = EmbarkJS.Messages.Whisper;
|
||||||
if (web3 === undefined) {
|
if (typeof variable === 'undefined') {
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -142,8 +142,6 @@ EmbarkJS.IPFS = 'ipfs';
|
||||||
EmbarkJS.Storage = {
|
EmbarkJS.Storage = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
|
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
if (provider === 'ipfs') {
|
if (provider === 'ipfs') {
|
||||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
|
@ -236,7 +234,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||||
var ipfs;
|
var ipfs;
|
||||||
if (provider === 'whisper') {
|
if (provider === 'whisper') {
|
||||||
this.currentMessages = EmbarkJS.Messages.Whisper;
|
this.currentMessages = EmbarkJS.Messages.Whisper;
|
||||||
if (web3 === undefined) {
|
if (typeof variable === 'undefined') {
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -94,10 +94,10 @@ ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJ
|
||||||
|
|
||||||
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
||||||
|
|
||||||
if (self.communicationConfig.provider === 'ipfs' && self.communicationConfig.enabled === true) {
|
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
||||||
result += "\nEmbarkJS.Storage.setProvider('" + self.communicationConfig.provider + "');";
|
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||||
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
|
} 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;
|
return result;
|
||||||
|
|
|
@ -3,7 +3,6 @@ var Web3 = require('web3');
|
||||||
|
|
||||||
var Deploy = require('./deploy.js');
|
var Deploy = require('./deploy.js');
|
||||||
var ContractsManager = require('./contracts.js');
|
var ContractsManager = require('./contracts.js');
|
||||||
var ABIGenerator = require('./abi.js');
|
|
||||||
|
|
||||||
var DeployManager = function(options) {
|
var DeployManager = function(options) {
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
@ -18,6 +17,7 @@ DeployManager.prototype.deployContracts = function(done) {
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
self.logger.info("Blockchain component is disabled in the config".underline);
|
self.logger.info("Blockchain component is disabled in the config".underline);
|
||||||
|
self.events.emit('blockchainDisabled', {});
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,19 +61,9 @@ DeployManager.prototype.deployContracts = function(done) {
|
||||||
});
|
});
|
||||||
deploy.deployAll(function() {
|
deploy.deployAll(function() {
|
||||||
callback(null, contractsManager);
|
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) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -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;
|
23
lib/index.js
23
lib/index.js
|
@ -1,5 +1,7 @@
|
||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
//require("./core/debug_util.js")(__filename, async);
|
||||||
|
|
||||||
var Web3 = require('web3');
|
var Web3 = require('web3');
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
|
|
||||||
|
@ -8,6 +10,7 @@ var Simulator = require('./cmds/simulator.js');
|
||||||
var TemplateGenerator = require('./cmds/template_generator.js');
|
var TemplateGenerator = require('./cmds/template_generator.js');
|
||||||
|
|
||||||
var DeployManager = require('./contracts/deploy_manager.js');
|
var DeployManager = require('./contracts/deploy_manager.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');
|
||||||
|
@ -148,6 +151,26 @@ var Embark = {
|
||||||
callback();
|
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) {
|
function deploy(callback) {
|
||||||
var deployManager = new DeployManager({
|
var deployManager = new DeployManager({
|
||||||
config: Embark.config,
|
config: Embark.config,
|
||||||
|
|
|
@ -28,7 +28,7 @@ $(document).ready(function() {
|
||||||
// Storage (IPFS) example
|
// Storage (IPFS) example
|
||||||
// ===========================
|
// ===========================
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
||||||
|
|
||||||
$("#storage button.setIpfsText").click(function() {
|
$("#storage button.setIpfsText").click(function() {
|
||||||
var value = $("#storage input.ipfsText").val();
|
var value = $("#storage input.ipfsText").val();
|
||||||
|
@ -73,13 +73,13 @@ $(document).ready(function() {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$("#communication .error").hide();
|
$("#communication .error").hide();
|
||||||
web3.version.getWhisper(function(err, res) {
|
//web3.version.getWhisper(function(err, res) {
|
||||||
if (err) {
|
// if (err) {
|
||||||
$("#communication .error").show();
|
// $("#communication .error").show();
|
||||||
} else {
|
// } else {
|
||||||
EmbarkJS.Messages.setProvider('whisper');
|
// EmbarkJS.Messages.setProvider('whisper');
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
|
|
||||||
$("#communication button.listenToChannel").click(function() {
|
$("#communication button.listenToChannel").click(function() {
|
||||||
var channel = $("#communication .listen input.channel").val();
|
var channel = $("#communication .listen input.channel").val();
|
||||||
|
|
Loading…
Reference in New Issue