@dedot/api 0.18.0 → 0.18.2

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.
@@ -114,6 +114,12 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
114
114
  const atApi = (await this.client.at(hash));
115
115
  return await atApi.query.system.events();
116
116
  }
117
+ toU8a() {
118
+ if (this.#alterTx) {
119
+ return (0, utils_1.hexToU8a)(this.#alterTx);
120
+ }
121
+ return super.toU8a();
122
+ }
117
123
  toHex() {
118
124
  return this.#alterTx || super.toHex();
119
125
  }
@@ -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)) {
@@ -21,6 +21,7 @@ export declare abstract class BaseSubmittableExtrinsic extends Extrinsic impleme
21
21
  send(): TxHash;
22
22
  send(callback: Callback): TxUnsub;
23
23
  protected getSystemEventsAt(hash: BlockHash): Promise<FrameSystemEventRecord[]>;
24
+ toU8a(): Uint8Array;
24
25
  toHex(): HexString;
25
26
  }
26
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { Extrinsic } from '@dedot/codecs';
2
- import { DedotError, isFunction, toHex, u8aToHex } from '@dedot/utils';
2
+ import { DedotError, hexToU8a, isFunction, toHex, u8aToHex } from '@dedot/utils';
3
3
  import { ExtraSignedExtension } from '../extensions/index.js';
4
4
  import { fakeSigner } from './fakeSigner.js';
5
5
  import { isKeyringPair, signRawMessage, txDefer } from './utils.js';
@@ -111,6 +111,12 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
111
111
  const atApi = (await this.client.at(hash));
112
112
  return await atApi.query.system.events();
113
113
  }
114
+ toU8a() {
115
+ if (this.#alterTx) {
116
+ return hexToU8a(this.#alterTx);
117
+ }
118
+ return super.toU8a();
119
+ }
114
120
  toHex() {
115
121
  return this.#alterTx || super.toHex();
116
122
  }
@@ -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.2",
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.2",
17
+ "@dedot/providers": "0.18.2",
18
+ "@dedot/runtime-specs": "0.18.2",
19
+ "@dedot/shape": "0.18.2",
20
+ "@dedot/storage": "0.18.2",
21
+ "@dedot/types": "0.18.2",
22
+ "@dedot/utils": "0.18.2"
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": "ed3c658d49d7fd9d9dc1befd1c838edc4656d317",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }