aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pending.ts
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-10-06 16:33:05 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-10-06 16:33:05 +0200
commitfe7b51ef2736edbf04f5bbd9d19f2a2d04baccc2 (patch)
tree66c68c8d6a666f6e74dc663c9ee4f07879f6626c /packages/taler-wallet-core/src/operations/pending.ts
parent35611f0bf9cf67638b171c2a300fab1797d3d8f0 (diff)
parent97d7be7503168f4f3bbd05905d32aa76ca1636b2 (diff)
Merge branch 'master' into age-withdraw
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pending.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pending.ts112
1 files changed, 71 insertions, 41 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts
index 6115f848b..1819aa1b8 100644
--- a/packages/taler-wallet-core/src/operations/pending.ts
+++ b/packages/taler-wallet-core/src/operations/pending.ts
@@ -21,42 +21,46 @@
/**
* Imports.
*/
+import { GlobalIDB } from "@gnu-taler/idb-bridge";
+import { AbsoluteTime, TransactionRecordFilter } from "@gnu-taler/taler-util";
import {
- PurchaseStatus,
- WalletStoresV1,
BackupProviderStateTag,
- RefreshCoinStatus,
- PeerPushDebitStatus,
- PeerPullDebitRecordStatus,
- PeerPushCreditStatus,
- PeerPullPaymentCreditStatus,
- WithdrawalGroupStatus,
- RewardRecordStatus,
- DepositOperationStatus,
- RefreshGroupRecord,
- WithdrawalGroupRecord,
+ DepositElementStatus,
DepositGroupRecord,
- RewardRecord,
- PurchaseRecord,
+ DepositOperationStatus,
+ ExchangeEntryDbUpdateStatus,
PeerPullCreditRecord,
+ PeerPullDebitRecordStatus,
+ PeerPullPaymentCreditStatus,
PeerPullPaymentIncomingRecord,
+ PeerPushCreditStatus,
PeerPushDebitRecord,
+ PeerPushDebitStatus,
PeerPushPaymentIncomingRecord,
+ PurchaseRecord,
+ PurchaseStatus,
+ RefreshCoinStatus,
+ RefreshGroupRecord,
+ RefreshOperationStatus,
RefundGroupRecord,
RefundGroupStatus,
- ExchangeEntryDbUpdateStatus,
- RefreshOperationStatus,
- DepositElementStatus,
+ RewardRecord,
+ RewardRecordStatus,
+ WalletStoresV1,
+ WithdrawalGroupRecord,
+ WithdrawalGroupStatus,
+ timestampAbsoluteFromDb,
+ timestampOptionalAbsoluteFromDb,
+ timestampPreciseFromDb,
+ timestampPreciseToDb,
} from "../db.js";
+import { InternalWalletState } from "../internal-wallet-state.js";
import {
PendingOperationsResponse,
PendingTaskType,
TaskId,
} from "../pending-types.js";
-import { AbsoluteTime, TransactionRecordFilter } from "@gnu-taler/taler-util";
-import { InternalWalletState } from "../internal-wallet-state.js";
import { GetReadOnlyAccess } from "../util/query.js";
-import { GlobalIDB } from "@gnu-taler/idb-bridge";
import { TaskIdentifiers } from "./common.js";
function getPendingCommon(
@@ -99,12 +103,14 @@ async function gatherExchangePending(
}
const opTag = TaskIdentifiers.forExchangeUpdate(exch);
let opr = await tx.operationRetries.get(opTag);
- const timestampDue =
- opr?.retryInfo.nextRetry ??
- AbsoluteTime.fromStampMs(exch.nextUpdateStampMs);
+ const timestampDue = opr?.retryInfo.nextRetry ?? exch.nextRefreshCheckStamp;
resp.pendingOperations.push({
type: PendingTaskType.ExchangeUpdate,
- ...getPendingCommon(ws, opTag, timestampDue),
+ ...getPendingCommon(
+ ws,
+ opTag,
+ AbsoluteTime.fromPreciseTimestamp(timestampPreciseFromDb(timestampDue)),
+ ),
givesLifeness: false,
exchangeBaseUrl: exch.baseUrl,
lastError: opr?.lastError,
@@ -115,8 +121,16 @@ async function gatherExchangePending(
if (!opr?.lastError) {
resp.pendingOperations.push({
type: PendingTaskType.ExchangeCheckRefresh,
- ...getPendingCommon(ws, opTag, timestampDue),
- timestampDue: AbsoluteTime.fromStampMs(exch.nextRefreshCheckStampMs),
+ ...getPendingCommon(
+ ws,
+ opTag,
+ AbsoluteTime.fromPreciseTimestamp(
+ timestampPreciseFromDb(timestampDue),
+ ),
+ ),
+ timestampDue: AbsoluteTime.fromPreciseTimestamp(
+ timestampPreciseFromDb(exch.nextRefreshCheckStamp),
+ ),
givesLifeness: false,
exchangeBaseUrl: exch.baseUrl,
});
@@ -165,7 +179,9 @@ async function gatherRefreshPending(
}
const opId = TaskIdentifiers.forRefresh(r);
const retryRecord = await tx.operationRetries.get(opId);
- const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ const timestampDue =
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.Refresh,
...getPendingCommon(ws, opId, timestampDue),
@@ -222,8 +238,8 @@ async function gatherWithdrawalPending(
opr = {
id: opTag,
retryInfo: {
- firstTry: now,
- nextRetry: now,
+ firstTry: timestampPreciseToDb(AbsoluteTime.toPreciseTimestamp(now)),
+ nextRetry: timestampPreciseToDb(AbsoluteTime.toPreciseTimestamp(now)),
retryCounter: 0,
},
};
@@ -233,7 +249,8 @@ async function gatherWithdrawalPending(
...getPendingCommon(
ws,
opTag,
- opr.retryInfo?.nextRetry ?? AbsoluteTime.now(),
+ timestampOptionalAbsoluteFromDb(opr.retryInfo?.nextRetry) ??
+ AbsoluteTime.now(),
),
givesLifeness: true,
withdrawalGroupId: wsr.withdrawalGroupId,
@@ -285,7 +302,9 @@ async function gatherDepositPending(
}
const opId = TaskIdentifiers.forDeposit(dg);
const retryRecord = await tx.operationRetries.get(opId);
- const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ const timestampDue =
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.Deposit,
...getPendingCommon(ws, opId, timestampDue),
@@ -330,13 +349,15 @@ async function gatherRewardPending(
await iterRecordsForReward(tx, { onlyState: "nonfinal" }, async (tip) => {
const opId = TaskIdentifiers.forTipPickup(tip);
const retryRecord = await tx.operationRetries.get(opId);
- const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ const timestampDue =
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
if (tip.acceptedTimestamp) {
resp.pendingOperations.push({
type: PendingTaskType.RewardPickup,
...getPendingCommon(ws, opId, timestampDue),
givesLifeness: true,
- timestampDue: retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now(),
+ timestampDue,
merchantBaseUrl: tip.merchantBaseUrl,
tipId: tip.walletRewardId,
merchantTipId: tip.merchantRewardId,
@@ -390,7 +411,9 @@ async function gatherPurchasePending(
await iterRecordsForPurchase(tx, { onlyState: "nonfinal" }, async (pr) => {
const opId = TaskIdentifiers.forPay(pr);
const retryRecord = await tx.operationRetries.get(opId);
- const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ const timestampDue =
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.Purchase,
...getPendingCommon(ws, opId, timestampDue),
@@ -419,7 +442,9 @@ async function gatherRecoupPending(
}
const opId = TaskIdentifiers.forRecoup(rg);
const retryRecord = await tx.operationRetries.get(opId);
- const timestampDue = retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ const timestampDue =
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.Recoup,
...getPendingCommon(ws, opId, timestampDue),
@@ -444,7 +469,7 @@ async function gatherBackupPending(
const opId = TaskIdentifiers.forBackup(bp);
const retryRecord = await tx.operationRetries.get(opId);
if (bp.state.tag === BackupProviderStateTag.Ready) {
- const timestampDue = AbsoluteTime.fromPreciseTimestamp(
+ const timestampDue = timestampAbsoluteFromDb(
bp.state.nextBackupTimestamp,
);
resp.pendingOperations.push({
@@ -456,7 +481,8 @@ async function gatherBackupPending(
});
} else if (bp.state.tag === BackupProviderStateTag.Retrying) {
const timestampDue =
- retryRecord?.retryInfo?.nextRetry ?? AbsoluteTime.now();
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo?.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.Backup,
...getPendingCommon(ws, opId, timestampDue),
@@ -503,7 +529,8 @@ async function gatherPeerPullInitiationPending(
const opId = TaskIdentifiers.forPeerPullPaymentInitiation(pi);
const retryRecord = await tx.operationRetries.get(opId);
const timestampDue =
- retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.PeerPullCredit,
...getPendingCommon(ws, opId, timestampDue),
@@ -549,7 +576,8 @@ async function gatherPeerPullDebitPending(
const opId = TaskIdentifiers.forPeerPullPaymentDebit(pi);
const retryRecord = await tx.operationRetries.get(opId);
const timestampDue =
- retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.PeerPullDebit,
...getPendingCommon(ws, opId, timestampDue),
@@ -595,7 +623,8 @@ async function gatherPeerPushInitiationPending(
const opId = TaskIdentifiers.forPeerPushPaymentInitiation(pi);
const retryRecord = await tx.operationRetries.get(opId);
const timestampDue =
- retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.PeerPushDebit,
...getPendingCommon(ws, opId, timestampDue),
@@ -645,7 +674,8 @@ async function gatherPeerPushCreditPending(
const opId = TaskIdentifiers.forPeerPushCredit(pi);
const retryRecord = await tx.operationRetries.get(opId);
const timestampDue =
- retryRecord?.retryInfo.nextRetry ?? AbsoluteTime.now();
+ timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
+ AbsoluteTime.now();
resp.pendingOperations.push({
type: PendingTaskType.PeerPushCredit,
...getPendingCommon(ws, opId, timestampDue),