aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/common.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/common.ts
parent35611f0bf9cf67638b171c2a300fab1797d3d8f0 (diff)
parent97d7be7503168f4f3bbd05905d32aa76ca1636b2 (diff)
Merge branch 'master' into age-withdraw
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts47
1 files changed, 26 insertions, 21 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index 50dd3dc5c..b28a5363d 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -40,6 +40,7 @@ import {
TalerError,
TalerErrorCode,
TalerErrorDetail,
+ TalerPreciseTimestamp,
TombstoneIdStr,
TransactionIdStr,
TransactionType,
@@ -49,6 +50,7 @@ import { CryptoApiStoppedError } from "../crypto/workers/crypto-dispatcher.js";
import {
BackupProviderRecord,
CoinRecord,
+ DbPreciseTimestamp,
DepositGroupRecord,
ExchangeDetailsRecord,
ExchangeEntryDbRecordStatus,
@@ -62,6 +64,7 @@ import {
RecoupGroupRecord,
RefreshGroupRecord,
RewardRecord,
+ timestampPreciseToDb,
WalletStoresV1,
WithdrawalGroupRecord,
} from "../db.js";
@@ -360,11 +363,11 @@ async function storePendingTaskError(
retryRecord = {
id: pendingTaskId,
lastError: e,
- retryInfo: RetryInfo.reset(),
+ retryInfo: DbRetryInfo.reset(),
};
} else {
retryRecord.lastError = e;
- retryRecord.retryInfo = RetryInfo.increment(retryRecord.retryInfo);
+ retryRecord.retryInfo = DbRetryInfo.increment(retryRecord.retryInfo);
}
await tx.operationRetries.put(retryRecord);
return taskToTransactionNotification(ws, tx, pendingTaskId, e);
@@ -383,7 +386,7 @@ export async function resetPendingTaskTimeout(
if (retryRecord) {
// Note that we don't reset the lastError, it should still be visible
// while the retry runs.
- retryRecord.retryInfo = RetryInfo.reset();
+ retryRecord.retryInfo = DbRetryInfo.reset();
await tx.operationRetries.put(retryRecord);
}
return taskToTransactionNotification(ws, tx, pendingTaskId, undefined);
@@ -403,14 +406,14 @@ async function storePendingTaskPending(
if (!retryRecord) {
retryRecord = {
id: pendingTaskId,
- retryInfo: RetryInfo.reset(),
+ retryInfo: DbRetryInfo.reset(),
};
} else {
if (retryRecord.lastError) {
hadError = true;
}
delete retryRecord.lastError;
- retryRecord.retryInfo = RetryInfo.increment(retryRecord.retryInfo);
+ retryRecord.retryInfo = DbRetryInfo.increment(retryRecord.retryInfo);
}
await tx.operationRetries.put(retryRecord);
if (hadError) {
@@ -590,7 +593,7 @@ export function makeExchangeListItem(
return {
exchangeBaseUrl: r.baseUrl,
- currency: exchangeDetails?.currency,
+ currency: exchangeDetails?.currency ?? r.presetCurrencyHint,
exchangeUpdateStatus,
exchangeEntryStatus,
tosStatus: exchangeDetails
@@ -736,9 +739,9 @@ export interface TaskRunLongpollResult {
type: TaskRunResultType.Longpoll;
}
-export interface RetryInfo {
- firstTry: AbsoluteTime;
- nextRetry: AbsoluteTime;
+export interface DbRetryInfo {
+ firstTry: DbPreciseTimestamp;
+ nextRetry: DbPreciseTimestamp;
retryCounter: number;
}
@@ -755,7 +758,7 @@ const defaultRetryPolicy: RetryPolicy = {
};
function updateTimeout(
- r: RetryInfo,
+ r: DbRetryInfo,
p: RetryPolicy = defaultRetryPolicy,
): void {
const now = AbsoluteTime.now();
@@ -763,7 +766,9 @@ function updateTimeout(
throw Error("assertion failed");
}
if (p.backoffDelta.d_ms === "forever") {
- r.nextRetry = AbsoluteTime.never();
+ r.nextRetry = timestampPreciseToDb(
+ AbsoluteTime.toPreciseTimestamp(AbsoluteTime.never()),
+ );
return;
}
@@ -775,12 +780,12 @@ function updateTimeout(
(p.maxTimeout.d_ms === "forever"
? nextIncrement
: Math.min(p.maxTimeout.d_ms, nextIncrement));
- r.nextRetry = AbsoluteTime.fromMilliseconds(t);
+ r.nextRetry = timestampPreciseToDb(TalerPreciseTimestamp.fromMilliseconds(t));
}
-export namespace RetryInfo {
+export namespace DbRetryInfo {
export function getDuration(
- r: RetryInfo | undefined,
+ r: DbRetryInfo | undefined,
p: RetryPolicy = defaultRetryPolicy,
): Duration {
if (!r) {
@@ -797,11 +802,11 @@ export namespace RetryInfo {
};
}
- export function reset(p: RetryPolicy = defaultRetryPolicy): RetryInfo {
- const now = AbsoluteTime.now();
- const info = {
- firstTry: now,
- nextRetry: now,
+ export function reset(p: RetryPolicy = defaultRetryPolicy): DbRetryInfo {
+ const now = TalerPreciseTimestamp.now();
+ const info: DbRetryInfo = {
+ firstTry: timestampPreciseToDb(now),
+ nextRetry: timestampPreciseToDb(now),
retryCounter: 0,
};
updateTimeout(info, p);
@@ -809,9 +814,9 @@ export namespace RetryInfo {
}
export function increment(
- r: RetryInfo | undefined,
+ r: DbRetryInfo | undefined,
p: RetryPolicy = defaultRetryPolicy,
- ): RetryInfo {
+ ): DbRetryInfo {
if (!r) {
return reset(p);
}