From 02f1d4b08116c24f0af1f32cb6d82be292fa6d10 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 2 Jun 2021 13:23:51 +0200 Subject: support multiple exchange details per base URL --- packages/taler-wallet-core/src/db.ts | 135 +++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 63 deletions(-) (limited to 'packages/taler-wallet-core/src/db.ts') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 0ff34d3c7..c457d0ffc 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -513,26 +513,43 @@ export interface DenominationRecord { exchangeBaseUrl: string; } -/** - * Details about the exchange that we only know after - * querying /keys and /wire. - */ -export interface ExchangeDetails { +export enum ExchangeUpdateStatus { + FetchKeys = "fetch-keys", + FetchWire = "fetch-wire", + FetchTerms = "fetch-terms", + FinalizeUpdate = "finalize-update", + Finished = "finished", +} + +export interface ExchangeBankAccount { + payto_uri: string; + master_sig: string; +} + +export enum ExchangeUpdateReason { + Initial = "initial", + Forced = "forced", + Scheduled = "scheduled", +} + +export interface ExchangeDetailsRecord { /** * Master public key of the exchange. */ masterPublicKey: string; - /** - * Auditors (partially) auditing the exchange. - */ - auditors: Auditor[]; + exchangeBaseUrl: string; /** * Currency that the exchange offers. */ currency: string; + /** + * Auditors (partially) auditing the exchange. + */ + auditors: Auditor[]; + /** * Last observed protocol version. */ @@ -546,6 +563,23 @@ export interface ExchangeDetails { */ signingKeys: ExchangeSignKeyJson[]; + /** + * Terms of service text or undefined if not downloaded yet. + * + * This is just used as a cache of the last downloaded ToS. + */ + termsOfServiceText: string | undefined; + + /** + * ETag for last terms of service download. + */ + termsOfServiceLastEtag: string | undefined; + + /** + * ETag for last terms of service download. + */ + termsOfServiceAcceptedEtag: string | undefined; + /** * Timestamp for last update. */ @@ -555,30 +589,25 @@ export interface ExchangeDetails { * When should we next update the information about the exchange? */ nextUpdateTime: Timestamp; -} -export enum ExchangeUpdateStatus { - FetchKeys = "fetch-keys", - FetchWire = "fetch-wire", - FetchTerms = "fetch-terms", - FinalizeUpdate = "finalize-update", - Finished = "finished", + wireInfo: WireInfo; } -export interface ExchangeBankAccount { - payto_uri: string; - master_sig: string; -} - -export interface ExchangeWireInfo { +export interface WireInfo { feesForType: { [wireMethod: string]: WireFee[] }; + accounts: ExchangeBankAccount[]; } -export enum ExchangeUpdateReason { - Initial = "initial", - Forced = "forced", - Scheduled = "scheduled", +export interface ExchangeDetailsPointer { + masterPublicKey: string; + currency: string; + + /** + * Timestamp when the (masterPublicKey, currency) pointer + * has been updated. + */ + updateClock: Timestamp; } /** @@ -590,48 +619,13 @@ export interface ExchangeRecord { */ baseUrl: string; - /** - * Did we finish adding the exchange? - */ - addComplete: boolean; + detailsPointer: ExchangeDetailsPointer | undefined; /** * Is this a permanent or temporary exchange record? */ permanent: boolean; - /** - * Was the exchange added as a built-in exchange? - */ - builtIn: boolean; - - /** - * Details, once known. - */ - details: ExchangeDetails | undefined; - - /** - * Mapping from wire method type to the wire fee. - */ - wireInfo: ExchangeWireInfo | undefined; - - /** - * Terms of service text or undefined if not downloaded yet. - * - * This is just used as a cache of the last downloaded ToS. - */ - termsOfServiceText: string | undefined; - - /** - * ETag for last terms of service download. - */ - termsOfServiceLastEtag: string | undefined; - - /** - * ETag for last terms of service download. - */ - termsOfServiceAcceptedEtag: string | undefined; - /** * Time when the update to the exchange has been started or * undefined if no update is in progress. @@ -640,6 +634,9 @@ export interface ExchangeRecord { /** * Status of updating the info about the exchange. + * + * FIXME: Adapt this to recent changes regarding how + * updating exchange details works. */ updateStatus: ExchangeUpdateStatus; @@ -1548,7 +1545,7 @@ export interface BackupProviderTerms { export interface BackupProviderRecord { /** * Base URL of the provider. - * + * * Primary key for the record. */ baseUrl: string; @@ -1692,6 +1689,17 @@ class ExchangesStore extends Store<"exchanges", ExchangeRecord> { } } +class ExchangeDetailsStore extends Store< + "exchangeDetails", + ExchangeDetailsRecord +> { + constructor() { + super("exchangeDetails", { + keyPath: ["exchangeBaseUrl", "currency", "masterPublicKey"], + }); + } +} + class CoinsStore extends Store<"coins", CoinRecord> { constructor() { super("coins", { keyPath: "coinPub" }); @@ -1924,6 +1932,7 @@ export const Stores = { exchangeTrustStore: new ExchangeTrustStore(), denominations: new DenominationsStore(), exchanges: new ExchangesStore(), + exchangeDetails: new ExchangeDetailsStore(), proposals: new ProposalsStore(), refreshGroups: new Store<"refreshGroups", RefreshGroupRecord>( "refreshGroups", -- cgit v1.2.3