diff options
author | Florian Dold <florian@dold.me> | 2023-08-30 15:54:56 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-08-30 15:54:56 +0200 |
commit | d19aef746c1e67deaccc7c8cefba008f2f0d46ca (patch) | |
tree | 26ee3734f6be8a418dc734761bdb48fc14dbafaf /packages/taler-wallet-core/src/operations/exchanges.ts | |
parent | 88f7338d7c84ac2a774b483ccff25faf6ceeb879 (diff) | |
download | wallet-core-d19aef746c1e67deaccc7c8cefba008f2f0d46ca.tar.xz |
wallet-core: towards DD48
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index c6b46e360..311a71a6e 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -32,6 +32,7 @@ import { encodeCrock, ExchangeAuditor, ExchangeDenomination, + ExchangeEntryStatus, ExchangeGlobalFees, ExchangeSignKeyJson, ExchangeWireJson, @@ -66,10 +67,15 @@ import { DenominationRecord, DenominationVerificationStatus, ExchangeDetailsRecord, - ExchangeRecord, + ExchangeEntryRecord, WalletStoresV1, } from "../db.js"; -import { isWithdrawableDenom } from "../index.js"; +import { + ExchangeEntryDbRecordStatus, + ExchangeEntryDbUpdateStatus, + isWithdrawableDenom, + WalletDbReadWriteTransaction, +} from "../index.js"; import { InternalWalletState, TrustInfo } from "../internal-wallet-state.js"; import { checkDbInvariant } from "../util/invariants.js"; import { @@ -326,6 +332,26 @@ export async function downloadExchangeInfo( }; } +export async function addPresetExchangeEntry( + tx: WalletDbReadWriteTransaction<"exchanges">, + exchangeBaseUrl: string, +): Promise<void> { + let exchange = await tx.exchanges.get(exchangeBaseUrl); + if (!exchange) { + const r: ExchangeEntryRecord = { + entryStatus: ExchangeEntryDbRecordStatus.Preset, + updateStatus: ExchangeEntryDbUpdateStatus.Initial, + baseUrl: exchangeBaseUrl, + detailsPointer: undefined, + lastUpdate: undefined, + lastKeysEtag: undefined, + nextRefreshCheckStampMs: AbsoluteTime.getStampMsNever(), + nextUpdateStampMs: AbsoluteTime.getStampMsNever(), + }; + await tx.exchanges.put(r); + } +} + export async function provideExchangeRecordInTx( ws: InternalWalletState, tx: GetReadWriteAccess<{ @@ -335,20 +361,20 @@ export async function provideExchangeRecordInTx( baseUrl: string, now: AbsoluteTime, ): Promise<{ - exchange: ExchangeRecord; + exchange: ExchangeEntryRecord; exchangeDetails: ExchangeDetailsRecord | undefined; }> { let exchange = await tx.exchanges.get(baseUrl); if (!exchange) { - const r: ExchangeRecord = { - permanent: true, + const r: ExchangeEntryRecord = { + entryStatus: ExchangeEntryDbRecordStatus.Ephemeral, + updateStatus: ExchangeEntryDbUpdateStatus.InitialUpdate, baseUrl: baseUrl, detailsPointer: undefined, lastUpdate: undefined, - nextUpdate: AbsoluteTime.toPreciseTimestamp(now), - nextRefreshCheck: AbsoluteTime.toPreciseTimestamp(now), + nextUpdateStampMs: AbsoluteTime.getStampMsNever(), + nextRefreshCheckStampMs: AbsoluteTime.getStampMsNever(), lastKeysEtag: undefined, - lastWireEtag: undefined, }; await tx.exchanges.put(r); exchange = r; @@ -534,6 +560,10 @@ export async function downloadTosFromAcceptedFormat( ); } +/** + * FIXME: Split this into two parts: (a) triggering the exchange + * to be updated and (b) waiting for the update to finish. + */ export async function updateExchangeFromUrl( ws: InternalWalletState, baseUrl: string, @@ -543,7 +573,7 @@ export async function updateExchangeFromUrl( cancellationToken?: CancellationToken; } = {}, ): Promise<{ - exchange: ExchangeRecord; + exchange: ExchangeEntryRecord; exchangeDetails: ExchangeDetailsRecord; }> { const canonUrl = canonicalizeBaseUrl(baseUrl); @@ -613,7 +643,7 @@ export async function updateExchangeFromUrlHandler( !forceNow && exchangeDetails !== undefined && !AbsoluteTime.isExpired( - AbsoluteTime.fromPreciseTimestamp(exchange.nextUpdate), + AbsoluteTime.fromStampMs(exchange.nextUpdateStampMs), ) ) { logger.trace("using existing exchange info"); @@ -755,11 +785,11 @@ export async function updateExchangeFromUrlHandler( newDetails.rowId = existingDetails.rowId; } r.lastUpdate = TalerPreciseTimestamp.now(); - r.nextUpdate = AbsoluteTime.toPreciseTimestamp( + r.nextUpdateStampMs = AbsoluteTime.toStampMs( AbsoluteTime.fromProtocolTimestamp(keysInfo.expiry), ); // New denominations might be available. - r.nextRefreshCheck = TalerPreciseTimestamp.now(); + r.nextRefreshCheckStampMs = AbsoluteTime.getStampMsNow(); if (detailsPointerChanged) { r.detailsPointer = { currency: newDetails.currency, @@ -948,7 +978,7 @@ export async function getExchangePaytoUri( */ export async function getExchangeTrust( ws: InternalWalletState, - exchangeInfo: ExchangeRecord, + exchangeInfo: ExchangeEntryRecord, ): Promise<TrustInfo> { let isTrusted = false; let isAudited = false; |