diff options
author | Florian Dold <florian@dold.me> | 2024-03-06 21:15:30 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-03-07 00:03:59 +0100 |
commit | 7ba1d1f3351e58a331e99337afea0fbedb6eb828 (patch) | |
tree | 60b7a485cd317c1fe55276acdc0e055cd9353bfb /packages/taler-wallet-core/src/deposits.ts | |
parent | 618caa117111b9fed6a792b6816fc724483eb349 (diff) | |
download | wallet-core-7ba1d1f3351e58a331e99337afea0fbedb6eb828.tar.gz wallet-core-7ba1d1f3351e58a331e99337afea0fbedb6eb828.tar.bz2 wallet-core-7ba1d1f3351e58a331e99337afea0fbedb6eb828.zip |
refactor coin selection, report maxEffectiveSpendAmount
Diffstat (limited to 'packages/taler-wallet-core/src/deposits.ts')
-rw-r--r-- | packages/taler-wallet-core/src/deposits.ts | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts index 2e28ba9b7..2c7ee3596 100644 --- a/packages/taler-wallet-core/src/deposits.ts +++ b/packages/taler-wallet-core/src/deposits.ts @@ -1378,8 +1378,8 @@ export async function createDepositGroup( const infoPerExchange: Record<string, DepositInfoPerExchange> = {}; await wex.db.runReadOnlyTx(["coins"], async (tx) => { - for (let i = 0; i < payCoinSel.coinSel.coinPubs.length; i++) { - const coin = await tx.coins.get(payCoinSel.coinSel.coinPubs[i]); + for (let i = 0; i < payCoinSel.coinSel.coins.length; i++) { + const coin = await tx.coins.get(payCoinSel.coinSel.coins[i].coinPub); if (!coin) { logger.error("coin not found anymore"); continue; @@ -1392,7 +1392,7 @@ export async function createDepositGroup( ), }; } - const contrib = payCoinSel.coinSel.coinContributions[i]; + const contrib = payCoinSel.coinSel.coins[i].contribution; depPerExchange.amountEffective = Amounts.stringify( Amounts.add(depPerExchange.amountEffective, contrib).amount, ); @@ -1417,10 +1417,13 @@ export async function createDepositGroup( AbsoluteTime.toPreciseTimestamp(now), ), timestampFinished: undefined, - statusPerCoin: payCoinSel.coinSel.coinPubs.map( + statusPerCoin: payCoinSel.coinSel.coins.map( () => DepositElementStatus.DepositPending, ), - payCoinSelection: payCoinSel.coinSel, + payCoinSelection: { + coinContributions: payCoinSel.coinSel.coins.map((x) => x.contribution), + coinPubs: payCoinSel.coinSel.coins.map((x) => x.coinPub), + }, payCoinSelectionUid: encodeCrock(getRandomBytes(32)), merchantPriv: merchantPair.priv, merchantPub: merchantPair.pub, @@ -1455,9 +1458,9 @@ export async function createDepositGroup( async (tx) => { await spendCoins(wex, tx, { allocationId: transactionId, - coinPubs: payCoinSel.coinSel.coinPubs, - contributions: payCoinSel.coinSel.coinContributions.map((x) => - Amounts.parseOrThrow(x), + coinPubs: payCoinSel.coinSel.coins.map((x) => x.coinPub), + contributions: payCoinSel.coinSel.coins.map((x) => + Amounts.parseOrThrow(x.contribution), ), refreshReason: RefreshReason.PayDeposit, }); @@ -1508,8 +1511,8 @@ export async function getCounterpartyEffectiveDepositAmount( await wex.db.runReadOnlyTx( ["coins", "denominations", "exchangeDetails", "exchanges"], async (tx) => { - for (let i = 0; i < pcs.coinPubs.length; i++) { - const coin = await tx.coins.get(pcs.coinPubs[i]); + for (let i = 0; i < pcs.coins.length; i++) { + const coin = await tx.coins.get(pcs.coins[i].coinPub); if (!coin) { throw Error("can't calculate deposit amount, coin not found"); } @@ -1522,7 +1525,7 @@ export async function getCounterpartyEffectiveDepositAmount( if (!denom) { throw Error("can't find denomination to calculate deposit amount"); } - amt.push(Amounts.parseOrThrow(pcs.coinContributions[i])); + amt.push(Amounts.parseOrThrow(pcs.coins[i].contribution)); fees.push(Amounts.parseOrThrow(denom.feeDeposit)); exchangeSet.add(coin.exchangeBaseUrl); } @@ -1574,8 +1577,8 @@ async function getTotalFeesForDepositAmount( await wex.db.runReadOnlyTx( ["coins", "denominations", "exchanges", "exchangeDetails"], async (tx) => { - for (let i = 0; i < pcs.coinPubs.length; i++) { - const coin = await tx.coins.get(pcs.coinPubs[i]); + for (let i = 0; i < pcs.coins.length; i++) { + const coin = await tx.coins.get(pcs.coins[i].coinPub); if (!coin) { throw Error("can't calculate deposit amount, coin not found"); } @@ -1599,7 +1602,7 @@ async function getTotalFeesForDepositAmount( ); const amountLeft = Amounts.sub( denom.value, - pcs.coinContributions[i], + pcs.coins[i].contribution, ).amount; const refreshCost = getTotalRefreshCost( allDenoms, |