@xyo-network/xl1-protocol-sdk 2.0.4 → 2.0.5

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.
@@ -2692,11 +2692,26 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
2692
2692
  }
2693
2693
 
2694
2694
  // src/transaction/confirmSubmittedTransaction.ts
2695
- import { delay, isDefined as isDefined15 } from "@xylabs/sdk-js";
2695
+ import {
2696
+ delay,
2697
+ isDefined as isDefined15,
2698
+ isNumber
2699
+ } from "@xylabs/sdk-js";
2696
2700
  var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
2697
2701
  var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
2702
+ var assertNotExpired = async (viewer, txHash, exp, options) => {
2703
+ const head = await viewer.currentBlockNumber();
2704
+ if (head > exp) {
2705
+ options?.logger?.error(`\u26A0\uFE0F Transaction expired: chain head ${head} moved past exp ${exp}`);
2706
+ throw new Error(`Transaction ${txHash} expired: chain head ${head} moved past exp ${exp}`);
2707
+ }
2708
+ };
2698
2709
  var confirmSubmittedTransaction = async (viewer, txHash, options) => {
2699
- const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options ?? {};
2710
+ const {
2711
+ attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS,
2712
+ delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS,
2713
+ exp
2714
+ } = options ?? {};
2700
2715
  options?.logger?.debug("Confirming transaction", txHash);
2701
2716
  let attempts = 0;
2702
2717
  while (true) {
@@ -2705,6 +2720,9 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
2705
2720
  options?.logger?.debug("Transaction confirmed", txHash);
2706
2721
  return tx;
2707
2722
  } else {
2723
+ if (isNumber(exp)) {
2724
+ await assertNotExpired(viewer, txHash, exp, options);
2725
+ }
2708
2726
  attempts++;
2709
2727
  if (attempts > maxAttempts) {
2710
2728
  options?.logger?.error(`\u26A0\uFE0F Transaction not confirmed after ${maxAttempts} attempts`);