@metamask/eth-block-tracker 12.2.1 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -327
- package/README.md +2 -51
- package/dist/{BlockTracker.js → BlockTracker.cjs} +1 -1
- package/dist/BlockTracker.cjs.map +1 -0
- package/dist/{BlockTracker.d.ts → BlockTracker.d.cts} +3 -2
- package/dist/BlockTracker.d.cts.map +1 -0
- package/dist/BlockTracker.d.mts +9 -0
- package/dist/BlockTracker.d.mts.map +1 -0
- package/dist/BlockTracker.mjs +2 -0
- package/dist/BlockTracker.mjs.map +1 -0
- package/dist/{PollingBlockTracker.js → PollingBlockTracker.cjs} +4 -5
- package/dist/PollingBlockTracker.cjs.map +1 -0
- package/dist/{PollingBlockTracker.d.ts → PollingBlockTracker.d.cts} +6 -5
- package/dist/PollingBlockTracker.d.cts.map +1 -0
- package/dist/PollingBlockTracker.d.mts +65 -0
- package/dist/PollingBlockTracker.d.mts.map +1 -0
- package/dist/PollingBlockTracker.mjs +352 -0
- package/dist/PollingBlockTracker.mjs.map +1 -0
- package/dist/{index.js → index.cjs} +2 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/{logging-utils.js → logging-utils.cjs} +1 -1
- package/dist/logging-utils.cjs.map +1 -0
- package/dist/{logging-utils.d.ts → logging-utils.d.cts} +2 -1
- package/dist/logging-utils.d.cts.map +1 -0
- package/dist/logging-utils.d.mts +5 -0
- package/dist/logging-utils.d.mts.map +1 -0
- package/dist/logging-utils.mjs +4 -0
- package/dist/logging-utils.mjs.map +1 -0
- package/package.json +56 -54
- package/dist/BlockTracker.js.map +0 -1
- package/dist/PollingBlockTracker.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/logging-utils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,334 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [
|
|
11
|
-
|
|
12
|
-
### Fixed
|
|
13
|
-
|
|
14
|
-
- `PollingBlockTracker.checkForLatestBlock()` and `getLatestBlock()` now clear the cached block after `blockReset` duration when called and the `PollingBlockTracker` is not polling. ([#348](https://github.com/MetaMask/eth-block-tracker/pull/348))
|
|
15
|
-
|
|
16
|
-
## [12.2.0]
|
|
17
|
-
|
|
18
|
-
### Changed
|
|
19
|
-
|
|
20
|
-
- `PollingBlockTracker.getLatestBlock()` now accepts an optional parameter `useCache` ([#340](https://github.com/MetaMask/eth-block-tracker/pull/340))
|
|
21
|
-
- This option defaults to `true`, but when `false`, it ignores the cached block number and instead updates and returns a new block number, ensuring that the frequency of requests is limited to the `pollingInterval` period
|
|
22
|
-
|
|
23
|
-
## [12.1.0]
|
|
24
|
-
|
|
25
|
-
### Changed
|
|
26
|
-
|
|
27
|
-
- Bump `@metamask/eth-json-rpc-provider` from `^4.1.5` to `^5.0.0` ([#334](https://github.com/MetaMask/eth-block-tracker/pull/334))
|
|
28
|
-
|
|
29
|
-
## [12.0.1]
|
|
30
|
-
|
|
31
|
-
### Fixed
|
|
32
|
-
|
|
33
|
-
- Fixed hanging `getLatestBlock()` promises when block tracker is stopped before request completion ([#320](https://github.com/MetaMask/eth-block-tracker/pull/320))
|
|
34
|
-
- Pending `getLatestBlock()` requests are now properly rejected with "Block tracker destroyed" error when the tracker is stopped
|
|
35
|
-
|
|
36
|
-
## [12.0.0]
|
|
37
|
-
|
|
38
|
-
### Changed
|
|
39
|
-
|
|
40
|
-
- Errors that occur while polling are no longer wrapped ([#310](https://github.com/MetaMask/eth-block-tracker/pull/310))
|
|
41
|
-
|
|
42
|
-
### Removed
|
|
43
|
-
|
|
44
|
-
- **BREAKING:** Remove `SubscribeBlockTracker` ([#309](https://github.com/MetaMask/eth-block-tracker/pull/309))
|
|
45
|
-
- Although we continue to maintain this, we have not used it internally for quite some time. In general we have found a polling-based approval to be reliable than a subscription-based approach. We recommend using `PollingBlockTracker` instead.
|
|
46
|
-
|
|
47
|
-
### Fixed
|
|
48
|
-
|
|
49
|
-
- Fix `PollingBlockTracker.getLatestBlock` so that it throws an error encountered while making the request instead of hanging, regardless of whether the request occurs inside or outside of a polling loop ([#313](https://github.com/MetaMask/eth-block-tracker/pull/313))
|
|
50
|
-
- Fix `PollingBlockTracker.getLatestBlock` so that if invoked while a previous invocation is pending, it will throw if that invocation also throws ([#313](https://github.com/MetaMask/eth-block-tracker/pull/313))
|
|
51
|
-
|
|
52
|
-
## [11.0.4]
|
|
53
|
-
|
|
54
|
-
### Changed
|
|
55
|
-
|
|
56
|
-
- Bump `@metamask/utils` from `^9.1.0` to `^11.0.1` ([#297](https://github.com/MetaMask/eth-block-tracker/pull/297))
|
|
57
|
-
|
|
58
|
-
## [11.0.3]
|
|
59
|
-
|
|
60
|
-
### Fixed
|
|
61
|
-
|
|
62
|
-
- Avoid risk of infinite retry loops when fetching new blocks ([#284](https://github.com/MetaMask/eth-block-tracker/pull/284))
|
|
63
|
-
- When the provider returns an error and `PollingBlockTracker` or `SubscribeBlockTracker` is destroyed, the promise returned by the `getLatestBlock` method will be rejected.
|
|
64
|
-
|
|
65
|
-
## [11.0.2]
|
|
66
|
-
|
|
67
|
-
### Fixed
|
|
68
|
-
|
|
69
|
-
- Bump `@metamask/eth-json-rpc-provider` from `^4.1.1` to `^4.1.5` ([#273](https://github.com/MetaMask/eth-block-tracker/pull/273))
|
|
70
|
-
|
|
71
|
-
## [11.0.1]
|
|
72
|
-
|
|
73
|
-
### Changed
|
|
74
|
-
|
|
75
|
-
- Bump `@metamask/eth-json-rpc-provider` from `^4.1.0` to `^4.1.1` ([#261](https://github.com/MetaMask/eth-block-tracker/pull/261))
|
|
76
|
-
- Bump `@metamask/safe-event-emitter` from `^3.0.0` to `^3.1.1` ([#261](https://github.com/MetaMask/eth-block-tracker/pull/261))
|
|
77
|
-
- Bump `@metamask/utils` from `^8.1.0` to `^9.1.0` ([#261](https://github.com/MetaMask/eth-block-tracker/pull/261))
|
|
78
|
-
|
|
79
|
-
## [11.0.0]
|
|
80
|
-
|
|
81
|
-
### Changed
|
|
82
|
-
|
|
83
|
-
- **BREAKING**: Adapt to EIP-1193 provider changes by using `request` method of provider instead of `sendAsync` ([#252](https://github.com/MetaMask/eth-block-tracker/pull/252))
|
|
84
|
-
- This change included in `10.1.0` was mistakenly categorised as a non-breaking change.
|
|
85
|
-
- This requires provider object to have the `request` method. You need to upgrade to minimum `4.1.0` of `@metamask/eth-json-rpc-provider` so that the `request` method is available.
|
|
86
|
-
|
|
87
|
-
## [10.1.0] [DEPRECATED]
|
|
88
|
-
|
|
89
|
-
### Changed
|
|
90
|
-
|
|
91
|
-
- Adapt to EIP-1193 provider changes ([#252](https://github.com/MetaMask/eth-block-tracker/pull/252))
|
|
92
|
-
- Deprecated `sendAsync` method is replaced with `request` method
|
|
93
|
-
- Bump `@metamask/eth-json-rpc-provider` from `^4.0.0` to `^4.1.0` ([#252](https://github.com/MetaMask/eth-block-tracker/pull/252))
|
|
94
|
-
|
|
95
|
-
## [10.0.0]
|
|
96
|
-
|
|
97
|
-
### Changed
|
|
98
|
-
|
|
99
|
-
- BREAKING: Drop support for Node.js v16; add support for Node.js v20, v22 ([#245](https://github.com/MetaMask/eth-block-tracker/pull/245))
|
|
100
|
-
- Update `@metamask/eth-json-rpc-provider` from `^3.0.2` to `^4.0.0` ([#247](https://github.com/MetaMask/eth-block-tracker/pull/247))
|
|
101
|
-
|
|
102
|
-
## [9.0.3]
|
|
103
|
-
|
|
104
|
-
### Fixed
|
|
105
|
-
|
|
106
|
-
- Update dependency `@metamask/eth-json-rpc-engine` from `^7.1.1` to `^8.0.2` ([#235](https://github.com/MetaMask/eth-block-tracker/pull/235))
|
|
107
|
-
- Update dependency `@metamask/eth-json-rpc-provider` from `^2.3.1` to `^3.0.2` ([#235](https://github.com/MetaMask/eth-block-tracker/pull/235))
|
|
108
|
-
|
|
109
|
-
## [9.0.2]
|
|
110
|
-
|
|
111
|
-
### Fixed
|
|
112
|
-
|
|
113
|
-
- Put back missing empty `params` to `eth_blockNumber` call removed in 9.0.1 ([#198](https://github.com/MetaMask/eth-block-tracker/pull/198))
|
|
114
|
-
|
|
115
|
-
## [9.0.1]
|
|
116
|
-
|
|
117
|
-
### Fixed
|
|
118
|
-
|
|
119
|
-
- Concurrency fix: Prevent multiple simultaneous polling loops ([#208](https://github.com/MetaMask/eth-block-tracker/pull/208))
|
|
120
|
-
- Bump `@metamask/eth-json-rpc-provider` from `^2.1.0` to `^2.3.1` ([#198](https://github.com/MetaMask/eth-block-tracker/pull/198)) ([#217](https://github.com/MetaMask/eth-block-tracker/pull/217))
|
|
121
|
-
|
|
122
|
-
## [9.0.0]
|
|
123
|
-
|
|
124
|
-
### Changed
|
|
125
|
-
|
|
126
|
-
- Rename package from `eth-block-tracker` to `@metamask/eth-block-tracker` ([#183](https://github.com/MetaMask/eth-block-tracker/pull/183))
|
|
127
|
-
|
|
128
|
-
## [8.1.0]
|
|
129
|
-
|
|
130
|
-
### Changed
|
|
131
|
-
|
|
132
|
-
- Typescript: Add `checkForLatestBlock` function to `BlockTracker` interface ([#184](https://github.com/MetaMask/eth-block-tracker/pull/184))
|
|
133
|
-
|
|
134
|
-
## [8.0.0]
|
|
135
|
-
|
|
136
|
-
### Changed
|
|
137
|
-
|
|
138
|
-
- Bump @metamask/utils from ^5.0.2 to ^8.1.0 ([#178](https://github.com/MetaMask/eth-block-tracker/pull/178))
|
|
139
|
-
- **BREAKING**: Bump @metamask/eth-json-rpc-provider from ^1.0.0 to ^2.1.0 ([#174](https://github.com/MetaMask/eth-block-tracker/pull/174))
|
|
140
|
-
- **BREAKING**: Increase minimum Node.js version to 16 ([#173](https://github.com/MetaMask/eth-block-tracker/pull/173))
|
|
141
|
-
|
|
142
|
-
## [7.2.0]
|
|
143
|
-
|
|
144
|
-
### Added
|
|
145
|
-
|
|
146
|
-
- Typescript: Export `BlockTracker` interface ([#168](https://github.com/MetaMask/eth-block-tracker/pull/168))
|
|
147
|
-
|
|
148
|
-
### Changed
|
|
149
|
-
|
|
150
|
-
- Dependency Updates: ([#165](https://github.com/MetaMask/eth-block-tracker/pull/165))
|
|
151
|
-
- Bump pify from ^3.0.0 to ^5.0.0
|
|
152
|
-
- Bump @metamask/utils from ^5.0.1 to ^5.0.2
|
|
153
|
-
|
|
154
|
-
## [7.1.0]
|
|
155
|
-
|
|
156
|
-
### Added
|
|
157
|
-
|
|
158
|
-
- Add `usePastBlocks` to constructor ([#151](https://github.com/MetaMask/eth-block-tracker/pull/151))
|
|
159
|
-
- Optional flag. When set to true, it allows blocks less than the current block number to be cached and returned.
|
|
160
|
-
|
|
161
|
-
## [7.0.1]
|
|
162
|
-
|
|
163
|
-
### Changed
|
|
164
|
-
|
|
165
|
-
- Dependency updates:
|
|
166
|
-
- Bump @metamask/utils from 5.0.1 to 5.0.2
|
|
167
|
-
- [#141](https://github.com/MetaMask/eth-block-tracker/pull/141)
|
|
168
|
-
- [#144](https://github.com/MetaMask/eth-block-tracker/pull/144)
|
|
169
|
-
- Bump @metamask/safe-event-emitter from 2.0.0 to 3.0.0 ([#143](https://github.com/MetaMask/eth-block-tracker/pull/143))
|
|
170
|
-
|
|
171
|
-
## [7.0.0]
|
|
172
|
-
|
|
173
|
-
### Changed
|
|
174
|
-
|
|
175
|
-
- **BREAKING:** The type of the `provider` option for `PollingBlockTracker` and `SubscribeBlockTracker` has changed ([#130](https://github.com/MetaMask/eth-block-tracker/pull/130))
|
|
176
|
-
- The `provider` option must be compatible with the `SafeEventEmitterProvider` type from `@metamask/eth-json-rpc-middleware`.
|
|
177
|
-
- The new provider type should be mostly equivalent, except that it's now expected to have a `send` method. We don't use that `send` method in this package though.
|
|
178
|
-
|
|
179
|
-
### Removed
|
|
180
|
-
|
|
181
|
-
- **BREAKING:** Remove the `Provider` exported type ([#130](https://github.com/MetaMask/eth-block-tracker/pull/130))
|
|
182
|
-
- We now use `@metamask/eth-json-rpc-provider` for this instead, so there was no need to re-export it.
|
|
183
|
-
|
|
184
|
-
## [6.1.0]
|
|
185
|
-
|
|
186
|
-
### Added
|
|
187
|
-
|
|
188
|
-
- Add back Provider type that was accidentally removed in 6.0.0 ([#117](https://github.com/MetaMask/eth-block-tracker/pull/117))
|
|
189
|
-
|
|
190
|
-
### Fixed
|
|
191
|
-
|
|
192
|
-
- Align Provider type with `eth-json-rpc-middleware` to prevent typecasting ([#117](https://github.com/MetaMask/eth-block-tracker/pull/117))
|
|
193
|
-
|
|
194
|
-
## [6.0.0]
|
|
195
|
-
|
|
196
|
-
### Added
|
|
197
|
-
|
|
198
|
-
- Add logging ([#112](https://github.com/MetaMask/eth-block-tracker/pull/112))
|
|
199
|
-
- You will not be able to see log messages by default, but you can turn them on for this library by setting the `DEBUG` environment variable to `metamask:eth-block-tracker:*` or `metamask:*`.
|
|
200
|
-
- Add `destroy` method to block tracker classes ([#106](https://github.com/MetaMask/eth-block-tracker/pull/106))
|
|
201
|
-
- Update PollingBlockTracker to support new `blockResetDuration` option ([#103](https://github.com/MetaMask/eth-block-tracker/pull/103))
|
|
202
|
-
- Expose types that represent options to PollingBlockTracker and SubscribeBlockTracker constructors ([#103](https://github.com/MetaMask/eth-block-tracker/pull/103))
|
|
10
|
+
## [14.0.0]
|
|
203
11
|
|
|
204
12
|
### Changed
|
|
205
13
|
|
|
206
|
-
- **BREAKING:**
|
|
207
|
-
-
|
|
208
|
-
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
- Make argument to `removeAllListeners` in BaseBlockTracker optional ([#103](https://github.com/MetaMask/eth-block-tracker/pull/103))
|
|
212
|
-
- **BREAKING:** Update signatures for `_start` and `_end` in BaseBlockTracker ([#103](https://github.com/MetaMask/eth-block-tracker/pull/103))
|
|
213
|
-
- Subclasses must provide an implementation for both of these methods; they are no longer no-ops.
|
|
214
|
-
- Both methods must return a promise.
|
|
215
|
-
- Update SubscribeBlockTracker to not pass empty `newHeads` parameter to `eth_subscribe` call ([#108](https://github.com/MetaMask/eth-block-tracker/pull/108))
|
|
216
|
-
- This change was made because OpenEthereum does not support this parameter. While we've done our best to confirm that this will not be a breaking change for other Ethereum implementations, you will want to confirm no breakages for yours.
|
|
217
|
-
|
|
218
|
-
### Security
|
|
219
|
-
|
|
220
|
-
- Add `@lavamoat/allow-scripts` to ensure that install scripts are opt-in for dependencies ([#97](https://github.com/MetaMask/eth-block-tracker/pull/97))
|
|
221
|
-
|
|
222
|
-
## [5.0.1] - 2021-03-25
|
|
223
|
-
|
|
224
|
-
### Fixed
|
|
225
|
-
|
|
226
|
-
- Add missing `types` field to `package.json` ([#75](https://github.com/MetaMask/eth-block-tracker/pull/75))
|
|
227
|
-
|
|
228
|
-
## [5.0.0] - 2021-03-25
|
|
229
|
-
|
|
230
|
-
### Changed
|
|
231
|
-
|
|
232
|
-
- **(BREAKING)** Refactor exports ([#71](https://github.com/MetaMask/eth-block-tracker/pull/71))
|
|
233
|
-
- **(BREAKING)** Target ES2017, remove ES5 builds ([#71](https://github.com/MetaMask/eth-block-tracker/pull/71))
|
|
234
|
-
- Migrate to TypeScript ([#71](https://github.com/MetaMask/eth-block-tracker/pull/71))
|
|
235
|
-
- Update various dependencies ([#44](https://github.com/MetaMask/eth-block-tracker/pull/44), [#49](https://github.com/MetaMask/eth-block-tracker/pull/49), [#54](https://github.com/MetaMask/eth-block-tracker/pull/54), [#59](https://github.com/MetaMask/eth-block-tracker/pull/59), [#61](https://github.com/MetaMask/eth-block-tracker/pull/61), [#62](https://github.com/MetaMask/eth-block-tracker/pull/62), [#63](https://github.com/MetaMask/eth-block-tracker/pull/63), [#70](https://github.com/MetaMask/eth-block-tracker/pull/70), [#72](https://github.com/MetaMask/eth-block-tracker/pull/72))
|
|
236
|
-
|
|
237
|
-
### Removed
|
|
238
|
-
|
|
239
|
-
- Remove unused production dependencies ([#60](https://github.com/MetaMask/eth-block-tracker/pull/60), [#68](https://github.com/MetaMask/eth-block-tracker/pull/68))
|
|
240
|
-
|
|
241
|
-
## [4.4.3] - 2019-08-30
|
|
242
|
-
|
|
243
|
-
### Added
|
|
244
|
-
|
|
245
|
-
- Add SubscribeBlockTracker
|
|
246
|
-
|
|
247
|
-
### Changed
|
|
248
|
-
|
|
249
|
-
- Change events so that they now only return the block number (internal polling is done via `eth_blockNumber`)
|
|
250
|
-
- Add `retryTimeout` and `keepEventLoopActive` to constructor
|
|
251
|
-
- Update block trackers to inherit from `safe-event-emitter` rather than EventEmitter
|
|
252
|
-
|
|
253
|
-
### Removed
|
|
254
|
-
|
|
255
|
-
- Remove `block` event
|
|
256
|
-
- Please use `latest` or `sync`.
|
|
257
|
-
|
|
258
|
-
## [4.0.0] - 2018-04-26
|
|
259
|
-
|
|
260
|
-
### Added
|
|
261
|
-
|
|
262
|
-
- Add isRunning method
|
|
263
|
-
- Add `error` event
|
|
264
|
-
|
|
265
|
-
### Changed
|
|
266
|
-
|
|
267
|
-
- Significantly rewrite `eth-block-tracker` (primarily due to optimizing network IO)
|
|
268
|
-
- Rename `awaitCurrentBlock` to `getLatestBlock`
|
|
269
|
-
|
|
270
|
-
### Removed
|
|
271
|
-
|
|
272
|
-
- Remove `stop`/`start` methods from BlockTrackers
|
|
273
|
-
- BlockTrackers now automatically start and stop based on listener count for the `latest` and `sync` events. You can force a stop by calling the `EventEmitter` method `removeAllListeners`.
|
|
274
|
-
- Remove tx body from block
|
|
275
|
-
- Remove getTrackingBlock
|
|
276
|
-
- Remove start/stop
|
|
277
|
-
- Remove test/util/testBlockMiddleware
|
|
278
|
-
|
|
279
|
-
## [3.0.0] - 2018-04-16
|
|
280
|
-
|
|
281
|
-
### Changed
|
|
282
|
-
|
|
283
|
-
- Update published version so main module now exports unprocessed source
|
|
284
|
-
- Module includes dist:
|
|
285
|
-
- Bundle: `dist/EthBlockTracker.js`
|
|
286
|
-
- ES5 source: `dist/es5/`
|
|
287
|
-
- Rename `lib` to `src`
|
|
288
|
-
- Update RpcBlockTracker to be a normal `EventEmitter`
|
|
289
|
-
- It no longer provides a callback to event handlers.
|
|
290
|
-
|
|
291
|
-
### Fixed
|
|
292
|
-
|
|
293
|
-
- Fix `awaitCurrentBlock` return value
|
|
294
|
-
|
|
295
|
-
## [2.0.0] - 2017-06-14
|
|
296
|
-
|
|
297
|
-
### Added
|
|
298
|
-
|
|
299
|
-
- Expose EventEmitter interface (via `async-eventemitter`)
|
|
300
|
-
- Add `getTrackingBlock`, `getCurrentBlock`, `start`, and `stop`
|
|
301
|
-
- Add events: `block`, `latest`, `sync`
|
|
302
|
-
|
|
303
|
-
## [1.0.0] - 2017-02-03
|
|
304
|
-
|
|
305
|
-
### Added
|
|
306
|
-
|
|
307
|
-
- Add RpcBlockTracker
|
|
14
|
+
- **BREAKING:** Update minimum Node.js version from `^18.16.0` to `^18.18.0` ([#6865](https://github.com/MetaMask/core/pull/6865))
|
|
15
|
+
- This package was migrated from `MetaMask/eth-block-tracker` to the
|
|
16
|
+
`MetaMask/core` monorepo ([#6865](https://github.com/MetaMask/core/pull/6865))
|
|
17
|
+
- See [`MetaMask/eth-block-tracker`](https://github.com/MetaMask/eth-block-tracker/blob/main/CHANGELOG.md)
|
|
18
|
+
for the original changelog.
|
|
308
19
|
|
|
309
|
-
[Unreleased]: https://github.com/MetaMask/eth-block-tracker
|
|
310
|
-
[
|
|
311
|
-
[12.2.0]: https://github.com/MetaMask/eth-block-tracker/compare/v12.1.0...v12.2.0
|
|
312
|
-
[12.1.0]: https://github.com/MetaMask/eth-block-tracker/compare/v12.0.1...v12.1.0
|
|
313
|
-
[12.0.1]: https://github.com/MetaMask/eth-block-tracker/compare/v12.0.0...v12.0.1
|
|
314
|
-
[12.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v11.0.4...v12.0.0
|
|
315
|
-
[11.0.4]: https://github.com/MetaMask/eth-block-tracker/compare/v11.0.3...v11.0.4
|
|
316
|
-
[11.0.3]: https://github.com/MetaMask/eth-block-tracker/compare/v11.0.2...v11.0.3
|
|
317
|
-
[11.0.2]: https://github.com/MetaMask/eth-block-tracker/compare/v11.0.1...v11.0.2
|
|
318
|
-
[11.0.1]: https://github.com/MetaMask/eth-block-tracker/compare/v11.0.0...v11.0.1
|
|
319
|
-
[11.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v10.1.0...v11.0.0
|
|
320
|
-
[10.1.0]: https://github.com/MetaMask/eth-block-tracker/compare/v10.0.0...v10.1.0
|
|
321
|
-
[10.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v9.0.3...v10.0.0
|
|
322
|
-
[9.0.3]: https://github.com/MetaMask/eth-block-tracker/compare/v9.0.2...v9.0.3
|
|
323
|
-
[9.0.2]: https://github.com/MetaMask/eth-block-tracker/compare/v9.0.1...v9.0.2
|
|
324
|
-
[9.0.1]: https://github.com/MetaMask/eth-block-tracker/compare/v9.0.0...v9.0.1
|
|
325
|
-
[9.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v8.1.0...v9.0.0
|
|
326
|
-
[8.1.0]: https://github.com/MetaMask/eth-block-tracker/compare/v8.0.0...v8.1.0
|
|
327
|
-
[8.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v7.2.0...v8.0.0
|
|
328
|
-
[7.2.0]: https://github.com/MetaMask/eth-block-tracker/compare/v7.1.0...v7.2.0
|
|
329
|
-
[7.1.0]: https://github.com/MetaMask/eth-block-tracker/compare/v7.0.1...v7.1.0
|
|
330
|
-
[7.0.1]: https://github.com/MetaMask/eth-block-tracker/compare/v7.0.0...v7.0.1
|
|
331
|
-
[7.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v6.1.0...v7.0.0
|
|
332
|
-
[6.1.0]: https://github.com/MetaMask/eth-block-tracker/compare/v6.0.0...v6.1.0
|
|
333
|
-
[6.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v5.0.1...v6.0.0
|
|
334
|
-
[5.0.1]: https://github.com/MetaMask/eth-block-tracker/compare/v5.0.0...v5.0.1
|
|
335
|
-
[5.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v4.4.3...v5.0.0
|
|
336
|
-
[4.4.3]: https://github.com/MetaMask/eth-block-tracker/compare/v4.0.0...v4.4.3
|
|
337
|
-
[4.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v3.0.0...v4.0.0
|
|
338
|
-
[3.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v2.0.0...v3.0.0
|
|
339
|
-
[2.0.0]: https://github.com/MetaMask/eth-block-tracker/compare/v1.0.0...v2.0.0
|
|
340
|
-
[1.0.0]: https://github.com/MetaMask/eth-block-tracker/releases/tag/v1.0.0
|
|
20
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/eth-block-tracker@14.0.0...HEAD
|
|
21
|
+
[14.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/eth-block-tracker@14.0.0
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@metamask/eth-block-tracker`
|
|
2
2
|
|
|
3
3
|
This module walks the Ethereum blockchain, keeping track of the latest block. It uses a web3 provider as a data source and will continuously poll for the next block.
|
|
4
4
|
|
|
@@ -88,53 +88,4 @@ blockTracker.on('error', (err) => console.error(err));
|
|
|
88
88
|
|
|
89
89
|
## Contributing
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- Install the current LTS version of [Node.js](https://nodejs.org)
|
|
94
|
-
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm install` will install the latest version and running `nvm use` will automatically choose the right node version for you.
|
|
95
|
-
- Install [Yarn](https://yarnpkg.com) v4 via [Corepack](https://github.com/nodejs/corepack?tab=readme-ov-file#how-to-install)
|
|
96
|
-
- Run `yarn install` to install dependencies and run any required post-install scripts
|
|
97
|
-
|
|
98
|
-
### Testing and Linting
|
|
99
|
-
|
|
100
|
-
Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
|
|
101
|
-
|
|
102
|
-
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
|
|
103
|
-
|
|
104
|
-
### Release & Publishing
|
|
105
|
-
|
|
106
|
-
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
|
|
107
|
-
|
|
108
|
-
1. Choose a release version.
|
|
109
|
-
|
|
110
|
-
- The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
|
|
111
|
-
|
|
112
|
-
2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
|
|
113
|
-
|
|
114
|
-
- The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
|
|
115
|
-
|
|
116
|
-
3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
|
|
117
|
-
|
|
118
|
-
- For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
|
|
119
|
-
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
|
|
120
|
-
|
|
121
|
-
4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
|
|
122
|
-
|
|
123
|
-
- Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
|
|
124
|
-
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
|
|
125
|
-
- Consolidate related changes into one change entry if it makes it easier to explain.
|
|
126
|
-
- Run `yarn auto-changelog validate --rc --prettier` to check that the changelog is correctly formatted.
|
|
127
|
-
|
|
128
|
-
5. Review and QA the release.
|
|
129
|
-
|
|
130
|
-
- If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
|
|
131
|
-
|
|
132
|
-
6. Squash & Merge the release.
|
|
133
|
-
|
|
134
|
-
- This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
|
|
135
|
-
|
|
136
|
-
7. Publish the release on npm.
|
|
137
|
-
|
|
138
|
-
- Be very careful to use a clean local environment to publish the release, and follow exactly the same steps used during CI.
|
|
139
|
-
- Use `npm publish --dry-run` to examine the release contents to ensure the correct files are included. Compare to previous releases if necessary (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`).
|
|
140
|
-
- Once you are confident the release contents are correct, publish the release using `npm publish`.
|
|
91
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTracker.cjs","sourceRoot":"","sources":["../src/BlockTracker.ts"],"names":[],"mappings":"","sourcesContent":["import type SafeEventEmitter from '@metamask/safe-event-emitter';\n\nexport type BlockTracker = SafeEventEmitter & {\n destroy(): Promise<void>;\n\n isRunning(): boolean;\n\n getCurrentBlock(): string | null;\n\n getLatestBlock(): Promise<string>;\n\n checkForLatestBlock(): Promise<string>;\n};\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type SafeEventEmitter from
|
|
2
|
-
export
|
|
1
|
+
import type SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
2
|
+
export type BlockTracker = SafeEventEmitter & {
|
|
3
3
|
destroy(): Promise<void>;
|
|
4
4
|
isRunning(): boolean;
|
|
5
5
|
getCurrentBlock(): string | null;
|
|
6
6
|
getLatestBlock(): Promise<string>;
|
|
7
7
|
checkForLatestBlock(): Promise<string>;
|
|
8
8
|
};
|
|
9
|
+
//# sourceMappingURL=BlockTracker.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTracker.d.cts","sourceRoot":"","sources":["../src/BlockTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,qCAAqC;AAEjE,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,SAAS,IAAI,OAAO,CAAC;IAErB,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IAEjC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAElC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
2
|
+
export type BlockTracker = SafeEventEmitter & {
|
|
3
|
+
destroy(): Promise<void>;
|
|
4
|
+
isRunning(): boolean;
|
|
5
|
+
getCurrentBlock(): string | null;
|
|
6
|
+
getLatestBlock(): Promise<string>;
|
|
7
|
+
checkForLatestBlock(): Promise<string>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=BlockTracker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTracker.d.mts","sourceRoot":"","sources":["../src/BlockTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,qCAAqC;AAEjE,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,SAAS,IAAI,OAAO,CAAC;IAErB,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IAEjC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAElC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTracker.mjs","sourceRoot":"","sources":["../src/BlockTracker.ts"],"names":[],"mappings":"","sourcesContent":["import type SafeEventEmitter from '@metamask/safe-event-emitter';\n\nexport type BlockTracker = SafeEventEmitter & {\n destroy(): Promise<void>;\n\n isRunning(): boolean;\n\n getCurrentBlock(): string | null;\n\n getLatestBlock(): Promise<string>;\n\n checkForLatestBlock(): Promise<string>;\n};\n"]}
|
|
@@ -19,7 +19,7 @@ exports.PollingBlockTracker = void 0;
|
|
|
19
19
|
const safe_event_emitter_1 = __importDefault(require("@metamask/safe-event-emitter"));
|
|
20
20
|
const utils_1 = require("@metamask/utils");
|
|
21
21
|
const json_rpc_random_id_1 = __importDefault(require("json-rpc-random-id"));
|
|
22
|
-
const logging_utils_1 = require("./logging-utils");
|
|
22
|
+
const logging_utils_1 = require("./logging-utils.cjs");
|
|
23
23
|
const log = (0, logging_utils_1.createModuleLogger)(logging_utils_1.projectLogger, 'polling-block-tracker');
|
|
24
24
|
const createRandomId = (0, json_rpc_random_id_1.default)();
|
|
25
25
|
const sec = 1000;
|
|
@@ -303,7 +303,7 @@ class PollingBlockTracker extends safe_event_emitter_1.default {
|
|
|
303
303
|
try {
|
|
304
304
|
this.emit('error', error);
|
|
305
305
|
}
|
|
306
|
-
catch
|
|
306
|
+
catch {
|
|
307
307
|
console.error(`Error updating latest block: ${(0, utils_1.getErrorMessage)(error)}`);
|
|
308
308
|
}
|
|
309
309
|
interval = this._retryTimeout;
|
|
@@ -336,8 +336,7 @@ _PollingBlockTracker_internalEventListeners = new WeakMap(), _PollingBlockTracke
|
|
|
336
336
|
}, _PollingBlockTracker_removeInternalListener = function _PollingBlockTracker_removeInternalListener(listener) {
|
|
337
337
|
__classPrivateFieldGet(this, _PollingBlockTracker_internalEventListeners, "f").splice(__classPrivateFieldGet(this, _PollingBlockTracker_internalEventListeners, "f").indexOf(listener), 1);
|
|
338
338
|
}, _PollingBlockTracker_rejectPendingLatestBlock = function _PollingBlockTracker_rejectPendingLatestBlock(error) {
|
|
339
|
-
|
|
340
|
-
(_a = __classPrivateFieldGet(this, _PollingBlockTracker_pendingLatestBlock, "f")) === null || _a === void 0 ? void 0 : _a.reject(error);
|
|
339
|
+
__classPrivateFieldGet(this, _PollingBlockTracker_pendingLatestBlock, "f")?.reject(error);
|
|
341
340
|
__classPrivateFieldSet(this, _PollingBlockTracker_pendingLatestBlock, undefined, "f");
|
|
342
341
|
};
|
|
343
342
|
/**
|
|
@@ -350,4 +349,4 @@ _PollingBlockTracker_internalEventListeners = new WeakMap(), _PollingBlockTracke
|
|
|
350
349
|
function hexToInt(hexInt) {
|
|
351
350
|
return Number.parseInt(hexInt, 16);
|
|
352
351
|
}
|
|
353
|
-
//# sourceMappingURL=PollingBlockTracker.
|
|
352
|
+
//# sourceMappingURL=PollingBlockTracker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PollingBlockTracker.cjs","sourceRoot":"","sources":["../src/PollingBlockTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,sFAA4D;AAC5D,2CAKyB;AACzB,4EAAmD;AAGnD,uDAAoE;AAEpE,MAAM,GAAG,GAAG,IAAA,kCAAkB,EAAC,6BAAa,EAAE,uBAAuB,CAAC,CAAC;AACvE,MAAM,cAAc,GAAG,IAAA,4BAAiB,GAAE,CAAC;AAC3C,MAAM,GAAG,GAAG,IAAI,CAAC;AAEjB,MAAM,kBAAkB,GAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAkBnE,MAAa,mBACX,SAAQ,4BAAgB;IA+BxB,YAAY,OAAmC,E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E;YACpB,OAAO;SACR;QAED,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE;YACjC,qEAAqE;YACrE,mEAAmE;YACnE,IAAI,CAAC,eAAe,EAAE,CAAC;QACzB,CAAC,EAAE,QAAQ,CAAC,CAAC;QAEb,IAAI,UAAU,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;YAClD,UAAU,CAAC,KAAK,EAAE,CAAC;SACpB;QAED,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC;QAElC,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxC,CAAC;IAED,oBAAoB;QAClB,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACnC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;SAClC;IACH,CAAC;CAiBF;AApZD,kDAoZC;sTAfsB,QAA0B;IAC7C,uBAAA,IAAI,mDAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC,qGAEuB,QAA0B;IAChD,uBAAA,IAAI,mDAAwB,CAAC,MAAM,CACjC,uBAAA,IAAI,mDAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC9C,CAAC,CACF,CAAC;AACJ,CAAC,yGAEyB,KAAc;IACtC,uBAAA,IAAI,+CAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,uBAAA,IAAI,2CAAuB,SAAS,MAAA,CAAC;AACvC,CAAC;AAGH;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport {\n createDeferredPromise,\n type DeferredPromise,\n getErrorMessage,\n type JsonRpcRequest,\n} from '@metamask/utils';\nimport getCreateRandomId from 'json-rpc-random-id';\n\nimport type { BlockTracker } from './BlockTracker';\nimport { projectLogger, createModuleLogger } from './logging-utils';\n\nconst log = createModuleLogger(projectLogger, 'polling-block-tracker');\nconst createRandomId = getCreateRandomId();\nconst sec = 1000;\n\nconst blockTrackerEvents: (string | symbol)[] = ['sync', 'latest'];\n\nexport type PollingBlockTrackerOptions = {\n provider?: SafeEventEmitterProvider;\n pollingInterval?: number;\n retryTimeout?: number;\n keepEventLoopActive?: boolean;\n setSkipCacheFlag?: boolean;\n blockResetDuration?: number;\n usePastBlocks?: boolean;\n};\n\ntype ExtendedJsonRpcRequest = {\n skipCache?: boolean;\n} & JsonRpcRequest<[]>;\n\ntype InternalListener = (value: string) => void;\n\nexport class PollingBlockTracker\n extends SafeEventEmitter\n implements BlockTracker\n{\n private _isRunning: boolean;\n\n private readonly _blockResetDuration: number;\n\n private readonly _usePastBlocks: boolean;\n\n private _currentBlock: string | null;\n\n private _blockResetTimeout?: ReturnType<typeof setTimeout>;\n\n private _pollingTimeout?: ReturnType<typeof setTimeout>;\n\n private readonly _provider: SafeEventEmitterProvider;\n\n private readonly _pollingInterval: number;\n\n private readonly _retryTimeout: number;\n\n private readonly _keepEventLoopActive: boolean;\n\n private readonly _setSkipCacheFlag: boolean;\n\n readonly #internalEventListeners: InternalListener[] = [];\n\n #pendingLatestBlock?: Omit<DeferredPromise<string>, 'resolve'>;\n\n #pendingFetch?: Omit<DeferredPromise<string>, 'resolve'>;\n\n constructor(opts: PollingBlockTrackerOptions = {}) {\n // parse + validate args\n if (!opts.provider) {\n throw new Error('PollingBlockTracker - no provider specified.');\n }\n\n super();\n\n // config\n this._blockResetDuration = opts.blockResetDuration || 20 * sec;\n this._usePastBlocks = opts.usePastBlocks || false;\n // state\n this._currentBlock = null;\n this._isRunning = false;\n\n // bind functions for internal use\n this._onNewListener = this._onNewListener.bind(this);\n this._onRemoveListener = this._onRemoveListener.bind(this);\n this._resetCurrentBlock = this._resetCurrentBlock.bind(this);\n\n // listen for handler changes\n this._setupInternalEvents();\n\n // config\n this._provider = opts.provider;\n this._pollingInterval = opts.pollingInterval || 20 * sec;\n this._retryTimeout = opts.retryTimeout || this._pollingInterval / 10;\n this._keepEventLoopActive =\n opts.keepEventLoopActive === undefined ? true : opts.keepEventLoopActive;\n this._setSkipCacheFlag = opts.setSkipCacheFlag || false;\n }\n\n async destroy() {\n this._cancelBlockResetTimeout();\n super.removeAllListeners();\n this._maybeEnd();\n }\n\n isRunning(): boolean {\n return this._isRunning;\n }\n\n getCurrentBlock(): string | null {\n return this._currentBlock;\n }\n\n async getLatestBlock({\n useCache = true,\n }: { useCache?: boolean } = {}): Promise<string> {\n // return if available\n if (this._currentBlock && useCache) {\n return this._currentBlock;\n }\n\n if (this.#pendingLatestBlock) {\n return await this.#pendingLatestBlock.promise;\n }\n\n const { promise, resolve, reject } = createDeferredPromise<string>({\n suppressUnhandledRejection: true,\n });\n this.#pendingLatestBlock = { reject, promise };\n\n if (this._isRunning) {\n try {\n // If tracker is running, wait for next block with timeout\n const onLatestBlock = (value: string) => {\n this.#removeInternalListener(onLatestBlock);\n this.removeListener('latest', onLatestBlock);\n resolve(value);\n };\n\n this.#addInternalListener(onLatestBlock);\n this.once('latest', onLatestBlock);\n\n return await promise;\n } catch (error) {\n reject(error);\n throw error;\n } finally {\n this.#pendingLatestBlock = undefined;\n }\n } else {\n // If tracker isn't running, just fetch directly\n try {\n const latestBlock = await this._updateLatestBlock();\n resolve(latestBlock);\n return latestBlock;\n } catch (error) {\n reject(error);\n throw error;\n } finally {\n // We want to rate limit calls to this method if we made a direct fetch\n // for the block number because the BlockTracker was not running. We\n // achieve this by delaying the unsetting of the #pendingLatestBlock promise.\n setTimeout(() => {\n this.#pendingLatestBlock = undefined;\n }, this._pollingInterval);\n }\n }\n }\n\n // dont allow module consumer to remove our internal event listeners\n removeAllListeners(eventName?: string | symbol) {\n // perform default behavior, preserve fn arity\n if (eventName) {\n super.removeAllListeners(eventName);\n } else {\n super.removeAllListeners();\n }\n\n // re-add internal events\n this._setupInternalEvents();\n // trigger stop check just in case\n this._onRemoveListener();\n\n return this;\n }\n\n private _setupInternalEvents(): void {\n // first remove listeners for idempotence\n this.removeListener('newListener', this._onNewListener);\n this.removeListener('removeListener', this._onRemoveListener);\n // then add them\n this.on('newListener', this._onNewListener);\n this.on('removeListener', this._onRemoveListener);\n }\n\n private _onNewListener(eventName: string | symbol): void {\n // `newListener` is called *before* the listener is added\n if (blockTrackerEvents.includes(eventName)) {\n // TODO: Handle dangling promise\n this._maybeStart();\n }\n }\n\n private _onRemoveListener(): void {\n // `removeListener` is called *after* the listener is removed\n if (this._getBlockTrackerEventCount() > 0) {\n return;\n }\n this._maybeEnd();\n }\n\n private _maybeStart() {\n if (this._isRunning) {\n return;\n }\n\n this._isRunning = true;\n // cancel setting latest block to stale\n this._cancelBlockResetTimeout();\n this._start();\n this.emit('_started');\n }\n\n private _maybeEnd() {\n if (!this._isRunning) {\n return;\n }\n\n this._isRunning = false;\n this._setupBlockResetTimeout();\n this._end();\n this.#rejectPendingLatestBlock(new Error('Block tracker destroyed'));\n this.emit('_ended');\n }\n\n private _getBlockTrackerEventCount(): number {\n return (\n blockTrackerEvents\n .map((eventName) => this.listeners(eventName))\n .flat()\n // internal listeners are not included in the count\n .filter((listener) =>\n this.#internalEventListeners.every(\n (internalListener) => !Object.is(internalListener, listener),\n ),\n ).length\n );\n }\n\n private _shouldUseNewBlock(newBlock: string) {\n const currentBlock = this._currentBlock;\n if (!currentBlock) {\n return true;\n }\n const newBlockInt = hexToInt(newBlock);\n const currentBlockInt = hexToInt(currentBlock);\n\n return (\n (this._usePastBlocks && newBlockInt < currentBlockInt) ||\n newBlockInt > currentBlockInt\n );\n }\n\n private _newPotentialLatest(newBlock: string): void {\n if (!this._shouldUseNewBlock(newBlock)) {\n return;\n }\n this._setCurrentBlock(newBlock);\n }\n\n private _setCurrentBlock(newBlock: string): void {\n const oldBlock = this._currentBlock;\n this._currentBlock = newBlock;\n this.emit('latest', newBlock);\n this.emit('sync', { oldBlock, newBlock });\n }\n\n private _setupBlockResetTimeout(): void {\n // clear any existing timeout\n this._cancelBlockResetTimeout();\n // clear latest block when stale\n this._blockResetTimeout = setTimeout(\n this._resetCurrentBlock,\n this._blockResetDuration,\n );\n\n // nodejs - dont hold process open\n if (this._blockResetTimeout.unref) {\n this._blockResetTimeout.unref();\n }\n }\n\n private _cancelBlockResetTimeout(): void {\n if (this._blockResetTimeout) {\n clearTimeout(this._blockResetTimeout);\n }\n }\n\n private _resetCurrentBlock(): void {\n this._currentBlock = null;\n }\n\n /**\n * Checks for the latest block, updates the internal state, and returns the\n * value immediately rather than waiting for the next polling interval.\n *\n * @deprecated Use {@link getLatestBlock} instead.\n * @returns A promise that resolves to the latest block number.\n */\n async checkForLatestBlock() {\n await this._updateLatestBlock();\n return await this.getLatestBlock();\n }\n\n private _start() {\n // Intentionally not awaited as this starts the polling via a timeout chain.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._updateAndQueue();\n }\n\n private _end() {\n this._clearPollingTimeout();\n }\n\n private async _updateLatestBlock(): Promise<string> {\n // fetch + set latest block\n const latestBlock = await this._fetchLatestBlock();\n this._newPotentialLatest(latestBlock);\n\n if (!this._isRunning) {\n // Ensure the one-time update is eventually reset once it's stale\n this._setupBlockResetTimeout();\n }\n\n // _newPotentialLatest() ensures that this._currentBlock is not null\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this._currentBlock!;\n }\n\n private async _fetchLatestBlock(): Promise<string> {\n // If there's already a pending fetch, reuse it\n if (this.#pendingFetch) {\n return await this.#pendingFetch.promise;\n }\n\n // Create a new deferred promise for this request\n const { promise, resolve, reject } = createDeferredPromise<string>({\n suppressUnhandledRejection: true,\n });\n this.#pendingFetch = { reject, promise };\n\n try {\n const req: ExtendedJsonRpcRequest = {\n jsonrpc: '2.0',\n id: createRandomId(),\n method: 'eth_blockNumber',\n params: [] as [],\n };\n if (this._setSkipCacheFlag) {\n req.skipCache = true;\n }\n\n log('Making request', req);\n const result = await this._provider.request<[], string>(req);\n log('Got result', result);\n resolve(result);\n return result;\n } catch (error) {\n log('Encountered error fetching block', getErrorMessage(error));\n reject(error);\n this.#rejectPendingLatestBlock(error);\n throw error;\n } finally {\n this.#pendingFetch = undefined;\n }\n }\n\n /**\n * The core polling function that runs after each interval.\n * Updates the latest block and then queues the next update.\n */\n private async _updateAndQueue() {\n let interval = this._pollingInterval;\n\n try {\n await this._updateLatestBlock();\n } catch (error: unknown) {\n try {\n this.emit('error', error);\n } catch {\n console.error(`Error updating latest block: ${getErrorMessage(error)}`);\n }\n\n interval = this._retryTimeout;\n }\n\n if (!this._isRunning) {\n return;\n }\n\n this._clearPollingTimeout();\n\n const timeoutRef = setTimeout(() => {\n // Intentionally not awaited as this just continues the polling loop.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._updateAndQueue();\n }, interval);\n\n if (timeoutRef.unref && !this._keepEventLoopActive) {\n timeoutRef.unref();\n }\n\n this._pollingTimeout = timeoutRef;\n\n this.emit('_waitingForNextIteration');\n }\n\n _clearPollingTimeout() {\n if (this._pollingTimeout) {\n clearTimeout(this._pollingTimeout);\n this._pollingTimeout = undefined;\n }\n }\n\n #addInternalListener(listener: InternalListener) {\n this.#internalEventListeners.push(listener);\n }\n\n #removeInternalListener(listener: InternalListener) {\n this.#internalEventListeners.splice(\n this.#internalEventListeners.indexOf(listener),\n 1,\n );\n }\n\n #rejectPendingLatestBlock(error: unknown) {\n this.#pendingLatestBlock?.reject(error);\n this.#pendingLatestBlock = undefined;\n }\n}\n\n/**\n * Converts a number represented as a string in hexadecimal format into a native\n * number.\n *\n * @param hexInt - The hex string.\n * @returns The number.\n */\nfunction hexToInt(hexInt: string): number {\n return Number.parseInt(hexInt, 16);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SafeEventEmitterProvider } from
|
|
2
|
-
import SafeEventEmitter from
|
|
3
|
-
import type { BlockTracker } from
|
|
4
|
-
export
|
|
1
|
+
import type { SafeEventEmitterProvider } from "@metamask/eth-json-rpc-provider";
|
|
2
|
+
import SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
3
|
+
import type { BlockTracker } from "./BlockTracker.cjs";
|
|
4
|
+
export type PollingBlockTrackerOptions = {
|
|
5
5
|
provider?: SafeEventEmitterProvider;
|
|
6
6
|
pollingInterval?: number;
|
|
7
7
|
retryTimeout?: number;
|
|
@@ -9,7 +9,7 @@ export interface PollingBlockTrackerOptions {
|
|
|
9
9
|
setSkipCacheFlag?: boolean;
|
|
10
10
|
blockResetDuration?: number;
|
|
11
11
|
usePastBlocks?: boolean;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
export declare class PollingBlockTracker extends SafeEventEmitter implements BlockTracker {
|
|
14
14
|
#private;
|
|
15
15
|
private _isRunning;
|
|
@@ -62,3 +62,4 @@ export declare class PollingBlockTracker extends SafeEventEmitter implements Blo
|
|
|
62
62
|
private _updateAndQueue;
|
|
63
63
|
_clearPollingTimeout(): void;
|
|
64
64
|
}
|
|
65
|
+
//# sourceMappingURL=PollingBlockTracker.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PollingBlockTracker.d.cts","sourceRoot":"","sources":["../src/PollingBlockTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,wCAAwC;AAChF,OAAO,gBAAgB,qCAAqC;AAS5D,OAAO,KAAK,EAAE,YAAY,EAAE,2BAAuB;AASnD,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAA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d,OAAO,CAAC,IAAI;YAIE,kBAAkB;YAelB,iBAAiB;IAsC/B;;;OAGG;YACW,eAAe;IAoC7B,oBAAoB;CAsBrB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SafeEventEmitterProvider } from "@metamask/eth-json-rpc-provider";
|
|
2
|
+
import SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
3
|
+
import type { BlockTracker } from "./BlockTracker.mjs";
|
|
4
|
+
export type PollingBlockTrackerOptions = {
|
|
5
|
+
provider?: SafeEventEmitterProvider;
|
|
6
|
+
pollingInterval?: number;
|
|
7
|
+
retryTimeout?: number;
|
|
8
|
+
keepEventLoopActive?: boolean;
|
|
9
|
+
setSkipCacheFlag?: boolean;
|
|
10
|
+
blockResetDuration?: number;
|
|
11
|
+
usePastBlocks?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare class PollingBlockTracker extends SafeEventEmitter implements BlockTracker {
|
|
14
|
+
#private;
|
|
15
|
+
private _isRunning;
|
|
16
|
+
private readonly _blockResetDuration;
|
|
17
|
+
private readonly _usePastBlocks;
|
|
18
|
+
private _currentBlock;
|
|
19
|
+
private _blockResetTimeout?;
|
|
20
|
+
private _pollingTimeout?;
|
|
21
|
+
private readonly _provider;
|
|
22
|
+
private readonly _pollingInterval;
|
|
23
|
+
private readonly _retryTimeout;
|
|
24
|
+
private readonly _keepEventLoopActive;
|
|
25
|
+
private readonly _setSkipCacheFlag;
|
|
26
|
+
constructor(opts?: PollingBlockTrackerOptions);
|
|
27
|
+
destroy(): Promise<void>;
|
|
28
|
+
isRunning(): boolean;
|
|
29
|
+
getCurrentBlock(): string | null;
|
|
30
|
+
getLatestBlock({ useCache, }?: {
|
|
31
|
+
useCache?: boolean;
|
|
32
|
+
}): Promise<string>;
|
|
33
|
+
removeAllListeners(eventName?: string | symbol): this;
|
|
34
|
+
private _setupInternalEvents;
|
|
35
|
+
private _onNewListener;
|
|
36
|
+
private _onRemoveListener;
|
|
37
|
+
private _maybeStart;
|
|
38
|
+
private _maybeEnd;
|
|
39
|
+
private _getBlockTrackerEventCount;
|
|
40
|
+
private _shouldUseNewBlock;
|
|
41
|
+
private _newPotentialLatest;
|
|
42
|
+
private _setCurrentBlock;
|
|
43
|
+
private _setupBlockResetTimeout;
|
|
44
|
+
private _cancelBlockResetTimeout;
|
|
45
|
+
private _resetCurrentBlock;
|
|
46
|
+
/**
|
|
47
|
+
* Checks for the latest block, updates the internal state, and returns the
|
|
48
|
+
* value immediately rather than waiting for the next polling interval.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Use {@link getLatestBlock} instead.
|
|
51
|
+
* @returns A promise that resolves to the latest block number.
|
|
52
|
+
*/
|
|
53
|
+
checkForLatestBlock(): Promise<string>;
|
|
54
|
+
private _start;
|
|
55
|
+
private _end;
|
|
56
|
+
private _updateLatestBlock;
|
|
57
|
+
private _fetchLatestBlock;
|
|
58
|
+
/**
|
|
59
|
+
* The core polling function that runs after each interval.
|
|
60
|
+
* Updates the latest block and then queues the next update.
|
|
61
|
+
*/
|
|
62
|
+
private _updateAndQueue;
|
|
63
|
+
_clearPollingTimeout(): void;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=PollingBlockTracker.d.mts.map
|