gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/02: simplify matching


From: gnunet
Subject: [taler-wallet-core] 02/02: simplify matching
Date: Thu, 02 Apr 2020 17:12:39 +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 05e43bb259810c305cf69f9323017d6a682c8213
Author: Florian Dold <address@hidden>
AuthorDate: Thu Apr 2 20:42:33 2020 +0530

    simplify matching
---
 src/util/reserveHistoryUtil.ts | 64 +++++++++++-------------------------------
 1 file changed, 17 insertions(+), 47 deletions(-)

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]