gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 96/277: fix FTBFS


From: gnunet
Subject: [taler-merchant] 96/277: fix FTBFS
Date: Sun, 05 Jul 2020 20:50:09 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 05afe21f0f4788451af7baaeda4f2f7fd6c547c5
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed May 6 22:16:27 2020 +0200

    fix FTBFS
---
 src/backend/Makefile.am                            |   2 +
 .../taler-merchant-httpd_private-post-transfers.c  | 378 ++++++++++-----------
 src/include/taler_merchantdb_plugin.h              |  90 +++--
 3 files changed, 259 insertions(+), 211 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 55029b0..2512143 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -55,6 +55,8 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-post-orders-ID-refund.h \
   taler-merchant-httpd_private-post-orders.c \
     taler-merchant-httpd_private-post-orders.h \
+  taler-merchant-httpd_private-post-transfers.c \
+    taler-merchant-httpd_private-post-transfers.h \
   taler-merchant-httpd_post-orders-ID-abort.c \
     taler-merchant-httpd_post-orders-ID-abort.h \
   taler-merchant-httpd_post-orders-ID-claim.c \
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c 
b/src/backend/taler-merchant-httpd_private-post-transfers.c
index 5c3a0e3..6071800 100644
--- a/src/backend/taler-merchant-httpd_private-post-transfers.c
+++ b/src/backend/taler-merchant-httpd_private-post-transfers.c
@@ -68,12 +68,12 @@ struct TrackTransferContext
   /**
    * URL of the exchange.
    */
-  char *exchange_url;
+  const char *exchange_url;
 
   /**
    * payto:// URI used for the transfer.
    */
-  char *payto_uri;
+  const char *payto_uri;
 
   /**
    * Master public key of the exchange at @e exchange_url.
@@ -88,7 +88,7 @@ struct TrackTransferContext
   /**
    * For which merchant instance is this tracking request?
    */
-  struct MerchantInstance *mi;
+  struct TMH_HandlerContext *hc;
 
   /**
    * HTTP connection we are handling.
@@ -141,12 +141,12 @@ struct TrackTransferContext
 /**
  * Head of list of suspended requests.
  */
-static struct TrackTransferContext *pth_head;
+static struct TrackTransferContext *ttc_head;
 
 /**
  * Tail of list of suspended requests.
  */
-static struct TrackTransferContext *pth_tail;
+static struct TrackTransferContext *ttc_tail;
 
 
 /**
@@ -178,39 +178,29 @@ struct Entry
 
 
 /**
- * Free the @a rctx.
+ * Free the @a ttc.
  *
- * @param rctx data to free
+ * @param ttc data to free
  */
 static void
-free_transfer_track_context (struct TrackTransferContext *rctx)
+free_transfer_track_context (struct TrackTransferContext *ttc)
 {
-  if (NULL != rctx->fo)
+  if (NULL != ttc->fo)
   {
-    TMH_EXCHANGES_find_exchange_cancel (rctx->fo);
-    rctx->fo = NULL;
+    TMH_EXCHANGES_find_exchange_cancel (ttc->fo);
+    ttc->fo = NULL;
   }
-  if (NULL != rctx->timeout_task)
+  if (NULL != ttc->timeout_task)
   {
-    GNUNET_SCHEDULER_cancel (rctx->timeout_task);
-    rctx->timeout_task = NULL;
+    GNUNET_SCHEDULER_cancel (ttc->timeout_task);
+    ttc->timeout_task = NULL;
   }
-  if (NULL != rctx->wdh)
+  if (NULL != ttc->wdh)
   {
-    TALER_EXCHANGE_transfers_get_cancel (rctx->wdh);
-    rctx->wdh = NULL;
+    TALER_EXCHANGE_transfers_get_cancel (ttc->wdh);
+    ttc->wdh = NULL;
   }
-  if (NULL != rctx->url)
-  {
-    GNUNET_free (rctx->url);
-    rctx->url = NULL;
-  }
-  if (NULL != rctx->wire_method)
-  {
-    GNUNET_free (rctx->wire_method);
-    rctx->wire_method = NULL;
-  }
-  GNUNET_free (rctx);
+  GNUNET_free (ttc);
 }
 
 
@@ -241,7 +231,7 @@ hashmap_free (void *cls,
  * Builds JSON response containing the summed-up amounts
  * from individual deposits.
  *
- * @param cls closure
+ * @param cls a `json_t *` array to append additional entries to
  * @param key map's current key
  * @param map's current value
  * @return #GNUNET_YES if iteration is to be continued,
@@ -252,7 +242,7 @@ build_deposits_response (void *cls,
                          const struct GNUNET_HashCode *key,
                          void *value)
 {
-  struct TrackTransferContext *rctx = cls;
+  json_t *deposits_response;
   struct Entry *entry = value;
   json_t *element;
 
@@ -264,7 +254,7 @@ build_deposits_response (void *cls,
                          &entry->deposit_fee));
   GNUNET_assert (NULL != element);
   GNUNET_assert (0 ==
-                 json_array_append_new (rctx->deposits_response,
+                 json_array_append_new (deposits_response,
                                         element));
   return GNUNET_YES;
 }
@@ -279,7 +269,7 @@ build_deposits_response (void *cls,
  */
 static json_t *
 transform_response (const json_t *result,
-                    struct TrackTransferContext *rctx)
+                    struct TrackTransferContext *ttc)
 {
   json_t *deposits;
   json_t *value;
@@ -356,21 +346,28 @@ transform_response (const json_t *result,
     }
     GNUNET_JSON_parse_free (spec);
   }
-  rctx->deposits_response = json_array ();
 
-  if (GNUNET_SYSERR ==
-      GNUNET_CONTAINER_multihashmap_iterate (map,
-                                             &build_deposits_response,
-                                             rctx))
-    goto cleanup;
-
-  result_mod = json_copy ((struct json_t *) result);
-  json_object_del (result_mod,
-                   "deposits");
-  json_object_set_new (result_mod,
-                       "deposits_sums",
-                       rctx->deposits_response);
-  rctx->deposits_response = NULL;
+  {
+    json_t *deposits_response;
+
+    deposits_response = json_array ();
+    GNUNET_assert (NULL != deposits_response);
+    if (GNUNET_SYSERR ==
+        GNUNET_CONTAINER_multihashmap_iterate (map,
+                                               &build_deposits_response,
+                                               deposits_response))
+    {
+      json_decref (deposits_response);
+      goto cleanup;
+    }
+
+    result_mod = json_copy ((struct json_t *) result);
+    json_object_del (result_mod,
+                     "deposits");
+    json_object_set_new (result_mod,
+                         "deposits_sums",
+                         deposits_response);
+  }
 cleanup:
   GNUNET_CONTAINER_multihashmap_iterate (map,
                                          &hashmap_free,
@@ -382,32 +379,32 @@ cleanup:
 
 /**
  * Resume the given /track/transfer operation and send the given response.
- * Stores the response in the @a rctx and signals MHD to resume
+ * Stores the response in the @a ttc and signals MHD to resume
  * the connection.  Also ensures MHD runs immediately.
  *
- * @param rctx transfer tracking context
+ * @param ttc transfer tracking context
  * @param response_code response code to use
  * @param response response data to send back
  */
 static void
-resume_track_transfer_with_response (struct TrackTransferContext *rctx,
+resume_track_transfer_with_response (struct TrackTransferContext *ttc,
                                      unsigned int response_code,
                                      struct MHD_Response *response)
 {
-  rctx->response_code = response_code;
-  rctx->response = response;
+  ttc->response_code = response_code;
+  ttc->response = response;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Resuming POST /transfers handling as exchange interaction is 
done (%u)\n",
               response_code);
-  if (NULL != rctx->timeout_task)
+  if (NULL != ttc->timeout_task)
   {
-    GNUNET_SCHEDULER_cancel (rctx->timeout_task);
-    rctx->timeout_task = NULL;
+    GNUNET_SCHEDULER_cancel (ttc->timeout_task);
+    ttc->timeout_task = NULL;
   }
-  GNUNET_CONTAINER_DLL_remove (pth_head,
-                               pth_tail,
-                               rctx);
-  MHD_resume_connection (rctx->connection);
+  GNUNET_CONTAINER_DLL_remove (ttc_head,
+                               ttc_tail,
+                               ttc);
+  MHD_resume_connection (ttc->connection);
   TMH_trigger_daemon (); /* we resumed, kick MHD */
 }
 
@@ -420,9 +417,9 @@ resume_track_transfer_with_response (struct 
TrackTransferContext *rctx,
 static void
 track_transfer_cleanup (void *cls)
 {
-  struct TrackTransferContext *rctx = cls;
+  struct TrackTransferContext *ttc = cls;
 
-  free_transfer_track_context (rctx);
+  free_transfer_track_context (ttc);
 }
 
 
@@ -451,10 +448,10 @@ check_transfer (void *cls,
                 const struct TALER_Amount *wire_fee,
                 const json_t *exchange_proof)
 {
-  struct TrackTransferContext *rctx = cls;
-  const struct TALER_TrackTransferDetails *ttd = rctx->current_detail;
+  struct TrackTransferContext *ttc = cls;
+  const struct TALER_TrackTransferDetails *ttd = ttc->current_detail;
 
-  if (GNUNET_SYSERR == rctx->check_transfer_result)
+  if (GNUNET_SYSERR == ttc->check_transfer_result)
     return; /* already had a serious issue; odd that we're called more than 
once as well... */
   if ( (0 != TALER_amount_cmp (amount_with_fee,
                                &ttd->coin_value)) ||
@@ -464,16 +461,15 @@ check_transfer (void *cls,
     /* Disagreement between the exchange and us about how much this
        coin is worth! */
     GNUNET_break_op (0);
-    rctx->check_transfer_result = GNUNET_SYSERR;
+    ttc->check_transfer_result = GNUNET_SYSERR;
     /* Build the `TrackTransferConflictDetails` */
-    rctx->response
+    ttc->response
       = TALER_MHD_make_json_pack (
-          "{s:I, s:s, s:o, s:I, s:o, s:o, s:s, s:o, s:o}",
+          "{s:I, s:s, s:o, s:I, s:o, s:s, s:o, s:o}",
           "code", (json_int_t) TALER_EC_TRACK_TRANSFER_CONFLICTING_REPORTS,
           "hint", "disagreement about deposit valuation",
           "exchange_deposit_proof", exchange_proof,
-          "conflict_offset", (json_int_t) rctx->current_offset,
-          "exchange_transfer_proof", rctx->original_response,
+          "conflict_offset", (json_int_t) ttc->current_offset,
           "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
           "h_contract_terms", GNUNET_JSON_from_data_auto (
             &ttd->h_contract_terms),
@@ -481,7 +477,7 @@ check_transfer (void *cls,
           "deposit_fee", TALER_JSON_from_amount (deposit_fee));
     return;
   }
-  rctx->check_transfer_result = GNUNET_OK;
+  ttc->check_transfer_result = GNUNET_OK;
 }
 
 
@@ -494,7 +490,7 @@ check_transfer (void *cls,
  * if we have proof that the fee is bogus, we respond with
  * the proof to the client and return #GNUNET_SYSERR.
  *
- * @param rctx context of the transfer to respond to
+ * @param ttc context of the transfer to respond to
  * @param json response from the exchange
  * @param execution_time time of the wire transfer
  * @param wire_fee fee claimed by the exchange
@@ -502,7 +498,7 @@ check_transfer (void *cls,
  *   missbehavior from the exchange to the client
  */
 static int
-check_wire_fee (struct TrackTransferContext *rctx,
+check_wire_fee (struct TrackTransferContext *ttc,
                 const json_t *json,
                 struct GNUNET_TIME_Absolute execution_time,
                 const struct TALER_Amount *wire_fee)
@@ -515,10 +511,10 @@ check_wire_fee (struct TrackTransferContext *rctx,
   enum GNUNET_DB_QueryStatus qs;
   char *wire_method;
 
-  wire_method = TALER_payto_get_method (rctx->payto_uri);
+  wire_method = TALER_payto_get_method (ttc->payto_uri);
   TMH_db->preflight (TMH_db->cls);
   qs = TMH_db->lookup_wire_fee (TMH_db->cls,
-                                &rctx->master_pub,
+                                &ttc->master_pub,
                                 wire_method,
                                 execution_time,
                                 &expected_fee,
@@ -530,7 +526,7 @@ check_wire_fee (struct TrackTransferContext *rctx,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Failed to find wire fee for `%s' and method `%s' at %s in DB, 
accepting blindly that the fee is %s\n",
-                TALER_B2S (&rctx->master_pub),
+                TALER_B2S (&ttc->master_pub),
                 wire_method,
                 GNUNET_STRINGS_absolute_time_to_string (execution_time),
                 TALER_amount2s (wire_fee));
@@ -545,7 +541,7 @@ check_wire_fee (struct TrackTransferContext *rctx,
   }
   /* Wire fee check failed, export proof to client */
   resume_track_transfer_with_response (
-    rctx,
+    ttc,
     MHD_HTTP_FAILED_DEPENDENCY,
     TALER_MHD_make_json_pack (
       "{s:I, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:O}",
@@ -557,7 +553,7 @@ check_wire_fee (struct TrackTransferContext *rctx,
       "start_date", GNUNET_JSON_from_time_abs (start_date),
       "end_date", GNUNET_JSON_from_time_abs (end_date),
       "master_sig", GNUNET_JSON_from_data_auto (&master_sig),
-      "master_pub", GNUNET_JSON_from_data_auto (&rctx->master_pub),
+      "master_pub", GNUNET_JSON_from_data_auto (&ttc->master_pub),
       "json", json));
   GNUNET_free (wire_method);
   return GNUNET_SYSERR;
@@ -577,18 +573,18 @@ wire_transfer_cb (void *cls,
                   const struct TALER_EXCHANGE_HttpResponse *hr,
                   const struct TALER_EXCHANGE_TransferData *td)
 {
-  struct TrackTransferContext *rctx = cls;
-  json_t *jresponse;
+  struct TrackTransferContext *ttc = cls;
+  const char *instance_id = ttc->hc->instance->settings.id;
   enum GNUNET_DB_QueryStatus qs;
 
-  rctx->wdh = NULL;
+  ttc->wdh = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Got response code %u from exchange for GET /transfers/$WTID\n",
               hr->http_status);
   if (MHD_HTTP_OK != hr->http_status)
   {
     resume_track_transfer_with_response (
-      rctx,
+      ttc,
       MHD_HTTP_FAILED_DEPENDENCY,
       TALER_MHD_make_json_pack (
         "{s:I, s:I, s:I, s:O}",
@@ -600,9 +596,10 @@ wire_transfer_cb (void *cls,
   }
   TMH_db->preflight (TMH_db->cls);
   qs = TMH_db->insert_transfer_details (TMH_db->cls,
-                                        rctx->exchange_url,
-                                        rctx->payto_uri,
-                                        &rctx->wtid,
+                                        instance_id,
+                                        ttc->exchange_url,
+                                        ttc->payto_uri,
+                                        &ttc->wtid,
                                         td);
   if (0 > qs)
   {
@@ -611,7 +608,7 @@ wire_transfer_cb (void *cls,
     /* Always report on hard error as well to enable diagnostics */
     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     resume_track_transfer_with_response (
-      rctx,
+      ttc,
       MHD_HTTP_INTERNAL_SERVER_ERROR,
       TALER_MHD_make_json_pack (
         "{s:I, s:s}",
@@ -623,7 +620,7 @@ wire_transfer_cb (void *cls,
   }
 
   if (GNUNET_SYSERR ==
-      check_wire_fee (rctx,
+      check_wire_fee (ttc,
                       hr->reply,
                       td->execution_time,
                       &td->wire_fee))
@@ -639,18 +636,19 @@ wire_transfer_cb (void *cls,
    *///
   for (unsigned int i = 0; i < td->details_length; i++)
   {
-    rctx->current_offset = i;
-    rctx->current_detail = &details[i];
+    const struct TALER_TrackTransferDetails *ttd = &td->details[i];
+
+    ttc->current_offset = i;
+    ttc->current_detail = ttd;
     /* Set the coin as "never seen" before. */
-    rctx->check_transfer_result = GNUNET_NO;
+    ttc->check_transfer_result = GNUNET_NO;
     TMH_db->preflight (TMH_db->cls);
-    qs = TMH_db->find_payments_by_hash_and_coin (TMH_db->cls,
-                                                 &details[i].h_contract_terms,
-                                                 &rctx->hc->instance->settings.
-                                                 id,
-                                                 &td->details[i].coin_pub,
-                                                 &check_transfer,
-                                                 rctx);
+    qs = TMH_db->lookup_deposits_by_contract_and_coin (TMH_db->cls,
+                                                       instance_id,
+                                                       &ttd->h_contract_terms,
+                                                       &ttd->coin_pub,
+                                                       &check_transfer,
+                                                       ttc);
     if (0 > qs)
     {
       /* single, read-only SQL statements should never cause
@@ -659,7 +657,7 @@ wire_transfer_cb (void *cls,
       /* Always report on hard error as well to enable diagnostics */
       GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
       resume_track_transfer_with_response (
-        rctx,
+        ttc,
         MHD_HTTP_INTERNAL_SERVER_ERROR,
         TALER_MHD_make_json_pack ("{s:I, s:s}",
                                   "code",
@@ -676,15 +674,15 @@ wire_transfer_cb (void *cls,
          Well, let's say thanks and accept the money! */
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   "Failed to find payment data in DB\n");
-      rctx->check_transfer_result = GNUNET_OK;
+      ttc->check_transfer_result = GNUNET_OK;
     }
-    if (GNUNET_NO == rctx->check_transfer_result)
+    if (GNUNET_NO == ttc->check_transfer_result)
     {
       /* Internal error: how can we have called #check_transfer()
          but still have no result? */
       GNUNET_break (0);
       resume_track_transfer_with_response (
-        rctx,
+        ttc,
         MHD_HTTP_INTERNAL_SERVER_ERROR,
         TALER_MHD_make_json_pack ("{s:I, s:s, s:I, s:s}",
                                   "code",
@@ -695,27 +693,29 @@ wire_transfer_cb (void *cls,
                                   "file", __FILE__));
       return;
     }
-    if (GNUNET_SYSERR == rctx->check_transfer_result)
+    if (GNUNET_SYSERR == ttc->check_transfer_result)
     {
       /* #check_transfer() failed, report conflict! */
       GNUNET_break_op (0);
-      GNUNET_assert (NULL != rctx->response);
+      GNUNET_assert (NULL != ttc->response);
       resume_track_transfer_with_response (
-        rctx,
+        ttc,
         MHD_HTTP_FAILED_DEPENDENCY,
-        rctx->response);
-      rctx->response = NULL;
+        ttc->response);
+      ttc->response = NULL;
       return;
     }
     /* Response is consistent with the /deposit we made,
        remember it for future reference */
     for (unsigned int r = 0; r<MAX_RETRIES; r++)
     {
+      const struct TALER_TrackTransferDetails *ttd = &td->details[i];
+
       TMH_db->preflight (TMH_db->cls);
       qs = TMH_db->store_coin_to_transfer (TMH_db->cls,
-                                           &td->details[i].h_contract_terms,
-                                           &td->details[i].coin_pub,
-                                           &rctx->wtid);
+                                           &ttd->h_contract_terms,
+                                           &ttd->coin_pub,
+                                           &ttc->wtid);
       if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
         break;
     }
@@ -726,7 +726,7 @@ wire_transfer_cb (void *cls,
       /* Always report on hard error as well to enable diagnostics */
       GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
       resume_track_transfer_with_response (
-        rctx,
+        ttc,
         MHD_HTTP_INTERNAL_SERVER_ERROR,
         TALER_MHD_make_json_pack ("{s:I, s:s}",
                                   "code",
@@ -739,7 +739,7 @@ wire_transfer_cb (void *cls,
   }
 
   /* resume processing, main function will build the response */
-  resume_track_transfer_with_response (rctx,
+  resume_track_transfer_with_response (ttc,
                                        0,
                                        NULL);
 }
@@ -762,15 +762,15 @@ process_track_transfer_with_exchange (
   const struct TALER_Amount *wire_fee,
   int exchange_trusted)
 {
-  struct TrackTransferContext *rctx = cls;
+  struct TrackTransferContext *ttc = cls;
 
-  rctx->fo = NULL;
+  ttc->fo = NULL;
   if (MHD_HTTP_OK != hr->http_status)
   {
     /* The request failed somehow */
     GNUNET_break_op (0);
     resume_track_transfer_with_response (
-      rctx,
+      ttc,
       MHD_HTTP_FAILED_DEPENDENCY,
       TALER_MHD_make_json_pack (
         (NULL != hr->reply)
@@ -792,26 +792,29 @@ process_track_transfer_with_exchange (
     if (NULL == keys)
     {
       GNUNET_break (0);
-      return GNUNET_NO;
+      resume_track_transfer_with_response (
+        ttc,
+        MHD_HTTP_INTERNAL_SERVER_ERROR,
+        TALER_MHD_make_error (
+          TALER_EC_TRACK_TRANSFER_EXCHANGE_KEYS_FAILURE,
+          "failed to get keys"));
+      return;
     }
-    rctx->master_pub = keys->master_pub;
+    ttc->master_pub = keys->master_pub;
   }
 
-  rctx->wdh = TALER_EXCHANGE_transfers_get (eh,
-                                            &rctx->wtid,
-                                            &wire_transfer_cb,
-                                            rctx);
-  if (NULL == rctx->wdh)
+  ttc->wdh = TALER_EXCHANGE_transfers_get (eh,
+                                           &ttc->wtid,
+                                           &wire_transfer_cb,
+                                           ttc);
+  if (NULL == ttc->wdh)
   {
     GNUNET_break (0);
     resume_track_transfer_with_response (
-      rctx,
+      ttc,
       MHD_HTTP_INTERNAL_SERVER_ERROR,
-      TALER_MHD_make_json_pack (
-        "{s:I, s:s}",
-        "code",
-        (json_int_t) TALER_EC_TRACK_TRANSFER_REQUEST_ERROR,
-        "error",
+      TALER_MHD_make_error (
+        TALER_EC_TRACK_TRANSFER_REQUEST_ERROR,
         "failed to run GET /transfers/ on exchange"));
   }
 }
@@ -827,10 +830,10 @@ process_track_transfer_with_exchange (
  * @param deposit_fee the fee charged for @a deposit_value
  */
 static void
-proof_cb (void *cls,
-          const char *order_id,
-          const struct TALER_Amount *deposit_value,
-          const struct TALER_Amount *deposit_fee)
+transfer_details_cb (void *cls,
+                     const char *order_id,
+                     const struct TALER_Amount *deposit_value,
+                     const struct TALER_Amount *deposit_fee)
 {
   json_t *ja = cls;
 
@@ -838,10 +841,10 @@ proof_cb (void *cls,
     0 ==
     json_array_append_new (
       ja,
-      "{s:s,s:o,s:o}",
-      "order_id", order_id,
-      "deposit_value", TALER_JSON_spec_amount (deposit_value),
-      "deposit_fee", TALER_JSON_spec_amount (deposit_fee)));
+      json_pack ("{s:s,s:o,s:o}",
+                 "order_id", order_id,
+                 "deposit_value", TALER_JSON_from_amount (deposit_value),
+                 "deposit_fee", TALER_JSON_from_amount (deposit_fee))));
 }
 
 
@@ -853,22 +856,22 @@ proof_cb (void *cls,
 static void
 handle_track_transfer_timeout (void *cls)
 {
-  struct TrackTransferContext *rctx = cls;
+  struct TrackTransferContext *ttc = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Resuming POST /private/transfers with error after timeout\n");
-  rctx->timeout_task = NULL;
-  if (NULL != rctx->fo)
+  ttc->timeout_task = NULL;
+  if (NULL != ttc->fo)
   {
-    TMH_EXCHANGES_find_exchange_cancel (rctx->fo);
-    rctx->fo = NULL;
+    TMH_EXCHANGES_find_exchange_cancel (ttc->fo);
+    ttc->fo = NULL;
   }
-  if (NULL != rctx->wdh)
+  if (NULL != ttc->wdh)
   {
-    TALER_EXCHANGE_transfers_get_cancel (rctx->wdh);
-    rctx->wdh = NULL;
+    TALER_EXCHANGE_transfers_get_cancel (ttc->wdh);
+    ttc->wdh = NULL;
   }
-  resume_track_transfer_with_response (rctx,
+  resume_track_transfer_with_response (ttc,
                                        MHD_HTTP_SERVICE_UNAVAILABLE,
                                        TALER_MHD_make_error (
                                          
TALER_EC_TRACK_TRANSFER_EXCHANGE_TIMEOUT,
@@ -891,46 +894,43 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
                             struct MHD_Connection *connection,
                             struct TMH_HandlerContext *hc)
 {
-  struct TrackTransferContext *rctx = hc->ctx;
-  const char *str;
-  const char *url;
-  const char *wire_method;
+  struct TrackTransferContext *ttc = hc->ctx;
   enum GNUNET_DB_QueryStatus qs;
 
-  if (NULL == rctx)
+  if (NULL == ttc)
   {
-    rctx = GNUNET_new (struct TrackTransferContext);
-    rctx->connection = connection;
-    hc->ctx = rctx;
-    hc->cleanup_cb = &track_transfer_cleanup;
+    ttc = GNUNET_new (struct TrackTransferContext);
+    ttc->connection = connection;
+    hc->ctx = ttc;
+    hc->cc = &track_transfer_cleanup;
   }
 
-  if (0 != rctx->response_code)
+  if (0 != ttc->response_code)
   {
     MHD_RESULT ret;
 
     /* We are *done* processing the request, just queue the response (!) */
-    if (UINT_MAX == rctx->response_code)
+    if (UINT_MAX == ttc->response_code)
     {
       GNUNET_break (0);
       return MHD_NO; /* hard error */
     }
     ret = MHD_queue_response (connection,
-                              rctx->response_code,
-                              rctx->response);
-    if (NULL != rctx->response)
+                              ttc->response_code,
+                              ttc->response);
+    if (NULL != ttc->response)
     {
-      MHD_destroy_response (rctx->response);
-      rctx->response = NULL;
+      MHD_destroy_response (ttc->response);
+      ttc->response = NULL;
     }
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Queueing response (%u) for POST /private/transfers (%s).\n",
-                (unsigned int) rctx->response_code,
+                (unsigned int) ttc->response_code,
                 ret ? "OK" : "FAILED");
     return ret;
   }
-  if ( (NULL != rctx->fo) ||
-       (NULL != rctx->wdh) )
+  if ( (NULL != ttc->fo) ||
+       (NULL != ttc->wdh) )
   {
     /* likely old MHD version */
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -941,17 +941,16 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
   {
     struct GNUNET_JSON_Specification spec[] = {
       GNUNET_JSON_spec_string ("exchange",
-                               &rctx->exchange_url),
+                               &ttc->exchange_url),
       GNUNET_JSON_spec_string ("payto_uri",
-                               &rctx->payto_uri),
+                               &ttc->payto_uri),
       TALER_JSON_spec_amount ("amount",
-                              &rctx->amount),
+                              &ttc->amount),
       GNUNET_JSON_spec_fixed_auto ("wtid",
-                                   &rctx->wtid),
+                                   &ttc->wtid),
       GNUNET_JSON_spec_end ()
     };
 
-    GNUNET_assert (NULL != mi);
     {
       enum GNUNET_GenericReturnValue res;
 
@@ -976,12 +975,13 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
     GNUNET_assert (NULL != deposit_sums);
     TMH_db->preflight (TMH_db->cls);
     qs = TMH_db->lookup_transfer_details (TMH_db->cls,
-                                          rctx->exchange_url,
-                                          rctx->payto_uri,
-                                          &rctx->wtid,
+                                          hc->instance->settings.id,
+                                          ttc->exchange_url,
+                                          ttc->payto_uri,
+                                          &ttc->wtid,
                                           &total_amount,
                                           &wire_fee,
-                                          &execution_time,
+                                          execution_time,
                                           &transfer_details_cb,
                                           deposit_sums);
     if (0 > qs)
@@ -1013,11 +1013,11 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
   /* reply not in database, ensure the POST is in the database, and
      start work to obtain the reply from the exchange */
   qs = TMH_db->insert_transfer (TMH_db->cls,
-                                rctx->hc->instance->settings.id,
-                                rctx->exchange_url,
-                                &rctx->wtid,
-                                &rctx->amount,
-                                rctx->payto_uri,
+                                ttc->hc->instance->settings.id,
+                                ttc->exchange_url,
+                                &ttc->wtid,
+                                &ttc->amount,
+                                ttc->payto_uri,
                                 true /* confirmed! */);
   if (0 > qs)
   {
@@ -1027,7 +1027,7 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                       TALER_EC_POST_TRANSFER_DB_STORE_ERROR,
+                                       TALER_EC_POST_TRANSFERS_DB_STORE_ERROR,
                                        "Fail to update database with transfer 
record");
   }
   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@@ -1038,31 +1038,31 @@ TMH_private_post_transfers (const struct 
TMH_RequestHandler *rh,
        the INSERT failed because we did not find the account based on
        the given payto-URI and the instance. */
     qs = TMH_db->lookup_account (TMH_db->cls,
-                                 rctx->hc->instance->settings.id,
-                                 rctx->payto_uri,
+                                 ttc->hc->instance->settings.id,
+                                 ttc->payto_uri,
                                  &account_serial);
     if (0 >= qs)
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_NOT_FOUND,
-                                         
TALER_EC_POST_TRANSFER_ACCOUNT_NOT_FOUND,
+                                         
TALER_EC_POST_TRANSFERS_ACCOUNT_NOT_FOUND,
                                          "Instance does not have this bank 
account");
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Suspending POST /private/transfers handling while working with 
exchange\n");
   MHD_suspend_connection (connection);
-  GNUNET_CONTAINER_DLL_insert (pth_head,
-                               pth_tail,
-                               rctx);
-  rctx->fo = TMH_EXCHANGES_find_exchange (rctx->exchange_url,
-                                          NULL,
-                                          GNUNET_NO,
-                                          
&process_track_transfer_with_exchange,
-                                          rctx);
-  rctx->timeout_task
+  GNUNET_CONTAINER_DLL_insert (ttc_head,
+                               ttc_tail,
+                               ttc);
+  ttc->fo = TMH_EXCHANGES_find_exchange (ttc->exchange_url,
+                                         NULL,
+                                         GNUNET_NO,
+                                         &process_track_transfer_with_exchange,
+                                         ttc);
+  ttc->timeout_task
     = GNUNET_SCHEDULER_add_delayed (TRACK_TIMEOUT,
                                     &handle_track_transfer_timeout,
-                                    rctx);
+                                    ttc);
   return MHD_YES;
 }
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 94fe618..51d48dc 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -394,6 +394,22 @@ enum TALER_MERCHANTDB_RefundStatus
 };
 
 
+/**
+ * Function called with information about a wire transfer identifier.
+ *
+ * @param cls closure
+ * @param order_id the order to which the deposits belong
+ * @param deposit_value the amount deposited under @a order_id
+ * @param deposit_fee the fee charged for @a deposit_value
+ */
+typedef void
+(*TALER_MERCHANTDB_TransferDetailsCallback)(
+  void *cls,
+  const char *order_id,
+  const struct TALER_Amount *deposit_value,
+  const struct TALER_Amount *deposit_fee);
+
+
 /* **************** OLD: ******************** */
 
 /**
@@ -1284,6 +1300,58 @@ struct TALER_MERCHANTDB_Plugin
                      struct TALER_MasterSignatureP *master_sig);
 
 
+  /* WIP: */
+  /**
+   * Lookup information about coin payments by @a h_contract_terms and
+   * @a coin_pub.
+   *
+   * @param cls closure
+   * @param instance_id instance to lookup payments for
+   * @param h_contract_terms proposal data's hashcode
+   * @param coin_pub public key to use for the search
+   * @param cb function to call with payment data
+   * @param cb_cls closure for @a cb
+   * @return transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+  (*lookup_deposits_by_contract_and_coin)(
+    void *cls,
+    const char *instance_id,
+    const struct GNUNET_HashCode *h_contract_terms,
+    const struct TALER_CoinSpendPublicKeyP *coin_pub,
+    TALER_MERCHANTDB_CoinDepositCallback cb,
+    void *cb_cls);
+
+
+  /**
+   * Lookup transfer details.
+   *
+   * @param cls closure
+   * @param instance_id instance to lookup payments for
+   * @param exchange_url
+   * @param payto_uri
+   * @param wtid
+   * @param total_amount
+   * @param wire_fee
+   * @param execution_time
+   * @param cb function to call with detailed transfer data
+   * @param cb_cls closure for @a cb
+   * @return transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+  (*lookup_transfer_details)(
+    void *cls,
+    const char *instance_id,
+    const char *exchange_url,
+    const char *payto_uri,
+    const struct TALER_WireTransferIdentifierRawP *wtid,
+    const struct TALER_Amount *total_amount,
+    const struct TALER_Amount *wire_fee,
+    struct GNUNET_TIME_Absolute execution_time,
+    TALER_MERCHANTDB_TransferDetailsCallback cb,
+    void *cb_cls);
+
+
   /* ****************** OLD API ******************** */
 
 
@@ -1462,28 +1530,6 @@ struct TALER_MERCHANTDB_Plugin
     const struct TALER_MasterSignatureP *exchange_sig);
 
 
-  /**
-   * Lookup information about coin payments by h_contract_terms and coin.
-   *
-   * @param cls closure
-   * @param h_contract_terms proposal data's hashcode
-   * @param merchant_pub merchant's public key. It's AND'd with @a 
h_contract_terms
-   *        in order to find the result.
-   * @param coin_pub public key to use for the search
-   * @param cb function to call with payment data
-   * @param cb_cls closure for @a cb
-   * @return transaction status
-   */
-  enum GNUNET_DB_QueryStatus
-  (*find_payments_by_hash_and_coin)(
-    void *cls,
-    const struct GNUNET_HashCode *h_contract_terms,
-    const struct TALER_MerchantPublicKeyP *merchant_pub,
-    const struct TALER_CoinSpendPublicKeyP *coin_pub,
-    TALER_MERCHANTDB_CoinDepositCallback cb,
-    void *cb_cls);
-
-
   /**
    * Lookup information about a transfer by @a h_contract_terms.  Note
    * that in theory there could be multiple wire transfers for a

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