gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (f9b77d3 -> 3b2b43c)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (f9b77d3 -> 3b2b43c)
Date: Tue, 04 Jul 2017 23:43:18 +0200

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

grothoff pushed a change to branch master
in repository merchant.

    from f9b77d3  comment
     new d85a856  implement first part of #4943: persist wire transfer fees of 
exchange in DB
     new 4ea441b  fix two minor typos / build compatibiltiy issues
     new 909a9a2  fix #4955
     new 3b2b43c  merge conflict resolution

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd_exchanges.c |  23 ++-
 src/backenddb/plugin_merchantdb_postgres.c   | 256 +++++++++++++++++++--------
 src/include/taler_merchantdb_plugin.h        |  27 +++
 src/lib/test_merchant_api.c                  |   4 +-
 4 files changed, 234 insertions(+), 76 deletions(-)

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..45ecab5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -68,75 +68,6 @@ postgres_drop_tables (void *cls)
                                     es);
 }
 
-/**
- * Start a transaction.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK on success
- */
-static int
-postgres_start (void *cls)
-{
-  struct PostgresClosure *pg = cls;
-  PGresult *result;
-  ExecStatusType ex;
-
-  result = PQexec (pg->conn,
-                   "START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
-  if (PGRES_COMMAND_OK !=
-      (ex = PQresultStatus (result)))
-  {
-    TALER_LOG_ERROR ("Failed to start transaction (%s): %s\n",
-                     PQresStatus (ex),
-                     PQerrorMessage (pg->conn));
-    GNUNET_break (0);
-    PQclear (result);
-    return GNUNET_SYSERR;
-  }
-  PQclear (result);
-  return GNUNET_OK;
-}
-
-
-/**
- * Roll back the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK on success
- */
-static void
-postgres_rollback (void *cls)
-{
-  struct PostgresClosure *pg = cls;
-  PGresult *result;
-
-  result = PQexec (pg->conn,
-                   "ROLLBACK");
-  GNUNET_break (PGRES_COMMAND_OK ==
-                PQresultStatus (result));
-  PQclear (result);
-}
-
-
-/**
- * Commit the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_commit (void *cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_end
-  };
-
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                            "end_transaction",
-                                            params);
-}
-
 
 /**
  * Initialize merchant tables
@@ -223,6 +154,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 +244,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_date"
+                            ",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"
@@ -489,6 +450,93 @@ postgres_initialize (void *cls)
 
 
 /**
+ * Check that the database connection is still up.
+ *
+ * @param pg connection to check
+ */
+static void
+check_connection (struct PostgresClosure *pg)
+{
+  if (CONNECTION_BAD != PQstatus (pg->conn))
+    return;
+  PQfinish (pg->conn);
+  GNUNET_break (GNUNET_OK ==
+               postgres_initialize (pg));
+}
+
+
+/**
+ * Start a transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+static int
+postgres_start (void *cls)
+{
+  struct PostgresClosure *pg = cls;
+  PGresult *result;
+  ExecStatusType ex;
+
+  check_connection (pg);
+  result = PQexec (pg->conn,
+                   "START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+  if (PGRES_COMMAND_OK !=
+      (ex = PQresultStatus (result)))
+  {
+    TALER_LOG_ERROR ("Failed to start transaction (%s): %s\n",
+                     PQresStatus (ex),
+                     PQerrorMessage (pg->conn));
+    GNUNET_break (0);
+    PQclear (result);
+    return GNUNET_SYSERR;
+  }
+  PQclear (result);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Roll back the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+static void
+postgres_rollback (void *cls)
+{
+  struct PostgresClosure *pg = cls;
+  PGresult *result;
+
+  result = PQexec (pg->conn,
+                   "ROLLBACK");
+  GNUNET_break (PGRES_COMMAND_OK ==
+                PQresultStatus (result));
+  PQclear (result);
+}
+
+
+/**
+ * Commit the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_commit (void *cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_end
+  };
+
+  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                            "end_transaction",
+                                            params);
+}
+
+
+/**
  * Retrieve proposal data given its proposal data's hashcode
  *
  * @param cls closure
@@ -515,6 +563,7 @@ postgres_find_contract_terms_from_hash (void *cls,
     GNUNET_PQ_result_spec_end
   };
 
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                   
"find_contract_terms_from_hash",
                                                   params,
@@ -553,6 +602,7 @@ postgres_find_contract_terms (void *cls,
               "Finding contract term, order_id: '%s', merchant_pub: '%s'.\n",
               order_id,
               TALER_B2S (merchant_pub));
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                   "find_contract_terms",
                                                   params,
@@ -595,6 +645,7 @@ postgres_insert_contract_terms (void *cls,
               order_id,
               TALER_B2S (merchant_pub),
               GNUNET_h2s (&h_contract_terms));
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_contract_terms",
                                             params);
@@ -641,6 +692,7 @@ postgres_store_transaction (void *cls,
               "Storing transaction with h_contract_terms '%s', merchant_pub 
'%s'.\n",
               GNUNET_h2s (h_contract_terms),
               TALER_B2S (merchant_pub));
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_transaction",
                                             params);
@@ -692,6 +744,7 @@ postgres_store_deposit (void *cls,
               TALER_B2S (coin_pub),
               TALER_amount_to_string (amount_with_fee),
               TALER_B2S (merchant_pub));
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_deposit",
                                             params);
@@ -723,6 +776,7 @@ postgres_store_coin_to_transfer (void *cls,
     GNUNET_PQ_query_param_end
   };
 
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_transfer",
                                             params);
@@ -758,6 +812,7 @@ postgres_store_transfer_to_proof (void *cls,
     GNUNET_PQ_query_param_end
   };
 
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_proof",
                                             params);
@@ -777,10 +832,10 @@ postgres_store_transfer_to_proof (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_find_contract_terms_history (void *cls,
-                                     const char *order_id,
-                                     const struct TALER_MerchantPublicKeyP 
*merchant_pub,
-                                     TALER_MERCHANTDB_ProposalDataCallback cb,
-                                     void *cb_cls)
+                                     const char *order_id,
+                                     const struct TALER_MerchantPublicKeyP 
*merchant_pub,
+                                     TALER_MERCHANTDB_ProposalDataCallback cb,
+                                     void *cb_cls)
 {
   struct PostgresClosure *pg = cls;
   json_t *contract_terms;
@@ -936,6 +991,7 @@ postgres_find_contract_terms_by_date_and_range (void *cls,
     stmt = "find_contract_terms_by_date_and_range_future";
   else
     stmt = "find_contract_terms_by_date_and_range";
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             stmt,
                                             params,
@@ -981,6 +1037,7 @@ postgres_find_contract_terms_by_date (void *cls,
     .cb_cls = cb_cls
   };
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             "find_contract_terms_by_date",
                                             params,
@@ -1040,6 +1097,7 @@ postgres_find_transaction (void *cls,
               GNUNET_h2s (h_contract_terms),
               TALER_B2S (merchant_pub));
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                 "find_transaction",
                                                 params,
@@ -1179,6 +1237,7 @@ postgres_find_payments (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Finding payment for h_contract_terms '%s'\n",
               GNUNET_h2s (h_contract_terms));
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             "find_deposits",
                                             params,
@@ -1311,6 +1370,7 @@ postgres_find_payments_by_hash_and_coin (void *cls,
   };
   enum GNUNET_DB_QueryStatus qs;
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             "find_deposits_by_hash_and_coin",
                                             params,
@@ -1435,6 +1495,7 @@ postgres_find_transfers_by_hash (void *cls,
   };
   enum GNUNET_DB_QueryStatus qs;
   
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             "find_transfers_by_hash",
                                             params,
@@ -1556,6 +1617,7 @@ postgres_find_deposits_by_wtid (void *cls,
   };
   enum GNUNET_DB_QueryStatus qs;
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             "find_deposits_by_wtid",
                                             params,
@@ -1679,6 +1741,7 @@ postgres_get_refunds_from_contract_terms_hash (void *cls,
                    GNUNET_h2s (h_contract_terms),
                    TALER_B2S (merchant_pub));
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                             
"find_refunds_from_contract_terms_hash",
                                             params,
@@ -1726,6 +1789,7 @@ insert_refund (void *cls,
                    GNUNET_h2s (h_contract_terms),
                    TALER_B2S (merchant_pub));
   
+  check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_refund",
                                              params);
@@ -1733,6 +1797,50 @@ 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
+  };
+
+  check_connection (pg);
+  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             "insert_wire_fee",
+                                             params);  
+}
+
+
+/**
  * Closure for #process_refund_cb.
  */
 struct FindRefundContext
@@ -2162,6 +2270,7 @@ postgres_find_proof_by_wtid (void *cls,
   };
   enum GNUNET_DB_QueryStatus qs;
 
+  check_connection (pg);
   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                 "find_proof_by_wtid",
                                                 params,
@@ -2227,6 +2336,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.
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index dfac9dd..1b1968b 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -2420,12 +2420,12 @@ do_shutdown (void *cls)
  *
  * @param cls closure
  * @param keys information about keys of the exchange
- * @param compat protocol compatibility information
+ * @param vc compatibility information
  */
 static void
 cert_cb (void *cls,
          const struct TALER_EXCHANGE_Keys *keys,
-         enum TALER_EXCHANGE_VersionCompatibility compat)
+        enum TALER_EXCHANGE_VersionCompatibility vc)
 {
   struct InterpreterState *is = cls;
 

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



reply via email to

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