gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: DB schema cleanup


From: gnunet
Subject: [taler-wallet-core] branch master updated: DB schema cleanup
Date: Tue, 24 Aug 2021 15:43:11 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 4c41e705 DB schema cleanup
4c41e705 is described below

commit 4c41e705658cbae6e4558bf29edeb39f474c244a
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Aug 24 15:43:06 2021 +0200

    DB schema cleanup
---
 packages/taler-util/src/walletTypes.ts             | 27 +++++++++++
 .../src/crypto/workers/cryptoImplementation.ts     |  9 ++--
 packages/taler-wallet-core/src/db-utils.ts         | 23 +++++++++-
 packages/taler-wallet-core/src/db.ts               | 52 ++--------------------
 .../src/operations/backup/import.ts                |  4 +-
 .../taler-wallet-core/src/operations/exchanges.ts  |  4 +-
 .../taler-wallet-core/src/operations/refresh.ts    |  4 +-
 .../src/operations/withdraw.test.ts                | 14 +++---
 .../taler-wallet-core/src/operations/withdraw.ts   | 36 +++++++++++----
 9 files changed, 96 insertions(+), 77 deletions(-)

diff --git a/packages/taler-util/src/walletTypes.ts 
b/packages/taler-util/src/walletTypes.ts
index e789b469..6e71de6e 100644
--- a/packages/taler-util/src/walletTypes.ts
+++ b/packages/taler-util/src/walletTypes.ts
@@ -788,6 +788,33 @@ export interface MakeSyncSignatureRequest {
   newHash: string;
 }
 
+/**
+ * Planchet for a coin during refresh.
+ */
+ export interface RefreshPlanchetInfo {
+  /**
+   * Public key for the coin.
+   */
+  publicKey: string;
+
+  /**
+   * Private key for the coin.
+   */
+  privateKey: string;
+
+  /**
+   * Blinded public key.
+   */
+  coinEv: string;
+
+  coinEvHash: string;
+
+  /**
+   * Blinding key used.
+   */
+  blindingKey: string;
+}
+
 /**
  * Strategy for loading recovery information.
  */
diff --git 
a/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts 
b/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts
index 61134ef6..e1580a7d 100644
--- a/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts
+++ b/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts
@@ -30,12 +30,11 @@
 import {
   CoinRecord,
   DenominationRecord,
-  RefreshPlanchet,
   WireFee,
   CoinSourceType,
 } from "../../db.js";
 
-import { CoinDepositPermission, RecoupRequest } from "@gnu-taler/taler-util";
+import { CoinDepositPermission, RecoupRequest, RefreshPlanchetInfo } from 
"@gnu-taler/taler-util";
 // FIXME: These types should be internal to the wallet!
 import {
   BenchmarkResult,
@@ -442,7 +441,7 @@ export class CryptoImplementation {
     const transferPubs: string[] = [];
     const transferPrivs: string[] = [];
 
-    const planchetsForGammas: RefreshPlanchet[][] = [];
+    const planchetsForGammas: RefreshPlanchetInfo[][] = [];
 
     for (let i = 0; i < kappa; i++) {
       const transferKeyPair = setupRefreshTransferPub(
@@ -464,7 +463,7 @@ export class CryptoImplementation {
     sessionHc.update(decodeCrock(meltCoinPub));
     sessionHc.update(amountToBuffer(valueWithFee));
     for (let i = 0; i < kappa; i++) {
-      const planchets: RefreshPlanchet[] = [];
+      const planchets: RefreshPlanchetInfo[] = [];
       for (let j = 0; j < newCoinDenoms.length; j++) {
         const denomSel = newCoinDenoms[j];
         for (let k = 0; k < denomSel.count; k++) {
@@ -482,7 +481,7 @@ export class CryptoImplementation {
           const pubHash = hash(coinPub);
           const denomPub = decodeCrock(denomSel.denomPub);
           const ev = rsaBlind(pubHash, blindingFactor, denomPub);
-          const planchet: RefreshPlanchet = {
+          const planchet: RefreshPlanchetInfo = {
             blindingKey: encodeCrock(blindingFactor),
             coinEv: encodeCrock(ev),
             privateKey: encodeCrock(coinPriv),
diff --git a/packages/taler-wallet-core/src/db-utils.ts 
b/packages/taler-wallet-core/src/db-utils.ts
index 424d12b8..849dcfd1 100644
--- a/packages/taler-wallet-core/src/db-utils.ts
+++ b/packages/taler-wallet-core/src/db-utils.ts
@@ -134,8 +134,27 @@ export async function openTalerDatabase(
     });
 
   if (currentMainVersion !== TALER_DB_NAME) {
-    // In the future, the migration logic will be implemented here.
-    throw Error(`migration from database ${currentMainVersion} not supported`);
+    switch (currentMainVersion) {
+      case "taler-wallet-main-v2": {
+        // We consider this a pre-release
+        // development version, no migration is done.
+        await metaDb
+          .mktx((x) => ({
+            metaConfig: x.metaConfig,
+          }))
+          .runReadWrite(async (tx) => {
+            await tx.metaConfig.put({
+              key: CURRENT_DB_CONFIG_KEY,
+              value: TALER_DB_NAME,
+            });
+          });
+        break;
+      }
+      default:
+        throw Error(
+          `migration from database ${currentMainVersion} not supported`,
+        );
+    }
   }
 
   const mainDbHandle = await openDatabase(
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index 66d79ebc..7ea8b9ea 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -46,7 +46,7 @@ import { PayCoinSelection } from "./util/coinSelection.js";
  * for all previous versions must be written, which should be
  * avoided.
  */
-export const TALER_DB_NAME = "taler-wallet-main-v2";
+export const TALER_DB_NAME = "taler-wallet-main-v3";
 
 /**
  * Name of the metadata database.  This database is used
@@ -283,7 +283,7 @@ export interface ExchangeTrustRecord {
 /**
  * Status of a denomination.
  */
-export enum DenominationStatus {
+export enum DenominationVerificationStatus {
   /**
    * Verification was delayed.
    */
@@ -366,10 +366,8 @@ export interface DenominationRecord {
 
   /**
    * Did we verify the signature on the denomination?
-   *
-   * FIXME:  Rename to "verificationStatus"?
    */
-  status: DenominationStatus;
+  verificationStatus: DenominationVerificationStatus;
 
   /**
    * Was this denomination still offered by the exchange the last time
@@ -590,35 +588,6 @@ export interface PlanchetRecord {
   isFromTip: boolean;
 }
 
-/**
- * Planchet for a coin during refresh.
- *
- * FIXME:  Not used in DB?
- */
-export interface RefreshPlanchet {
-  /**
-   * Public key for the coin.
-   */
-  publicKey: string;
-
-  /**
-   * Private key for the coin.
-   */
-  privateKey: string;
-
-  /**
-   * Blinded public key.
-   */
-  coinEv: string;
-
-  coinEvHash: string;
-
-  /**
-   * Blinding key used.
-   */
-  blindingKey: string;
-}
-
 /**
  * Status of a coin.
  */
@@ -1319,21 +1288,6 @@ export interface WalletBackupConfState {
   lastBackupNonce?: string;
 }
 
-/**
- * FIXME: Eliminate this in favor of DenomSelectionState.
- */
-export interface DenominationSelectionInfo {
-  totalCoinValue: AmountJson;
-  totalWithdrawCost: AmountJson;
-  selectedDenoms: {
-    /**
-     * How many times do we withdraw this denomination?
-     */
-    count: number;
-    denom: DenominationRecord;
-  }[];
-}
-
 /**
  * Selected denominations withn some extra info.
  */
diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts 
b/packages/taler-wallet-core/src/operations/backup/import.ts
index a694d9f4..9eee34cf 100644
--- a/packages/taler-wallet-core/src/operations/backup/import.ts
+++ b/packages/taler-wallet-core/src/operations/backup/import.ts
@@ -31,7 +31,7 @@ import {
 import {
   WalletContractData,
   DenomSelectionState,
-  DenominationStatus,
+  DenominationVerificationStatus,
   CoinSource,
   CoinSourceType,
   CoinStatus,
@@ -359,7 +359,7 @@ export async function importBackup(
               stampExpireLegal: backupDenomination.stamp_expire_legal,
               stampExpireWithdraw: backupDenomination.stamp_expire_withdraw,
               stampStart: backupDenomination.stamp_start,
-              status: DenominationStatus.VerifiedGood,
+              verificationStatus: DenominationVerificationStatus.VerifiedGood,
               value: Amounts.parseOrThrow(backupDenomination.value),
               listIssueDate: backupDenomination.list_issue_date,
             });
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts 
b/packages/taler-wallet-core/src/operations/exchanges.ts
index 23459de9..cf52e00b 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -44,7 +44,7 @@ import { decodeCrock, encodeCrock, hash } from 
"../crypto/talerCrypto.js";
 import { CryptoApi } from "../crypto/workers/cryptoApi.js";
 import {
   DenominationRecord,
-  DenominationStatus,
+  DenominationVerificationStatus,
   ExchangeDetailsRecord,
   ExchangeRecord,
   WalletStoresV1,
@@ -95,7 +95,7 @@ function denominationRecordFromKeys(
     stampExpireLegal: denomIn.stamp_expire_legal,
     stampExpireWithdraw: denomIn.stamp_expire_withdraw,
     stampStart: denomIn.stamp_start,
-    status: DenominationStatus.Unverified,
+    verificationStatus: DenominationVerificationStatus.Unverified,
     value: Amounts.parseOrThrow(denomIn.value),
     listIssueDate,
   };
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts 
b/packages/taler-wallet-core/src/operations/refresh.ts
index 8926559e..a7b64f5d 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -22,7 +22,6 @@ import {
   DenominationRecord,
   RefreshCoinStatus,
   RefreshGroupRecord,
-  RefreshPlanchet,
   WalletStoresV1,
 } from "../db.js";
 import {
@@ -32,6 +31,7 @@ import {
   fnutil,
   NotificationType,
   RefreshGroupId,
+  RefreshPlanchetInfo,
   RefreshReason,
   stringifyTimestamp,
   TalerErrorDetails,
@@ -534,7 +534,7 @@ async function refreshReveal(
     throw Error("refresh index error");
   }
 
-  const evs = planchets.map((x: RefreshPlanchet) => x.coinEv);
+  const evs = planchets.map((x: RefreshPlanchetInfo) => x.coinEv);
   const newDenomsFlat: string[] = [];
   const linkSigs: string[] = [];
 
diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts 
b/packages/taler-wallet-core/src/operations/withdraw.test.ts
index 061a4222..b4f0d35e 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.test.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts
@@ -16,7 +16,7 @@
 
 import { Amounts } from "@gnu-taler/taler-util";
 import test from "ava";
-import { DenominationRecord, DenominationStatus } from "../db.js";
+import { DenominationRecord, DenominationVerificationStatus } from "../db.js";
 import { selectWithdrawalDenominations } from "./withdraw.js";
 
 test("withdrawal selection bug repro", (t) => {
@@ -70,7 +70,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 0,
@@ -121,7 +121,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 0,
@@ -172,7 +172,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 0,
@@ -223,7 +223,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 0,
@@ -274,7 +274,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 10000000,
@@ -325,7 +325,7 @@ test("withdrawal selection bug repro", (t) => {
       stampStart: {
         t_ms: 1585229388000,
       },
-      status: DenominationStatus.Unverified,
+      verificationStatus: DenominationVerificationStatus.Unverified,
       value: {
         currency: "KUDOS",
         fraction: 0,
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts 
b/packages/taler-wallet-core/src/operations/withdraw.ts
index 521cfa11..e6b6e874 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -47,8 +47,7 @@ import {
   CoinSourceType,
   CoinStatus,
   DenominationRecord,
-  DenominationSelectionInfo,
-  DenominationStatus,
+  DenominationVerificationStatus,
   DenomSelectionState,
   ExchangeDetailsRecord,
   ExchangeRecord,
@@ -73,6 +72,21 @@ import {
  */
 const logger = new Logger("withdraw.ts");
 
+/**
+ * FIXME: Eliminate this in favor of DenomSelectionState.
+ */
+interface DenominationSelectionInfo {
+  totalCoinValue: AmountJson;
+  totalWithdrawCost: AmountJson;
+  selectedDenoms: {
+    /**
+     * How many times do we withdraw this denomination?
+     */
+    count: number;
+    denom: DenominationRecord;
+  }[];
+}
+
 /**
  * Information about what will happen when creating a reserve.
  *
@@ -231,9 +245,13 @@ export function selectWithdrawalDenominations(
   }
 
   if (logger.shouldLogTrace()) {
-    logger.trace(`selected withdrawal denoms for 
${Amounts.stringify(totalCoinValue)}`);
+    logger.trace(
+      `selected withdrawal denoms for ${Amounts.stringify(totalCoinValue)}`,
+    );
     for (const sd of selectedDenoms) {
-      logger.trace(`denom_pub_hash=${sd.denom.denomPubHash}, 
count=${sd.count}`);
+      logger.trace(
+        `denom_pub_hash=${sd.denom.denomPubHash}, count=${sd.count}`,
+      );
     }
     logger.trace("(end of withdrawal denom list)");
   }
@@ -314,7 +332,9 @@ export async function getCandidateWithdrawalDenoms(
   return await ws.db
     .mktx((x) => ({ denominations: x.denominations }))
     .runReadOnly(async (tx) => {
-      const allDenoms = await 
tx.denominations.indexes.byExchangeBaseUrl.getAll(exchangeBaseUrl);
+      const allDenoms = await 
tx.denominations.indexes.byExchangeBaseUrl.getAll(
+        exchangeBaseUrl,
+      );
       return allDenoms.filter(isWithdrawableDenom);
     });
 }
@@ -708,7 +728,7 @@ export async function updateWithdrawalDenoms(
       batchIdx++, current++
     ) {
       const denom = denominations[current];
-      if (denom.status === DenominationStatus.Unverified) {
+      if (denom.verificationStatus === 
DenominationVerificationStatus.Unverified) {
         logger.trace(
           `Validating denomination (${current + 1}/${
             denominations.length
@@ -723,9 +743,9 @@ export async function updateWithdrawalDenoms(
           logger.warn(
             `Signature check for denomination h=${denom.denomPubHash} failed`,
           );
-          denom.status = DenominationStatus.VerifiedBad;
+          denom.verificationStatus = 
DenominationVerificationStatus.VerifiedBad;
         } else {
-          denom.status = DenominationStatus.VerifiedGood;
+          denom.verificationStatus = 
DenominationVerificationStatus.VerifiedGood;
         }
         updatedDenominations.push(denom);
       }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]