create planchets only in one place

This commit is contained in:
Florian Dold 2020-05-11 20:51:45 +05:30
parent 4c614429a0
commit d7ee78669d
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 1 additions and 37 deletions

View File

@ -647,40 +647,6 @@ async function depleteReserve(
const withdrawalGroupId = encodeCrock(randomBytes(32));
const planchets: PlanchetRecord[] = [];
let coinIdx = 0;
for (let i = 0; i < denomsForWithdraw.selectedDenoms.length; i++) {
const d = denomsForWithdraw.selectedDenoms[i];
const denom = d.denom;
for (let j = 0; j < d.count; j++) {
const r = await ws.cryptoApi.createPlanchet({
denomPub: denom.denomPub,
feeWithdraw: denom.feeWithdraw,
reservePriv: reserve.reservePriv,
reservePub: reserve.reservePub,
value: denom.value,
});
const planchet: PlanchetRecord = {
blindingKey: r.blindingKey,
coinEv: r.coinEv,
coinEvHash: r.coinEvHash,
coinIdx,
coinPriv: r.coinPriv,
coinPub: r.coinPub,
coinValue: r.coinValue,
denomPub: r.denomPub,
denomPubHash: r.denomPubHash,
isFromTip: false,
reservePub: r.reservePub,
withdrawalDone: false,
withdrawSig: r.withdrawSig,
withdrawalGroupId: withdrawalGroupId,
};
planchets.push(planchet);
coinIdx++;
}
}
logger.trace("created plachets");
const withdrawalRecord: WithdrawalGroupRecord = {
@ -747,9 +713,6 @@ async function depleteReserve(
newReserve.retryInfo = initRetryInfo(false);
await tx.put(Stores.reserves, newReserve);
await tx.put(Stores.withdrawalGroups, withdrawalRecord);
for (const p of planchets) {
await tx.put(Stores.planchets, p);
}
return true;
},
);

View File

@ -522,6 +522,7 @@ async function processInBatches(workGen: Iterator<Promise<void>>, batchSize: num
if (batch.length == 0) {
break;
}
logger.trace(`processing withdrawal batch of ${batch.length} elements`);
await Promise.all(batch);
}
}