summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-01-14 17:24:44 +0100
committerFlorian Dold <florian@dold.me>2021-01-14 17:24:44 +0100
commit6293de7bfa4d8a52091b251e2333e9710ce1b22a (patch)
tree79fa71811fff50886568fcd4a5f5d9406565e9d9 /packages/taler-wallet-core/src/operations
parent657c4b6377d405640d353a8c5e15dbb6ac59800b (diff)
downloadwallet-core-6293de7bfa4d8a52091b251e2333e9710ce1b22a.tar.gz
wallet-core-6293de7bfa4d8a52091b251e2333e9710ce1b22a.tar.bz2
wallet-core-6293de7bfa4d8a52091b251e2333e9710ce1b22a.zip
fix reserve state machine bug, use simpler denominations in revocation test
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r--packages/taler-wallet-core/src/operations/recoup.ts10
-rw-r--r--packages/taler-wallet-core/src/operations/reserves.ts67
2 files changed, 48 insertions, 29 deletions
diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts
index 7bbac8a99..f6b29536b 100644
--- a/packages/taler-wallet-core/src/operations/recoup.ts
+++ b/packages/taler-wallet-core/src/operations/recoup.ts
@@ -83,6 +83,9 @@ async function putGroupAsFinished(
recoupGroup: RecoupGroupRecord,
coinIdx: number,
): Promise<void> {
+ logger.trace(
+ `setting coin ${coinIdx} of ${recoupGroup.coinPubs.length} as finished`,
+ );
if (recoupGroup.timestampFinished) {
return;
}
@@ -94,6 +97,7 @@ async function putGroupAsFinished(
}
}
if (allFinished) {
+ logger.trace("all recoups of recoup group are finished");
recoupGroup.timestampFinished = getTimestampNow();
recoupGroup.retryInfo = initRetryInfo(false);
recoupGroup.lastError = undefined;
@@ -230,7 +234,7 @@ async function recoupRefreshCoin(
const recoupRequest = await ws.cryptoApi.createRecoupRequest(coin);
const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, coin.exchangeBaseUrl);
- logger.trace("making recoup request");
+ logger.trace(`making recoup request for ${coin.coinPub}`);
const resp = await ws.http.postJson(reqUrl.href, recoupRequest);
const recoupConfirmation = await readSuccessResponseJsonOrThrow(
@@ -244,12 +248,14 @@ async function recoupRefreshCoin(
const exchange = await ws.db.get(Stores.exchanges, coin.exchangeBaseUrl);
if (!exchange) {
+ logger.warn("exchange for recoup does not exist anymore");
// FIXME: report inconsistency?
return;
}
const exchangeDetails = exchange.details;
if (!exchangeDetails) {
// FIXME: report inconsistency?
+ logger.warn("exchange details for recoup not found");
return;
}
@@ -272,9 +278,11 @@ async function recoupRefreshCoin(
const oldCoin = await tx.get(Stores.coins, cs.oldCoinPub);
const revokedCoin = await tx.get(Stores.coins, coin.coinPub);
if (!revokedCoin) {
+ logger.warn("revoked coin for recoup not found");
return;
}
if (!oldCoin) {
+ logger.warn("refresh old coin for recoup not found");
return;
}
revokedCoin.status = CoinStatus.Dormant;
diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts
index 4e4db1fc9..7c878668f 100644
--- a/packages/taler-wallet-core/src/operations/reserves.ts
+++ b/packages/taler-wallet-core/src/operations/reserves.ts
@@ -604,37 +604,50 @@ async function updateReserve(
denoms,
);
- if (denomSelInfo.selectedDenoms.length > 0) {
- let withdrawalGroupId: string;
-
- if (!newReserve.initialWithdrawalStarted) {
- withdrawalGroupId = newReserve.initialWithdrawalGroupId;
- newReserve.initialWithdrawalStarted = true;
- } else {
- withdrawalGroupId = encodeCrock(randomBytes(32));
- }
-
- const withdrawalRecord: WithdrawalGroupRecord = {
- withdrawalGroupId: withdrawalGroupId,
- exchangeBaseUrl: reserve.exchangeBaseUrl,
- reservePub: reserve.reservePub,
- rawWithdrawalAmount: remainingAmount,
- timestampStart: getTimestampNow(),
- retryInfo: initRetryInfo(),
- lastError: undefined,
- denomsSel: denomSelectionInfoToState(denomSelInfo),
- secretSeed: encodeCrock(getRandomBytes(64)),
- };
+ logger.trace(
+ `Remaining unclaimed amount in reseve is ${Amounts.stringify(
+ remainingAmount,
+ )} and can be withdrawn with ${
+ denomSelInfo.selectedDenoms.length
+ } coins`,
+ );
+ if (denomSelInfo.selectedDenoms.length === 0) {
+ newReserve.reserveStatus = ReserveRecordStatus.DORMANT;
newReserve.lastError = undefined;
newReserve.retryInfo = initRetryInfo(false);
- newReserve.reserveStatus = ReserveRecordStatus.DORMANT;
-
await tx.put(Stores.reserves, newReserve);
- await tx.put(Stores.withdrawalGroups, withdrawalRecord);
- return withdrawalRecord;
+ return;
}
- return;
+
+ let withdrawalGroupId: string;
+
+ if (!newReserve.initialWithdrawalStarted) {
+ withdrawalGroupId = newReserve.initialWithdrawalGroupId;
+ newReserve.initialWithdrawalStarted = true;
+ } else {
+ withdrawalGroupId = encodeCrock(randomBytes(32));
+ }
+
+ const withdrawalRecord: WithdrawalGroupRecord = {
+ withdrawalGroupId: withdrawalGroupId,
+ exchangeBaseUrl: reserve.exchangeBaseUrl,
+ reservePub: reserve.reservePub,
+ rawWithdrawalAmount: remainingAmount,
+ timestampStart: getTimestampNow(),
+ retryInfo: initRetryInfo(),
+ lastError: undefined,
+ denomsSel: denomSelectionInfoToState(denomSelInfo),
+ secretSeed: encodeCrock(getRandomBytes(64)),
+ };
+
+ newReserve.lastError = undefined;
+ newReserve.retryInfo = initRetryInfo(false);
+ newReserve.reserveStatus = ReserveRecordStatus.DORMANT;
+
+ await tx.put(Stores.reserves, newReserve);
+ await tx.put(Stores.withdrawalGroups, withdrawalRecord);
+ return withdrawalRecord;
},
);
@@ -645,8 +658,6 @@ async function updateReserve(
withdrawalGroupId: newWithdrawalGroup.withdrawalGroupId,
});
await processWithdrawGroup(ws, newWithdrawalGroup.withdrawalGroupId);
- } else {
- console.trace("withdraw session already existed");
}
return { ready: true };