mirror of https://github.com/embarklabs/embark.git
Merge branch 'develop' of github.com:iurimatias/embark-framework into develop
This commit is contained in:
commit
9f40958e6a
|
@ -285,14 +285,15 @@ class CodeGenerator {
|
||||||
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "'\n";
|
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "'\n";
|
||||||
code += "\nimport web3 from 'Embark/web3';\n";
|
code += "\nimport web3 from 'Embark/web3';\n";
|
||||||
|
|
||||||
if (this.storageConfig !== {} && this.storageConfig.provider === 'ipfs' && this.storageConfig.enabled === true) {
|
|
||||||
code += "\nimport IpfsApi from 'ipfs-api';\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
code += "\n" + embarkjsCode + "\n";
|
code += "\n" + embarkjsCode + "\n";
|
||||||
|
|
||||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/ipfs.js')).toString();
|
let pluginsWithCode = this.plugins.getPluginsFor('embarkjsCode');
|
||||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/whisper.js')).toString();
|
if (pluginsWithCode.length > 0) {
|
||||||
|
for (let plugin of pluginsWithCode) {
|
||||||
|
code += plugin.embarkjs_code.join('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
//code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
||||||
|
|
||||||
code += this.generateCommunicationInitialization(true);
|
code += this.generateCommunicationInitialization(true);
|
||||||
|
|
|
@ -200,14 +200,10 @@ class Engine {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Whisper', function (cb) {
|
this.registerModule('whisper', {
|
||||||
self.web3.version.getWhisper(function (err, version) {
|
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||||
if (err) {
|
communicationConfig: this.config.communicationConfig,
|
||||||
return cb({name: 'Whisper', status: 'off'});
|
web3: this.web3
|
||||||
} else {
|
|
||||||
return cb({name: 'Whisper (version ' + version + ')', status: 'on'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ var Plugin = function(options) {
|
||||||
this.serviceChecks = [];
|
this.serviceChecks = [];
|
||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
this.uploadCmds = [];
|
this.uploadCmds = [];
|
||||||
|
this.embarkjs_code = [];
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
@ -142,6 +143,11 @@ Plugin.prototype.registerUploadCommand = function(cmd, cb) {
|
||||||
this.pluginTypes.push('uploadCmds');
|
this.pluginTypes.push('uploadCmds');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.addCodeToEmbarkJS = function(code) {
|
||||||
|
this.embarkjs_code.push(code);
|
||||||
|
this.pluginTypes.push('embarkjsCode');
|
||||||
|
};
|
||||||
|
|
||||||
Plugin.prototype.runCommands = function(cmd, options) {
|
Plugin.prototype.runCommands = function(cmd, options) {
|
||||||
return this.console.map(function(cb) {
|
return this.console.map(function(cb) {
|
||||||
return cb.call(this, cmd, options);
|
return cb.call(this, cmd, options);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
import IpfsApi from 'ipfs-api';
|
||||||
|
|
||||||
let __embarkIPFS = {};
|
let __embarkIPFS = {};
|
||||||
|
|
||||||
__embarkIPFS.setProvider = function(options) {
|
__embarkIPFS.setProvider = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
self.currentStorage = EmbarkJS.Storage.IPFS;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
self.ipfsConnection = IpfsApi('localhost', '5001');
|
self.ipfsConnection = IpfsApi('localhost', '5001');
|
||||||
|
@ -26,7 +26,7 @@ __embarkIPFS.setProvider = function(options) {
|
||||||
__embarkIPFS.saveText = function(text) {
|
__embarkIPFS.saveText = function(text) {
|
||||||
const self = this;
|
const self = this;
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
if (!this.ipfsConnection) {
|
if (!self.ipfsConnection) {
|
||||||
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
reject(connectionError);
|
reject(connectionError);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ __embarkIPFS.saveText = function(text) {
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkIPFS.get = function(hash) {
|
__embarkIPFS.get = function(hash) {
|
||||||
|
const self = this;
|
||||||
// TODO: detect type, then convert if needed
|
// TODO: detect type, then convert if needed
|
||||||
//var ipfsHash = web3.toAscii(hash);
|
//var ipfsHash = web3.toAscii(hash);
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
@ -61,6 +62,7 @@ __embarkIPFS.get = function(hash) {
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkIPFS.uploadFile = function(inputSelector) {
|
__embarkIPFS.uploadFile = function(inputSelector) {
|
||||||
|
const self = this;
|
||||||
var file = inputSelector[0].files[0];
|
var file = inputSelector[0].files[0];
|
||||||
|
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
|
@ -94,4 +96,3 @@ __embarkIPFS.getUrl = function(hash) {
|
||||||
return (self._getUrl || "http://localhost:8080/ipfs/") + hash;
|
return (self._getUrl || "http://localhost:8080/ipfs/") + hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);
|
|
|
@ -1,5 +1,6 @@
|
||||||
let UploadIPFS = require('./upload.js');
|
let UploadIPFS = require('./upload.js');
|
||||||
let utils = require('../../utils/utils.js');
|
let utils = require('../../utils/utils.js');
|
||||||
|
let fs = require('../../core/fs.js');
|
||||||
|
|
||||||
class IPFS {
|
class IPFS {
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ class IPFS {
|
||||||
|
|
||||||
this.commandlineDeploy();
|
this.commandlineDeploy();
|
||||||
this.setServiceCheck();
|
this.setServiceCheck();
|
||||||
|
this.addIPFSToEmbarkJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
commandlineDeploy() {
|
commandlineDeploy() {
|
||||||
|
@ -82,6 +84,20 @@ class IPFS {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addIPFSToEmbarkJS() {
|
||||||
|
if (this.storageConfig === {}) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(this.storageConfig.provider !== 'ipfs' || this.storageConfig.enabled !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let code = "";
|
||||||
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||||
|
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);";
|
||||||
|
|
||||||
|
this.embark.addCodeToEmbarkJS(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = IPFS;
|
module.exports = IPFS;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/*global EmbarkJS, Web3 */
|
||||||
|
|
||||||
let __embarkWhisper = {};
|
let __embarkWhisper = {};
|
||||||
|
|
||||||
__embarkWhisper.setProvider = function(options) {
|
__embarkWhisper.setProvider = function(options) {
|
||||||
|
@ -32,20 +34,21 @@ __embarkWhisper.setProvider = function(options) {
|
||||||
|
|
||||||
__embarkWhisper.web3CompatibleWithV5 = function() {
|
__embarkWhisper.web3CompatibleWithV5 = function() {
|
||||||
var _web3 = new Web3();
|
var _web3 = new Web3();
|
||||||
if (typeof(_web3.version) === "string") {
|
if ((typeof _web3.version) === "string") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return parseInt(_web3.version.api.split('.')[1], 10) >= 20;
|
return parseInt(_web3.version.api.split('.')[1], 10) >= 20;
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkWhisper.getWhisperVersion = function(cb) {
|
__embarkWhisper.getWhisperVersion = function(cb) {
|
||||||
|
const self = this;
|
||||||
if (EmbarkJS.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3()) {
|
||||||
this.web3.shh.getVersion(function(err, version) {
|
this.web3.shh.getVersion(function(err, version) {
|
||||||
cb(err, version);
|
cb(err, version);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.web3.version.getWhisper(function(err, res) {
|
this.web3.version.getWhisper(function(err, _res) {
|
||||||
cb(err, web3.version.whisper);
|
cb(err, self.web3.version.whisper);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -88,7 +91,7 @@ __embarkWhisper.sendMessage = function(options) {
|
||||||
data = options.data || options.payload;
|
data = options.data || options.payload;
|
||||||
ttl = options.ttl || 100;
|
ttl = options.ttl || 100;
|
||||||
priority = options.priority || 1000;
|
priority = options.priority || 1000;
|
||||||
var identity = options.identity || this.identity || web3.shh.newIdentity();
|
var identity = options.identity || this.identity || this.web3.shh.newIdentity();
|
||||||
var _topics;
|
var _topics;
|
||||||
|
|
||||||
if (topics === undefined) {
|
if (topics === undefined) {
|
|
@ -0,0 +1,47 @@
|
||||||
|
let utils = require('../../utils/utils.js');
|
||||||
|
let fs = require('../../core/fs.js');
|
||||||
|
|
||||||
|
class Whisper {
|
||||||
|
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
this.events = embark.events;
|
||||||
|
this.communicationConfig = options.communicationConfig;
|
||||||
|
this.addCheck = options.addCheck;
|
||||||
|
this.web3 = options.web3;
|
||||||
|
this.embark = embark;
|
||||||
|
|
||||||
|
this.setServiceCheck();
|
||||||
|
this.addWhisperToEmbarkJS();
|
||||||
|
}
|
||||||
|
|
||||||
|
setServiceCheck() {
|
||||||
|
const self = this;
|
||||||
|
self.addCheck('Whisper', function (cb) {
|
||||||
|
self.web3.version.getWhisper(function (err, version) {
|
||||||
|
if (err) {
|
||||||
|
return cb({name: 'Whisper', status: 'off'});
|
||||||
|
} else {
|
||||||
|
return cb({name: 'Whisper (version ' + version + ')', status: 'on'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addWhisperToEmbarkJS() {
|
||||||
|
if (this.communicationConfig === {}) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(this.communicationConfig.provider !== 'whisper' || this.communicationConfig.enabled !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let code = "";
|
||||||
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||||
|
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkWhisper);";
|
||||||
|
|
||||||
|
this.embark.addCodeToEmbarkJS(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Whisper;
|
|
@ -1,13 +0,0 @@
|
||||||
var Web3 = require('web3');
|
|
||||||
|
|
||||||
web3 = new Web3();
|
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
|
|
||||||
|
|
||||||
EmbarkJS = require('./js/embark.js');
|
|
||||||
|
|
||||||
MyToken = require('./test_app/dist/js/mytoken.js');
|
|
||||||
|
|
||||||
console.log(MyToken.address);
|
|
||||||
|
|
||||||
MyToken.balanceOf(web3.eth.accounts[0]).then((x) => console.log(x.toNumber()));
|
|
Loading…
Reference in New Issue