gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: rudimentary search


From: gnunet
Subject: [taler-wallet-core] branch master updated: rudimentary search
Date: Fri, 15 May 2020 13:28:20 +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 cf3eb520 rudimentary search
cf3eb520 is described below

commit cf3eb52033a1f33cc2d47e6dfb3381a6fc34bb6a
Author: Florian Dold <address@hidden>
AuthorDate: Fri May 15 16:58:15 2020 +0530

    rudimentary search
---
 src/headless/taler-wallet-cli.ts |  9 +++-
 src/operations/transactions.ts   | 99 ++++++++++++++++++++++++++++------------
 2 files changed, 77 insertions(+), 31 deletions(-)

diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 3e9d993d..bceb8295 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -232,10 +232,15 @@ walletCli
   });
 
 walletCli
-  .subcommand("", "transactions", { help: "Show transactions." })
+  .subcommand("transactions", "transactions", { help: "Show transactions." })
+  .maybeOption("currency", ["--currency"], clk.STRING)
+  .maybeOption("search", ["--search"], clk.STRING)
   .action(async (args) => {
     await withWallet(args, async (wallet) => {
-      const pending = await wallet.getTransactions({});
+      const pending = await wallet.getTransactions({
+        currency: args.transactions.currency,
+        search: args.transactions.search,
+      });
       console.log(JSON.stringify(pending, undefined, 2));
     });
   });
diff --git a/src/operations/transactions.ts b/src/operations/transactions.ts
index 9e07d4ff..20adf320 100644
--- a/src/operations/transactions.ts
+++ b/src/operations/transactions.ts
@@ -75,10 +75,8 @@ function getRefundStats(
       Amounts.parseOrThrow(perm.refund_fee),
     ).amount;
     if (pr.refundsRefreshCost[rk]) {
-      amountEffective = Amounts.sub(
-        amountEffective,
-        pr.refundsRefreshCost[rk],
-      ).amount;
+      amountEffective = Amounts.sub(amountEffective, pr.refundsRefreshCost[rk])
+        .amount;
     }
   }
 
@@ -100,6 +98,32 @@ function getRefundStats(
   };
 }
 
+function shouldSkipCurrency(
+  transactionsRequest: TransactionsRequest | undefined,
+  currency: string,
+): boolean {
+  if (!transactionsRequest?.currency) {
+    return false;
+  }
+  return transactionsRequest.currency.toLowerCase() !== currency.toLowerCase();
+}
+
+function shouldSkipSearch(
+  transactionsRequest: TransactionsRequest | undefined,
+  fields: string[],
+): boolean {
+  if (!transactionsRequest?.search) {
+    return false;
+  }
+  const needle = transactionsRequest.search.trim();
+  for (const f of fields) {
+    if (f.indexOf(needle) >= 0) {
+      return false;
+    }
+  }
+  return true;
+}
+
 /**
  * Retrive the full event history for this wallet.
  */
@@ -130,34 +154,44 @@ export async function getTransactions(
     async (tx) => {
       tx.iter(Stores.withdrawalGroups).forEach((wsr) => {
         if (
-          transactionsRequest?.currency &&
-          wsr.rawWithdrawalAmount.currency != transactionsRequest.currency
+          shouldSkipCurrency(
+            transactionsRequest,
+            wsr.rawWithdrawalAmount.currency,
+          )
         ) {
           return;
         }
-        if (wsr.rawWithdrawalAmount.currency)
-          if (wsr.timestampFinish) {
-            transactions.push({
-              type: TransactionType.Withdrawal,
-              amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
-              amountRaw: Amounts.stringify(wsr.denomsSel.totalWithdrawCost),
-              confirmed: true,
-              exchangeBaseUrl: wsr.exchangeBaseUrl,
-              pending: !wsr.timestampFinish,
-              timestamp: wsr.timestampStart,
-              transactionId: makeEventId(
-                TransactionType.Withdrawal,
-                wsr.withdrawalGroupId,
-              ),
-            });
-          }
+
+        if (shouldSkipSearch(transactionsRequest, [])) {
+          return;
+        }
+
+        if (transactionsRequest?.search)
+          if (wsr.rawWithdrawalAmount.currency)
+            if (wsr.timestampFinish) {
+              transactions.push({
+                type: TransactionType.Withdrawal,
+                amountEffective: Amounts.stringify(
+                  wsr.denomsSel.totalCoinValue,
+                ),
+                amountRaw: Amounts.stringify(wsr.denomsSel.totalWithdrawCost),
+                confirmed: true,
+                exchangeBaseUrl: wsr.exchangeBaseUrl,
+                pending: !wsr.timestampFinish,
+                timestamp: wsr.timestampStart,
+                transactionId: makeEventId(
+                  TransactionType.Withdrawal,
+                  wsr.withdrawalGroupId,
+                ),
+              });
+            }
       });
 
       tx.iter(Stores.reserves).forEach((r) => {
-        if (
-          transactionsRequest?.currency &&
-          r.currency != transactionsRequest.currency
-        ) {
+        if (shouldSkipCurrency(transactionsRequest, r.currency)) {
+          return;
+        }
+        if (shouldSkipSearch(transactionsRequest, [])) {
           return;
         }
         if (r.reserveStatus !== ReserveRecordStatus.WAIT_CONFIRM_BANK) {
@@ -170,7 +204,9 @@ export async function getTransactions(
           type: TransactionType.Withdrawal,
           confirmed: false,
           amountRaw: Amounts.stringify(r.bankInfo.denomSel.totalWithdrawCost),
-          amountEffective: 
Amounts.stringify(r.bankInfo.denomSel.totalCoinValue),
+          amountEffective: Amounts.stringify(
+            r.bankInfo.denomSel.totalCoinValue,
+          ),
           exchangeBaseUrl: r.exchangeBaseUrl,
           pending: true,
           timestamp: r.timestampCreated,
@@ -184,11 +220,16 @@ export async function getTransactions(
 
       tx.iter(Stores.purchases).forEachAsync(async (pr) => {
         if (
-          transactionsRequest?.currency &&
-          pr.contractData.amount.currency != transactionsRequest.currency
+          shouldSkipCurrency(
+            transactionsRequest,
+            pr.contractData.amount.currency,
+          )
         ) {
           return;
         }
+        if (shouldSkipSearch(transactionsRequest, [pr.contractData.summary])) {
+          return;
+        }
         const proposal = await tx.get(Stores.proposals, pr.proposalId);
         if (!proposal) {
           return;

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



reply via email to

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