Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 9fa8152

Browse files
authored
Merge branch '1.0' into fix/polling-contract-timeout
2 parents 105e814 + 2a4a722 commit 9fa8152

File tree

7 files changed

+264
-160
lines changed

7 files changed

+264
-160
lines changed

dist/web3.js

+242-130
Large diffs are not rendered by default.

dist/web3.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/web3-core-requestmanager/src/index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,21 @@ RequestManager.prototype.setProvider = function (p, net) {
9595

9696
// listen to incoming notifications
9797
if(this.provider && this.provider.on) {
98-
this.provider.on('data', function requestManagerNotification(err, result){
99-
if(!err) {
100-
if(_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback)
101-
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
102-
} else {
103-
104-
Object.keys(_this.subscriptions).forEach(function(id){
105-
if(_this.subscriptions[id].callback)
106-
_this.subscriptions[id].callback(err);
107-
});
98+
this.provider.on('data', function requestManagerNotification(result, deprecatedResult){
99+
result = result || deprecatedResult; // this is for possible old providers, which may had the error first handler
100+
101+
// check for result.method, to prevent old providers errors to pass as result
102+
if(result.method && _this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
103+
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
108104
}
109105
});
106+
// TODO add error, end, timeout, connect??
107+
// this.provider.on('error', function requestManagerNotification(result){
108+
// Object.keys(_this.subscriptions).forEach(function(id){
109+
// if(_this.subscriptions[id].callback)
110+
// _this.subscriptions[id].callback(err);
111+
// });
112+
// }
110113
}
111114
};
112115

packages/web3-core-subscriptions/src/subscription.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ Subscription.prototype.subscribe = function() {
276276
if(_this.options.requestManager.provider.once) {
277277
_this._reconnectIntervalId = setInterval(function () {
278278
// TODO check if that makes sense!
279-
_this.options.requestManager.provider.reconnect();
279+
if (_this.options.requestManager.provider.reconnect) {
280+
_this.options.requestManager.provider.reconnect();
281+
}
280282
}, 500);
281283

282284
_this.options.requestManager.provider.once('connect', function () {

packages/web3-providers-ipc/src/index.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var IpcProvider = function IpcProvider(path, net) {
5757
if(!id && result.method.indexOf('_subscription') !== -1) {
5858
_this.notificationCallbacks.forEach(function(callback){
5959
if(_.isFunction(callback))
60-
callback(null, result);
60+
callback(result);
6161
});
6262

6363
// fire the callback
@@ -95,12 +95,6 @@ IpcProvider.prototype.addDefaultEvents = function(){
9595

9696
this.connection.on('end', function(){
9797
_this._timeout();
98-
99-
// inform notifications
100-
_this.notificationCallbacks.forEach(function (callback) {
101-
if (_.isFunction(callback))
102-
callback(new Error('IPC socket connection closed'));
103-
});
10498
});
10599

106100
this.connection.on('timeout', function(){
@@ -231,6 +225,7 @@ IpcProvider.prototype.on = function (type, callback) {
231225
this.notificationCallbacks.push(callback);
232226
break;
233227

228+
// adds error, end, timeout, connect
234229
default:
235230
this.connection.on(type, callback);
236231
break;

packages/web3-providers-ws/src/index.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var WebsocketProvider = function WebsocketProvider(url) {
6868
if(!id && result.method.indexOf('_subscription') !== -1) {
6969
_this.notificationCallbacks.forEach(function(callback){
7070
if(_.isFunction(callback))
71-
callback(null, result);
71+
callback(result);
7272
});
7373

7474
// fire the callback
@@ -92,19 +92,11 @@ WebsocketProvider.prototype.addDefaultEvents = function(){
9292
_this._timeout();
9393
};
9494

95-
this.connection.onclose = function(e){
95+
this.connection.onclose = function(){
9696
_this._timeout();
9797

98-
var noteCb = _this.notificationCallbacks;
99-
10098
// reset all requests and callbacks
10199
_this.reset();
102-
103-
// cancel subscriptions
104-
noteCb.forEach(function (callback) {
105-
if (_.isFunction(callback))
106-
callback(e);
107-
});
108100
};
109101

110102
// this.connection.on('timeout', function(){

test/helpers/FakeIpcProvider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ FakeIpcProvider.prototype.injectNotification = function (notification) {
9696
setTimeout(function(){
9797
_this.notificationCallbacks.forEach(function(cb){
9898
if(notification && cb)
99-
cb(null, notification);
99+
cb(notification);
100100
});
101101
}, 100 + this.notificationCount);
102102

0 commit comments

Comments
 (0)