From 553da649902f71d5ca34c9a6289ab6b1ef0ba7cb Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 20 Nov 2019 19:48:43 +0100 Subject: WIP: simplify DB queries and error handling --- src/dbTypes.ts | 90 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 41 deletions(-) (limited to 'src/dbTypes.ts') diff --git a/src/dbTypes.ts b/src/dbTypes.ts index 28893b8eb..0d54069ec 100644 --- a/src/dbTypes.ts +++ b/src/dbTypes.ts @@ -36,6 +36,7 @@ import { } from "./talerTypes"; import { Index, Store } from "./query"; +import { Timestamp, OperationError } from "./walletTypes"; /** * Current database version, should be incremented @@ -310,13 +311,10 @@ export class DenominationRecord { } /** - * Exchange record as stored in the wallet's database. + * Details about the exchange that we only know after + * querying /keys and /wire. */ -export interface ExchangeRecord { - /** - * Base url of the exchange. - */ - baseUrl: string; +export interface ExchangeDetails { /** * Master public key of the exchange. */ @@ -331,22 +329,60 @@ export interface ExchangeRecord { */ currency: string; + /** + * Last observed protocol version. + */ + protocolVersion: string; + /** * Timestamp for last update. */ - lastUpdateTime: number; + lastUpdateTime: Timestamp; +} + +export enum ExchangeUpdateStatus { + NONE = "none", + FETCH_KEYS = "fetch_keys", + FETCH_WIRE = "fetch_wire", +} + +export interface ExchangeBankAccount { + url: string; +} +export interface ExchangeWireInfo { + feesForType: { [wireMethod: string]: WireFee[] }; + accounts: ExchangeBankAccount[]; +} + +/** + * Exchange record as stored in the wallet's database. + */ +export interface ExchangeRecord { /** - * When did we actually use this exchange last (in milliseconds). If we - * never used the exchange for anything but just updated its info, this is - * set to 0. (Currently only updated when reserves are created.) + * Base url of the exchange. */ - lastUsedTime: number; + baseUrl: string; /** - * Last observed protocol version. + * Details, once known. */ - protocolVersion?: string; + details: ExchangeDetails | undefined; + + /** + * Mapping from wire method type to the wire fee. + */ + wireInfo: ExchangeWireInfo | undefined; + + /** + * Time when the update to the exchange has been started or + * undefined if no update is in progress. + */ + updateStarted: Timestamp | undefined; + + updateStatus: ExchangeUpdateStatus; + + lastError?: OperationError; } /** @@ -554,21 +590,6 @@ export class ProposalDownloadRecord { static checked: (obj: any) => ProposalDownloadRecord; } -/** - * Wire fees for an exchange. - */ -export interface ExchangeWireFeesRecord { - /** - * Base URL of the exchange. - */ - exchangeBaseUrl: string; - - /** - * Mapping from wire method type to the wire fee. - */ - feesForType: { [wireMethod: string]: WireFee[] }; -} - /** * Status of a tip we got from a merchant. */ @@ -931,12 +952,6 @@ export namespace Stores { constructor() { super("exchanges", { keyPath: "baseUrl" }); } - - pubKeyIndex = new Index( - this, - "pubKeyIndex", - "masterPublicKey", - ); } class CoinsStore extends Store { @@ -1034,12 +1049,6 @@ export namespace Stores { } } - class ExchangeWireFeesStore extends Store { - constructor() { - super("exchangeWireFees", { keyPath: "exchangeBaseUrl" }); - } - } - class ReservesStore extends Store { constructor() { super("reserves", { keyPath: "reserve_pub" }); @@ -1094,7 +1103,6 @@ export namespace Stores { export const config = new ConfigStore(); export const currencies = new CurrenciesStore(); export const denominations = new DenominationsStore(); - export const exchangeWireFees = new ExchangeWireFeesStore(); export const exchanges = new ExchangeStore(); export const precoins = new Store("precoins", { keyPath: "coinPub", -- cgit v1.2.3