diff options
Diffstat (limited to 'packages/taler-wallet-core/src/db.ts')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 118 |
1 files changed, 80 insertions, 38 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 9bf9a29cc..cebe3635b 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -28,7 +28,6 @@ import { } from "@gnu-taler/idb-bridge"; import { AgeCommitmentProof, - AmountJson, AmountString, Amounts, AttentionInfo, @@ -45,12 +44,8 @@ import { ExchangeAuditor, ExchangeGlobalFees, HashCodeString, - InternationalizedString, Logger, - MerchantContractTerms, - MerchantInfo, PayCoinSelection, - PeerContractTerms, RefreshReason, TalerErrorDetail, TalerPreciseTimestamp, @@ -151,6 +146,53 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName"; */ export const WALLET_DB_MINOR_VERSION = 1; +declare const symDbProtocolTimestamp: unique symbol; + +declare const symDbPreciseTimestamp: unique symbol; + +/** + * Timestamp, stored as microseconds. + * + * Always rounded to a full second. + */ +export type DbProtocolTimestamp = number & { [symDbProtocolTimestamp]: true }; + +/** + * Timestamp, stored as microseconds. + */ +export type DbPreciseTimestamp = number & { [symDbPreciseTimestamp]: true }; + +const DB_TIMESTAMP_FOREVER = Number.MAX_SAFE_INTEGER; + +export function timestampPreciseFromDb( + dbTs: DbPreciseTimestamp, +): TalerPreciseTimestamp { + return TalerPreciseTimestamp.fromMilliseconds(Math.floor(dbTs / 1000)); +} + +export function timestampOptionalPreciseFromDb( + dbTs: DbPreciseTimestamp | undefined, +): TalerPreciseTimestamp | undefined { + if (!dbTs) { + return undefined; + } + return TalerPreciseTimestamp.fromMilliseconds(Math.floor(dbTs / 1000)); +} + +export function timestampPreciseToDb( + stamp: TalerPreciseTimestamp, +): DbPreciseTimestamp { + if (stamp.t_s === "never") { + return DB_TIMESTAMP_FOREVER as DbPreciseTimestamp; + } else { + let tUs = stamp.t_s * 1000000; + if (stamp.off_us) { + tUs == stamp.off_us; + } + return tUs as DbPreciseTimestamp; + } +} + /** * Format of the operation status code: 0x0abc_nnnn @@ -217,7 +259,7 @@ export enum WithdrawalGroupStatus { * Exchange is doing AML checks. */ PendingAml = 0x0100_0006, - SuspendedAml = 0x0100_0006, + SuspendedAml = 0x0110_0006, /** * The corresponding withdraw record has been created. @@ -268,14 +310,14 @@ export interface ReserveBankInfo { * * Set to undefined if that hasn't happened yet. */ - timestampReserveInfoPosted: TalerPreciseTimestamp | undefined; + timestampReserveInfoPosted: DbPreciseTimestamp | undefined; /** * Time when the reserve was confirmed by the bank. * * Set to undefined if not confirmed yet. */ - timestampBankConfirmed: TalerPreciseTimestamp | undefined; + timestampBankConfirmed: DbPreciseTimestamp | undefined; } /** @@ -488,7 +530,7 @@ export interface ExchangeDetailsRecord { tosAccepted: | { etag: string; - timestamp: TalerPreciseTimestamp; + timestamp: DbPreciseTimestamp; } | undefined; @@ -528,7 +570,7 @@ export interface ExchangeDetailsPointer { * Timestamp when the (masterPublicKey, currency) pointer * has been updated. */ - updateClock: TalerPreciseTimestamp; + updateClock: DbPreciseTimestamp; } export enum ExchangeEntryDbRecordStatus { @@ -567,7 +609,7 @@ export interface ExchangeEntryRecord { * * Used mostly in the UI to suggest exchanges. */ - lastWithdrawal?: TalerPreciseTimestamp; + lastWithdrawal?: DbPreciseTimestamp; /** * Pointer to the current exchange details. @@ -588,7 +630,7 @@ export interface ExchangeEntryRecord { /** * Last time when the exchange /keys info was updated. */ - lastUpdate: TalerPreciseTimestamp | undefined; + lastUpdate: DbPreciseTimestamp | undefined; /** * Next scheduled update for the exchange. @@ -816,7 +858,7 @@ export interface RewardRecord { * Has the user accepted the tip? Only after the tip has been accepted coins * withdrawn from the tip may be used. */ - acceptedTimestamp: TalerPreciseTimestamp | undefined; + acceptedTimestamp: DbPreciseTimestamp | undefined; /** * The tipped amount. @@ -869,7 +911,7 @@ export interface RewardRecord { */ merchantRewardId: string; - createdTimestamp: TalerPreciseTimestamp; + createdTimestamp: DbPreciseTimestamp; /** * The url to be redirected after the tip is accepted. @@ -880,7 +922,7 @@ export interface RewardRecord { * Timestamp for when the wallet finished picking up the tip * from the merchant. */ - pickedUpTimestamp: TalerPreciseTimestamp | undefined; + pickedUpTimestamp: DbPreciseTimestamp | undefined; status: RewardRecordStatus; } @@ -978,12 +1020,12 @@ export interface RefreshGroupRecord { */ statusPerCoin: RefreshCoinStatus[]; - timestampCreated: TalerPreciseTimestamp; + timestampCreated: DbPreciseTimestamp; /** * Timestamp when the refresh session finished. */ - timestampFinished: TalerPreciseTimestamp | undefined; + timestampFinished: DbPreciseTimestamp | undefined; } /** @@ -1208,7 +1250,7 @@ export interface PurchaseRecord { * Timestamp of the first time that sending a payment to the merchant * for this purchase was successful. */ - timestampFirstSuccessfulPay: TalerPreciseTimestamp | undefined; + timestampFirstSuccessfulPay: DbPreciseTimestamp | undefined; merchantPaySig: string | undefined; @@ -1223,19 +1265,19 @@ export interface PurchaseRecord { /** * When was the purchase record created? */ - timestamp: TalerPreciseTimestamp; + timestamp: DbPreciseTimestamp; /** * When was the purchase made? * Refers to the time that the user accepted. */ - timestampAccept: TalerPreciseTimestamp | undefined; + timestampAccept: DbPreciseTimestamp | undefined; /** * When was the last refund made? * Set to 0 if no refund was made on the purchase. */ - timestampLastRefundStatus: TalerPreciseTimestamp | undefined; + timestampLastRefundStatus: DbPreciseTimestamp | undefined; /** * Last session signature that we submitted to /pay (if any). @@ -1285,12 +1327,12 @@ export interface WalletBackupConfState { /** * Timestamp stored in the last backup. */ - lastBackupTimestamp?: TalerPreciseTimestamp; + lastBackupTimestamp?: DbPreciseTimestamp; /** * Last time we tried to do a backup. */ - lastBackupCheckTimestamp?: TalerPreciseTimestamp; + lastBackupCheckTimestamp?: DbPreciseTimestamp; lastBackupNonce?: string; } @@ -1398,12 +1440,12 @@ export interface WithdrawalGroupRecord { * When was the withdrawal operation started started? * Timestamp in milliseconds. */ - timestampStart: TalerPreciseTimestamp; + timestampStart: DbPreciseTimestamp; /** * When was the withdrawal operation completed? */ - timestampFinish?: TalerPreciseTimestamp; + timestampFinish?: DbPreciseTimestamp; /** * Current status of the reserve. @@ -1494,9 +1536,9 @@ export interface RecoupGroupRecord { exchangeBaseUrl: string; - timestampStarted: TalerPreciseTimestamp; + timestampStarted: DbPreciseTimestamp; - timestampFinished: TalerPreciseTimestamp | undefined; + timestampFinished: DbPreciseTimestamp | undefined; /** * Public keys that identify the coins being recouped @@ -1530,7 +1572,7 @@ export type BackupProviderState = } | { tag: BackupProviderStateTag.Ready; - nextBackupTimestamp: TalerPreciseTimestamp; + nextBackupTimestamp: DbPreciseTimestamp; } | { tag: BackupProviderStateTag.Retrying; @@ -1575,7 +1617,7 @@ export interface BackupProviderRecord { * Does NOT correspond to the timestamp of the backup, * which only changes when the backup content changes. */ - lastBackupCycleTimestamp?: TalerPreciseTimestamp; + lastBackupCycleTimestamp?: DbPreciseTimestamp; /** * Proposal that we're currently trying to pay for. @@ -1678,9 +1720,9 @@ export interface DepositGroupRecord { */ counterpartyEffectiveDepositAmount: AmountString; - timestampCreated: TalerPreciseTimestamp; + timestampCreated: DbPreciseTimestamp; - timestampFinished: TalerPreciseTimestamp | undefined; + timestampFinished: DbPreciseTimestamp | undefined; operationStatus: DepositOperationStatus; @@ -1791,7 +1833,7 @@ export interface PeerPushDebitRecord { purseExpiration: TalerProtocolTimestamp; - timestampCreated: TalerPreciseTimestamp; + timestampCreated: DbPreciseTimestamp; abortRefreshGroupId?: string; @@ -1864,7 +1906,7 @@ export interface PeerPullCreditRecord { contractEncNonce: string; - mergeTimestamp: TalerPreciseTimestamp; + mergeTimestamp: DbPreciseTimestamp; mergeReserveRowId: number; @@ -1916,7 +1958,7 @@ export interface PeerPushPaymentIncomingRecord { contractPriv: string; - timestamp: TalerPreciseTimestamp; + timestamp: DbPreciseTimestamp; estimatedAmountEffective: AmountString; @@ -1988,7 +2030,7 @@ export interface PeerPullPaymentIncomingRecord { contractTermsHash: string; - timestampCreated: TalerPreciseTimestamp; + timestampCreated: DbPreciseTimestamp; /** * Contract priv that we got from the other party. @@ -2095,7 +2137,7 @@ export interface UserAttentionRecord { /** * When the user mark this notification as read. */ - read: TalerPreciseTimestamp | undefined; + read: DbPreciseTimestamp | undefined; } export interface DbExchangeHandle { @@ -2139,7 +2181,7 @@ export interface RefundGroupRecord { /** * Timestamp when the refund group was created. */ - timestampCreated: TalerPreciseTimestamp; + timestampCreated: DbPreciseTimestamp; proposalId: string; @@ -2196,7 +2238,7 @@ export interface RefundItemRecord { /** * Time when the wallet became aware of the refund. */ - obtainedTime: TalerPreciseTimestamp; + obtainedTime: DbPreciseTimestamp; refundAmount: AmountString; |