gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (ef0acf06 -> 05e43bb2)


From: gnunet
Subject: [taler-wallet-core] branch master updated (ef0acf06 -> 05e43bb2)
Date: Thu, 02 Apr 2020 17:12:37 +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 ef0acf06 model reserve history in the exchange, improve reserve 
handling logic
     new 1be738b8 don't print in test
     new 05e43bb2 simplify matching

The 2 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:
 src/util/reserveHistoryUtil-test.ts |  1 -
 src/util/reserveHistoryUtil.ts      | 64 ++++++++++---------------------------
 2 files changed, 17 insertions(+), 48 deletions(-)

diff --git a/src/util/reserveHistoryUtil-test.ts 
b/src/util/reserveHistoryUtil-test.ts
index 910d6a01..79022de7 100644
--- a/src/util/reserveHistoryUtil-test.ts
+++ b/src/util/reserveHistoryUtil-test.ts
@@ -243,7 +243,6 @@ test("withdrawal new match", (t) => {
   ];
   const r = reconcileReserveHistory(localHistory, remoteHistory);
   const s = summarizeReserveHistory(r.updatedLocalHistory, "TESTKUDOS");
-  console.log(r);
   t.deepEqual(r.updatedLocalHistory.length, 2);
   t.deepEqual(Amounts.stringify(s.computedReserveBalance), "TESTKUDOS:95");
   t.deepEqual(Amounts.stringify(s.awaitedReserveAmount), "TESTKUDOS:0");
diff --git a/src/util/reserveHistoryUtil.ts b/src/util/reserveHistoryUtil.ts
index 95f58449..03322187 100644
--- a/src/util/reserveHistoryUtil.ts
+++ b/src/util/reserveHistoryUtil.ts
@@ -56,6 +56,10 @@ export interface ReserveReconciliationResult {
   newMatchedItems: WalletReserveHistoryItem[];
 }
 
+/**
+ * Various totals computed from the wallet's view
+ * on the reserve history.
+ */
 export interface ReserveHistorySummary {
   /**
    * Balance computed by the wallet, should match the balance
@@ -80,7 +84,10 @@ export interface ReserveHistorySummary {
   withdrawnAmount: Amounts.AmountJson;
 }
 
-export function isRemoteHistoryMatch(
+/**
+ * Check if two reserve history items (exchange's version) match.
+ */
+function isRemoteHistoryMatch(
   t1: ReserveTransaction,
   t2: ReserveTransaction,
 ): boolean {
@@ -104,7 +111,10 @@ export function isRemoteHistoryMatch(
   }
 }
 
-export function isLocalRemoteHistoryPreferredMatch(
+/**
+ * Check a local reserve history item and a remote history item are a match.
+ */
+export function isLocalRemoteHistoryMatch(
   t1: WalletReserveHistoryItem,
   t2: ReserveTransaction,
 ): boolean {
@@ -121,7 +131,7 @@ export function isLocalRemoteHistoryPreferredMatch(
         t2.type === ReserveTransactionType.Withdraw &&
         !!t1.expectedAmount &&
         Amounts.cmp(t1.expectedAmount, Amounts.parseOrThrow(t2.amount)) === 0
-      )
+      );
     case WalletReserveHistoryItemType.Recoup: {
       return (
         t2.type === ReserveTransactionType.Recoup &&
@@ -133,22 +143,6 @@ export function isLocalRemoteHistoryPreferredMatch(
   return false;
 }
 
-export function isLocalRemoteHistoryAcceptableMatch(
-  t1: WalletReserveHistoryItem,
-  t2: ReserveTransaction,
-): boolean {
-  switch (t1.type) {
-    case WalletReserveHistoryItemType.Closing:
-      throw Error("invariant violated");
-    case WalletReserveHistoryItemType.Credit:
-      return !t1.expectedAmount && t2.type == ReserveTransactionType.Credit;
-    case WalletReserveHistoryItemType.Recoup:
-      return !t1.expectedAmount && t2.type == ReserveTransactionType.Recoup;
-    case WalletReserveHistoryItemType.Withdraw:
-      return !t1.expectedAmount && t2.type == ReserveTransactionType.Withdraw;
-  }
-}
-
 export function summarizeReserveHistory(
   localHistory: WalletReserveHistoryItem[],
   currency: string,
@@ -197,7 +191,9 @@ export function summarizeReserveHistory(
           negAmounts.push(
             Amounts.parseOrThrow(item.matchedExchangeTransaction.amount),
           );
-          
withdrawnAmounts.push(Amounts.parseOrThrow(item.matchedExchangeTransaction.amount));
+          withdrawnAmounts.push(
+            Amounts.parseOrThrow(item.matchedExchangeTransaction.amount),
+          );
         } else if (item.expectedAmount) {
           expectedNegAmounts.push(item.expectedAmount);
         } else {
@@ -299,33 +295,7 @@ export function reconcileReserveHistory(
       if (remoteMatched[remoteIndex]) {
         continue;
       }
-      if (isLocalRemoteHistoryPreferredMatch(lhi, rhi)) {
-        localMatched[localIndex] = true;
-        remoteMatched[remoteIndex] = true;
-        updatedLocalHistory[localIndex].matchedExchangeTransaction = rhi as 
any;
-        newMatchedItems.push(lhi);
-        break;
-      }
-    }
-  }
-
-  // Next, find out if there are any acceptable new matches between local and 
remote
-  // history items
-  for (let localIndex = 0; localIndex < localHistory.length; localIndex++) {
-    if (localMatched[localIndex]) {
-      continue;
-    }
-    const lhi = localHistory[localIndex];
-    for (
-      let remoteIndex = 0;
-      remoteIndex < remoteHistory.length;
-      remoteIndex++
-    ) {
-      const rhi = remoteHistory[remoteIndex];
-      if (remoteMatched[remoteIndex]) {
-        continue;
-      }
-      if (isLocalRemoteHistoryAcceptableMatch(lhi, rhi)) {
+      if (isLocalRemoteHistoryMatch(lhi, rhi)) {
         localMatched[localIndex] = true;
         remoteMatched[remoteIndex] = true;
         updatedLocalHistory[localIndex].matchedExchangeTransaction = rhi as 
any;

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



reply via email to

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