gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 01/03: helpers and tests for reserve reconciliation


From: gnunet
Subject: [taler-wallet-core] 01/03: helpers and tests for reserve reconciliation
Date: Thu, 02 Apr 2020 17:04:47 +0200

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

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

commit 62de27d2acc2a59e8125d2b7d2cbcf6a41bdc62d
Author: Florian Dold <address@hidden>
AuthorDate: Thu Apr 2 14:29:16 2020 +0530

    helpers and tests for reserve reconciliation
---
 src/operations/reserves.ts      |  1 +
 src/types/ReserveTransaction.ts | 22 ++++++------
 src/types/dbTypes.ts            | 75 ++++++++++++++++++++++++++++++++++++++++-
 src/util/helpers.ts             |  5 +++
 tsconfig.json                   |  2 ++
 5 files changed, 93 insertions(+), 12 deletions(-)

diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index 5cf189d3..2e1b487b 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -115,6 +115,7 @@ export async function createReserve(
     retryInfo: initRetryInfo(),
     lastError: undefined,
     reserveTransactions: [],
+    history: [],
   };
 
   const senderWire = req.senderWire;
diff --git a/src/types/ReserveTransaction.ts b/src/types/ReserveTransaction.ts
index 3b2553de..cebccd2d 100644
--- a/src/types/ReserveTransaction.ts
+++ b/src/types/ReserveTransaction.ts
@@ -39,7 +39,7 @@ import { Timestamp, codecForTimestamp } from "../util/time";
 
 export const enum ReserveTransactionType {
   Withdraw = "WITHDRAW",
-  Deposit = "CREDIT",
+  Credit = "CREDIT",
   Recoup = "RECOUP",
   Closing = "CLOSING",
 }
@@ -74,8 +74,8 @@ export interface ReserveWithdrawTransaction {
   withdraw_fee: AmountString;
 }
 
-export interface ReserveDepositTransaction {
-  type: ReserveTransactionType.Deposit;
+export interface ReserveCreditTransaction {
+  type: ReserveTransactionType.Credit;
 
   /**
    * Amount withdrawn.
@@ -175,7 +175,7 @@ export interface ReserveRecoupTransaction {
  */
 export type ReserveTransaction =
   | ReserveWithdrawTransaction
-  | ReserveDepositTransaction
+  | ReserveCreditTransaction
   | ReserveClosingTransaction
   | ReserveRecoupTransaction;
 
@@ -194,15 +194,15 @@ export const codecForReserveWithdrawTransaction = () =>
       .build("ReserveWithdrawTransaction"),
   );
 
-export const codecForReserveDepositTransaction = () =>
-  typecheckedCodec<ReserveDepositTransaction>(
-    makeCodecForObject<ReserveDepositTransaction>()
+export const codecForReserveCreditTransaction = () =>
+  typecheckedCodec<ReserveCreditTransaction>(
+    makeCodecForObject<ReserveCreditTransaction>()
       .property("amount", codecForString)
       .property("sender_account_url", codecForString)
       .property("timestamp", codecForTimestamp)
       .property("wire_reference", codecForString)
-      .property("type", 
makeCodecForConstString(ReserveTransactionType.Deposit))
-      .build("ReserveDepositTransaction"),
+      .property("type", makeCodecForConstString(ReserveTransactionType.Credit))
+      .build("ReserveCreditTransaction"),
   );
 
 export const codecForReserveClosingTransaction = () =>
@@ -248,8 +248,8 @@ export const codecForReserveTransaction = () =>
         codecForReserveRecoupTransaction(),
       )
       .alternative(
-        ReserveTransactionType.Deposit,
-        codecForReserveDepositTransaction(),
+        ReserveTransactionType.Credit,
+        codecForReserveCreditTransaction(),
       )
       .build<ReserveTransaction>("ReserveTransaction"),
   );
diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts
index db71db71..c88148e7 100644
--- a/src/types/dbTypes.ts
+++ b/src/types/dbTypes.ts
@@ -35,8 +35,9 @@ import {
 
 import { Index, Store } from "../util/query";
 import { OperationError, RefreshReason } from "./walletTypes";
-import { ReserveTransaction } from "./ReserveTransaction";
+import { ReserveTransaction, ReserveCreditTransaction, 
ReserveWithdrawTransaction, ReserveClosingTransaction, ReserveRecoupTransaction 
} from "./ReserveTransaction";
 import { Timestamp, Duration, getTimestampNow } from "../util/time";
+import { Wallet } from "../wallet";
 
 export enum ReserveRecordStatus {
   /**
@@ -131,6 +132,71 @@ export function initRetryInfo(
   return info;
 }
 
+export const enum WalletReserveHistoryItemType {
+  Credit = "credit",
+  Withdraw = "withdraw",
+  Closing = "closing",
+  Recoup = "recoup",
+}
+
+export interface WalletReserveHistoryCreditItem {
+  type: WalletReserveHistoryItemType.Credit;
+
+  /**
+   * Amount we expect to see credited.
+   */
+  expectedAmount?: string;
+
+  /**
+   * Item from the reserve transaction history that this
+   * wallet reserve history item matches up with.
+   */
+  matchedExchangeTransaction?: ReserveCreditTransaction;
+}
+
+export interface WalletReserveHistoryWithdrawItem {
+  expectedAmount?: string;
+
+  type: WalletReserveHistoryItemType.Withdraw;
+
+  /**
+   * Item from the reserve transaction history that this
+   * wallet reserve history item matches up with.
+   */
+  matchedExchangeTransaction?: ReserveWithdrawTransaction;
+}
+
+export interface WalletReserveHistoryClosingItem {
+  type: WalletReserveHistoryItemType.Closing;
+
+  /**
+   * Item from the reserve transaction history that this
+   * wallet reserve history item matches up with.
+   */
+  matchedExchangeTransaction?: ReserveClosingTransaction;
+}
+
+export interface WalletReserveHistoryRecoupItem {
+  type: WalletReserveHistoryItemType.Recoup;
+
+  /**
+   * Amount we expect to see recouped.
+   */
+  expectedAmount?: string;
+
+  /**
+   * Item from the reserve transaction history that this
+   * wallet reserve history item matches up with.
+   */
+  matchedExchangeTransaction?: ReserveRecoupTransaction;
+}
+
+export type WalletReserveHistoryItem = 
+  | WalletReserveHistoryCreditItem
+  | WalletReserveHistoryWithdrawItem
+  | WalletReserveHistoryRecoupItem
+  | WalletReserveHistoryClosingItem;
+
 /**
  * A reserve record as stored in the wallet's database.
  */
@@ -234,6 +300,13 @@ export interface ReserveRecord {
   lastError: OperationError | undefined;
 
   reserveTransactions: ReserveTransaction[];
+
+  /**
+   * History of the reserve as modeled by the wallet.
+   * Reconciled with the history kept by the exchange
+   * when we request the reserve status.
+   */
+  history: WalletReserveHistoryItem[];
 }
 
 /**
diff --git a/src/util/helpers.ts b/src/util/helpers.ts
index 130dcdae..0e19d7ab 100644
--- a/src/util/helpers.ts
+++ b/src/util/helpers.ts
@@ -102,6 +102,11 @@ export function deepEquals(x: any, y: any): boolean {
   );
 }
 
+export function deepCopy(x: any): any {
+  // FIXME: this has many issues ...
+  return JSON.parse(JSON.stringify(x));
+}
+
 /**
  * Map from a collection to a list or results and then
  * concatenate the results.
diff --git a/tsconfig.json b/tsconfig.json
index 6808b337..f87e16b1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -86,6 +86,8 @@
     "src/util/payto.ts",
     "src/util/promiseUtils.ts",
     "src/util/query.ts",
+    "src/util/reserveHistoryUtil-test.ts",
+    "src/util/reserveHistoryUtil.ts",
     "src/util/talerconfig.ts",
     "src/util/taleruri-test.ts",
     "src/util/taleruri.ts",

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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