From 6e17a6069282b87fa7e872de44505b9676bc3e78 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 13 May 2020 01:20:40 +0530 Subject: fix cost computation, formatting --- src/operations/withdraw.ts | 50 +++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts index 977d998fd..21c30d7af 100644 --- a/src/operations/withdraw.ts +++ b/src/operations/withdraw.ts @@ -105,7 +105,10 @@ export function getWithdrawDenomList( totalCoinValue, Amounts.mult(d.value, count).amount, ).amount; - totalWithdrawCost = Amounts.add(totalWithdrawCost, cost).amount; + totalWithdrawCost = Amounts.add( + totalWithdrawCost, + Amounts.mult(cost, count).amount, + ).amount; selectedDenoms.push({ count, denom: d, @@ -195,7 +198,11 @@ async function processPlanchet( if (!planchet) { let ci = 0; let denomPubHash: string | undefined; - for (let di = 0; di < withdrawalGroup.denomsSel.selectedDenoms.length; di++) { + for ( + let di = 0; + di < withdrawalGroup.denomsSel.selectedDenoms.length; + di++ + ) { const d = withdrawalGroup.denomsSel.selectedDenoms[di]; if (coinIdx >= ci && coinIdx < ci + d.count) { denomPubHash = d.denomPubHash; @@ -206,14 +213,20 @@ async function processPlanchet( if (!denomPubHash) { throw Error("invariant violated"); } - const denom = await ws.db.getIndexed(Stores.denominations.denomPubHashIndex, denomPubHash); + const denom = await ws.db.getIndexed( + Stores.denominations.denomPubHashIndex, + denomPubHash, + ); if (!denom) { throw Error("invariant violated"); } if (withdrawalGroup.source.type != WithdrawalSourceType.Reserve) { throw Error("invariant violated"); } - const reserve = await ws.db.get(Stores.reserves, withdrawalGroup.source.reservePub); + const reserve = await ws.db.get( + Stores.reserves, + withdrawalGroup.source.reservePub, + ); if (!reserve) { throw Error("invariant violated"); } @@ -279,7 +292,9 @@ async function processPlanchet( return; } - logger.trace(`processing planchet #${coinIdx} in withdrawal ${withdrawalGroupId}`); + logger.trace( + `processing planchet #${coinIdx} in withdrawal ${withdrawalGroupId}`, + ); const wd: any = {}; wd.denom_pub_hash = planchet.denomPubHash; @@ -362,14 +377,18 @@ async function processPlanchet( let numDone = 0; - await tx.iterIndexed(Stores.planchets.byGroup, withdrawalGroupId).forEach((x) => { - if (x.withdrawalDone) { - numDone++; - } - }); + await tx + .iterIndexed(Stores.planchets.byGroup, withdrawalGroupId) + .forEach((x) => { + if (x.withdrawalDone) { + numDone++; + } + }); if (numDone > numTotal) { - throw Error("invariant violated (created more planchets than expected)"); + throw Error( + "invariant violated (created more planchets than expected)", + ); } if (numDone == numTotal) { @@ -513,7 +532,10 @@ async function resetWithdrawalGroupRetry( }); } -async function processInBatches(workGen: Iterator>, batchSize: number): Promise { +async function processInBatches( + workGen: Iterator>, + batchSize: number, +): Promise { for (;;) { const batch: Promise[] = []; for (let i = 0; i < batchSize; i++) { @@ -550,7 +572,7 @@ async function processWithdrawGroupImpl( } const numDenoms = withdrawalGroup.denomsSel.selectedDenoms.length; - const genWork = function*(): Iterator> { + const genWork = function* (): Iterator> { let coinIdx = 0; for (let i = 0; i < numDenoms; i++) { const count = withdrawalGroup.denomsSel.selectedDenoms[i].count; @@ -559,7 +581,7 @@ async function processWithdrawGroupImpl( coinIdx++; } } - } + }; // Withdraw coins in batches. // The batch size is relatively large -- cgit v1.2.3