good morning!!!!

Skip to content
Snippets Groups Projects
Commit 9adb6258 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

polling whisper in progress

parent 0b10cbd7
No related branches found
No related tags found
No related merge requests found
...@@ -102,6 +102,28 @@ ...@@ -102,6 +102,28 @@
]; ];
}; };
var ethWatchMethods = function () {
var newFilter = function (args) {
return typeof args[0] === 'string' ? 'newFilterString' : 'newFilter';
};
return [
{ name: 'newFilter', call: newFilter },
{ name: 'uninstallFilter', call: 'uninstallFilter' },
{ name: 'changed', call: 'changed' },
{ name: 'getMessages', call: 'getMessages' }
];
};
var shhWatchMethods = function () {
return [
{ name: 'newFilter', call: 'shhNewFilter' },
{ name: 'uninstallFilter', call: 'shhUninstallFilter' },
{ name: 'changed', call: 'shhChanged' },
{ name: 'getMessage', call: 'shhGetMessages' }
];
};
var setupMethods = function (obj, methods) { var setupMethods = function (obj, methods) {
methods.forEach(function (method) { methods.forEach(function (method) {
obj[method.name] = function () { obj[method.name] = function () {
...@@ -186,6 +208,10 @@ ...@@ -186,6 +208,10 @@
return str; return str;
}, },
toDecimal: function (val) {
return parseInt(val, 16);
},
fromAscii: function(str, pad) { fromAscii: function(str, pad) {
if(pad === undefined) { if(pad === undefined) {
pad = 32 pad = 32
...@@ -202,7 +228,7 @@ ...@@ -202,7 +228,7 @@
eth: { eth: {
prototype: Object(), prototype: Object(),
watch: function (params) { watch: function (params) {
return new Filter(params); return new Filter(params, ethWatch);
}, },
}, },
...@@ -211,7 +237,10 @@ ...@@ -211,7 +237,10 @@
}, },
shh: { shh: {
prototype: Object() prototype: Object(),
watch: function (params) {
return new Filter(params, shhWatch);
}
}, },
on: function(event, cb) { on: function(event, cb) {
...@@ -259,6 +288,11 @@ ...@@ -259,6 +288,11 @@
setupMethods(web3.db, dbMethods()); setupMethods(web3.db, dbMethods());
setupMethods(web3.shh, shhMethods()); setupMethods(web3.shh, shhMethods());
var ethWatch = {};
setupMethods(ethWatch, ethWatchMethods());
var shhWatch = {};
setupMethods(shhWatch, shhWatchMethods());
var ProviderManager = function() { var ProviderManager = function() {
this.queued = []; this.queued = [];
this.polls = []; this.polls = [];
...@@ -340,33 +374,22 @@ ...@@ -340,33 +374,22 @@
web3.setProvider = function(provider) { web3.setProvider = function(provider) {
provider.onmessage = messageHandler; provider.onmessage = messageHandler;
web3.provider.set(provider); web3.provider.set(provider);
web3.provider.sendQueued(); web3.provider.sendQueued();
}; };
var filters = []; var filters = [];
var Filter = function(options) { var Filter = function(options, impl) {
filters.push(this); filters.push(this);
this.impl = impl;
this.callbacks = []; this.callbacks = [];
this.options = options;
var call;
if(options === "chain" || options === "pending") {
call = "newFilterString"
} else if(typeof options === "object") {
call = "newFilter"
}
var self = this; // Cheaper than binding var self = this; // Cheaper than binding
this.promise = new Promise(function(resolve, reject) { this.promise = impl.newFilter(options);
web3.provider.send({call: call, args: [options]}, function(id) { this.promise.then(function (id) {
self.id = id; self.id = id;
web3.provider.startPolling({call: "changed", args: [id]}, id); web3.provider.startPolling({call: 'changed', args: [id]}, id);
resolve(id);
});
}); });
}; };
...@@ -386,21 +409,17 @@ ...@@ -386,21 +409,17 @@
}; };
Filter.prototype.uninstall = function() { Filter.prototype.uninstall = function() {
var self = this;
this.promise.then(function (id) { this.promise.then(function (id) {
web3.provider.send({call: "uninstallFilter", args:[id]}); self.impl.uninstallFilter(id);
web3.provider.stopPolling(id); web3.provider.stopPolling(id);
}); });
}; };
Filter.prototype.messages = function() { Filter.prototype.messages = function() {
var self = this; var self = this;
return Promise.all([this.promise]).then(function() { return this.promise.then(function (id) {
var id = self.id return self.impl.getMessages(id);
return new Promise(function(resolve, reject) {
web3.provider.send({call: "getMessages", args: [id]}, function(messages) {
resolve(messages);
});
});
}); });
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment