@argonprotocol/mainchain 1.4.9-dev.8f82736f → 1.4.9-dev.c17ec6c5

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/lib/index.d.cts CHANGED
@@ -13808,6 +13808,12 @@ type IBigIntLike = bigint | {
13808
13808
  };
13809
13809
 
13810
13810
  type ITxProgressCallback = (progressToInBlock: number, result?: TxResult) => void;
13811
+ type IBlockInclusion = {
13812
+ blockHash: Uint8Array;
13813
+ blockNumber?: number;
13814
+ extrinsicIndex: number;
13815
+ events: GenericEvent[];
13816
+ };
13811
13817
  declare class TxResult {
13812
13818
  #private;
13813
13819
  protected readonly client: ArgonClient;
@@ -13857,14 +13863,10 @@ declare class TxResult {
13857
13863
  accountAddress: string;
13858
13864
  nonce: number;
13859
13865
  });
13860
- setSeenInBlock(block: {
13861
- blockHash: Uint8Array;
13862
- blockNumber?: number;
13863
- extrinsicIndex: number;
13864
- events: GenericEvent[];
13865
- }): Promise<void>;
13866
- setFinalized(): void;
13866
+ setSeenInBlock(block: IBlockInclusion): Promise<void>;
13867
+ setFinalized(): Promise<void>;
13867
13868
  onSubscriptionResult(result: ISubmittableResult): void;
13869
+ private publishSeenInBlock;
13868
13870
  private updateProgress;
13869
13871
  private parseEvents;
13870
13872
  }
package/lib/index.d.ts CHANGED
@@ -13808,6 +13808,12 @@ type IBigIntLike = bigint | {
13808
13808
  };
13809
13809
 
13810
13810
  type ITxProgressCallback = (progressToInBlock: number, result?: TxResult) => void;
13811
+ type IBlockInclusion = {
13812
+ blockHash: Uint8Array;
13813
+ blockNumber?: number;
13814
+ extrinsicIndex: number;
13815
+ events: GenericEvent[];
13816
+ };
13811
13817
  declare class TxResult {
13812
13818
  #private;
13813
13819
  protected readonly client: ArgonClient;
@@ -13857,14 +13863,10 @@ declare class TxResult {
13857
13863
  accountAddress: string;
13858
13864
  nonce: number;
13859
13865
  });
13860
- setSeenInBlock(block: {
13861
- blockHash: Uint8Array;
13862
- blockNumber?: number;
13863
- extrinsicIndex: number;
13864
- events: GenericEvent[];
13865
- }): Promise<void>;
13866
- setFinalized(): void;
13866
+ setSeenInBlock(block: IBlockInclusion): Promise<void>;
13867
+ setFinalized(): Promise<void>;
13867
13868
  onSubscriptionResult(result: ISubmittableResult): void;
13869
+ private publishSeenInBlock;
13868
13870
  private updateProgress;
13869
13871
  private parseEvents;
13870
13872
  }
package/lib/index.js CHANGED
@@ -220,6 +220,7 @@ var TxResult = class {
220
220
  }
221
221
  #isBroadcast = false;
222
222
  #submissionError;
223
+ #pendingInBlock;
223
224
  set isBroadcast(value) {
224
225
  this.#isBroadcast = value;
225
226
  this.updateProgress();
@@ -265,21 +266,44 @@ var TxResult = class {
265
266
  inBlockResolve;
266
267
  inBlockReject;
267
268
  async setSeenInBlock(block) {
268
- const { blockHash, blockNumber, events } = block;
269
- if (blockHash !== this.blockHash) {
270
- this.parseEvents(events);
271
- this.blockHash = blockHash;
272
- this.blockNumber = blockNumber ?? await this.client.rpc.chain.getHeader(blockHash).then((h) => h.number.toNumber());
273
- this.extrinsicIndex = block.extrinsicIndex;
274
- this.updateProgress();
275
- if (this.extrinsicError) {
276
- this.inBlockReject(this.extrinsicError);
277
- } else {
278
- this.inBlockResolve(blockHash);
279
- }
269
+ if (block.blockNumber === void 0) {
270
+ this.#pendingInBlock = {
271
+ blockHash: block.blockHash,
272
+ extrinsicIndex: block.extrinsicIndex,
273
+ events: block.events
274
+ };
275
+ return;
276
+ }
277
+ if (this.blockHash && this.blockNumber === block.blockNumber && this.extrinsicIndex === block.extrinsicIndex && u8aEq(this.blockHash, block.blockHash)) {
278
+ this.#pendingInBlock = void 0;
279
+ return;
280
+ }
281
+ this.#pendingInBlock = void 0;
282
+ this.parseEvents(block.events);
283
+ this.blockHash = block.blockHash;
284
+ this.blockNumber = block.blockNumber;
285
+ this.extrinsicIndex = block.extrinsicIndex;
286
+ this.updateProgress();
287
+ if (this.extrinsicError) {
288
+ this.inBlockReject(this.extrinsicError);
289
+ } else {
290
+ this.inBlockResolve(block.blockHash);
280
291
  }
281
292
  }
282
- setFinalized() {
293
+ async setFinalized() {
294
+ const pendingInBlock = this.#pendingInBlock;
295
+ if (pendingInBlock) {
296
+ await this.publishSeenInBlock(pendingInBlock);
297
+ } else if (this.blockHash && this.blockNumber === void 0) {
298
+ if (this.extrinsicIndex === void 0) {
299
+ throw new Error("Cannot finalize transaction before extrinsic index is known");
300
+ }
301
+ await this.publishSeenInBlock({
302
+ blockHash: this.blockHash,
303
+ extrinsicIndex: this.extrinsicIndex,
304
+ events: this.events
305
+ });
306
+ }
283
307
  this.isFinalized = true;
284
308
  this.updateProgress();
285
309
  let error = this.extrinsicError ?? this.submissionError;
@@ -302,33 +326,73 @@ var TxResult = class {
302
326
  if (result2.internalError) this.submissionError = result2.internalError;
303
327
  }
304
328
  if (status.isInBlock) {
305
- void this.setSeenInBlock({
306
- blockHash: Uint8Array.from(status.asInBlock),
307
- events: extrinsicEvents,
308
- extrinsicIndex: txIndex
309
- });
329
+ try {
330
+ const pendingInBlock = createPendingInBlock(
331
+ Uint8Array.from(status.asInBlock),
332
+ txIndex,
333
+ extrinsicEvents
334
+ );
335
+ this.#pendingInBlock = pendingInBlock;
336
+ void this.publishSeenInBlock(pendingInBlock).catch((error) => {
337
+ if (!isMissingBlockHeaderError(error)) {
338
+ this.submissionError = error;
339
+ }
340
+ });
341
+ } catch (error) {
342
+ this.submissionError = error;
343
+ }
310
344
  }
311
345
  if (status.isUsurped) {
346
+ this.#pendingInBlock = void 0;
312
347
  this.submissionError = new TxSubmissionError(
313
348
  TxSubmissionErrorCode.Usurped,
314
349
  `Transaction was usurped by ${status.asUsurped.toHex()}.`
315
350
  );
316
351
  }
317
352
  if (status.isDropped) {
353
+ this.#pendingInBlock = void 0;
318
354
  this.submissionError = new TxSubmissionError(
319
355
  TxSubmissionErrorCode.Dropped,
320
356
  "Transaction was dropped before it was included in a block."
321
357
  );
322
358
  }
323
359
  if (status.isInvalid) {
360
+ this.#pendingInBlock = void 0;
324
361
  this.submissionError = new TxSubmissionError(
325
362
  TxSubmissionErrorCode.Invalid,
326
363
  "Transaction was rejected as invalid by the node."
327
364
  );
328
365
  }
329
366
  if (isFinalized) {
330
- this.setFinalized();
367
+ try {
368
+ this.#pendingInBlock = createPendingInBlock(
369
+ Uint8Array.from(status.asFinalized),
370
+ txIndex ?? this.#pendingInBlock?.extrinsicIndex ?? this.extrinsicIndex,
371
+ extrinsicEvents.length ? extrinsicEvents : this.events
372
+ );
373
+ } catch (error) {
374
+ this.submissionError = error;
375
+ return;
376
+ }
377
+ void this.setFinalized().catch((error) => {
378
+ this.submissionError = error;
379
+ });
380
+ }
381
+ }
382
+ async publishSeenInBlock(block) {
383
+ const pendingInBlock = this.#pendingInBlock;
384
+ if (!pendingInBlock || pendingInBlock.extrinsicIndex !== block.extrinsicIndex || !u8aEq(pendingInBlock.blockHash, block.blockHash)) {
385
+ return;
331
386
  }
387
+ const blockNumber = await this.client.rpc.chain.getHeader(block.blockHash).then((h) => h.number.toNumber());
388
+ const currentPendingInBlock = this.#pendingInBlock;
389
+ if (!currentPendingInBlock || currentPendingInBlock.extrinsicIndex !== block.extrinsicIndex || !u8aEq(currentPendingInBlock.blockHash, block.blockHash)) {
390
+ return;
391
+ }
392
+ await this.setSeenInBlock({
393
+ ...block,
394
+ blockNumber
395
+ });
332
396
  }
333
397
  updateProgress() {
334
398
  if (this.isFinalized || this.submissionError) {
@@ -375,6 +439,19 @@ var TxResult = class {
375
439
  this.events = events;
376
440
  }
377
441
  };
442
+ function createPendingInBlock(blockHash, extrinsicIndex, events) {
443
+ if (extrinsicIndex === void 0) {
444
+ throw new Error("Cannot publish transaction block state before extrinsic index is known");
445
+ }
446
+ return {
447
+ blockHash,
448
+ extrinsicIndex,
449
+ events
450
+ };
451
+ }
452
+ function isMissingBlockHeaderError(error) {
453
+ return String(error).includes("Unable to retrieve header and parent from supplied hash");
454
+ }
378
455
 
379
456
  // src/TxSubmitter.ts
380
457
  var TxSubmitter = class {
@@ -8484,7 +8561,7 @@ function isRetryableBeaconLightClientError(error) {
8484
8561
 
8485
8562
  // src/index.ts
8486
8563
  import { u8aToHex as u8aToHex2, hexToU8a as hexToU8a2, u8aEq } from "@polkadot/util";
8487
- import { GenericEvent, GenericBlock, GenericAddress } from "@polkadot/types/generic";
8564
+ import { GenericEvent as GenericEvent2, GenericBlock, GenericAddress } from "@polkadot/types/generic";
8488
8565
  import {
8489
8566
  BTreeMap,
8490
8567
  Bytes,
@@ -8549,7 +8626,7 @@ export {
8549
8626
  FIXED_U128_DECIMALS,
8550
8627
  GenericAddress,
8551
8628
  GenericBlock,
8552
- GenericEvent,
8629
+ GenericEvent2 as GenericEvent,
8553
8630
  Keyring,
8554
8631
  MICROGONS_PER_ARGON,
8555
8632
  Null,