fix cost computation, formatting
This commit is contained in:
parent
3007419c98
commit
6e17a60692
@ -105,7 +105,10 @@ export function getWithdrawDenomList(
|
|||||||
totalCoinValue,
|
totalCoinValue,
|
||||||
Amounts.mult(d.value, count).amount,
|
Amounts.mult(d.value, count).amount,
|
||||||
).amount;
|
).amount;
|
||||||
totalWithdrawCost = Amounts.add(totalWithdrawCost, cost).amount;
|
totalWithdrawCost = Amounts.add(
|
||||||
|
totalWithdrawCost,
|
||||||
|
Amounts.mult(cost, count).amount,
|
||||||
|
).amount;
|
||||||
selectedDenoms.push({
|
selectedDenoms.push({
|
||||||
count,
|
count,
|
||||||
denom: d,
|
denom: d,
|
||||||
@ -195,7 +198,11 @@ async function processPlanchet(
|
|||||||
if (!planchet) {
|
if (!planchet) {
|
||||||
let ci = 0;
|
let ci = 0;
|
||||||
let denomPubHash: string | undefined;
|
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];
|
const d = withdrawalGroup.denomsSel.selectedDenoms[di];
|
||||||
if (coinIdx >= ci && coinIdx < ci + d.count) {
|
if (coinIdx >= ci && coinIdx < ci + d.count) {
|
||||||
denomPubHash = d.denomPubHash;
|
denomPubHash = d.denomPubHash;
|
||||||
@ -206,14 +213,20 @@ async function processPlanchet(
|
|||||||
if (!denomPubHash) {
|
if (!denomPubHash) {
|
||||||
throw Error("invariant violated");
|
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) {
|
if (!denom) {
|
||||||
throw Error("invariant violated");
|
throw Error("invariant violated");
|
||||||
}
|
}
|
||||||
if (withdrawalGroup.source.type != WithdrawalSourceType.Reserve) {
|
if (withdrawalGroup.source.type != WithdrawalSourceType.Reserve) {
|
||||||
throw Error("invariant violated");
|
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) {
|
if (!reserve) {
|
||||||
throw Error("invariant violated");
|
throw Error("invariant violated");
|
||||||
}
|
}
|
||||||
@ -279,7 +292,9 @@ async function processPlanchet(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace(`processing planchet #${coinIdx} in withdrawal ${withdrawalGroupId}`);
|
logger.trace(
|
||||||
|
`processing planchet #${coinIdx} in withdrawal ${withdrawalGroupId}`,
|
||||||
|
);
|
||||||
|
|
||||||
const wd: any = {};
|
const wd: any = {};
|
||||||
wd.denom_pub_hash = planchet.denomPubHash;
|
wd.denom_pub_hash = planchet.denomPubHash;
|
||||||
@ -362,14 +377,18 @@ async function processPlanchet(
|
|||||||
|
|
||||||
let numDone = 0;
|
let numDone = 0;
|
||||||
|
|
||||||
await tx.iterIndexed(Stores.planchets.byGroup, withdrawalGroupId).forEach((x) => {
|
await tx
|
||||||
|
.iterIndexed(Stores.planchets.byGroup, withdrawalGroupId)
|
||||||
|
.forEach((x) => {
|
||||||
if (x.withdrawalDone) {
|
if (x.withdrawalDone) {
|
||||||
numDone++;
|
numDone++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (numDone > numTotal) {
|
if (numDone > numTotal) {
|
||||||
throw Error("invariant violated (created more planchets than expected)");
|
throw Error(
|
||||||
|
"invariant violated (created more planchets than expected)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numDone == numTotal) {
|
if (numDone == numTotal) {
|
||||||
@ -513,7 +532,10 @@ async function resetWithdrawalGroupRetry(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processInBatches(workGen: Iterator<Promise<void>>, batchSize: number): Promise<void> {
|
async function processInBatches(
|
||||||
|
workGen: Iterator<Promise<void>>,
|
||||||
|
batchSize: number,
|
||||||
|
): Promise<void> {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const batch: Promise<void>[] = [];
|
const batch: Promise<void>[] = [];
|
||||||
for (let i = 0; i < batchSize; i++) {
|
for (let i = 0; i < batchSize; i++) {
|
||||||
@ -559,7 +581,7 @@ async function processWithdrawGroupImpl(
|
|||||||
coinIdx++;
|
coinIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Withdraw coins in batches.
|
// Withdraw coins in batches.
|
||||||
// The batch size is relatively large
|
// The batch size is relatively large
|
||||||
|
Loading…
Reference in New Issue
Block a user