eth-block-tracker
Advanced tools
Comparing version 4.4.1 to 4.4.2
@@ -1,23 +0,37 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var EthQuery = require('eth-query'); | ||
var pify = require('pify'); | ||
var SafeEventEmitter = require('safe-event-emitter'); | ||
@@ -30,5 +44,8 @@ | ||
}; | ||
var blockTrackerEvents = ['sync', 'latest']; | ||
var BaseBlockTracker = function (_SafeEventEmitter) { | ||
var BaseBlockTracker = | ||
/*#__PURE__*/ | ||
function (_SafeEventEmitter) { | ||
_inherits(BaseBlockTracker, _SafeEventEmitter); | ||
@@ -39,4 +56,5 @@ | ||
// | ||
function BaseBlockTracker() { | ||
var _this; | ||
function BaseBlockTracker() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -46,16 +64,16 @@ | ||
// config | ||
var _this = _possibleConstructorReturn(this, (BaseBlockTracker.__proto__ || Object.getPrototypeOf(BaseBlockTracker)).call(this)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BaseBlockTracker).call(this)); // config | ||
_this._blockResetDuration = opts.blockResetDuration || 20 * sec; | ||
// state | ||
_this._blockResetDuration = opts.blockResetDuration || 20 * sec; // state | ||
_this._blockResetTimeout; | ||
_this._currentBlock = null; | ||
_this._isRunning = false; | ||
// bind functions for internal use | ||
_this._onNewListener = _this._onNewListener.bind(_this); | ||
_this._onRemoveListener = _this._onRemoveListener.bind(_this); | ||
_this._resetCurrentBlock = _this._resetCurrentBlock.bind(_this); | ||
// listen for handler changes | ||
_this._isRunning = false; // bind functions for internal use | ||
_this._onNewListener = _this._onNewListener.bind(_assertThisInitialized(_this)); | ||
_this._onRemoveListener = _this._onRemoveListener.bind(_assertThisInitialized(_this)); | ||
_this._resetCurrentBlock = _this._resetCurrentBlock.bind(_assertThisInitialized(_this)); // listen for handler changes | ||
_this._setupInternalEvents(); | ||
return _this; | ||
@@ -65,3 +83,3 @@ } | ||
_createClass(BaseBlockTracker, [{ | ||
key: 'isRunning', | ||
key: "isRunning", | ||
value: function isRunning() { | ||
@@ -71,3 +89,3 @@ return this._isRunning; | ||
}, { | ||
key: 'getCurrentBlock', | ||
key: "getCurrentBlock", | ||
value: function getCurrentBlock() { | ||
@@ -77,9 +95,11 @@ return this._currentBlock; | ||
}, { | ||
key: 'getLatestBlock', | ||
key: "getLatestBlock", | ||
value: function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
var _getLatestBlock = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee() { | ||
var _this2 = this; | ||
var latestBlock; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -93,3 +113,3 @@ switch (_context.prev = _context.next) { | ||
return _context.abrupt('return', this._currentBlock); | ||
return _context.abrupt("return", this._currentBlock); | ||
@@ -104,6 +124,6 @@ case 2: | ||
latestBlock = _context.sent; | ||
return _context.abrupt('return', latestBlock); | ||
return _context.abrupt("return", latestBlock); | ||
case 6: | ||
case 'end': | ||
case "end": | ||
return _context.stop(); | ||
@@ -116,26 +136,24 @@ } | ||
function getLatestBlock() { | ||
return _ref.apply(this, arguments); | ||
return _getLatestBlock.apply(this, arguments); | ||
} | ||
return getLatestBlock; | ||
}() | ||
}() // dont allow module consumer to remove our internal event listeners | ||
// dont allow module consumer to remove our internal event listeners | ||
}, { | ||
key: 'removeAllListeners', | ||
key: "removeAllListeners", | ||
value: function removeAllListeners(eventName) { | ||
// perform default behavior, preserve fn arity | ||
if (eventName) { | ||
_get(BaseBlockTracker.prototype.__proto__ || Object.getPrototypeOf(BaseBlockTracker.prototype), 'removeAllListeners', this).call(this, eventName); | ||
_get(_getPrototypeOf(BaseBlockTracker.prototype), "removeAllListeners", this).call(this, eventName); | ||
} else { | ||
_get(BaseBlockTracker.prototype.__proto__ || Object.getPrototypeOf(BaseBlockTracker.prototype), 'removeAllListeners', this).call(this); | ||
} | ||
// re-add internal events | ||
this._setupInternalEvents(); | ||
// trigger stop check just in case | ||
_get(_getPrototypeOf(BaseBlockTracker.prototype), "removeAllListeners", this).call(this); | ||
} // re-add internal events | ||
this._setupInternalEvents(); // trigger stop check just in case | ||
this._onRemoveListener(); | ||
} | ||
// | ||
} // | ||
// to be implemented in subclass | ||
@@ -145,12 +163,8 @@ // | ||
}, { | ||
key: '_start', | ||
value: function _start() { | ||
// default behavior is noop | ||
key: "_start", | ||
value: function _start() {// default behavior is noop | ||
} | ||
}, { | ||
key: '_end', | ||
value: function _end() {} | ||
// default behavior is noop | ||
key: "_end", | ||
value: function _end() {} // default behavior is noop | ||
// | ||
@@ -161,8 +175,8 @@ // private | ||
}, { | ||
key: '_setupInternalEvents', | ||
key: "_setupInternalEvents", | ||
value: function _setupInternalEvents() { | ||
// first remove listeners for idempotence | ||
this.removeListener('newListener', this._onNewListener); | ||
this.removeListener('removeListener', this._onRemoveListener); | ||
// then add them | ||
this.removeListener('removeListener', this._onRemoveListener); // then add them | ||
this.on('newListener', this._onNewListener); | ||
@@ -172,34 +186,39 @@ this.on('removeListener', this._onRemoveListener); | ||
}, { | ||
key: '_onNewListener', | ||
key: "_onNewListener", | ||
value: function _onNewListener(eventName, handler) { | ||
// `newListener` is called *before* the listener is added | ||
if (!blockTrackerEvents.includes(eventName)) return; | ||
this._maybeStart(); | ||
} | ||
}, { | ||
key: '_onRemoveListener', | ||
key: "_onRemoveListener", | ||
value: function _onRemoveListener(eventName, handler) { | ||
// `removeListener` is called *after* the listener is removed | ||
if (this._getBlockTrackerEventCount() > 0) return; | ||
this._maybeEnd(); | ||
} | ||
}, { | ||
key: '_maybeStart', | ||
key: "_maybeStart", | ||
value: function _maybeStart() { | ||
if (this._isRunning) return; | ||
this._isRunning = true; | ||
// cancel setting latest block to stale | ||
this._isRunning = true; // cancel setting latest block to stale | ||
this._cancelBlockResetTimeout(); | ||
this._start(); | ||
} | ||
}, { | ||
key: '_maybeEnd', | ||
key: "_maybeEnd", | ||
value: function _maybeEnd() { | ||
if (!this._isRunning) return; | ||
this._isRunning = false; | ||
this._setupBlockResetTimeout(); | ||
this._end(); | ||
} | ||
}, { | ||
key: '_getBlockTrackerEventCount', | ||
key: "_getBlockTrackerEventCount", | ||
value: function _getBlockTrackerEventCount() { | ||
@@ -213,11 +232,12 @@ var _this3 = this; | ||
}, { | ||
key: '_newPotentialLatest', | ||
key: "_newPotentialLatest", | ||
value: function _newPotentialLatest(newBlock) { | ||
var currentBlock = this._currentBlock; | ||
// only update if blok number is higher | ||
var currentBlock = this._currentBlock; // only update if blok number is higher | ||
if (currentBlock && hexToInt(newBlock) <= hexToInt(currentBlock)) return; | ||
this._setCurrentBlock(newBlock); | ||
} | ||
}, { | ||
key: '_setCurrentBlock', | ||
key: "_setCurrentBlock", | ||
value: function _setCurrentBlock(newBlock) { | ||
@@ -227,12 +247,16 @@ var oldBlock = this._currentBlock; | ||
this.emit('latest', newBlock); | ||
this.emit('sync', { oldBlock: oldBlock, newBlock: newBlock }); | ||
this.emit('sync', { | ||
oldBlock: oldBlock, | ||
newBlock: newBlock | ||
}); | ||
} | ||
}, { | ||
key: '_setupBlockResetTimeout', | ||
key: "_setupBlockResetTimeout", | ||
value: function _setupBlockResetTimeout() { | ||
// clear any existing timeout | ||
this._cancelBlockResetTimeout(); | ||
// clear latest block when stale | ||
this._blockResetTimeout = setTimeout(this._resetCurrentBlock, this._blockResetDuration); | ||
// nodejs - dont hold process open | ||
this._cancelBlockResetTimeout(); // clear latest block when stale | ||
this._blockResetTimeout = setTimeout(this._resetCurrentBlock, this._blockResetDuration); // nodejs - dont hold process open | ||
if (this._blockResetTimeout.unref) { | ||
@@ -243,3 +267,3 @@ this._blockResetTimeout.unref(); | ||
}, { | ||
key: '_cancelBlockResetTimeout', | ||
key: "_cancelBlockResetTimeout", | ||
value: function _cancelBlockResetTimeout() { | ||
@@ -249,3 +273,3 @@ clearTimeout(this._blockResetTimeout); | ||
}, { | ||
key: '_resetCurrentBlock', | ||
key: "_resetCurrentBlock", | ||
value: function _resetCurrentBlock() { | ||
@@ -252,0 +276,0 @@ this._currentBlock = null; |
@@ -1,20 +0,31 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var pify = require('pify'); | ||
var BaseBlockTracker = require('./base'); | ||
@@ -24,6 +35,10 @@ | ||
var PollingBlockTracker = function (_BaseBlockTracker) { | ||
var PollingBlockTracker = | ||
/*#__PURE__*/ | ||
function (_BaseBlockTracker) { | ||
_inherits(PollingBlockTracker, _BaseBlockTracker); | ||
function PollingBlockTracker() { | ||
var _this; | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -38,9 +53,7 @@ | ||
var keepEventLoopActive = opts.keepEventLoopActive !== undefined ? opts.keepEventLoopActive : true; | ||
var setSkipCacheFlag = opts.setSkipCacheFlag || false; | ||
// BaseBlockTracker constructor | ||
var setSkipCacheFlag = opts.setSkipCacheFlag || false; // BaseBlockTracker constructor | ||
// config | ||
var _this = _possibleConstructorReturn(this, (PollingBlockTracker.__proto__ || Object.getPrototypeOf(PollingBlockTracker)).call(this, Object.assign({ | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(PollingBlockTracker).call(this, Object.assign({ | ||
blockResetDuration: pollingInterval | ||
}, opts))); | ||
}, opts))); // config | ||
@@ -53,8 +66,5 @@ _this._provider = opts.provider; | ||
return _this; | ||
} | ||
// | ||
} // | ||
// public | ||
// | ||
// trigger block polling | ||
@@ -64,6 +74,8 @@ | ||
_createClass(PollingBlockTracker, [{ | ||
key: 'checkForLatestBlock', | ||
key: "checkForLatestBlock", | ||
value: function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
var _checkForLatestBlock = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee() { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -80,6 +92,6 @@ switch (_context.prev = _context.next) { | ||
case 4: | ||
return _context.abrupt('return', _context.sent); | ||
return _context.abrupt("return", _context.sent); | ||
case 5: | ||
case 'end': | ||
case "end": | ||
return _context.stop(); | ||
@@ -92,9 +104,7 @@ } | ||
function checkForLatestBlock() { | ||
return _ref.apply(this, arguments); | ||
return _checkForLatestBlock.apply(this, arguments); | ||
} | ||
return checkForLatestBlock; | ||
}() | ||
// | ||
}() // | ||
// private | ||
@@ -104,7 +114,7 @@ // | ||
}, { | ||
key: '_start', | ||
key: "_start", | ||
value: function _start() { | ||
var _this2 = this; | ||
this._performSync().catch(function (err) { | ||
this._performSync()["catch"](function (err) { | ||
return _this2.emit('error', err); | ||
@@ -114,7 +124,9 @@ }); | ||
}, { | ||
key: '_performSync', | ||
key: "_performSync", | ||
value: function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var _performSync2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee2() { | ||
var newErr; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -142,4 +154,4 @@ switch (_context2.prev = _context2.next) { | ||
_context2.prev = 8; | ||
_context2.t0 = _context2['catch'](1); | ||
newErr = new Error('PollingBlockTracker - encountered an error while attempting to update latest block:\n' + _context2.t0.stack); | ||
_context2.t0 = _context2["catch"](1); | ||
newErr = new Error("PollingBlockTracker - encountered an error while attempting to update latest block:\n".concat(_context2.t0.stack)); | ||
@@ -151,2 +163,3 @@ try { | ||
} | ||
_context2.next = 14; | ||
@@ -160,3 +173,3 @@ return timeout(this._retryTimeout, !this._keepEventLoopActive); | ||
case 16: | ||
case 'end': | ||
case "end": | ||
return _context2.stop(); | ||
@@ -169,3 +182,3 @@ } | ||
function _performSync() { | ||
return _ref2.apply(this, arguments); | ||
return _performSync2.apply(this, arguments); | ||
} | ||
@@ -176,7 +189,9 @@ | ||
}, { | ||
key: '_updateLatestBlock', | ||
key: "_updateLatestBlock", | ||
value: function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { | ||
var _updateLatestBlock2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee3() { | ||
var latestBlock; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
return _regenerator["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
@@ -194,3 +209,3 @@ switch (_context3.prev = _context3.next) { | ||
case 4: | ||
case 'end': | ||
case "end": | ||
return _context3.stop(); | ||
@@ -203,3 +218,3 @@ } | ||
function _updateLatestBlock() { | ||
return _ref3.apply(this, arguments); | ||
return _updateLatestBlock2.apply(this, arguments); | ||
} | ||
@@ -210,14 +225,20 @@ | ||
}, { | ||
key: '_fetchLatestBlock', | ||
key: "_fetchLatestBlock", | ||
value: function () { | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee4() { | ||
var _fetchLatestBlock2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee4() { | ||
var _this3 = this; | ||
var req, res; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
return _regenerator["default"].wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
req = { jsonrpc: "2.0", id: 1, method: 'eth_blockNumber', params: [] }; | ||
req = { | ||
jsonrpc: "2.0", | ||
id: 1, | ||
method: 'eth_blockNumber', | ||
params: [] | ||
}; | ||
if (this._setSkipCacheFlag) req.skipCache = true; | ||
@@ -237,9 +258,9 @@ _context4.next = 4; | ||
throw new Error('PollingBlockTracker - encountered error fetching block:\n' + res.error); | ||
throw new Error("PollingBlockTracker - encountered error fetching block:\n".concat(res.error)); | ||
case 7: | ||
return _context4.abrupt('return', res.result); | ||
return _context4.abrupt("return", res.result); | ||
case 8: | ||
case 'end': | ||
case "end": | ||
return _context4.stop(); | ||
@@ -252,3 +273,3 @@ } | ||
function _fetchLatestBlock() { | ||
return _ref4.apply(this, arguments); | ||
return _fetchLatestBlock2.apply(this, arguments); | ||
} | ||
@@ -267,4 +288,4 @@ | ||
return new Promise(function (resolve) { | ||
var timoutRef = setTimeout(resolve, duration); | ||
// don't keep process open | ||
var timoutRef = setTimeout(resolve, duration); // don't keep process open | ||
if (timoutRef.unref && unref) { | ||
@@ -271,0 +292,0 @@ timoutRef.unref(); |
@@ -1,27 +0,43 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var EventEmitter = require('events'); | ||
var BaseBlockTracker = require('./base'); | ||
var createRandomId = require('json-rpc-random-id')(); | ||
var SubscribeBlockTracker = function (_BaseBlockTracker) { | ||
var SubscribeBlockTracker = | ||
/*#__PURE__*/ | ||
function (_BaseBlockTracker) { | ||
_inherits(SubscribeBlockTracker, _BaseBlockTracker); | ||
function SubscribeBlockTracker() { | ||
var _this; | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -32,21 +48,20 @@ | ||
// parse + validate args | ||
if (!opts.provider) throw new Error('SubscribeBlockTracker - no provider specified.'); | ||
// BaseBlockTracker constructor | ||
if (!opts.provider) throw new Error('SubscribeBlockTracker - no provider specified.'); // BaseBlockTracker constructor | ||
// config | ||
var _this = _possibleConstructorReturn(this, (SubscribeBlockTracker.__proto__ || Object.getPrototypeOf(SubscribeBlockTracker)).call(this, opts)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(SubscribeBlockTracker).call(this, opts)); // config | ||
_this._provider = opts.provider; | ||
return _this; | ||
} | ||
// | ||
} // | ||
// public | ||
// | ||
_createClass(SubscribeBlockTracker, [{ | ||
key: 'checkForLatestBlock', | ||
key: "checkForLatestBlock", | ||
value: function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
var _checkForLatestBlock = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee() { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -59,6 +74,6 @@ switch (_context.prev = _context.next) { | ||
case 2: | ||
return _context.abrupt('return', _context.sent); | ||
return _context.abrupt("return", _context.sent); | ||
case 3: | ||
case 'end': | ||
case "end": | ||
return _context.stop(); | ||
@@ -71,9 +86,7 @@ } | ||
function checkForLatestBlock() { | ||
return _ref.apply(this, arguments); | ||
return _checkForLatestBlock.apply(this, arguments); | ||
} | ||
return checkForLatestBlock; | ||
}() | ||
// | ||
}() // | ||
// private | ||
@@ -83,7 +96,9 @@ // | ||
}, { | ||
key: '_start', | ||
key: "_start", | ||
value: function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var _start2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee2() { | ||
var blockNumber; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -110,3 +125,5 @@ switch (_context2.prev = _context2.next) { | ||
this._provider.on('data', this._handleSubData.bind(this)); | ||
this._newPotentialLatest(blockNumber); | ||
_context2.next = 15; | ||
@@ -117,8 +134,7 @@ break; | ||
_context2.prev = 12; | ||
_context2.t0 = _context2['catch'](1); | ||
_context2.t0 = _context2["catch"](1); | ||
this.emit('error', _context2.t0); | ||
case 15: | ||
case 'end': | ||
case "end": | ||
return _context2.stop(); | ||
@@ -131,3 +147,3 @@ } | ||
function _start() { | ||
return _ref2.apply(this, arguments); | ||
return _start2.apply(this, arguments); | ||
} | ||
@@ -138,6 +154,8 @@ | ||
}, { | ||
key: '_end', | ||
key: "_end", | ||
value: function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
var _end2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee3() { | ||
return _regenerator["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
@@ -162,8 +180,7 @@ switch (_context3.prev = _context3.next) { | ||
_context3.prev = 7; | ||
_context3.t0 = _context3['catch'](1); | ||
_context3.t0 = _context3["catch"](1); | ||
this.emit('error', _context3.t0); | ||
case 10: | ||
case 'end': | ||
case "end": | ||
return _context3.stop(); | ||
@@ -176,3 +193,3 @@ } | ||
function _end() { | ||
return _ref3.apply(this, arguments); | ||
return _end2.apply(this, arguments); | ||
} | ||
@@ -183,3 +200,3 @@ | ||
}, { | ||
key: '_call', | ||
key: "_call", | ||
value: function _call(method) { | ||
@@ -191,3 +208,6 @@ var _this2 = this; | ||
_this2._provider.sendAsync({ | ||
id: createRandomId(), method: method, params: params, jsonrpc: "2.0" | ||
id: createRandomId(), | ||
method: method, | ||
params: params, | ||
jsonrpc: "2.0" | ||
}, function (err, res) { | ||
@@ -199,3 +219,3 @@ if (err) reject(err);else resolve(res.result); | ||
}, { | ||
key: '_handleSubData', | ||
key: "_handleSubData", | ||
value: function _handleSubData(err, data) { | ||
@@ -202,0 +222,0 @@ if (data.method === 'eth_subscription' && data.params.subscription === this._subscriptionId) { |
{ | ||
"name": "eth-block-tracker", | ||
"version": "4.4.1", | ||
"version": "4.4.2", | ||
"description": "A block tracker for the Ethereum blockchain. Keeps track of the latest block.", | ||
@@ -9,3 +9,3 @@ "main": "src/polling.js", | ||
"test:unit": "node test/index.js", | ||
"test:lint:deps": "npx depcheck --ignore-dirs dist --ignores babelify,babel-preset-env,babel-plugin-transform-runtime", | ||
"test:lint:deps": "npx depcheck --ignore-dirs dist --ignores babelify,@babel/runtime,@babel/preset-env,@babel/plugin-transform-runtime", | ||
"prepublishOnly": "npm run build", | ||
@@ -24,3 +24,4 @@ "build": "npm run build:clean && npm run build:es5 && npm run build:bundle && npm run build:validate", | ||
"dependencies": { | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"@babel/plugin-transform-runtime": "^7.5.5", | ||
"@babel/runtime": "^7.5.5", | ||
"eth-query": "^2.1.0", | ||
@@ -32,8 +33,10 @@ "json-rpc-random-id": "^1.0.1", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-preset-env": "^1.7.0", | ||
"babelify": "^8.0.0", | ||
"browserify": "^16.2.3", | ||
"eth-json-rpc-infura": "^3.1.2", | ||
"ganache-core": "^2.5.5", | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-transform-regenerator": "^7.4.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"babelify": "^10.0.0", | ||
"browserify": "^16.5.0", | ||
"eth-json-rpc-infura": "^4.0.1", | ||
"ganache-core": "^2.7.0", | ||
"tape": "^4.9.0", | ||
@@ -40,0 +43,0 @@ "uglify-js": "^3.4.10" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
3
330579
6
10
8140
+ Added@babel/runtime@^7.5.5
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.24.7(transitive)
+ Added@babel/compat-data@7.24.7(transitive)
+ Added@babel/core@7.24.7(transitive)
+ Added@babel/generator@7.24.7(transitive)
+ Added@babel/helper-compilation-targets@7.24.7(transitive)
+ Added@babel/helper-define-polyfill-provider@0.6.2(transitive)
+ Added@babel/helper-environment-visitor@7.24.7(transitive)
+ Added@babel/helper-function-name@7.24.7(transitive)
+ Added@babel/helper-hoist-variables@7.24.7(transitive)
+ Added@babel/helper-module-imports@7.24.7(transitive)
+ Added@babel/helper-module-transforms@7.24.7(transitive)
+ Added@babel/helper-plugin-utils@7.24.7(transitive)
+ Added@babel/helper-simple-access@7.24.7(transitive)
+ Added@babel/helper-split-export-declaration@7.24.7(transitive)
+ Added@babel/helper-string-parser@7.24.7(transitive)
+ Added@babel/helper-validator-identifier@7.24.7(transitive)
+ Added@babel/helper-validator-option@7.24.7(transitive)
+ Added@babel/helpers@7.24.7(transitive)
+ Added@babel/highlight@7.24.7(transitive)
+ Added@babel/parser@7.24.7(transitive)
+ Added@babel/plugin-transform-runtime@7.24.7(transitive)
+ Added@babel/runtime@7.24.7(transitive)
+ Added@babel/template@7.24.7(transitive)
+ Added@babel/traverse@7.24.7(transitive)
+ Added@babel/types@7.24.7(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.4.15(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbabel-plugin-polyfill-corejs2@0.4.11(transitive)
+ Addedbabel-plugin-polyfill-corejs3@0.10.4(transitive)
+ Addedbabel-plugin-polyfill-regenerator@0.6.2(transitive)
+ Addedbrowserslist@4.23.1(transitive)
+ Addedcaniuse-lite@1.0.30001640(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedcore-js-compat@3.37.1(transitive)
+ Addeddebug@4.3.5(transitive)
+ Addedelectron-to-chromium@1.4.819(transitive)
+ Addedescalade@3.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.14.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@2.5.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlodash.debounce@4.0.8(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedms@2.1.2(transitive)
+ Addednode-releases@2.0.14(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.0.1(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
+ Addedupdate-browserslist-db@1.1.0(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedbabel-plugin-transform-runtime@6.23.0(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)