2022-09-05 16:57:11 -04:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.BlockConnectionSubscriber = void 0;
|
2022-09-15 22:58:45 -04:00
|
|
|
const index_js_1 = require("../utils/index.js");
|
2022-11-30 15:44:23 -05:00
|
|
|
/**
|
|
|
|
* @TODO
|
|
|
|
*
|
|
|
|
* @_docloc: api/providers/abstract-provider
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
class BlockConnectionSubscriber {
|
|
|
|
#provider;
|
|
|
|
#blockNumber;
|
|
|
|
#filterId;
|
|
|
|
constructor(provider) {
|
|
|
|
this.#provider = provider;
|
|
|
|
this.#blockNumber = -2;
|
|
|
|
this.#filterId = null;
|
|
|
|
}
|
|
|
|
start() {
|
|
|
|
this.#filterId = this.#provider._subscribe(["newHeads"], (result) => {
|
2022-09-15 22:58:45 -04:00
|
|
|
const blockNumber = (0, index_js_1.getNumber)(result.number);
|
2022-09-05 16:57:11 -04:00
|
|
|
const initial = (this.#blockNumber === -2) ? blockNumber : (this.#blockNumber + 1);
|
|
|
|
for (let b = initial; b <= blockNumber; b++) {
|
|
|
|
this.#provider.emit("block", b);
|
|
|
|
}
|
|
|
|
this.#blockNumber = blockNumber;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
stop() {
|
|
|
|
if (this.#filterId != null) {
|
|
|
|
this.#provider._unsubscribe(this.#filterId);
|
|
|
|
this.#filterId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pause(dropWhilePaused) {
|
|
|
|
if (dropWhilePaused) {
|
|
|
|
this.#blockNumber = -2;
|
|
|
|
}
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
resume() {
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.BlockConnectionSubscriber = BlockConnectionSubscriber;
|
|
|
|
//# sourceMappingURL=subscriber-connection.js.map
|