gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated: implement select_re


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: implement select_refunds_by_coin in exchangedb plugin
Date: Tue, 02 Jan 2018 14:43:19 +0100

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 41b5dde  implement select_refunds_by_coin in exchangedb plugin
41b5dde is described below

commit 41b5dde70945b6cb468e412caf6ab7ecd7f56651
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jan 2 14:43:15 2018 +0100

    implement select_refunds_by_coin in exchangedb plugin
---
 src/exchangedb/plugin_exchangedb_postgres.c | 123 ++++++++++++++++++++++++++++
 src/include/taler_exchangedb_plugin.h       |  40 +++++++++
 2 files changed, 163 insertions(+)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 36ae3e5..9c91259 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3033,6 +3033,128 @@ postgres_insert_refund (void *cls,
 
 
 /**
+ * Closure for #get_refunds_cb().
+ */
+struct SelectRefundContext
+{
+  /**
+   * Function to call on each result.
+   */
+  TALER_EXCHANGEDB_RefundCoinCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Set to #GNUNET_SYSERR on error.
+   */ 
+  int status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct SelectRefundContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+get_refunds_cb (void *cls,
+               PGresult *result,
+               unsigned int num_results)
+{
+  struct SelectRefundContext *srctx = cls;
+
+  for (unsigned int i=0;i<num_results;i++)
+  {
+    struct TALER_MerchantPublicKeyP merchant_pub;
+    struct TALER_MerchantSignatureP merchant_sig;
+    struct GNUNET_HashCode h_contract;
+    uint64_t rtransaction_id;
+    struct TALER_Amount amount_with_fee;
+    struct TALER_Amount refund_fee;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+                                           &merchant_pub),
+      GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
+                                           &merchant_sig),
+      GNUNET_PQ_result_spec_auto_from_type ("h_contract",
+                                           &h_contract),
+      GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+                                   &rtransaction_id),
+      TALER_PQ_result_spec_amount ("amount_with_fee",
+                                  &amount_with_fee),
+      TALER_PQ_result_spec_amount ("fee_refund",
+                                  &refund_fee),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+       GNUNET_PQ_extract_result (result,
+                                 rs,
+                                 i))
+    {
+      GNUNET_break (0);
+      srctx->status = GNUNET_SYSERR;
+      return;
+    }
+    if (GNUNET_OK !=
+       srctx->cb (srctx->cb_cls,
+                  &merchant_pub,
+                  &merchant_sig,
+                  &h_contract,
+                  rtransaction_id,
+                  &amount_with_fee,
+                  &refund_fee))
+      return;
+  }
+}
+
+
+/**
+ * Select refunds by @a coin_pub.
+ *
+ * @param cls closure of plugin
+ * @param session database handle to use
+ * @param coin_pub coin to get refunds for
+ * @param cb function to call for each refund found
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_select_refunds_by_coin (void *cls,
+                                struct TALER_EXCHANGEDB_Session *session,
+                                const struct TALER_CoinSpendPublicKeyP 
*coin_pub,
+                                TALER_EXCHANGEDB_RefundCoinCallback cb,
+                                void *cb_cls)
+{
+  enum GNUNET_DB_QueryStatus qs;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (coin_pub),
+    GNUNET_PQ_query_param_end
+  };
+  struct SelectRefundContext srctx = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .status = GNUNET_OK
+  };
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
+                                             "get_refunds_by_coin",
+                                             params,
+                                             &get_refunds_cb,
+                                             &srctx);
+  if (GNUNET_SYSERR == srctx.status)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
+
+
+/**
  * Lookup refresh melt commitment data under the given @a rc.
  *
  * @param cls the `struct PostgresClosure` with the plugin-specific state
@@ -6236,6 +6358,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
   plugin->iterate_matching_deposits = &postgres_iterate_matching_deposits;
   plugin->insert_deposit = &postgres_insert_deposit;
   plugin->insert_refund = &postgres_insert_refund;
+  plugin->select_refunds_by_coin = &postgres_select_refunds_by_coin;
   plugin->insert_melt = &postgres_insert_melt;
   plugin->get_melt = &postgres_get_melt;
   plugin->insert_refresh_reveal = &postgres_insert_refresh_reveal;
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index e64b0ad..c531d83 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -733,6 +733,29 @@ typedef int
 
 
 /**
+ * Callback invoked with information about refunds applicable
+ * to a particular coin.
+ *
+ * @param cls closure
+ * @param merchant_pub public key of merchant who authorized refund
+ * @param merchant_sig signature of merchant authorizing refund
+ * @param h_contract hash of contract being refunded
+ * @param rtransaction_id refund transaction ID
+ * @param amount_with_fee amount being refunded
+ * @param refund_fee fee the exchange keeps for the refund processing
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef int
+(*TALER_EXCHANGEDB_RefundCoinCallback)(void *cls,
+                                      const struct TALER_MerchantPublicKeyP 
*merchant_pub,
+                                      const struct TALER_MerchantSignatureP 
*merchant_sig,
+                                      const struct GNUNET_HashCode *h_contract,
+                                      uint64_t rtransaction_id,
+                                      const struct TALER_Amount 
*amount_with_fee,
+                                      const struct TALER_Amount *refund_fee);
+
+
+/**
  * Information about a coin that was revealed to the exchange
  * during /refresh/reveal.
  */
@@ -1358,6 +1381,23 @@ struct TALER_EXCHANGEDB_Plugin
                     struct TALER_EXCHANGEDB_Session *session,
                     const struct TALER_EXCHANGEDB_Refund *refund);
 
+  /**
+   * Select refunds by @a coin_pub.
+   *
+   * @param cls closure of plugin
+   * @param session database handle to use
+   * @param coin_pub coin to get refunds for
+   * @param cb function to call for each refund found
+   * @param cb_cls closure for @a cb
+   * @return query result status
+   */
+  enum GNUNET_DB_QueryStatus
+  (*select_refunds_by_coin)(void *cls,
+                           struct TALER_EXCHANGEDB_Session *session,
+                           const struct TALER_CoinSpendPublicKeyP *coin_pub,
+                           TALER_EXCHANGEDB_RefundCoinCallback cb,
+                           void *cb_cls);
+  
 
   /**
    * Mark a deposit as tiny, thereby declaring that it cannot be

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



reply via email to

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