eth-block-tracker
Advanced tools
Comparing version 6.1.0 to 7.1.0
import SafeEventEmitter from '@metamask/safe-event-emitter'; | ||
interface BaseBlockTrackerArgs { | ||
blockResetDuration?: number; | ||
usePastBlocks?: boolean; | ||
} | ||
@@ -8,2 +9,3 @@ export declare abstract class BaseBlockTracker extends SafeEventEmitter { | ||
private _blockResetDuration; | ||
private _usePastBlocks; | ||
private _currentBlock; | ||
@@ -31,2 +33,3 @@ private _blockResetTimeout?; | ||
private _getBlockTrackerEventCount; | ||
protected _shouldUseNewBlock(newBlock: string): boolean; | ||
protected _newPotentialLatest(newBlock: string): void; | ||
@@ -33,0 +36,0 @@ private _setCurrentBlock; |
@@ -16,2 +16,3 @@ "use strict"; | ||
this._blockResetDuration = opts.blockResetDuration || 20 * sec; | ||
this._usePastBlocks = opts.usePastBlocks || false; | ||
// state | ||
@@ -108,6 +109,14 @@ this._currentBlock = null; | ||
} | ||
_shouldUseNewBlock(newBlock) { | ||
const currentBlock = this._currentBlock; | ||
if (!currentBlock) { | ||
return true; | ||
} | ||
const newBlockInt = hexToInt(newBlock); | ||
const currentBlockInt = hexToInt(currentBlock); | ||
return ((this._usePastBlocks && newBlockInt < currentBlockInt) || | ||
newBlockInt > currentBlockInt); | ||
} | ||
_newPotentialLatest(newBlock) { | ||
const currentBlock = this._currentBlock; | ||
// only update if blok number is higher | ||
if (currentBlock && hexToInt(newBlock) <= hexToInt(currentBlock)) { | ||
if (!this._shouldUseNewBlock(newBlock)) { | ||
return; | ||
@@ -114,0 +123,0 @@ } |
export * from './PollingBlockTracker'; | ||
export * from './SubscribeBlockTracker'; | ||
export * from './types'; |
@@ -15,3 +15,2 @@ "use strict"; | ||
__exportStar(require("./SubscribeBlockTracker"), exports); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,5 +1,5 @@ | ||
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; | ||
import { BaseBlockTracker } from './BaseBlockTracker'; | ||
import { Provider } from './types'; | ||
export interface PollingBlockTrackerOptions { | ||
provider?: Provider; | ||
provider?: SafeEventEmitterProvider; | ||
pollingInterval?: number; | ||
@@ -10,2 +10,3 @@ retryTimeout?: number; | ||
blockResetDuration?: number; | ||
usePastBlocks?: boolean; | ||
} | ||
@@ -12,0 +13,0 @@ export declare class PollingBlockTracker extends BaseBlockTracker { |
@@ -21,5 +21,3 @@ "use strict"; | ||
} | ||
super({ | ||
blockResetDuration: (_a = opts.blockResetDuration) !== null && _a !== void 0 ? _a : opts.pollingInterval, | ||
}); | ||
super(Object.assign(Object.assign({}, opts), { blockResetDuration: (_a = opts.blockResetDuration) !== null && _a !== void 0 ? _a : opts.pollingInterval })); | ||
// config | ||
@@ -26,0 +24,0 @@ this._provider = opts.provider; |
@@ -0,6 +1,7 @@ | ||
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; | ||
import { BaseBlockTracker } from './BaseBlockTracker'; | ||
import { Provider } from './types'; | ||
export interface SubscribeBlockTrackerOptions { | ||
provider?: Provider; | ||
provider?: SafeEventEmitterProvider; | ||
blockResetDuration?: number; | ||
usePastBlocks?: boolean; | ||
} | ||
@@ -7,0 +8,0 @@ export declare class SubscribeBlockTracker extends BaseBlockTracker { |
{ | ||
"name": "eth-block-tracker", | ||
"version": "6.1.0", | ||
"version": "7.1.0", | ||
"description": "A block tracker for the Ethereum blockchain. Keeps track of the latest block.", | ||
@@ -28,4 +28,5 @@ "repository": { | ||
"dependencies": { | ||
"@metamask/safe-event-emitter": "^2.0.0", | ||
"@metamask/utils": "^3.0.1", | ||
"@metamask/eth-json-rpc-provider": "^1.0.0", | ||
"@metamask/safe-event-emitter": "^3.0.0", | ||
"@metamask/utils": "^5.0.1", | ||
"json-rpc-random-id": "^1.0.1", | ||
@@ -35,3 +36,3 @@ "pify": "^3.0.0" | ||
"devDependencies": { | ||
"@lavamoat/allow-scripts": "^2.0.2", | ||
"@lavamoat/allow-scripts": "^2.3.1", | ||
"@metamask/auto-changelog": "^3.0.0", | ||
@@ -38,0 +39,0 @@ "@metamask/eslint-config": "^9.0.0", |
@@ -38,5 +38,8 @@ # eth-block-tracker | ||
#### new PollingBlockTracker({ provider, pollingInterval, retryTimeout, keepEventLoopActive }) | ||
#### new PollingBlockTracker({ provider, pollingInterval, retryTimeout, keepEventLoopActive, usePastBlocks }) | ||
Creates a new block tracker with `provider` as a data source and `pollingInterval` (ms) timeout between polling for the latest block. If an error is encountered when fetching blocks, it will wait `retryTimeout` (ms) before attempting again. If `keepEventLoopActive` is false, in Node.js it will [unref the polling timeout](https://nodejs.org/api/timers.html#timers_timeout_unref), allowing the process to exit during the polling interval. Defaults to `true`, meaning the process will be kept alive. | ||
- Creates a new block tracker with `provider` as a data source and `pollingInterval` (ms) timeout between polling for the latest block. | ||
- If an error is encountered when fetching blocks, it will wait `retryTimeout` (ms) before attempting again. | ||
- If `keepEventLoopActive` is `false`, in Node.js it will [unref the polling timeout](https://nodejs.org/api/timers.html#timers_timeout_unref), allowing the process to exit during the polling interval. Defaults to `true`, meaning the process will be kept alive. | ||
- If `usePastBlocks` is `true`, block numbers less than the current block number can used and emitted. Defaults to `false`, meaning that only block numbers greater than the current block number will be used and emitted. | ||
@@ -43,0 +46,0 @@ #### getCurrentBlock() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58105
292782
446
142
5
19
+ Added@ethereumjs/common@3.2.0(transitive)
+ Added@ethereumjs/rlp@4.0.1(transitive)
+ Added@ethereumjs/tx@4.2.0(transitive)
+ Added@ethereumjs/util@8.1.0(transitive)
+ Added@metamask/eth-json-rpc-provider@1.0.1(transitive)
+ Added@metamask/json-rpc-engine@7.3.3(transitive)
+ Added@metamask/rpc-errors@6.4.0(transitive)
+ Added@metamask/superstruct@3.1.0(transitive)
+ Added@metamask/utils@5.0.28.5.09.3.0(transitive)
+ Added@noble/curves@1.4.2(transitive)
+ Added@noble/hashes@1.4.01.5.0(transitive)
+ Added@scure/base@1.1.9(transitive)
+ Added@scure/bip32@1.4.0(transitive)
+ Added@scure/bip39@1.3.0(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedethereum-cryptography@2.2.1(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedmicro-ftch@0.3.1(transitive)
+ Addedpony-cause@2.1.11(transitive)
+ Addeduuid@9.0.1(transitive)
- Removed@metamask/utils@3.6.0(transitive)
Updated@metamask/utils@^5.0.1