aboutsummaryrefslogtreecommitdiffstats
path: root/lib/providermanager.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/providermanager.js')
-rw-r--r--lib/providermanager.js65
1 files changed, 25 insertions, 40 deletions
diff --git a/lib/providermanager.js b/lib/providermanager.js
index f79a9b087..1a550e5f4 100644
--- a/lib/providermanager.js
+++ b/lib/providermanager.js
@@ -35,74 +35,59 @@ var web3 = require('./web3'); // jshint ignore:line
* and provider manager polling mechanism is not used
*/
var ProviderManager = function() {
- this.queued = [];
this.polls = [];
- this.ready = false;
this.provider = undefined;
this.id = 1;
var self = this;
var poll = function () {
- if (self.provider && self.provider.poll) {
+ if (self.provider) {
self.polls.forEach(function (data) {
data.data._id = self.id;
self.id++;
- self.provider.poll(data.data, data.id);
+ var result = self.provider.send(data.data);
+
+ result = JSON.parse(result);
+
+ // dont call the callback if result is not an array, or empty one
+ if (result.error || !(result.result instanceof Array) || result.result.length === 0) {
+ return;
+ }
+
+ data.callback(result.result);
});
}
- setTimeout(poll, 12000);
+ setTimeout(poll, 1000);
};
poll();
};
-/// sends outgoing requests, if provider is not available, enqueue the request
-ProviderManager.prototype.send = function(data, cb) {
- data._id = this.id;
- if (cb) {
- web3._callbacks[data._id] = cb;
- }
+/// sends outgoing requests
+ProviderManager.prototype.send = function(data) {
data.args = data.args || [];
- this.id++;
+ data._id = this.id++;
- if(this.provider !== undefined) {
- this.provider.send(data);
- } else {
- console.warn("provider is not set");
- this.queued.push(data);
+ if (this.provider === undefined) {
+ console.error('provider is not set');
+ return null;
}
+
+ //TODO: handle error here?
+ var result = this.provider.send(data);
+ result = JSON.parse(result);
+ return result.result;
};
/// setups provider, which will be used for sending messages
ProviderManager.prototype.set = function(provider) {
- if(this.provider !== undefined && this.provider.unload !== undefined) {
- this.provider.unload();
- }
-
this.provider = provider;
- this.ready = true;
-};
-
-/// resends queued messages
-ProviderManager.prototype.sendQueued = function() {
- for(var i = 0; this.queued.length; i++) {
- // Resend
- this.send(this.queued[i]);
- }
-};
-
-/// @returns true if the provider i properly set
-ProviderManager.prototype.installed = function() {
- return this.provider !== undefined;
};
/// this method is only used, when we do not have native qt bindings and have to do polling on our own
/// should be callled, on start watching for eth/shh changes
-ProviderManager.prototype.startPolling = function (data, pollId) {
- if (!this.provider || !this.provider.poll) {
- return;
- }
- this.polls.push({data: data, id: pollId});
+ProviderManager.prototype.startPolling = function (data, pollId, callback) {
+ this.polls.push({data: data, id: pollId, callback: callback});
};
/// should be called to stop polling for certain watch changes