@bsv/wallet-toolbox-client 2.6.4 → 2.6.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.
@@ -10021,16 +10021,15 @@ async function createActionCore(storage, auth, vargs, parent) {
10021
10021
  });
10022
10022
  const feeModel = validateStorageFeeModel(storage.feeModel);
10023
10023
  logger?.log(`validated fee model ${JSON.stringify(feeModel)}`);
10024
- const initialFundingPlan = await prepareFundingPlan(storage, [
10024
+ const initialFundingPlan = await prepareFundingPlanWithSendingFallback(storage, [
10025
10025
  userId,
10026
10026
  vargs,
10027
10027
  xinputs,
10028
10028
  xoutputs,
10029
10029
  changeBasket,
10030
10030
  noSendChangeIn,
10031
- feeModel,
10032
- parent
10033
- ]);
10031
+ feeModel
10032
+ ], parent);
10034
10033
  logger?.log(`planned funding from ${initialFundingPlan.availableChangeCount} change inputs`);
10035
10034
  const allocatedBeefPrefetch = startAllocatedChangeBeefPrefetch(storage, vargs, initialFundingPlan.selected, beef, parent);
10036
10035
  const storageBeefBytes = storageBeef.toBinary();
@@ -10630,8 +10629,7 @@ function makeFundingParams(vargs, xinputs, xoutputs, changeBasket, feeModel, ava
10630
10629
  };
10631
10630
  }
10632
10631
  async function prepareFundingPlan(storage, context) {
10633
- const [userId, vargs, xinputs, xoutputs, changeBasket, noSendChangeIn, feeModel, parent, trx] = context;
10634
- const excludeSending = !vargs.isDelayed;
10632
+ const [userId, vargs, xinputs, xoutputs, changeBasket, noSendChangeIn, feeModel, excludeSending, parent, trx] = context;
10635
10633
  const candidates = await traceStorageStep(storage, "wallet.storage.create_action.funding_candidates", parent, { "funding.exclude_sending": excludeSending }, async (span) => {
10636
10634
  const outputs = await storage.findAvailableManagedChangeInputCandidates(userId, changeBasket.basketId, excludeSending, trx);
10637
10635
  span?.end({ attributes: {
@@ -10680,10 +10678,30 @@ async function prepareFundingPlan(storage, context) {
10680
10678
  params,
10681
10679
  result,
10682
10680
  selected,
10683
- availableChangeCount: candidates.length
10681
+ availableChangeCount: candidates.length,
10682
+ excludeSending
10684
10683
  };
10685
10684
  });
10686
10685
  }
10686
+ async function prepareFundingPlanWithSendingFallback(storage, context, parent, trx) {
10687
+ const excludeSending = !context[1].isDelayed;
10688
+ try {
10689
+ return await prepareFundingPlan(storage, [
10690
+ ...context,
10691
+ excludeSending,
10692
+ parent,
10693
+ trx
10694
+ ]);
10695
+ } catch (error) {
10696
+ if (!excludeSending || !(error instanceof WERR_INSUFFICIENT_FUNDS)) throw error;
10697
+ return await prepareFundingPlan(storage, [
10698
+ ...context,
10699
+ false,
10700
+ parent,
10701
+ trx
10702
+ ]);
10703
+ }
10704
+ }
10687
10705
  async function claimFundingPlan(storage, request) {
10688
10706
  const [userId, basketId, excludeSending, transactionId, noSendChangeIn, plan, trx] = request;
10689
10707
  if (plan.selected.length === 0) return {
@@ -10766,7 +10784,7 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx, initialPlan, p
10766
10784
  const claim = await claimFundingPlan(storage, [
10767
10785
  userId,
10768
10786
  ctx.changeBasket.basketId,
10769
- !vargs.isDelayed,
10787
+ plan.excludeSending,
10770
10788
  ctx.transactionId,
10771
10789
  ctx.noSendChangeIn,
10772
10790
  plan,
@@ -10784,17 +10802,15 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx, initialPlan, p
10784
10802
  }
10785
10803
  if (claim.conflict === "noSendChange") throw new WERR_INVALID_PARAMETER("noSendChange", "outputs that remain spendable during action planning");
10786
10804
  retryCount++;
10787
- plan = await prepareFundingPlan(storage, [
10805
+ plan = await prepareFundingPlanWithSendingFallback(storage, [
10788
10806
  userId,
10789
10807
  vargs,
10790
10808
  ctx.xinputs,
10791
10809
  ctx.xoutputs,
10792
10810
  ctx.changeBasket,
10793
10811
  ctx.noSendChangeIn,
10794
- ctx.feeModel,
10795
- parent,
10796
- trx
10797
- ]);
10812
+ ctx.feeModel
10813
+ ], parent, trx);
10798
10814
  }
10799
10815
  throw new WERR_INVALID_OPERATION("wallet funding changed repeatedly during action planning; retry createAction");
10800
10816
  });