summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/db.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/db.ts')
-rw-r--r--packages/taler-wallet-core/src/db.ts153
1 files changed, 123 insertions, 30 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 98390805b..ad9b4f1cb 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -34,11 +34,13 @@ import {
Amounts,
AttentionInfo,
BackupProviderTerms,
+ CancellationToken,
Codec,
CoinEnvelope,
CoinPublicKeyString,
CoinRefreshRequest,
CoinStatus,
+ DenomLossEventType,
DenomSelectionState,
DenominationInfo,
DenominationPubKey,
@@ -149,7 +151,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 8;
+export const WALLET_DB_MINOR_VERSION = 10;
declare const symDbProtocolTimestamp: unique symbol;
@@ -296,6 +298,11 @@ export enum WithdrawalGroupStatus {
SuspendedReady = 0x0110_0004,
/**
+ * Proposed to the user, has can choose to accept/refuse.
+ */
+ DialogProposed = 0x0101_0000,
+
+ /**
* We are telling the bank that we don't want to complete
* the withdrawal!
*/
@@ -336,6 +343,21 @@ export enum WithdrawalGroupStatus {
AbortedExchange = 0x0503_0001,
AbortedBank = 0x0503_0002,
+
+ /**
+ * User didn't refused the withdrawal.
+ */
+ AbortedUserRefused = 0x0503_0003,
+
+ /**
+ * Another wallet confirmed the withdrawal
+ * (by POSTing the reserve pub to the bank)
+ * before we had the chance.
+ *
+ * In this situation, we'll let the other wallet continue
+ * and give up ourselves.
+ */
+ AbortedOtherWallet = 0x0503_0004,
}
/**
@@ -354,7 +376,7 @@ export interface ReserveBankInfo {
/**
* Exchange payto URI that the bank will use to fund the reserve.
*/
- exchangePaytoUri: string;
+ exchangePaytoUri?: string;
/**
* Time when the information about this reserve was posted to the bank.
@@ -371,6 +393,8 @@ export interface ReserveBankInfo {
* Set to undefined if not confirmed yet.
*/
timestampBankConfirmed: DbPreciseTimestamp | undefined;
+
+ wireTypes: string[] | undefined;
}
/**
@@ -673,6 +697,8 @@ export interface ExchangeEntryRecord {
*/
nextUpdateStamp: DbPreciseTimestamp;
+ updateRetryCounter?: number;
+
lastKeysEtag: string | undefined;
/**
@@ -1225,9 +1251,15 @@ export interface DbCoinSelection {
}
export interface PurchasePayInfo {
- payCoinSelection: DbCoinSelection;
+ /**
+ * Undefined if payment is blocked by a pending refund.
+ */
+ payCoinSelection?: DbCoinSelection;
+ /**
+ * Undefined if payment is blocked by a pending refund.
+ */
+ payCoinSelectionUid?: string;
totalPayCost: AmountString;
- payCoinSelectionUid: string;
}
/**
@@ -1366,7 +1398,6 @@ export type ConfigRecord =
value: WalletBackupConfState;
}
| { key: ConfigRecordKey.CurrencyDefaultsApplied; value: boolean }
- | { key: ConfigRecordKey.DevMode; value: boolean }
| { key: ConfigRecordKey.TestLoopTx; value: number }
| { key: ConfigRecordKey.LastInitInfo; value: DbProtocolTimestamp };
@@ -1408,6 +1439,7 @@ export interface WgInfoBankIntegrated {
* a Taler-integrated bank.
*/
bankInfo: ReserveBankInfo;
+
/**
* Info about withdrawal accounts, possibly including currency conversion.
*/
@@ -1533,7 +1565,7 @@ export interface WithdrawalGroupRecord {
/**
* Amount that was sent by the user to fund the reserve.
*/
- instructedAmount: AmountString;
+ instructedAmount?: AmountString;
/**
* Amount that was observed when querying the reserve that
@@ -1550,7 +1582,7 @@ export interface WithdrawalGroupRecord {
* (Initial amount confirmed by the user, might differ with denomSel
* on reselection.)
*/
- rawWithdrawalAmount: AmountString;
+ rawWithdrawalAmount?: AmountString;
/**
* Amount that will be added to the balance when the withdrawal succeeds.
@@ -1558,12 +1590,12 @@ export interface WithdrawalGroupRecord {
* (Initial amount confirmed by the user, might differ with denomSel
* on reselection.)
*/
- effectiveWithdrawalAmount: AmountString;
+ effectiveWithdrawalAmount?: AmountString;
/**
* Denominations selected for withdrawal.
*/
- denomsSel: DenomSelectionState;
+ denomsSel?: DenomSelectionState;
/**
* UID of the denomination selection.
@@ -1786,9 +1818,9 @@ export interface DepositGroupRecord {
contractTermsHash: string;
- payCoinSelection: DbCoinSelection;
+ payCoinSelection?: DbCoinSelection;
- payCoinSelectionUid: string;
+ payCoinSelectionUid?: string;
totalPayCost: AmountString;
@@ -1803,7 +1835,7 @@ export interface DepositGroupRecord {
operationStatus: DepositOperationStatus;
- statusPerCoin: DepositElementStatus[];
+ statusPerCoin?: DepositElementStatus[];
infoPerExchange?: Record<string, DepositInfoPerExchange>;
@@ -1885,7 +1917,7 @@ export interface PeerPushDebitRecord {
totalCost: AmountString;
- coinSel: DbPeerPushPaymentCoinSelection;
+ coinSel?: DbPeerPushPaymentCoinSelection;
contractTermsHash: HashCodeString;
@@ -2197,6 +2229,11 @@ export interface CoinAvailabilityRecord {
* a final state.
*/
visibleCoinCount: number;
+
+ /**
+ * Number of coins that we expect to obtain via a pending refresh.
+ */
+ pendingRefreshOutputCount?: number;
}
export interface ContractTermsRecord {
@@ -2355,11 +2392,48 @@ export interface TransactionRecord {
currency: string;
}
+export enum DenomLossStatus {
+ /**
+ * Done indicates that the loss happened.
+ */
+ Done = 0x0500_0000,
+
+ /**
+ * Aborted in the sense that the loss was reversed.
+ */
+ Aborted = 0x0503_0001,
+}
+
+export interface DenomLossEventRecord {
+ denomLossEventId: string;
+ currency: string;
+ denomPubHashes: string[];
+ status: DenomLossStatus;
+ timestampCreated: DbPreciseTimestamp;
+ amount: string;
+ eventType: DenomLossEventType;
+ exchangeBaseUrl: string;
+}
+
/**
* Schema definition for the IndexedDB
* wallet database.
*/
export const WalletStoresV1 = {
+ denomLossEvents: describeStoreV2({
+ recordCodec: passthroughCodec<DenomLossEventRecord>(),
+ storeName: "denomLossEvents",
+ keyPath: "denomLossEventId",
+ versionAdded: 9,
+ indexes: {
+ byCurrency: describeIndex("byCurrency", "currency", {
+ versionAdded: 9,
+ }),
+ byStatus: describeIndex("byStatus", "status", {
+ versionAdded: 10,
+ }),
+ },
+ }),
transactions: describeStoreV2({
recordCodec: passthroughCodec<TransactionRecord>(),
storeName: "transactions",
@@ -2606,7 +2680,9 @@ export const WalletStoresV1 = {
describeContents<BankWithdrawUriRecord>({
keyPath: "talerWithdrawUri",
}),
- {},
+ {
+ byGroup: describeIndex("byGroup", "withdrawalGroupId"),
+ },
),
backupProviders: describeStore(
"backupProviders",
@@ -2865,6 +2941,8 @@ export interface DbDump {
};
}
+const logger = new Logger("db.ts");
+
export async function exportSingleDb(
idb: IDBFactory,
dbName: string,
@@ -3006,8 +3084,6 @@ export interface FixupDescription {
*/
export const walletDbFixups: FixupDescription[] = [];
-const logger = new Logger("db.ts");
-
export async function applyFixups(
db: DbAccess<typeof WalletStoresV1>,
): Promise<void> {
@@ -3219,7 +3295,12 @@ export async function openStoredBackupsDatabase(
onStoredBackupsDbUpgradeNeeded,
);
- const handle = new DbAccessImpl(backupsDbHandle, StoredBackupStores);
+ const handle = new DbAccessImpl(
+ backupsDbHandle,
+ StoredBackupStores,
+ {},
+ CancellationToken.CONTINUE,
+ );
return handle;
}
@@ -3233,7 +3314,7 @@ export async function openStoredBackupsDatabase(
export async function openTalerDatabase(
idbFactory: IDBFactory,
onVersionChange: () => void,
-): Promise<DbAccess<typeof WalletStoresV1>> {
+): Promise<IDBDatabase> {
const metaDbHandle = await openDatabase(
idbFactory,
TALER_WALLET_META_DB_NAME,
@@ -3242,9 +3323,14 @@ export async function openTalerDatabase(
onMetaDbUpgradeNeeded,
);
- const metaDb = new DbAccessImpl(metaDbHandle, walletMetadataStore);
+ const metaDb = new DbAccessImpl(
+ metaDbHandle,
+ walletMetadataStore,
+ {},
+ CancellationToken.CONTINUE,
+ );
let currentMainVersion: string | undefined;
- await metaDb.runReadWriteTx(["metaConfig"], async (tx) => {
+ await metaDb.runReadWriteTx({ storeNames: ["metaConfig"] }, async (tx) => {
const dbVersionRecord = await tx.metaConfig.get(CURRENT_DB_CONFIG_KEY);
if (!dbVersionRecord) {
currentMainVersion = TALER_WALLET_MAIN_DB_NAME;
@@ -3269,12 +3355,15 @@ export async function openTalerDatabase(
case "taler-wallet-main-v9":
// We consider this a pre-release
// development version, no migration is done.
- await metaDb.runReadWriteTx(["metaConfig"], async (tx) => {
- await tx.metaConfig.put({
- key: CURRENT_DB_CONFIG_KEY,
- value: TALER_WALLET_MAIN_DB_NAME,
- });
- });
+ await metaDb.runReadWriteTx(
+ { storeNames: ["metaConfig"] },
+ async (tx) => {
+ await tx.metaConfig.put({
+ key: CURRENT_DB_CONFIG_KEY,
+ value: TALER_WALLET_MAIN_DB_NAME,
+ });
+ },
+ );
break;
default:
throw Error(
@@ -3291,11 +3380,15 @@ export async function openTalerDatabase(
onTalerDbUpgradeNeeded,
);
- const handle = new DbAccessImpl(mainDbHandle, WalletStoresV1);
-
- await applyFixups(handle);
+ const mainDbAccess = new DbAccessImpl(
+ mainDbHandle,
+ WalletStoresV1,
+ {},
+ CancellationToken.CONTINUE,
+ );
+ await applyFixups(mainDbAccess);
- return handle;
+ return mainDbHandle;
}
export async function deleteTalerDatabase(