@dedot/api 0.18.0 → 0.18.1

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.
@@ -192,10 +192,19 @@ class ChainHead extends JsonRpcGroup_js_1.JsonRpcGroup {
192
192
  }
193
193
  case 'finalized': {
194
194
  const { finalizedBlockHashes, prunedBlockHashes } = result;
195
- this.#finalizedHash = finalizedBlockHashes.at(-1);
196
- const finalizedRuntime = this.#findRuntimeAt(this.#finalizedHash);
197
- if (finalizedRuntime) {
198
- this.#finalizedRuntime = finalizedRuntime;
195
+ const currentFinalizedNumber = this.findBlock(this.#finalizedHash).number;
196
+ for (const hash of finalizedBlockHashes) {
197
+ const block = this.findBlock(hash);
198
+ // Skip if block not found OR blocks that are already finalized (block number <= previous finalized number)
199
+ if (!block || block.number <= currentFinalizedNumber) {
200
+ continue;
201
+ }
202
+ this.#finalizedHash = hash;
203
+ const finalizedRuntime = this.#findRuntimeAt(hash);
204
+ if (finalizedRuntime) {
205
+ this.#finalizedRuntime = finalizedRuntime;
206
+ }
207
+ this.emit('finalizedBlock', block);
199
208
  }
200
209
  // push new finalized hashes into the queue, we'll adjust the size later if needed
201
210
  finalizedBlockHashes.forEach((hash) => {
@@ -204,7 +213,6 @@ class ChainHead extends JsonRpcGroup_js_1.JsonRpcGroup {
204
213
  this.#finalizedQueue.push(hash);
205
214
  });
206
215
  const currentFinalizedBlock = this.findBlock(this.#finalizedHash);
207
- this.emit('finalizedBlock', currentFinalizedBlock);
208
216
  // TODO account for operations that haven't received its operationId yet
209
217
  Object.values(this.#handlers).forEach(({ defer, hash, operationId }) => {
210
218
  if (prunedBlockHashes.includes(hash)) {
@@ -189,10 +189,19 @@ export class ChainHead extends JsonRpcGroup {
189
189
  }
190
190
  case 'finalized': {
191
191
  const { finalizedBlockHashes, prunedBlockHashes } = result;
192
- this.#finalizedHash = finalizedBlockHashes.at(-1);
193
- const finalizedRuntime = this.#findRuntimeAt(this.#finalizedHash);
194
- if (finalizedRuntime) {
195
- this.#finalizedRuntime = finalizedRuntime;
192
+ const currentFinalizedNumber = this.findBlock(this.#finalizedHash).number;
193
+ for (const hash of finalizedBlockHashes) {
194
+ const block = this.findBlock(hash);
195
+ // Skip if block not found OR blocks that are already finalized (block number <= previous finalized number)
196
+ if (!block || block.number <= currentFinalizedNumber) {
197
+ continue;
198
+ }
199
+ this.#finalizedHash = hash;
200
+ const finalizedRuntime = this.#findRuntimeAt(hash);
201
+ if (finalizedRuntime) {
202
+ this.#finalizedRuntime = finalizedRuntime;
203
+ }
204
+ this.emit('finalizedBlock', block);
196
205
  }
197
206
  // push new finalized hashes into the queue, we'll adjust the size later if needed
198
207
  finalizedBlockHashes.forEach((hash) => {
@@ -201,7 +210,6 @@ export class ChainHead extends JsonRpcGroup {
201
210
  this.#finalizedQueue.push(hash);
202
211
  });
203
212
  const currentFinalizedBlock = this.findBlock(this.#finalizedHash);
204
- this.emit('finalizedBlock', currentFinalizedBlock);
205
213
  // TODO account for operations that haven't received its operationId yet
206
214
  Object.values(this.#handlers).forEach(({ defer, hash, operationId }) => {
207
215
  if (prunedBlockHashes.includes(hash)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@dedot.dev>",
6
6
  "homepage": "https://dedot.dev",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.18.0",
17
- "@dedot/providers": "0.18.0",
18
- "@dedot/runtime-specs": "0.18.0",
19
- "@dedot/shape": "0.18.0",
20
- "@dedot/storage": "0.18.0",
21
- "@dedot/types": "0.18.0",
22
- "@dedot/utils": "0.18.0"
16
+ "@dedot/codecs": "0.18.1",
17
+ "@dedot/providers": "0.18.1",
18
+ "@dedot/runtime-specs": "0.18.1",
19
+ "@dedot/shape": "0.18.1",
20
+ "@dedot/storage": "0.18.1",
21
+ "@dedot/types": "0.18.1",
22
+ "@dedot/utils": "0.18.1"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -48,7 +48,7 @@
48
48
  "node": ">=18"
49
49
  },
50
50
  "license": "Apache-2.0",
51
- "gitHead": "32395b356a4febaac0d52506742947c916ac9895",
51
+ "gitHead": "3ffda568232b50a3993d13c6ccac2894b0759dd7",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }