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 '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" + fs.readFileSync(fs.embarkPath('js/embarkjs/ipfs.js')).toString();
|
||||
code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/whisper.js')).toString();
|
||||
let pluginsWithCode = this.plugins.getPluginsFor('embarkjsCode');
|
||||
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 += this.generateCommunicationInitialization(true);
|
||||
|
|
|
@ -200,14 +200,10 @@ class Engine {
|
|||
}
|
||||
});
|
||||
|
||||
self.servicesMonitor.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'});
|
||||
}
|
||||
});
|
||||
this.registerModule('whisper', {
|
||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||
communicationConfig: this.config.communicationConfig,
|
||||
web3: this.web3
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ var Plugin = function(options) {
|
|||
this.serviceChecks = [];
|
||||
this.pluginTypes = [];
|
||||
this.uploadCmds = [];
|
||||
this.embarkjs_code = [];
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
|
@ -142,6 +143,11 @@ Plugin.prototype.registerUploadCommand = function(cmd, cb) {
|
|||
this.pluginTypes.push('uploadCmds');
|
||||
};
|
||||
|
||||
Plugin.prototype.addCodeToEmbarkJS = function(code) {
|
||||
this.embarkjs_code.push(code);
|
||||
this.pluginTypes.push('embarkjsCode');
|
||||
};
|
||||
|
||||
Plugin.prototype.runCommands = function(cmd, options) {
|
||||
return this.console.map(function(cb) {
|
||||
return cb.call(this, cmd, options);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import IpfsApi from 'ipfs-api';
|
||||
|
||||
let __embarkIPFS = {};
|
||||
|
||||
__embarkIPFS.setProvider = function(options) {
|
||||
var self = this;
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
self.currentStorage = EmbarkJS.Storage.IPFS;
|
||||
|
||||
try {
|
||||
if (options === undefined) {
|
||||
self.ipfsConnection = IpfsApi('localhost', '5001');
|
||||
|
@ -26,7 +26,7 @@ __embarkIPFS.setProvider = function(options) {
|
|||
__embarkIPFS.saveText = function(text) {
|
||||
const self = this;
|
||||
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()');
|
||||
reject(connectionError);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ __embarkIPFS.saveText = function(text) {
|
|||
};
|
||||
|
||||
__embarkIPFS.get = function(hash) {
|
||||
const self = this;
|
||||
// TODO: detect type, then convert if needed
|
||||
//var ipfsHash = web3.toAscii(hash);
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
|
@ -61,6 +62,7 @@ __embarkIPFS.get = function(hash) {
|
|||
};
|
||||
|
||||
__embarkIPFS.uploadFile = function(inputSelector) {
|
||||
const self = this;
|
||||
var file = inputSelector[0].files[0];
|
||||
|
||||
if (file === undefined) {
|
||||
|
@ -94,4 +96,3 @@ __embarkIPFS.getUrl = function(hash) {
|
|||
return (self._getUrl || "http://localhost:8080/ipfs/") + hash;
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);
|
|
@ -1,5 +1,6 @@
|
|||
let UploadIPFS = require('./upload.js');
|
||||
let utils = require('../../utils/utils.js');
|
||||
let fs = require('../../core/fs.js');
|
||||
|
||||
class IPFS {
|
||||
|
||||
|
@ -15,6 +16,7 @@ class IPFS {
|
|||
|
||||
this.commandlineDeploy();
|
||||
this.setServiceCheck();
|
||||
this.addIPFSToEmbarkJS();
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/*global EmbarkJS, Web3 */
|
||||
|
||||
let __embarkWhisper = {};
|
||||
|
||||
__embarkWhisper.setProvider = function(options) {
|
||||
|
@ -18,8 +20,8 @@ __embarkWhisper.setProvider = function(options) {
|
|||
console.log("whisper not available");
|
||||
} else if (version >= 5) {
|
||||
if (self.web3CompatibleWithV5()) {
|
||||
self.web3.shh.newSymKey().then((id) => {self.symKeyID = id;});
|
||||
self.web3.shh.newKeyPair().then((id) => {self.sig = id;});
|
||||
self.web3.shh.newSymKey().then((id) => { self.symKeyID = id; });
|
||||
self.web3.shh.newKeyPair().then((id) => { self.sig = id; });
|
||||
} else {
|
||||
console.log("this version of whisper in this node");
|
||||
}
|
||||
|
@ -32,20 +34,21 @@ __embarkWhisper.setProvider = function(options) {
|
|||
|
||||
__embarkWhisper.web3CompatibleWithV5 = function() {
|
||||
var _web3 = new Web3();
|
||||
if (typeof(_web3.version) === "string") {
|
||||
if ((typeof _web3.version) === "string") {
|
||||
return true;
|
||||
}
|
||||
return parseInt(_web3.version.api.split('.')[1], 10) >= 20;
|
||||
};
|
||||
|
||||
__embarkWhisper.getWhisperVersion = function(cb) {
|
||||
const self = this;
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
this.web3.shh.getVersion(function(err, version) {
|
||||
cb(err, version);
|
||||
});
|
||||
} else {
|
||||
this.web3.version.getWhisper(function(err, res) {
|
||||
cb(err, web3.version.whisper);
|
||||
this.web3.version.getWhisper(function(err, _res) {
|
||||
cb(err, self.web3.version.whisper);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -88,7 +91,7 @@ __embarkWhisper.sendMessage = function(options) {
|
|||
data = options.data || options.payload;
|
||||
ttl = options.ttl || 100;
|
||||
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;
|
||||
|
||||
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