From 12619532db035538b1590184cb19b42930746cd6 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 29 May 2020 21:27:59 -0400 Subject: [PATCH] Updated dist files. --- lib.esm/_version.d.ts | 2 +- lib.esm/_version.js | 2 +- lib.esm/base-provider.js | 13 ++++++++----- lib.esm/websocket-provider.js | 20 +++++++++++++++++--- lib/_version.d.ts | 2 +- lib/_version.js | 2 +- lib/base-provider.js | 13 ++++++++----- lib/websocket-provider.js | 20 +++++++++++++++++--- package.json | 4 ++-- src.ts/_version.ts | 2 +- 10 files changed, 57 insertions(+), 23 deletions(-) diff --git a/lib.esm/_version.d.ts b/lib.esm/_version.d.ts index f8ef8ce91a..364041d2ea 100644 --- a/lib.esm/_version.d.ts +++ b/lib.esm/_version.d.ts @@ -1 +1 @@ -export declare const version = "providers/5.0.0-beta.168"; +export declare const version = "providers/5.0.0-beta.169"; diff --git a/lib.esm/_version.js b/lib.esm/_version.js index 32ed653d0d..bb8bc32a6e 100644 --- a/lib.esm/_version.js +++ b/lib.esm/_version.js @@ -1 +1 @@ -export const version = "providers/5.0.0-beta.168"; +export const version = "providers/5.0.0-beta.169"; diff --git a/lib.esm/base-provider.js b/lib.esm/base-provider.js index 6d77629ea0..72e9b8e4bc 100644 --- a/lib.esm/base-provider.js +++ b/lib.esm/base-provider.js @@ -205,11 +205,14 @@ export class BaseProvider extends Provider { network = yield this.detectNetwork(); } // This should never happen; every Provider sub-class should have - // suggested a network by here (or thrown). + // suggested a network by here (or have thrown). if (!network) { logger.throwError("no network detected", Logger.errors.UNKNOWN_ERROR, {}); } - defineReadOnly(this, "_network", network); + // Possible this call stacked so do not call defineReadOnly again + if (this._network == null) { + defineReadOnly(this, "_network", network); + } } return this._network; }); @@ -732,7 +735,7 @@ export class BaseProvider extends Provider { return this.formatter.blockWithTransactions(block); } return this.formatter.block(block); - }), { onceBlock: this }); + }), { oncePoll: this }); }); } getBlock(blockHashOrBlockTag) { @@ -770,7 +773,7 @@ export class BaseProvider extends Provider { tx.confirmations = confirmations; } return this._wrapTransaction(tx); - }), { onceBlock: this }); + }), { oncePoll: this }); }); } getTransactionReceipt(transactionHash) { @@ -806,7 +809,7 @@ export class BaseProvider extends Provider { receipt.confirmations = confirmations; } return receipt; - }), { onceBlock: this }); + }), { oncePoll: this }); }); } getLogs(filter) { diff --git a/lib.esm/websocket-provider.js b/lib.esm/websocket-provider.js index e10a01413e..3e803c5fe8 100644 --- a/lib.esm/websocket-provider.js +++ b/lib.esm/websocket-provider.js @@ -82,6 +82,15 @@ export class WebSocketProvider extends JsonRpcProvider { console.warn("this should not happen"); } }; + // This Provider does not actually poll, but we want to trigger + // poll events for things that depend on them (like stalling for + // block and transaction lookups) + const fauxPoll = setInterval(() => { + this.emit("poll"); + }, 1000); + if (fauxPoll.unref) { + fauxPoll.unref(); + } } get pollingInterval() { return 0; @@ -149,8 +158,10 @@ export class WebSocketProvider extends JsonRpcProvider { _startEvent(event) { switch (event.type) { case "block": - this._subscribe("block", ["newHeads", {}], (result) => { - this.emit("block", BigNumber.from(result.number).toNumber()); + this._subscribe("block", ["newHeads"], (result) => { + const blockNumber = BigNumber.from(result.number).toNumber(); + this._emitted.block = blockNumber; + this.emit("block", blockNumber); }); break; case "pending": @@ -182,13 +193,16 @@ export class WebSocketProvider extends JsonRpcProvider { // to keep an eye out for transactions we are watching for. // Starting a subscription for an event (i.e. "tx") that is already // running is (basically) a nop. - this._subscribe("tx", ["newHeads", {}], (result) => { + this._subscribe("tx", ["newHeads"], (result) => { this._events.filter((e) => (e.type === "tx")).forEach(emitReceipt); }); break; } // Nothing is needed case "debug": + case "poll": + case "willPoll": + case "didPoll": case "error": break; default: diff --git a/lib/_version.d.ts b/lib/_version.d.ts index f8ef8ce91a..364041d2ea 100644 --- a/lib/_version.d.ts +++ b/lib/_version.d.ts @@ -1 +1 @@ -export declare const version = "providers/5.0.0-beta.168"; +export declare const version = "providers/5.0.0-beta.169"; diff --git a/lib/_version.js b/lib/_version.js index 4f2cb99cfa..c4e3d2ff11 100644 --- a/lib/_version.js +++ b/lib/_version.js @@ -1,3 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.version = "providers/5.0.0-beta.168"; +exports.version = "providers/5.0.0-beta.169"; diff --git a/lib/base-provider.js b/lib/base-provider.js index efc9c21fed..0856aafde8 100644 --- a/lib/base-provider.js +++ b/lib/base-provider.js @@ -280,11 +280,14 @@ var BaseProvider = /** @class */ (function (_super) { _a.label = 6; case 6: // This should never happen; every Provider sub-class should have - // suggested a network by here (or thrown). + // suggested a network by here (or have thrown). if (!network) { logger.throwError("no network detected", logger_1.Logger.errors.UNKNOWN_ERROR, {}); } - properties_1.defineReadOnly(this, "_network", network); + // Possible this call stacked so do not call defineReadOnly again + if (this._network == null) { + properties_1.defineReadOnly(this, "_network", network); + } _a.label = 7; case 7: return [2 /*return*/, this._network]; } @@ -1015,7 +1018,7 @@ var BaseProvider = /** @class */ (function (_super) { case 8: return [2 /*return*/, this.formatter.block(block)]; } }); - }); }, { onceBlock: this })]; + }); }, { oncePoll: this })]; } }); }); @@ -1073,7 +1076,7 @@ var BaseProvider = /** @class */ (function (_super) { case 4: return [2 /*return*/, this._wrapTransaction(tx)]; } }); - }); }, { onceBlock: this })]; + }); }, { oncePoll: this })]; } }); }); @@ -1129,7 +1132,7 @@ var BaseProvider = /** @class */ (function (_super) { case 4: return [2 /*return*/, receipt]; } }); - }); }, { onceBlock: this })]; + }); }, { oncePoll: this })]; } }); }); diff --git a/lib/websocket-provider.js b/lib/websocket-provider.js index 2492d087d4..c692a5598a 100644 --- a/lib/websocket-provider.js +++ b/lib/websocket-provider.js @@ -127,6 +127,15 @@ var WebSocketProvider = /** @class */ (function (_super) { console.warn("this should not happen"); } }; + // This Provider does not actually poll, but we want to trigger + // poll events for things that depend on them (like stalling for + // block and transaction lookups) + var fauxPoll = setInterval(function () { + _this.emit("poll"); + }, 1000); + if (fauxPoll.unref) { + fauxPoll.unref(); + } return _this; } Object.defineProperty(WebSocketProvider.prototype, "pollingInterval", { @@ -217,8 +226,10 @@ var WebSocketProvider = /** @class */ (function (_super) { var _this = this; switch (event.type) { case "block": - this._subscribe("block", ["newHeads", {}], function (result) { - _this.emit("block", bignumber_1.BigNumber.from(result.number).toNumber()); + this._subscribe("block", ["newHeads"], function (result) { + var blockNumber = bignumber_1.BigNumber.from(result.number).toNumber(); + _this._emitted.block = blockNumber; + _this.emit("block", blockNumber); }); break; case "pending": @@ -250,13 +261,16 @@ var WebSocketProvider = /** @class */ (function (_super) { // to keep an eye out for transactions we are watching for. // Starting a subscription for an event (i.e. "tx") that is already // running is (basically) a nop. - this._subscribe("tx", ["newHeads", {}], function (result) { + this._subscribe("tx", ["newHeads"], function (result) { _this._events.filter(function (e) { return (e.type === "tx"); }).forEach(emitReceipt_1); }); break; } // Nothing is needed case "debug": + case "poll": + case "willPoll": + case "didPoll": case "error": break; default: diff --git a/package.json b/package.json index b2510ffaad..d5e7a484a3 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "tarballHash": "0x04e34eb73e41646f6dd85015b26d8aa77676d53896f60341d34809deb87f701a", + "tarballHash": "0x2c7517b23e6eb918b668110c930001103934b54b78a357e775e232be9dfc7c25", "types": "./lib/index.d.ts", - "version": "5.0.0-beta.168" + "version": "5.0.0-beta.169" } diff --git a/src.ts/_version.ts b/src.ts/_version.ts index 32ed653d0d..bb8bc32a6e 100644 --- a/src.ts/_version.ts +++ b/src.ts/_version.ts @@ -1 +1 @@ -export const version = "providers/5.0.0-beta.168"; +export const version = "providers/5.0.0-beta.169";