gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (baaa11c3 -> 8d0081b6)


From: gnunet
Subject: [taler-wallet-core] branch master updated (baaa11c3 -> 8d0081b6)
Date: Wed, 02 Sep 2020 08:55:06 +0200

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

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

    from baaa11c3 fix bank API test
     new 0ffea74a no more const enum, remove unused field
     new 659e9cdb respect cache header
     new 46ba5167 rename test
     new 8d0081b6 missing file

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ...t-timetravel.ts => test-timetravel-withdraw.ts} |  0
 .../taler-wallet-core/src/operations/exchanges.ts  | 19 +++++++++--
 .../src/types/ReserveTransaction.ts                |  2 +-
 packages/taler-wallet-core/src/types/dbTypes.ts    | 39 +++++++++-------------
 .../taler-wallet-core/src/types/notifications.ts   |  2 +-
 packages/taler-wallet-core/src/types/pending.ts    |  6 ++--
 .../taler-wallet-core/src/types/transactions.ts    |  6 ++--
 .../taler-wallet-core/src/types/walletTypes.ts     |  6 ++--
 packages/taler-wallet-core/src/util/http.ts        | 18 +++++++++-
 .../src/util/invariants.ts}                        | 17 +++++++---
 packages/taler-wallet-core/src/util/taleruri.ts    |  2 +-
 packages/taler-wallet-core/src/util/time.ts        |  4 +++
 12 files changed, 78 insertions(+), 43 deletions(-)
 rename packages/taler-integrationtests/src/{test-timetravel.ts => 
test-timetravel-withdraw.ts} (100%)
 copy packages/{taler-wallet-webextension/src/permissions.ts => 
taler-wallet-core/src/util/invariants.ts} (71%)

diff --git a/packages/taler-integrationtests/src/test-timetravel.ts 
b/packages/taler-integrationtests/src/test-timetravel-withdraw.ts
similarity index 100%
rename from packages/taler-integrationtests/src/test-timetravel.ts
rename to packages/taler-integrationtests/src/test-timetravel-withdraw.ts
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts 
b/packages/taler-wallet-core/src/operations/exchanges.ts
index 76ce874d..618b1cf4 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -43,16 +43,19 @@ import {
   WALLET_CACHE_BREAKER_CLIENT_VERSION,
   WALLET_EXCHANGE_PROTOCOL_VERSION,
 } from "./versions";
-import { getTimestampNow, Duration } from "../util/time";
+import { getTimestampNow, Duration, isTimestampExpired } from "../util/time";
 import { compare } from "../util/libtoolVersion";
 import { createRecoupGroup, processRecoupGroup } from "./recoup";
 import { TalerErrorCode } from "../TalerErrorCode";
 import {
   readSuccessResponseJsonOrThrow,
   readSuccessResponseTextOrThrow,
+  getExpiryTimestamp,
 } from "../util/http";
 import { Logger } from "../util/logging";
 import { URL } from "../util/url";
+import { reconcileReserveHistory } from "../util/reserveHistoryUtil";
+import { checkDbInvariant } from "../util/invariants";
 
 const logger = new Logger("exchanges.ts");
 
@@ -195,6 +198,7 @@ async function updateExchangeWithKeys(
         masterPublicKey: exchangeKeysJson.master_public_key,
         protocolVersion: protocolVersion,
         signingKeys: exchangeKeysJson.signkeys,
+        nextUpdateTime: getExpiryTimestamp(resp),
       };
       r.updateStatus = ExchangeUpdateStatus.FetchWire;
       r.lastError = undefined;
@@ -459,7 +463,7 @@ async function updateExchangeFromUrlImpl(
   const now = getTimestampNow();
   baseUrl = canonicalizeBaseUrl(baseUrl);
 
-  const r = await ws.db.get(Stores.exchanges, baseUrl);
+  let r = await ws.db.get(Stores.exchanges, baseUrl);
   if (!r) {
     const newExchangeRecord: ExchangeRecord = {
       builtIn: false,
@@ -476,7 +480,6 @@ async function updateExchangeFromUrlImpl(
       termsOfServiceAcceptedTimestamp: undefined,
       termsOfServiceLastEtag: undefined,
       termsOfServiceText: undefined,
-      updateDiff: undefined,
     };
     await ws.db.put(Stores.exchanges, newExchangeRecord);
   } else {
@@ -498,6 +501,16 @@ async function updateExchangeFromUrlImpl(
     });
   }
 
+  r = await ws.db.get(Stores.exchanges, baseUrl);
+  checkDbInvariant(!!r);
+
+
+  const t = r.details?.nextUpdateTime;
+  if (!forceNow && t && !isTimestampExpired(t)) {
+    logger.trace("using cached exchange info");
+    return r;
+  }
+
   await updateExchangeWithKeys(ws, baseUrl);
   await updateExchangeWithWireInfo(ws, baseUrl);
   await updateExchangeWithTermsOfService(ws, baseUrl);
diff --git a/packages/taler-wallet-core/src/types/ReserveTransaction.ts 
b/packages/taler-wallet-core/src/types/ReserveTransaction.ts
index 0d946518..aa98473a 100644
--- a/packages/taler-wallet-core/src/types/ReserveTransaction.ts
+++ b/packages/taler-wallet-core/src/types/ReserveTransaction.ts
@@ -37,7 +37,7 @@ import {
 } from "./talerTypes";
 import { Timestamp, codecForTimestamp } from "../util/time";
 
-export const enum ReserveTransactionType {
+export enum ReserveTransactionType {
   Withdraw = "WITHDRAW",
   Credit = "CREDIT",
   Recoup = "RECOUP",
diff --git a/packages/taler-wallet-core/src/types/dbTypes.ts 
b/packages/taler-wallet-core/src/types/dbTypes.ts
index 9ba07a0f..b74a9ce3 100644
--- a/packages/taler-wallet-core/src/types/dbTypes.ts
+++ b/packages/taler-wallet-core/src/types/dbTypes.ts
@@ -151,7 +151,7 @@ export function initRetryInfo(
   return info;
 }
 
-export const enum WalletReserveHistoryItemType {
+export enum WalletReserveHistoryItemType {
   Credit = "credit",
   Withdraw = "withdraw",
   Closing = "closing",
@@ -539,9 +539,14 @@ export interface ExchangeDetails {
    * Timestamp for last update.
    */
   lastUpdateTime: Timestamp;
+
+  /**
+   * When should we next update the information about the exchange?
+   */
+  nextUpdateTime: Timestamp;
 }
 
-export const enum ExchangeUpdateStatus {
+export enum ExchangeUpdateStatus {
   FetchKeys = "fetch-keys",
   FetchWire = "fetch-wire",
   FetchTerms = "fetch-terms",
@@ -558,15 +563,7 @@ export interface ExchangeWireInfo {
   accounts: ExchangeBankAccount[];
 }
 
-/**
- * Summary of updates to the exchange.
- */
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-export interface ExchangeUpdateDiff {
-  // FIXME: implement!
-}
-
-export const enum ExchangeUpdateReason {
+export enum ExchangeUpdateReason {
   Initial = "initial",
   Forced = "forced",
   Scheduled = "scheduled",
@@ -644,14 +641,10 @@ export interface ExchangeRecord {
 
   updateReason?: ExchangeUpdateReason;
 
-  /**
-   * Update diff, will be incorporated when the update is finalized.
-   */
-  updateDiff: ExchangeUpdateDiff | undefined;
-
   lastError?: TalerErrorDetails;
 }
 
+
 /**
  * A coin that isn't yet signed by an exchange.
  */
@@ -721,7 +714,7 @@ export interface RefreshPlanchetRecord {
 /**
  * Status of a coin.
  */
-export const enum CoinStatus {
+export enum CoinStatus {
   /**
    * Withdrawn and never shown to anybody.
    */
@@ -732,7 +725,7 @@ export const enum CoinStatus {
   Dormant = "dormant",
 }
 
-export const enum CoinSourceType {
+export enum CoinSourceType {
   Withdraw = "withdraw",
   Refresh = "refresh",
   Tip = "tip",
@@ -827,7 +820,7 @@ export interface CoinRecord {
   status: CoinStatus;
 }
 
-export const enum ProposalStatus {
+export enum ProposalStatus {
   /**
    * Not downloaded yet.
    */
@@ -1170,7 +1163,7 @@ export interface RefundEventRecord {
   proposalId: string;
 }
 
-export const enum RefundState {
+export enum RefundState {
   Failed = "failed",
   Applied = "applied",
   Pending = "pending",
@@ -1222,7 +1215,7 @@ export interface WalletRefundAppliedItem extends 
WalletRefundItemCommon {
   type: RefundState.Applied;
 }
 
-export const enum RefundReason {
+export enum RefundReason {
   /**
    * Normal refund given by the merchant.
    */
@@ -1464,7 +1457,7 @@ export interface CoinsReturnRecord {
   wire: any;
 }
 
-export const enum WithdrawalSourceType {
+export enum WithdrawalSourceType {
   Tip = "tip",
   Reserve = "reserve",
 }
@@ -1613,7 +1606,7 @@ export interface RecoupGroupRecord {
   lastError: TalerErrorDetails | undefined;
 }
 
-export const enum ImportPayloadType {
+export enum ImportPayloadType {
   CoreSchema = "core-schema",
 }
 
diff --git a/packages/taler-wallet-core/src/types/notifications.ts 
b/packages/taler-wallet-core/src/types/notifications.ts
index 0196cebf..7d3795a6 100644
--- a/packages/taler-wallet-core/src/types/notifications.ts
+++ b/packages/taler-wallet-core/src/types/notifications.ts
@@ -25,7 +25,7 @@
 import { TalerErrorDetails } from "./walletTypes";
 import { WithdrawalSource } from "./dbTypes";
 
-export const enum NotificationType {
+export enum NotificationType {
   CoinWithdrawn = "coin-withdrawn",
   ProposalAccepted = "proposal-accepted",
   ProposalDownloaded = "proposal-downloaded",
diff --git a/packages/taler-wallet-core/src/types/pending.ts 
b/packages/taler-wallet-core/src/types/pending.ts
index 23c736a5..69613bec 100644
--- a/packages/taler-wallet-core/src/types/pending.ts
+++ b/packages/taler-wallet-core/src/types/pending.ts
@@ -25,7 +25,7 @@ import { TalerErrorDetails, BalancesResponse } from 
"./walletTypes";
 import { WithdrawalSource, RetryInfo, ReserveRecordStatus } from "./dbTypes";
 import { Timestamp, Duration } from "../util/time";
 
-export const enum PendingOperationType {
+export enum PendingOperationType {
   Bug = "bug",
   ExchangeUpdate = "exchange-update",
   Pay = "pay",
@@ -84,13 +84,13 @@ export interface PendingBugOperation {
 /**
  * Current state of an exchange update operation.
  */
-export const enum ExchangeUpdateOperationStage {
+export enum ExchangeUpdateOperationStage {
   FetchKeys = "fetch-keys",
   FetchWire = "fetch-wire",
   FinalizeUpdate = "finalize-update",
 }
 
-export const enum ReserveType {
+export enum ReserveType {
   /**
    * Manually created.
    */
diff --git a/packages/taler-wallet-core/src/types/transactions.ts 
b/packages/taler-wallet-core/src/types/transactions.ts
index dce48083..1d1eb649 100644
--- a/packages/taler-wallet-core/src/types/transactions.ts
+++ b/packages/taler-wallet-core/src/types/transactions.ts
@@ -96,7 +96,7 @@ export type Transaction =
   | TransactionTip
   | TransactionRefresh;
 
-export const enum TransactionType {
+export enum TransactionType {
   Withdrawal = "withdrawal",
   Payment = "payment",
   Refund = "refund",
@@ -104,7 +104,7 @@ export const enum TransactionType {
   Tip = "tip",
 }
 
-export const enum WithdrawalType {
+export enum WithdrawalType {
   TalerBankIntegrationApi = "taler-bank-integration-api",
   ManualTransfer = "manual-transfer",
 }
@@ -164,7 +164,7 @@ interface TransactionWithdrawal extends TransactionCommon {
   withdrawalDetails: WithdrawalDetails;
 }
 
-export const enum PaymentStatus {
+export enum PaymentStatus {
   /**
    * Explicitly aborted after timeout / failure
    */
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts 
b/packages/taler-wallet-core/src/types/walletTypes.ts
index dbaefae3..01fd95e0 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -202,7 +202,7 @@ export function mkAmount(
   return { value, fraction, currency };
 }
 
-export const enum ConfirmPayResultType {
+export enum ConfirmPayResultType {
   Done = "done",
   Pending = "pending",
 }
@@ -370,7 +370,7 @@ export interface BenchmarkResult {
   repetitions: number;
 }
 
-export const enum PreparePayResultType {
+export enum PreparePayResultType {
   PaymentPossible = "payment-possible",
   InsufficientBalance = "insufficient-balance",
   AlreadyConfirmed = "already-confirmed",
@@ -529,7 +529,7 @@ export interface PlanchetCreationRequest {
 /**
  * Reasons for why a coin is being refreshed.
  */
-export const enum RefreshReason {
+export enum RefreshReason {
   Manual = "manual",
   Pay = "pay",
   Refund = "refund",
diff --git a/packages/taler-wallet-core/src/util/http.ts 
b/packages/taler-wallet-core/src/util/http.ts
index 58b04d45..0977b429 100644
--- a/packages/taler-wallet-core/src/util/http.ts
+++ b/packages/taler-wallet-core/src/util/http.ts
@@ -26,7 +26,7 @@ import { Codec } from "./codec";
 import { OperationFailedError, makeErrorDetails } from "../operations/errors";
 import { TalerErrorCode } from "../TalerErrorCode";
 import { Logger } from "./logging";
-import { Duration } from "./time";
+import { Duration, Timestamp, getTimestampNow } from "./time";
 
 const logger = new Logger("http.ts");
 
@@ -253,3 +253,19 @@ export async function readSuccessResponseTextOrThrow<T>(
   }
   throwUnexpectedRequestError(httpResponse, r.talerErrorResponse);
 }
+
+/**
+ * Get the timestamp at which the response's content is considered expired.
+ */
+export function getExpiryTimestamp(httpResponse: HttpResponse): Timestamp {
+  const expiryDateMs = new Date(
+    httpResponse.headers.get("expiry") ?? "",
+  ).getTime();
+  if (Number.isNaN(expiryDateMs)) {
+    return getTimestampNow();
+  } else {
+    return {
+      t_ms: expiryDateMs,
+    }
+  }
+}
diff --git a/packages/taler-wallet-webextension/src/permissions.ts 
b/packages/taler-wallet-core/src/util/invariants.ts
similarity index 71%
copy from packages/taler-wallet-webextension/src/permissions.ts
copy to packages/taler-wallet-core/src/util/invariants.ts
index bcd357fd..fa381d33 100644
--- a/packages/taler-wallet-webextension/src/permissions.ts
+++ b/packages/taler-wallet-core/src/util/invariants.ts
@@ -14,7 +14,16 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-export const extendedPermissions = {
-  permissions: ["webRequest", "webRequestBlocking"],
-  origins: ["http://*/*";, "https://*/*";],
-};
+/**
+ * Helpers for invariants.
+ */
+
+export function checkDbInvariant(b: boolean, m?: string): asserts b {
+  if (!b) {
+    if (m) {
+      throw Error(`BUG: database invariant failed (${m})`);
+    } else {
+      throw Error("BUG: database invariant failed");
+    }
+  }
+}
diff --git a/packages/taler-wallet-core/src/util/taleruri.ts 
b/packages/taler-wallet-core/src/util/taleruri.ts
index 56b46c0f..5b2c5aba 100644
--- a/packages/taler-wallet-core/src/util/taleruri.ts
+++ b/packages/taler-wallet-core/src/util/taleruri.ts
@@ -64,7 +64,7 @@ export function parseWithdrawUri(s: string): 
WithdrawUriResult | undefined {
   };
 }
 
-export const enum TalerUriType {
+export enum TalerUriType {
   TalerPay = "taler-pay",
   TalerWithdraw = "taler-withdraw",
   TalerTip = "taler-tip",
diff --git a/packages/taler-wallet-core/src/util/time.ts 
b/packages/taler-wallet-core/src/util/time.ts
index ccd75e14..ff4c1885 100644
--- a/packages/taler-wallet-core/src/util/time.ts
+++ b/packages/taler-wallet-core/src/util/time.ts
@@ -46,6 +46,10 @@ export function getTimestampNow(): Timestamp {
   };
 }
 
+export function isTimestampExpired(t: Timestamp) {
+  return timestampCmp(t, getTimestampNow()) <= 0;
+}
+
 export function getDurationRemaining(
   deadline: Timestamp,
   now = getTimestampNow(),

-- 
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]