do not apply the same refresh twice
This commit is contained in:
parent
5e77b222d5
commit
e124e05d53
@ -238,7 +238,7 @@ async function refreshMelt(
|
|||||||
rc: refreshSession.hash,
|
rc: refreshSession.hash,
|
||||||
value_with_fee: Amounts.toString(refreshSession.amountRefreshInput),
|
value_with_fee: Amounts.toString(refreshSession.amountRefreshInput),
|
||||||
};
|
};
|
||||||
logger.trace("melt request:", meltReq);
|
logger.trace(`melt request for coin:`, meltReq);
|
||||||
const resp = await ws.http.postJson(reqUrl.href, meltReq);
|
const resp = await ws.http.postJson(reqUrl.href, meltReq);
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
console.log(`got status ${resp.status} for refresh/melt`);
|
console.log(`got status ${resp.status} for refresh/melt`);
|
||||||
|
@ -54,6 +54,9 @@ import { randomBytes } from "../crypto/primitives/nacl-fast";
|
|||||||
import { encodeCrock } from "../crypto/talerCrypto";
|
import { encodeCrock } from "../crypto/talerCrypto";
|
||||||
import { HttpResponseStatus } from "../util/http";
|
import { HttpResponseStatus } from "../util/http";
|
||||||
import { getTimestampNow } from "../util/time";
|
import { getTimestampNow } from "../util/time";
|
||||||
|
import { Logger } from "../util/logging";
|
||||||
|
|
||||||
|
const logger = new Logger("refund.ts");
|
||||||
|
|
||||||
async function incrementPurchaseQueryRefundRetry(
|
async function incrementPurchaseQueryRefundRetry(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
@ -468,15 +471,24 @@ async function processPurchaseApplyRefundImpl(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
refreshCoinsMap[c.coinPub] = { coinPub: c.coinPub };
|
refreshCoinsMap[c.coinPub] = { coinPub: c.coinPub };
|
||||||
|
logger.trace(`commiting refund ${perm.merchant_sig} to coin ${c.coinPub}`);
|
||||||
|
logger.trace(`coin amount before is ${Amounts.toString(c.currentAmount)}`)
|
||||||
|
logger.trace(`refund amount (via merchant) is ${perm.refund_amount}`);
|
||||||
|
logger.trace(`refund fee (via merchant) is ${perm.refund_fee}`);
|
||||||
const refundAmount = Amounts.parseOrThrow(perm.refund_amount);
|
const refundAmount = Amounts.parseOrThrow(perm.refund_amount);
|
||||||
const refundFee = Amounts.parseOrThrow(perm.refund_fee);
|
const refundFee = Amounts.parseOrThrow(perm.refund_fee);
|
||||||
c.status = CoinStatus.Dormant;
|
c.status = CoinStatus.Dormant;
|
||||||
c.currentAmount = Amounts.add(c.currentAmount, refundAmount).amount;
|
c.currentAmount = Amounts.add(c.currentAmount, refundAmount).amount;
|
||||||
c.currentAmount = Amounts.sub(c.currentAmount, refundFee).amount;
|
c.currentAmount = Amounts.sub(c.currentAmount, refundFee).amount;
|
||||||
|
logger.trace(`coin amount after is ${Amounts.toString(c.currentAmount)}`)
|
||||||
await tx.put(Stores.coins, c);
|
await tx.put(Stores.coins, c);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const pk of Object.keys(newRefundsFailed)) {
|
for (const pk of Object.keys(newRefundsFailed)) {
|
||||||
|
if (p.refundState.refundsDone[pk]) {
|
||||||
|
// We already processed this one.
|
||||||
|
break;
|
||||||
|
}
|
||||||
const r = newRefundsFailed[pk];
|
const r = newRefundsFailed[pk];
|
||||||
groups[r.refundGroupId] = true;
|
groups[r.refundGroupId] = true;
|
||||||
delete p.refundState.refundsPending[pk];
|
delete p.refundState.refundsPending[pk];
|
||||||
@ -484,6 +496,10 @@ async function processPurchaseApplyRefundImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const pk of Object.keys(newRefundsDone)) {
|
for (const pk of Object.keys(newRefundsDone)) {
|
||||||
|
if (p.refundState.refundsDone[pk]) {
|
||||||
|
// We already processed this one.
|
||||||
|
break;
|
||||||
|
}
|
||||||
const r = newRefundsDone[pk];
|
const r = newRefundsDone[pk];
|
||||||
groups[r.refundGroupId] = true;
|
groups[r.refundGroupId] = true;
|
||||||
delete p.refundState.refundsPending[pk];
|
delete p.refundState.refundsPending[pk];
|
||||||
@ -516,11 +532,15 @@ async function processPurchaseApplyRefundImpl(
|
|||||||
allRefundsProcessed = true;
|
allRefundsProcessed = true;
|
||||||
}
|
}
|
||||||
await tx.put(Stores.purchases, p);
|
await tx.put(Stores.purchases, p);
|
||||||
await createRefreshGroup(
|
const coinsPubsToBeRefreshed = Object.values(refreshCoinsMap);
|
||||||
tx,
|
if (coinsPubsToBeRefreshed.length > 0)
|
||||||
Object.values(refreshCoinsMap),
|
{
|
||||||
RefreshReason.Refund,
|
await createRefreshGroup(
|
||||||
);
|
tx,
|
||||||
|
coinsPubsToBeRefreshed,
|
||||||
|
RefreshReason.Refund,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (allRefundsProcessed) {
|
if (allRefundsProcessed) {
|
||||||
|
Loading…
Reference in New Issue
Block a user