mirror of https://github.com/embarklabs/embark.git
fix whisper code
This commit is contained in:
parent
ff6a092ecc
commit
e46fce4c48
37
js/embark.js
37
js/embark.js
|
@ -177,7 +177,6 @@ EmbarkJS.Contract.prototype.send = function(value, unit, _options) {
|
||||||
|
|
||||||
options.to = this.address;
|
options.to = this.address;
|
||||||
options.value = wei;
|
options.value = wei;
|
||||||
console.log(options);
|
|
||||||
|
|
||||||
this.web3.eth.sendTransaction(options);
|
this.web3.eth.sendTransaction(options);
|
||||||
};
|
};
|
||||||
|
@ -209,35 +208,19 @@ EmbarkJS.Storage.registerProvider = function(providerName, obj) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
let provider = this.Providers[provider];
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
if (!provider) {
|
if (!providerObj) {
|
||||||
throw new Error('Unknown storage provider');
|
throw new Error('Unknown storage provider');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentStorage = provider;
|
this.currentStorage = providerObj;
|
||||||
|
|
||||||
return provider.setProvider(options);
|
return providerObj.setProvider(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages = {};
|
EmbarkJS.Messages = {};
|
||||||
|
|
||||||
EmbarkJS.Messages.web3CompatibleWithV5 = function() {
|
|
||||||
var _web3 = new Web3();
|
|
||||||
if (typeof(_web3.version) === "string") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return parseInt(_web3.version.api.split('.')[1], 10) >= 20;
|
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.isNewWeb3 = function() {
|
|
||||||
var _web3 = new Web3();
|
|
||||||
if (typeof(_web3.version) === "string") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.Providers = {};
|
EmbarkJS.Messages.Providers = {};
|
||||||
|
|
||||||
EmbarkJS.Messages.registerProvider = function(providerName, obj) {
|
EmbarkJS.Messages.registerProvider = function(providerName, obj) {
|
||||||
|
@ -245,18 +228,18 @@ EmbarkJS.Messages.registerProvider = function(providerName, obj) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var ipfs;
|
var ipfs;
|
||||||
if (provider === 'whisper') {
|
if (provider === 'whisper') {
|
||||||
let provider = this.Providers[provider];
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
if (!provider) {
|
if (!providerObj) {
|
||||||
throw new Error('Unknown storage provider');
|
throw new Error('Unknown storage provider');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentMessages = provider;
|
this.currentMessages = providerObj;
|
||||||
|
|
||||||
return provider.setProvider(options);
|
return providerObj.setProvider(options);
|
||||||
|
|
||||||
} else if (provider === 'orbit') {
|
} else if (provider === 'orbit') {
|
||||||
|
|
||||||
|
|
|
@ -18,25 +18,33 @@ __embarkWhisper.setProvider = function(options) {
|
||||||
console.log("whisper not available");
|
console.log("whisper not available");
|
||||||
} else if (version >= 5) {
|
} else if (version >= 5) {
|
||||||
if (self.web3CompatibleWithV5()) {
|
if (self.web3CompatibleWithV5()) {
|
||||||
self.web3.shh.newSymKey().then((id) => {self.currentMessages.symKeyID = id;});
|
self.web3.shh.newSymKey().then((id) => {self.symKeyID = id;});
|
||||||
self.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;});
|
self.web3.shh.newKeyPair().then((id) => {self.sig = id;});
|
||||||
} else {
|
} else {
|
||||||
console.log("this version of whisper in this node");
|
console.log("this version of whisper in this node");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity();
|
self.identity = self.web3.shh.newIdentity();
|
||||||
}
|
}
|
||||||
self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper;
|
self.whisperVersion = self.web3.version.whisper;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__embarkWhisper.web3CompatibleWithV5 = function() {
|
||||||
|
var _web3 = new Web3();
|
||||||
|
if (typeof(_web3.version) === "string") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return parseInt(_web3.version.api.split('.')[1], 10) >= 20;
|
||||||
|
};
|
||||||
|
|
||||||
__embarkWhisper.getWhisperVersion = function(cb) {
|
__embarkWhisper.getWhisperVersion = function(cb) {
|
||||||
if (this.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3()) {
|
||||||
this.currentMessages.web3.shh.getVersion(function(err, version) {
|
this.web3.shh.getVersion(function(err, version) {
|
||||||
cb(err, version);
|
cb(err, version);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.currentMessages.web3.version.getWhisper(function(err, res) {
|
this.web3.version.getWhisper(function(err, res) {
|
||||||
cb(err, web3.version.whisper);
|
cb(err, web3.version.whisper);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -44,7 +52,7 @@ __embarkWhisper.getWhisperVersion = function(cb) {
|
||||||
|
|
||||||
__embarkWhisper.sendMessage = function(options) {
|
__embarkWhisper.sendMessage = function(options) {
|
||||||
var topics, data, ttl, priority, payload;
|
var topics, data, ttl, priority, payload;
|
||||||
if (EmbarkJS.Messages.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3()) {
|
||||||
topics = options.topic || options.topics;
|
topics = options.topic || options.topics;
|
||||||
data = options.data || options.payload;
|
data = options.data || options.payload;
|
||||||
ttl = options.ttl || 100;
|
ttl = options.ttl || 100;
|
||||||
|
@ -115,7 +123,7 @@ __embarkWhisper.sendMessage = function(options) {
|
||||||
|
|
||||||
__embarkWhisper.listenTo = function(options) {
|
__embarkWhisper.listenTo = function(options) {
|
||||||
var topics, _topics, messageEvents;
|
var topics, _topics, messageEvents;
|
||||||
if (EmbarkJS.Messages.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3()) {
|
||||||
messageEvents = function() {
|
messageEvents = function() {
|
||||||
this.cb = function() {};
|
this.cb = function() {};
|
||||||
};
|
};
|
||||||
|
@ -218,4 +226,4 @@ __embarkWhisper.listenTo = function(options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.registerProvider('whisper', __embarkWhisper);
|
EmbarkJS.Messages.registerProvider('whisper', __embarkWhisper);
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
},
|
},
|
||||||
"afterDeploy": [
|
"afterDeploy": [
|
||||||
"Test.changeAddress('$MyToken')",
|
"Test.changeAddress('$MyToken')",
|
||||||
"Test.changeAddress(web3.eth.accounts[1])"
|
"Test.changeAddress(web3.eth.accounts[0])"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"development": {
|
"development": {
|
||||||
|
|
Loading…
Reference in New Issue