Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eth-block-tracker

Package Overview
Dependencies
Maintainers
10
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-block-tracker - npm Package Compare versions

Comparing version 6.1.0 to 7.1.0

CHANGELOG.md

3

dist/BaseBlockTracker.d.ts
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;

15

dist/BaseBlockTracker.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc