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: updating DB schema


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: updating DB schema for new wire history operations and future auditor checks of wire transfers
Date: Fri, 05 May 2017 13:36:26 +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 7654551  updating DB schema for new wire history operations and future 
auditor checks of wire transfers
7654551 is described below

commit 76545519c647b66ef99391b503f5d90fd4a43cb4
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri May 5 13:41:32 2017 +0200

    updating DB schema for new wire history operations and future auditor 
checks of wire transfers
---
 src/auditor/taler-auditor.c                        | 12 ++++--
 src/exchange-tools/taler-exchange-reservemod.c     |  2 +
 src/exchange/taler-exchange-httpd_db.c             |  2 +
 src/exchange/taler-exchange-wirewatch.c            | 18 +++++----
 src/exchangedb/perf_taler_exchangedb_interpreter.c |  2 +
 src/exchangedb/plugin_exchangedb_common.c          |  3 +-
 src/exchangedb/plugin_exchangedb_postgres.c        | 46 ++++++++++++++++------
 src/exchangedb/test_exchangedb.c                   | 12 +++++-
 src/include/taler_exchangedb_plugin.h              | 26 ++++++++++--
 9 files changed, 91 insertions(+), 32 deletions(-)

diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c
index fa8940f..aad4cea 100644
--- a/src/auditor/taler-auditor.c
+++ b/src/auditor/taler-auditor.c
@@ -615,6 +615,8 @@ struct ReserveContext
  * @param credit amount that was received
  * @param sender_account_details information about the sender's bank account
  * @param transfer_details information that uniquely identifies the wire 
transfer
+ * @param wire_reference unique reference identifying the wire transfer 
(binary blob)
+ * @param wire_reference_size number of bytes in @a wire_reference
  * @param execution_date when did we receive the funds
  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
  */
@@ -625,6 +627,8 @@ handle_reserve_in (void *cls,
                    const struct TALER_Amount *credit,
                    const json_t *sender_account_details,
                    const json_t *transfer_details,
+                   const void *wire_reference,
+                   size_t wire_reference_size,
                    struct GNUNET_TIME_Absolute execution_date)
 {
   struct ReserveContext *rc = cls;
@@ -633,7 +637,7 @@ handle_reserve_in (void *cls,
   struct GNUNET_TIME_Absolute expiry;
 
   /* should be monotonically increasing */
-  GNUNET_assert (rowid >= pp.last_reserve_in_serial_id); 
+  GNUNET_assert (rowid >= pp.last_reserve_in_serial_id);
   pp.last_reserve_in_serial_id = rowid + 1;
 
   GNUNET_CRYPTO_hash (reserve_pub,
@@ -904,13 +908,13 @@ handle_payback_by_reserve (void *cls,
     {
       report_row_inconsistency ("payback",
                                rowid,
-                               "denomination key not in revocation set");      
+                               "denomination key not in revocation set");
     }
     else
     {
       /* verify msig */
       struct TALER_MasterDenominationKeyRevocation kr;
-      
+
       kr.purpose.purpose = htonl 
(TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED);
       kr.purpose.size = htonl (sizeof (kr));
       kr.h_denom_pub = pr.h_denom_pub;
@@ -1012,7 +1016,7 @@ handle_reserve_closed (void *cls,
   struct ReserveContext *rc = cls;
   struct GNUNET_HashCode key;
   struct ReserveSummary *rs;
-  
+
   /* should be monotonically increasing */
   GNUNET_assert (rowid >= pp.last_reserve_close_serial_id);
   pp.last_reserve_close_serial_id = rowid + 1;
diff --git a/src/exchange-tools/taler-exchange-reservemod.c 
b/src/exchange-tools/taler-exchange-reservemod.c
index 01114a9..6264990 100644
--- a/src/exchange-tools/taler-exchange-reservemod.c
+++ b/src/exchange-tools/taler-exchange-reservemod.c
@@ -95,6 +95,8 @@ run_transaction (const struct TALER_ReservePublicKeyP 
*reserve_pub,
                                     add_value,
                                     GNUNET_TIME_absolute_get (),
                                     jdetails,
+                                    "FIXME",
+                                    5,
                                     tdetails);
   if (GNUNET_SYSERR == ret)
   {
diff --git a/src/exchange/taler-exchange-httpd_db.c 
b/src/exchange/taler-exchange-httpd_db.c
index dbaffc4..085438d 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -1880,6 +1880,8 @@ TEH_DB_execute_admin_add_incoming (struct MHD_Connection 
*connection,
                                         amount,
                                         execution_time,
                                         sender_account_details,
+                                        "FIXME",
+                                        5,
                                         transfer_details);
   if (GNUNET_SYSERR == ret)
   {
diff --git a/src/exchange/taler-exchange-wirewatch.c 
b/src/exchange/taler-exchange-wirewatch.c
index d343bb5..a7f3cd7 100644
--- a/src/exchange/taler-exchange-wirewatch.c
+++ b/src/exchange/taler-exchange-wirewatch.c
@@ -40,7 +40,7 @@
  * Handle to the plugin.
  */
 static struct TALER_WIRE_Plugin *wire_plugin;
-  
+
 /**
  * Which currency is used by this exchange?
  */
@@ -63,7 +63,7 @@ static struct TALER_EXCHANGEDB_Plugin *db_plugin;
 static int global_ret;
 
 /**
- * Encoded offset in the wire transfer list that we 
+ * Encoded offset in the wire transfer list that we
  * processed last.
  */
 static void *last_row_off;
@@ -180,7 +180,7 @@ exchange_serve_process_config ()
     TALER_EXCHANGEDB_plugin_unload (db_plugin);
     return GNUNET_SYSERR;
   }
-  
+
   return GNUNET_OK;
 }
 
@@ -248,16 +248,18 @@ history_cb (void *cls,
   {
     /* FIXME: need way to wire money back immediately... */
     GNUNET_break (0); // not implemented
-    
+
     return GNUNET_OK;
   }
-  // FIXME: store row_off+row_off_size instead of json_t?
+  // FIXME: create json!
   ret = db_plugin->reserves_in_insert (db_plugin->cls,
                                       session,
                                       &reserve_pub,
                                       &details->amount,
                                       details->execution_date,
                                       details->account_details,
+                                       row_off,
+                                       row_off_size,
                                       NULL /* FIXME */);
   if (GNUNET_OK != ret)
   {
@@ -269,7 +271,7 @@ history_cb (void *cls,
                                     NULL);
     return GNUNET_SYSERR;
   }
-  
+
   if (last_row_off_size != row_off_size)
   {
     GNUNET_free_non_null (last_row_off);
@@ -291,7 +293,7 @@ static void
 find_transfers (void *cls)
 {
   struct TALER_EXCHANGEDB_Session *session;
-  
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Checking for incoming wire transfers\n");
 
@@ -357,7 +359,7 @@ run (void *cls,
     global_ret = 1;
     return;
   }
-  
+
   task = GNUNET_SCHEDULER_add_now (&find_transfers,
                                    NULL);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c 
b/src/exchangedb/perf_taler_exchangedb_interpreter.c
index 26c2764..06078cf 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.c
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c
@@ -1394,6 +1394,8 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state 
*state)
                                                    &reserve->reserve.balance,
                                                    GNUNET_TIME_absolute_get (),
                                                    sndr,
+                                                   "PERF",
+                                                   4,
                                                    just);
           GNUNET_assert (GNUNET_SYSERR != ret);
           json_decref (sndr);
diff --git a/src/exchangedb/plugin_exchangedb_common.c 
b/src/exchangedb/plugin_exchangedb_common.c
index fac911d..0f7d2fe 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -35,7 +35,7 @@ common_free_reserve_history (void *cls,
   struct TALER_EXCHANGEDB_Payback *payback;
   struct TALER_EXCHANGEDB_ReserveHistory *backref;
   struct TALER_EXCHANGEDB_ClosingTransfer *closing;
-    
+
   while (NULL != rh)
   {
     switch(rh->type)
@@ -46,6 +46,7 @@ common_free_reserve_history (void *cls,
         json_decref (bt->sender_account_details);
       if (NULL != bt->transfer_details)
         json_decref (bt->transfer_details);
+      GNUNET_free_non_null (bt->wire_reference);
       GNUNET_free (bt);
       break;
     case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 35b24ed..352d51c 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -352,13 +352,14 @@ postgres_create_tables (void *cls)
   SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in"
           "(reserve_in_serial_id BIGSERIAL"
          ",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON 
DELETE CASCADE"
+          ",wire_reference BYTEA NOT NULL"
           ",credit_val INT8 NOT NULL"
           ",credit_frac INT4 NOT NULL"
           ",credit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
-          ",sender_account_details TEXT NOT NULL "
-          ",transfer_details TEXT NOT NULL "
+          ",sender_account_details TEXT NOT NULL"
+          ",transfer_details TEXT NOT NULL"
           ",execution_date INT8 NOT NULL"
-          ",PRIMARY KEY (reserve_pub, transfer_details)"
+          ",PRIMARY KEY (reserve_pub, wire_reference)"
           ");");
   /* Create indices on reserves_in */
   SQLEXEC_INDEX ("CREATE INDEX reserves_in_execution_index"
@@ -381,7 +382,7 @@ postgres_create_tables (void *cls)
           ")");
   SQLEXEC_INDEX("CREATE INDEX reserves_close_by_reserve "
                 "ON reserves_close(reserve_pub)");
-  
+
   /* Table with the withdraw operations that have been performed on a reserve.
      The 'h_blind_ev' is the hash of the blinded coin. It serves as a primary
      key, as (broken) clients that use a non-random coin and blinding factor
@@ -587,7 +588,7 @@ postgres_create_tables (void *cls)
   SQLEXEC_INDEX("CREATE INDEX prepare_iteration_index "
                 "ON prewire(type,finished)");
 
-  
+
 #undef SQLEXEC
 #undef SQLEXEC_INDEX
 
@@ -758,6 +759,7 @@ postgres_prepare (PGconn *db_conn)
   PREPARE ("reserves_in_add_transaction",
            "INSERT INTO reserves_in "
            "(reserve_pub"
+           ",wire_reference"
            ",credit_val"
            ",credit_frac"
            ",credit_curr"
@@ -765,8 +767,8 @@ postgres_prepare (PGconn *db_conn)
            ",transfer_details"
            ",execution_date"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);",
-           7, NULL);
+           "($1, $2, $3, $4, $5, $6, $7, $8);",
+           8, NULL);
 
 
   /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
@@ -774,6 +776,7 @@ postgres_prepare (PGconn *db_conn)
   PREPARE ("audit_reserves_in_get_transactions_incr",
            "SELECT"
            " reserve_pub"
+           ",wire_reference"
            ",credit_val"
            ",credit_frac"
            ",credit_curr"
@@ -790,7 +793,8 @@ postgres_prepare (PGconn *db_conn)
      for a reserve */
   PREPARE ("reserves_in_get_transactions",
            "SELECT"
-           " credit_val"
+           " wire_reference"
+           ",credit_val"
            ",credit_frac"
            ",credit_curr"
            ",execution_date"
@@ -1531,7 +1535,7 @@ postgres_prepare (PGconn *db_conn)
            " ORDER BY payback_uuid ASC",
            1, NULL);
 
-    /* Used in #postgres_select_reserve_closed_above_serial_id() to 
+    /* Used in #postgres_select_reserve_closed_above_serial_id() to
        obtain information about closed reserves */
   PREPARE ("reserves_close_get_incr",
            "SELECT"
@@ -2074,6 +2078,8 @@ reserves_update (void *cls,
  * @param balance the amount that has to be added to the reserve
  * @param execution_time when was the amount added
  * @param sender_account_details account information for the sender
+ * @param wire_reference unique reference identifying the wire transfer 
(binary blob)
+ * @param wire_reference_size number of bytes in @a wire_reference
  * @param transfer_details information that uniquely identifies the transfer
  * @return #GNUNET_OK upon success; #GNUNET_NO if the given
  *         @a details are already known for this @a reserve_pub,
@@ -2086,6 +2092,8 @@ postgres_reserves_in_insert (void *cls,
                              const struct TALER_Amount *balance,
                              struct GNUNET_TIME_Absolute execution_time,
                              const json_t *sender_account_details,
+                             const void *wire_reference,
+                             size_t wire_reference_size,
                              const json_t *transfer_details)
 {
   struct PostgresClosure *pg = cls;
@@ -2127,7 +2135,7 @@ postgres_reserves_in_insert (void *cls,
        the wire transfer subjects (i.e. when using Bitcoin).
     */
   }
-  
+
   expiry = GNUNET_TIME_absolute_add (execution_time,
                                      pg->idle_reserve_expiration_time);
   if (GNUNET_NO == reserve_exists)
@@ -2166,6 +2174,8 @@ postgres_reserves_in_insert (void *cls,
   {
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (&reserve.pub),
+      GNUNET_PQ_query_param_fixed_size (wire_reference,
+                                        wire_reference_size),
       TALER_PQ_query_param_amount (balance),
       TALER_PQ_query_param_json (sender_account_details),
       TALER_PQ_query_param_json (transfer_details),
@@ -2460,6 +2470,9 @@ postgres_get_reserve_history (void *cls,
       bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer);
       {
         struct GNUNET_PQ_ResultSpec rs[] = {
+          GNUNET_PQ_result_spec_variable_size ("wire_reference",
+                                               &bt->wire_reference,
+                                               &bt->wire_reference_size),
           TALER_PQ_result_spec_amount ("credit",
                                        &bt->amount),
           GNUNET_PQ_result_spec_absolute_time ("execution_date",
@@ -2690,7 +2703,7 @@ postgres_get_reserve_history (void *cls,
     PQclear (result);
   }
 
-  
+
  cleanup:
   if (GNUNET_SYSERR == ret)
   {
@@ -5037,7 +5050,7 @@ postgres_get_expired_reserves (void *cls,
                                   &remaining_balance),
       GNUNET_PQ_result_spec_end
     };
-  
+
     if (GNUNET_OK !=
        GNUNET_PQ_extract_result (result,
                                  rs,
@@ -5097,7 +5110,7 @@ postgres_insert_reserve_closed (void *cls,
   };
   PGresult *result;
   int ret;
-  
+
   result = GNUNET_PQ_exec_prepared (session->conn,
                                    "reserves_close_insert",
                                    params);
@@ -5830,10 +5843,15 @@ postgres_select_reserves_in_above_serial_id (void *cls,
     json_t *transfer_details;
     struct GNUNET_TIME_Absolute execution_date;
     uint64_t rowid;
+    void *wire_reference;
+    size_t wire_reference_size;
 
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
                                             &reserve_pub),
+      GNUNET_PQ_result_spec_variable_size ("wire_reference",
+                                           &wire_reference,
+                                           &wire_reference_size),
       TALER_PQ_result_spec_amount ("credit",
                                    &credit),
       GNUNET_PQ_result_spec_absolute_time("execution_date",
@@ -5862,6 +5880,8 @@ postgres_select_reserves_in_above_serial_id (void *cls,
               &credit,
               sender_account_details,
               transfer_details,
+              wire_reference,
+              wire_reference_size,
               execution_date);
     GNUNET_PQ_cleanup_result (rs);
     if (GNUNET_OK != ret)
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 341d31f..7c6c362 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1033,6 +1033,8 @@ audit_refund_cb (void *cls,
  * @param credit amount that was received
  * @param sender_account_details information about the sender's bank account
  * @param transfer_details information that uniquely identifies the wire 
transfer
+ * @param wire_reference unique reference identifying the wire transfer 
(binary blob)
+ * @param wire_reference_size number of bytes in @a wire_reference
  * @param execution_date when did we receive the funds
  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
  */
@@ -1043,6 +1045,8 @@ audit_reserve_in_cb (void *cls,
                      const struct TALER_Amount *credit,
                      const json_t *sender_account_details,
                      const json_t *transfer_details,
+                     const void *wire_reference,
+                     size_t wire_reference_size,
                      struct GNUNET_TIME_Absolute execution_date)
 {
   auditor_row_cnt++;
@@ -1511,6 +1515,8 @@ run (void *cls)
                                       &value,
                                       GNUNET_TIME_absolute_get (),
                                       sndr,
+                                      "TEST",
+                                      4,
                                      just));
   json_decref (just);
   FAILIF (GNUNET_OK !=
@@ -1527,6 +1533,8 @@ run (void *cls)
                                       &value,
                                       GNUNET_TIME_absolute_get (),
                                      sndr,
+                                      "TEST2",
+                                      5,
                                       just));
   json_decref (just);
   json_decref (sndr);
@@ -1642,8 +1650,8 @@ run (void *cls)
                         0,
                         0,
                          value.currency));
-  
-  json_decref (sndr);  
+
+  json_decref (sndr);
   result = 7;
   rh = plugin->get_reserve_history (plugin->cls,
                                     session,
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index b040077..370b114 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -61,11 +61,21 @@ struct TALER_EXCHANGEDB_BankTransfer
    */
   json_t *transfer_details;
 
+  /**
+   * Data uniquely identifying the wire transfer (wire transfer-type specific)
+   */
+  void *wire_reference;
+
+  /**
+   * Number of bytes in @e wire_reference.
+   */
+  size_t wire_reference_size;
+
 };
 
 
 /**
- * @brief Information we keep on bank transfer(s) that 
+ * @brief Information we keep on bank transfer(s) that
  * closed a reserve.
  */
 struct TALER_EXCHANGEDB_ClosingTransfer
@@ -101,7 +111,7 @@ struct TALER_EXCHANGEDB_ClosingTransfer
    * wire transfer.
    */
   struct TALER_WireTransferIdentifierRawP transfer_details;
-  
+
 };
 
 
@@ -800,6 +810,8 @@ typedef int
  * @param credit amount that was received
  * @param sender_account_details information about the sender's bank account
  * @param transfer_details information that uniquely identifies the wire 
transfer
+ * @param wire_reference unique identifier for the wire transfer 
(plugin-specific format)
+ * @param wire_reference_size number of bytes in @a wire_reference
  * @param execution_date when did we receive the funds
  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
  */
@@ -810,6 +822,8 @@ typedef int
                                       const struct TALER_Amount *credit,
                                       const json_t *sender_account_details,
                                       const json_t *transfer_details,
+                                      const void *wire_reference,
+                                      size_t wire_reference_size,
                                       struct GNUNET_TIME_Absolute 
execution_date);
 
 
@@ -1181,6 +1195,8 @@ struct TALER_EXCHANGEDB_Plugin
    * @param balance the amount that has to be added to the reserve
    * @param execution_time when was the amount added
    * @param sender_account_details information about the sender's bank account
+   * @param wire_reference unique reference identifying the wire transfer 
(binary blob)
+   * @param wire_reference_size number of bytes in @a wire_reference
    * @param transfer_details information that uniquely identifies the wire 
transfer
    * @return #GNUNET_OK upon success; #GNUNET_NO if the given
    *         @a details are already known for this @a reserve_pub,
@@ -1193,6 +1209,8 @@ struct TALER_EXCHANGEDB_Plugin
                          const struct TALER_Amount *balance,
                          struct GNUNET_TIME_Absolute execution_time,
                          const json_t *sender_account_details,
+                         const void *wire_reference,
+                         size_t wire_reference_size,
                          const json_t *transfer_details);
 
 
@@ -1821,7 +1839,7 @@ struct TALER_EXCHANGEDB_Plugin
                          TALER_EXCHANGEDB_ReserveExpiredCallback rec,
                          void *rec_cls);
 
-  
+
   /**
    * Insert reserve close operation into database.
    *
@@ -2102,7 +2120,7 @@ struct TALER_EXCHANGEDB_Plugin
    * @param cls closure
    * @param session database connection
    * @param serial_id lowest serial ID to include (select larger or equal)
-   * @param cb function to call 
+   * @param cb function to call
    * @param cb_cls closure for @a cb
    * @return #GNUNET_OK on success,
    *         #GNUNET_NO if there are no entries,

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



reply via email to

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