fix logic bug in recoup (refresh variant)
This commit is contained in:
parent
86c8a8fcf3
commit
5d1b0df8a4
@ -238,19 +238,24 @@ async function recoupRefreshCoin(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const oldCoin = await tx.get(Stores.coins, cs.oldCoinPub);
|
const oldCoin = await tx.get(Stores.coins, cs.oldCoinPub);
|
||||||
const updatedCoin = await tx.get(Stores.coins, coin.coinPub);
|
const revokedCoin = await tx.get(Stores.coins, coin.coinPub);
|
||||||
if (!updatedCoin) {
|
if (!revokedCoin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!oldCoin) {
|
if (!oldCoin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updatedCoin.status = CoinStatus.Dormant;
|
revokedCoin.status = CoinStatus.Dormant;
|
||||||
oldCoin.currentAmount = Amounts.add(
|
oldCoin.currentAmount = Amounts.add(
|
||||||
oldCoin.currentAmount,
|
oldCoin.currentAmount,
|
||||||
updatedCoin.currentAmount,
|
recoupGroup.oldAmountPerCoin[coinIdx],
|
||||||
).amount;
|
).amount;
|
||||||
await tx.put(Stores.coins, updatedCoin);
|
console.log(
|
||||||
|
"recoup: setting old coin amount to",
|
||||||
|
Amounts.toString(oldCoin.currentAmount),
|
||||||
|
);
|
||||||
|
await tx.put(Stores.coins, revokedCoin);
|
||||||
|
await tx.put(Stores.coins, oldCoin);
|
||||||
await putGroupAsFinished(tx, recoupGroup, coinIdx);
|
await putGroupAsFinished(tx, recoupGroup, coinIdx);
|
||||||
return await createRefreshGroup(
|
return await createRefreshGroup(
|
||||||
tx,
|
tx,
|
||||||
@ -333,6 +338,8 @@ export async function createRecoupGroup(
|
|||||||
timestampStarted: getTimestampNow(),
|
timestampStarted: getTimestampNow(),
|
||||||
retryInfo: initRetryInfo(),
|
retryInfo: initRetryInfo(),
|
||||||
recoupFinishedPerCoin: coinPubs.map(() => false),
|
recoupFinishedPerCoin: coinPubs.map(() => false),
|
||||||
|
// Will be populated later
|
||||||
|
oldAmountPerCoin: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let coinIdx = 0; coinIdx < coinPubs.length; coinIdx++) {
|
for (let coinIdx = 0; coinIdx < coinPubs.length; coinIdx++) {
|
||||||
@ -346,6 +353,7 @@ export async function createRecoupGroup(
|
|||||||
await putGroupAsFinished(tx, recoupGroup, coinIdx);
|
await putGroupAsFinished(tx, recoupGroup, coinIdx);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
recoupGroup.oldAmountPerCoin[coinIdx] = coin.currentAmount;
|
||||||
coin.currentAmount = Amounts.getZero(coin.currentAmount.currency);
|
coin.currentAmount = Amounts.getZero(coin.currentAmount.currency);
|
||||||
await tx.put(Stores.coins, coin);
|
await tx.put(Stores.coins, coin);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,6 @@ async function refreshCreateSession(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rg.finishedPerCoin[coinIndex] = true;
|
rg.finishedPerCoin[coinIndex] = true;
|
||||||
rg.finishedPerCoin[coinIndex] = true;
|
|
||||||
let allDone = true;
|
let allDone = true;
|
||||||
for (const f of rg.finishedPerCoin) {
|
for (const f of rg.finishedPerCoin) {
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
@ -1397,6 +1397,8 @@ export interface RecoupGroupRecord {
|
|||||||
*/
|
*/
|
||||||
recoupFinishedPerCoin: boolean[];
|
recoupFinishedPerCoin: boolean[];
|
||||||
|
|
||||||
|
oldAmountPerCoin: AmountJson[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retry info.
|
* Retry info.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user