gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 01/04: implement first part of #4943: pers


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 01/04: implement first part of #4943: persist wire transfer fees of exchange in DB
Date: Tue, 04 Jul 2017 23:43:19 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit d85a8566f3339f271e65caead9c68bd8d648d2b4
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Jul 1 15:55:29 2017 +0200

    implement first part of #4943: persist wire transfer fees of exchange in DB
---
 src/backend/taler-merchant-httpd_exchanges.c | 23 ++++++++-
 src/backenddb/plugin_merchantdb_postgres.c   | 74 ++++++++++++++++++++++++++++
 src/include/taler_merchantdb_plugin.h        | 27 ++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/src/backend/taler-merchant-httpd_exchanges.c 
b/src/backend/taler-merchant-httpd_exchanges.c
index a0d3202..a011be4 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -341,15 +341,36 @@ process_wire_fees (void *cls,
   }
   while (NULL != fees)
   {
+    struct GNUNET_HashCode h_wire_method;
+    enum GNUNET_DB_QueryStatus qs;
+    
     af = GNUNET_new (struct TALER_EXCHANGE_WireAggregateFees);
     *af = *fees;
+    GNUNET_CRYPTO_hash (wire_method,
+                       strlen (wire_method) + 1,
+                       &h_wire_method);
+    qs = db->store_wire_fee_by_exchange (db->cls,
+                                        &exchange->master_pub,
+                                        &h_wire_method,
+                                        &af->wire_fee,
+                                        &af->closing_fee,
+                                        af->start_date,
+                                        af->end_date,
+                                        &af->master_sig);
+    if (0 > qs)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Failed to persist exchange wire fees in merchant DB!\n");
+      GNUNET_free (af);
+      fees = fees->next;
+      continue;
+    }
     af->next = NULL;
     if (NULL == endp)
       f->af = af;
     else
       endp->next = af;
     endp = af;
-    // FIXME #4943: also preserve `fees` in backend DB (under wire method + 
exchange master pub!)
     fees = fees->next;
   }
 }
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index bb1f286..a05f468 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -223,6 +223,20 @@ postgres_initialize (void *cls)
                                 " ON merchant_transfers (h_contract_terms, 
coin_pub)"),
     GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS 
merchant_transfers_by_wtid"
                                 " ON merchant_transfers (wtid)"),
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS exchange_wire_fees ("
+                           " exchange_pub BYTEA NOT NULL CHECK 
(length(exchange_pub)=32)"
+                           ",h_wire_method BYTEA NOT NULL CHECK 
(length(h_wire_method)=64)"
+                            ",wire_fee_val INT8 NOT NULL"
+                            ",wire_fee_frac INT4 NOT NULL"
+                            ",wire_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR 
") NOT NULL"
+                            ",closing_fee_val INT8 NOT NULL"
+                            ",closing_fee_frac INT4 NOT NULL"
+                            ",closing_fee_curr VARCHAR(" 
TALER_CURRENCY_LEN_STR ") NOT NULL"
+                           ",start_date INT8 NOT NULL"
+                           ",end_date INT8 NOT NULL"
+                           ",exchange_sig BYTEA NOT NULL CHECK 
(length(exchange_sig)=64)"
+                           ",PRIMARY KEY 
(exchange_pub,h_wire_method,start_date,end_date)"
+                           ");"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
   };
   struct GNUNET_PQ_PreparedStatement ps[] = {
@@ -299,6 +313,22 @@ postgres_initialize (void *cls)
                             " VALUES "
                             "($1, $2, $3, $4, $5)",
                             4),
+    GNUNET_PQ_make_prepare ("insert_wire_fee",
+                            "INSERT INTO exchange_wire_fees"
+                            "(exchange_pub"
+                            ",h_wire_method"
+                            ",wire_fee_val"
+                            ",wire_fee_frac"
+                            ",wire_fee_curr"
+                            ",closing_fee_val"
+                            ",closing_fee_frac"
+                            ",closing_fee_curr"
+                            ",start_date"
+                            ",end_data"
+                            ",exchange_sig)"
+                            " VALUES "
+                            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
+                            11),
     GNUNET_PQ_make_prepare ("find_contract_terms_from_hash",
                             "SELECT"
                             " contract_terms"
@@ -1733,6 +1763,49 @@ insert_refund (void *cls,
 
 
 /**
+ * Store information about wire fees charged by an exchange,
+ * including signature (so we have proof).
+ *
+ * @param cls closure
+ * @paramm exchange_pub public key of the exchange
+ * @param h_wire_method hash of wire method
+ * @param wire_fee wire fee charged
+ * @param closing_fee closing fee charged (irrelevant for us,
+ *              but needed to check signature)
+ * @param start_date start of fee being used
+ * @param end_date end of fee being used
+ * @param exchange_sig signature of exchange over fee structure
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_store_wire_fee_by_exchange (void *cls,
+                                    const struct TALER_MasterPublicKeyP 
*exchange_pub,
+                                    const struct GNUNET_HashCode 
*h_wire_method,
+                                    const struct TALER_Amount *wire_fee,
+                                    const struct TALER_Amount *closing_fee,
+                                    struct GNUNET_TIME_Absolute start_date,
+                                    struct GNUNET_TIME_Absolute end_date,
+                                    const struct TALER_MasterSignatureP 
*exchange_sig)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+    GNUNET_PQ_query_param_auto_from_type (h_wire_method),
+    TALER_PQ_query_param_amount (wire_fee),
+    TALER_PQ_query_param_amount (closing_fee),
+    GNUNET_PQ_query_param_absolute_time (&start_date),
+    GNUNET_PQ_query_param_absolute_time (&end_date),
+    GNUNET_PQ_query_param_auto_from_type (exchange_sig),
+    GNUNET_PQ_query_param_end
+  };
+
+  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             "insert_wire_fee",
+                                             params);  
+}
+
+
+/**
  * Closure for #process_refund_cb.
  */
 struct FindRefundContext
@@ -2227,6 +2300,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
   plugin->store_deposit = &postgres_store_deposit;
   plugin->store_coin_to_transfer = &postgres_store_coin_to_transfer;
   plugin->store_transfer_to_proof = &postgres_store_transfer_to_proof;
+  plugin->store_wire_fee_by_exchange = &postgres_store_wire_fee_by_exchange;
   plugin->find_transaction = &postgres_find_transaction;
   plugin->find_payments_by_hash_and_coin = 
&postgres_find_payments_by_hash_and_coin;
   plugin->find_payments = &postgres_find_payments;
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index f856fc7..efb03cb 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -391,6 +391,32 @@ struct TALER_MERCHANTDB_Plugin
 
 
   /**
+   * Store information about wire fees charged by an exchange,
+   * including signature (so we have proof).
+   *
+   * @param cls closure
+   * @paramm exchange_pub public key of the exchange
+   * @param h_wire_method hash of wire method
+   * @param wire_fee wire fee charged
+   * @param closing_fee closing fee charged (irrelevant for us,
+   *              but needed to check signature)
+   * @param start_date start of fee being used
+   * @param end_date end of fee being used
+   * @param exchange_sig signature of exchange over fee structure
+   * @return transaction status code
+   */
+  enum GNUNET_DB_QueryStatus
+  (*store_wire_fee_by_exchange) (void *cls,
+                                const struct TALER_MasterPublicKeyP 
*exchange_pub,
+                                const struct GNUNET_HashCode *h_wire_method,
+                                const struct TALER_Amount *wire_fee,
+                                const struct TALER_Amount *closing_fee,
+                                struct GNUNET_TIME_Absolute start_date,
+                                struct GNUNET_TIME_Absolute end_date,
+                                const struct TALER_MasterSignatureP 
*exchange_sig);
+                                
+
+  /**
    * Find information about a transaction.
    *
    * @param cls our plugin handle
@@ -404,6 +430,7 @@ struct TALER_MERCHANTDB_Plugin
                                 struct GNUNET_TIME_Absolute date,
                                 TALER_MERCHANTDB_TransactionCallback cb,
                                 void *cb_cls);
+  
 
   /**
    * Find information about a transaction.

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



reply via email to

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