gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: add logic to return information


From: gnunet
Subject: [taler-exchange] branch master updated: add logic to return information about purse refunds in coin histories
Date: Sat, 15 Oct 2022 10:43:31 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new eebc030f add logic to return information about purse refunds in coin 
histories
eebc030f is described below

commit eebc030f6cf61d36b80e3273709fd9f254b155c3
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Oct 15 10:43:26 2022 +0200

    add logic to return information about purse refunds in coin histories
---
 src/exchangedb/exchangedb_transactions.c  | 20 ++++++++
 src/exchangedb/pg_get_coin_transactions.c | 77 +++++++++++++++++++++++++++++++
 src/exchangedb/plugin_exchangedb_common.c |  8 ++++
 src/include/taler_exchangedb_plugin.h     | 38 ++++++++++++++-
 4 files changed, 142 insertions(+), 1 deletion(-)

diff --git a/src/exchangedb/exchangedb_transactions.c 
b/src/exchangedb/exchangedb_transactions.c
index 60b95d6f..f7839377 100644
--- a/src/exchangedb/exchangedb_transactions.c
+++ b/src/exchangedb/exchangedb_transactions.c
@@ -131,6 +131,26 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
       }
       deposit_fee = pos->details.purse_deposit->deposit_fee;
       break;
+    case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+      /* refunded += pos->refund_amount - pos->refund_fee */
+      if (0 >
+          TALER_amount_add (&refunded,
+                            &refunded,
+                            &pos->details.purse_refund->refund_amount))
+      {
+        GNUNET_break (0);
+        return GNUNET_SYSERR;
+      }
+      if (0 >
+          TALER_amount_add (&spent,
+                            &spent,
+                            &pos->details.purse_refund->refund_fee))
+      {
+        GNUNET_break (0);
+        return GNUNET_SYSERR;
+      }
+      have_refund = true;
+      break;
     case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
       /* spent += pos->amount_with_fee */
       if (0 >
diff --git a/src/exchangedb/pg_get_coin_transactions.c 
b/src/exchangedb/pg_get_coin_transactions.c
index 54dce7f6..b6b892e5 100644
--- a/src/exchangedb/pg_get_coin_transactions.c
+++ b/src/exchangedb/pg_get_coin_transactions.c
@@ -343,6 +343,63 @@ add_coin_refund (void *cls,
 }
 
 
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_purse_refund (void *cls,
+                       PGresult *result,
+                       unsigned int num_results)
+{
+  struct CoinHistoryContext *chc = cls;
+  struct PostgresClosure *pg = chc->pg;
+
+  for (unsigned int i = 0; i<num_results; i++)
+  {
+    struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
+    struct TALER_EXCHANGEDB_TransactionList *tl;
+    uint64_t serial_id;
+
+    prefund = GNUNET_new (struct TALER_EXCHANGEDB_PurseRefundListEntry);
+    {
+      struct GNUNET_PQ_ResultSpec rs[] = {
+        GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+                                              &prefund->purse_pub),
+        TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+                                     &prefund->refund_amount),
+        TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+                                     &prefund->refund_fee),
+        GNUNET_PQ_result_spec_uint64 ("purse_refunds_serial_id",
+                                      &serial_id),
+        GNUNET_PQ_result_spec_end
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_PQ_extract_result (result,
+                                    rs,
+                                    i))
+      {
+        GNUNET_break (0);
+        GNUNET_free (prefund);
+        chc->failed = true;
+        return;
+      }
+    }
+    tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+    tl->next = chc->head;
+    tl->type = TALER_EXCHANGEDB_TT_PURSE_REFUND;
+    tl->details.purse_refund = prefund;
+    tl->serial_id = serial_id;
+    chc->head = tl;
+  }
+}
+
+
 /**
  * Function to be called with the results of a SELECT statement
  * that has returned @a num_results results.
@@ -629,6 +686,9 @@ TEH_PG_get_coin_transactions (
     /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
     { "get_purse_deposit_by_coin_pub",
       &add_coin_purse_deposit },
+    /** #TALER_EXCHANGEDB_TT_PURSE_REFUND */
+    { "get_purse_refund_by_coin_pub",
+      &add_coin_purse_refund },
     /** #TALER_EXCHANGEDB_TT_REFUND */
     { "get_refunds_by_coin",
       &add_coin_refund },
@@ -748,6 +808,23 @@ TEH_PG_get_coin_transactions (
            " JOIN denominations denom"
            "   USING (denominations_serial)"
            " WHERE ref.coin_pub=$1;");
+  PREPARE (pg,
+           "get_purse_refund_by_coin",
+           "SELECT"
+           " pr.purse_pub"
+           ",pd.amount_with_fee_val"
+           ",pd.amount_with_fee_frac"
+           ",denom.fee_refund_val "
+           ",denom.fee_refund_frac "
+           ",pr.purse_refunds_serial_id"
+           " FROM purse_deposits pd"
+           " JOIN purse_refunds pr"
+           "   USING (purse_pub)"
+           " JOIN known_coins kc"
+           "   ON (pd.coin_pub = kc.coin_pub)"
+           " JOIN denominations denom"
+           "   USING (denominations_serial)"
+           " WHERE pd.coin_pub=$1;");
   PREPARE (pg,
            "recoup_by_old_coin",
            "SELECT"
diff --git a/src/exchangedb/plugin_exchangedb_common.c 
b/src/exchangedb/plugin_exchangedb_common.c
index 84198ddd..a0159fb8 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -152,6 +152,14 @@ TEH_COMMON_free_coin_transaction_list (
         GNUNET_free (deposit);
         break;
       }
+    case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+      {
+        struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
+
+        prefund = tl->details.purse_refund;
+        GNUNET_free (prefund);
+        break;
+      }
     case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
       {
         struct TALER_EXCHANGEDB_ReserveOpenListEntry *role;
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index 0df32241..a12c2ac3 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1788,6 +1788,31 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry
 };
 
 
+/**
+ * @brief Specification for a purse refund operation in a coin's transaction 
list.
+ */
+struct TALER_EXCHANGEDB_PurseRefundListEntry
+{
+
+  /**
+   * Public key of the purse.
+   */
+  struct TALER_PurseContractPublicKeyP purse_pub;
+
+  /**
+   * Fraction of the original deposit's value to be refunded, including
+   * refund fee (if any).  The coin is identified by @e coin_pub.
+   */
+  struct TALER_Amount refund_amount;
+
+  /**
+   * Refund fee to be covered by the customer.
+   */
+  struct TALER_Amount refund_fee;
+
+};
+
+
 /**
  * Information about a /reserves/$RID/open operation in a coin transaction 
history.
  */
@@ -1974,10 +1999,15 @@ enum TALER_EXCHANGEDB_TransactionType
    */
   TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6,
 
+  /**
+   * Purse deposit operation.
+   */
+  TALER_EXCHANGEDB_TT_PURSE_REFUND = 7,
+
   /**
    * Reserve open deposit operation.
    */
-  TALER_EXCHANGEDB_TT_RESERVE_OPEN = 7
+  TALER_EXCHANGEDB_TT_RESERVE_OPEN = 8
 
 };
 
@@ -2053,6 +2083,12 @@ struct TALER_EXCHANGEDB_TransactionList
      */
     struct TALER_EXCHANGEDB_PurseDepositListEntry *purse_deposit;
 
+    /**
+     * Coin was refunded upon purse expiration
+     * (#TALER_EXCHANGEDB_TT_PURSE_REFUND)
+     */
+    struct TALER_EXCHANGEDB_PurseRefundListEntry *purse_refund;
+
     /**
      * Coin was used to pay to open a reserve.
      * (#TALER_EXCHANGEDB_TT_RESERVE_OPEN)

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