tolerate when whisper is not available; support latest geth

This commit is contained in:
Iuri Matias 2017-03-06 22:44:16 -05:00
parent b42031de6b
commit 8348f0a224
2 changed files with 18 additions and 4 deletions

View File

@ -57,7 +57,7 @@ var EmbarkJS =
this.abi = options.abi; this.abi = options.abi;
this.address = options.address; this.address = options.address;
this.code = options.code; this.code = '0x' + options.code;
this.web3 = options.web3 || web3; this.web3 = options.web3 || web3;
var ContractClass = this.web3.eth.contract(this.abi); var ContractClass = this.web3.eth.contract(this.abi);
@ -278,6 +278,7 @@ var EmbarkJS =
}; };
EmbarkJS.Messages.setProvider = function(provider, options) { EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this;
var ipfs; var ipfs;
if (provider === 'whisper') { if (provider === 'whisper') {
this.currentMessages = EmbarkJS.Messages.Whisper; this.currentMessages = EmbarkJS.Messages.Whisper;
@ -288,7 +289,13 @@ var EmbarkJS =
web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port)); web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port));
} }
} }
this.currentMessages.identity = web3.shh.newIdentity(); web3.version.getWhisper(function(err, res) {
if (err) {
console.log("whisper not available");
} else {
self.currentMessages.identity = web3.shh.newIdentity();
}
});
} else if (provider === 'orbit') { } else if (provider === 'orbit') {
this.currentMessages = EmbarkJS.Messages.Orbit; this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) { if (options === undefined) {

View File

@ -10,7 +10,7 @@ EmbarkJS.Contract = function(options) {
this.abi = options.abi; this.abi = options.abi;
this.address = options.address; this.address = options.address;
this.code = options.code; this.code = '0x' + options.code;
this.web3 = options.web3 || web3; this.web3 = options.web3 || web3;
var ContractClass = this.web3.eth.contract(this.abi); var ContractClass = this.web3.eth.contract(this.abi);
@ -231,6 +231,7 @@ EmbarkJS.Messages = {
}; };
EmbarkJS.Messages.setProvider = function(provider, options) { EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this;
var ipfs; var ipfs;
if (provider === 'whisper') { if (provider === 'whisper') {
this.currentMessages = EmbarkJS.Messages.Whisper; this.currentMessages = EmbarkJS.Messages.Whisper;
@ -241,7 +242,13 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port)); web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port));
} }
} }
this.currentMessages.identity = web3.shh.newIdentity(); web3.version.getWhisper(function(err, res) {
if (err) {
console.log("whisper not available");
} else {
self.currentMessages.identity = web3.shh.newIdentity();
}
});
} else if (provider === 'orbit') { } else if (provider === 'orbit') {
this.currentMessages = EmbarkJS.Messages.Orbit; this.currentMessages = EmbarkJS.Messages.Orbit;
if (options === undefined) { if (options === undefined) {