gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 71/277: work on /abort logic


From: gnunet
Subject: [taler-merchant] 71/277: work on /abort logic
Date: Sun, 05 Jul 2020 20:49:44 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 49217808de28559964ca3f2b42e50c3990436520
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri May 1 14:16:47 2020 +0200

    work on /abort logic
---
 src/backend/Makefile.am                            |   4 +-
 .../taler-merchant-httpd_post-orders-ID-abort.c    | 133 ++++++---------------
 .../taler-merchant-httpd_post-orders-ID-pay.c      |   8 +-
 src/backenddb/plugin_merchantdb_postgres.c         |   7 +-
 src/include/taler_merchantdb_plugin.h              |   3 +-
 5 files changed, 55 insertions(+), 100 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 4f74af4..f842257 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -54,7 +54,9 @@ taler_merchant_httpd_SOURCES = \
   taler-merchant-httpd_post-orders-ID-claim.c \
     taler-merchant-httpd_post-orders-ID-claim.h \
   taler-merchant-httpd_post-orders-ID-pay.c \
-    taler-merchant-httpd_post-orders-ID-pay.h
+    taler-merchant-httpd_post-orders-ID-pay.h \
+  taler-merchant-httpd_post-orders-ID-abort.c \
+    taler-merchant-httpd_post-orders-ID-abort.h
 
 DEAD = \
   taler-merchant-httpd_check-payment.c taler-merchant-httpd_check-payment.h \
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
index 604490d..27a8381 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
@@ -103,7 +103,7 @@ struct RefundDetails
   /**
    * Did we try to process this refund yet?
    */
-  boolean processed;
+  bool processed;
 
 };
 
@@ -242,7 +242,7 @@ abort_refunds (struct AbortContext *ac)
   {
     struct RefundDetails *rdi = &ac->rd[i];
 
-    if (NULL != rdi->dh)
+    if (NULL != rdi->rh)
     {
       TALER_EXCHANGE_refund_cancel (rdi->rh);
       rdi->rh = NULL;
@@ -262,7 +262,7 @@ TMH_force_ac_resume ()
        NULL != ac;
        ac = ac->next)
   {
-    abort_deposit (ac);
+    abort_refunds (ac);
     if (NULL != ac->timeout_task)
     {
       GNUNET_SCHEDULER_cancel (ac->timeout_task);
@@ -358,10 +358,10 @@ generate_success_response (struct AbortContext *ac)
         json_array_append_new (
           refunds,
           json_pack ("{s:I, s:O, s:o s:o s:o}",
-                     "exchange_status",
-                     (json_int_t) rdi->exchange_status,
-                     "exchange_body",
-                     rdi->exchange_body)))
+                     "exchange_http_status",
+                     (json_int_t) rdi->http_status,
+                     "exchange_reply",
+                     rdi->exchange_reply)))
     {
       json_decref (refunds);
       GNUNET_break (0);
@@ -385,12 +385,12 @@ generate_success_response (struct AbortContext *ac)
 /**
  * Custom cleanup routine for a `struct AbortContext`.
  *
- * @param hc the `struct AbortContext` to clean up.
+ * @param cls the `struct AbortContext` to clean up.
  */
 static void
-abort_context_cleanup (struct TM_HandlerContext *hc)
+abort_context_cleanup (void *cls)
 {
-  struct AbortContext *ac = (struct AbortContext *) hc;
+  struct AbortContext *ac = cls;
 
   if (NULL != ac->timeout_task)
   {
@@ -400,14 +400,14 @@ abort_context_cleanup (struct TM_HandlerContext *hc)
   abort_refunds (ac);
   for (unsigned int i = 0; i<ac->coins_cnt; i++)
   {
-    struct RefundDetails *rd = &ac->rd[i];
+    struct RefundDetails *rdi = &ac->rd[i];
 
     if (NULL != rdi->exchange_reply)
     {
       json_decref (rdi->exchange_reply);
-      rdi->reply = NULL;
+      rdi->exchange_reply = NULL;
     }
-    GNUNET_free_non_null (rd->exchange_url);
+    GNUNET_free_non_null (rdi->exchange_url);
   }
   GNUNET_free_non_null (ac->rd);
   if (NULL != ac->fo)
@@ -458,8 +458,8 @@ refund_cb (void *cls,
   (void) sign_key;
   (void) signature;
   rd->rh = NULL;
-  rd.http_status = hr->status;
-  rd.exchange_reply = json_incref ((json_t*) hr->reply);
+  rd->http_status = hr->http_status;
+  rd->exchange_reply = json_incref ((json_t*) hr->reply);
   ac->pending_at_ce--;
   if (0 == ac->pending_at_ce)
     find_next_exchange (ac);
@@ -485,16 +485,15 @@ process_abort_with_exchange (void *cls,
                              int exchange_trusted)
 {
   struct AbortContext *ac = cls;
-  struct TMH_HandlerContext *hc = pc->hc;
 
-  pc->fo = NULL;
-  GNUNET_assert (GNUNET_YES == pc->suspended);
+  ac->fo = NULL;
+  GNUNET_assert (GNUNET_YES == ac->suspended);
   if (MHD_HTTP_OK != hr->http_status)
   {
     /* The request failed somehow */
     GNUNET_break_op (0);
-    resume_pay_with_response (
-      pc,
+    resume_abort_with_response (
+      ac,
       MHD_HTTP_FAILED_DEPENDENCY,
       TALER_MHD_make_json_pack (
         (NULL != hr->reply)
@@ -534,7 +533,7 @@ process_abort_with_exchange (void *cls,
                                      &rdi->coin_pub,
                                      0, /* rtransaction_id */
                                      &ac->hc->instance->merchant_priv,
-                                     &refund_Cb,
+                                     &refund_cb,
                                      rdi);
     if (NULL == rdi->rh)
     {
@@ -545,7 +544,7 @@ process_abort_with_exchange (void *cls,
                                "Failed to start refund with exchange");
       return;
     }
-    pc->pending_at_ce++;
+    ac->pending_at_ce++;
   }
 }
 
@@ -576,9 +575,9 @@ find_next_exchange (struct AbortContext *ac)
 
     if (! rdi->processed)
     {
-      ac->current_exchange = rd->exchange_url;
+      ac->current_exchange = rdi->exchange_url;
       ac->fo = TMH_EXCHANGES_find_exchange (ac->current_exchange,
-                                            ac->wm->wire_method,
+                                            NULL,
                                             GNUNET_NO,
                                             &process_abort_with_exchange,
                                             ac);
@@ -606,30 +605,32 @@ find_next_exchange (struct AbortContext *ac)
  * Function called with information about a coin that was deposited.
  *
  * @param cls closure
- * @param h_contract_terms hashed proposal data
+ * @param exchange_url exchange where @a coin_pub was deposited
  * @param coin_pub public key of the coin
- * @param exchange_url URL of the exchange that issued @a coin_pub
  * @param amount_with_fee amount the exchange will deposit for this coin
  * @param deposit_fee fee the exchange will charge for this coin
  * @param refund_fee fee the exchange will charge for refunding this coin
  * @param wire_fee wire fee the exchange of this coin charges
- * @param exchange_proof proof from exchange that coin was accepted
  */
 static void
 refund_coins (void *cls,
-              const struct TALER_CoinSpendPublicKeyP *coin_pub,
               const char *exchange_url,
+              const struct TALER_CoinSpendPublicKeyP *coin_pub,
               const struct TALER_Amount *amount_with_fee,
               const struct TALER_Amount *deposit_fee,
               const struct TALER_Amount *refund_fee,
-              const struct TALER_Amount *wire_fee,
-              const json_t *exchange_proof)
+              const struct TALER_Amount *wire_fee)
 {
   struct AbortContext *ac = cls;
 
+  (void) amount_with_fee;
+  (void) deposit_fee;
+  (void) refund_fee;
+  (void) wire_fee;
   for (unsigned int i = 0; i<ac->coins_cnt; i++)
   {
     struct RefundDetails *rdi = &ac->rd[i];
+    enum GNUNET_DB_QueryStatus qs;
 
     if ( (0 !=
           GNUNET_memcmp (coin_pub,
@@ -711,7 +712,6 @@ begin_transaction (struct AbortContext *ac)
   if (0 < qs)
   {
     /* Payment is complete, refuse to abort. */
-    json_decref (terms);
     TMH_db->rollback (TMH_db->cls);
     resume_abort_with_error (ac,
                              MHD_HTTP_FORBIDDEN,
@@ -875,12 +875,12 @@ parse_abort (struct MHD_Connection *connection,
   /* Check request against contract on file */
   {
     enum GNUNET_DB_QueryStatus qs;
-    json_t *contract_terms;
+    struct GNUNET_HashCode h_contract_terms;
 
-    qs = TMH_db->lookup_contract_terms (TMH_db->cls,
-                                        hc->instance->settings.id,
-                                        hc->infix,
-                                        &contract_terms);
+    qs = TMH_db->lookup_contract_terms_hash (TMH_db->cls,
+                                             hc->instance->settings.id,
+                                             hc->infix,
+                                             &h_contract_terms);
     if (0 > qs)
     {
       /* single, read-only SQL statements should never cause
@@ -909,23 +909,8 @@ parse_abort (struct MHD_Connection *connection,
 
     /* check client provided the right hash and is thus authorized to request 
aborting */
     {
-      struct GNUNET_HashCode h_contract_terms;
-
-      if (GNUNET_OK !=
-          TALER_JSON_hash (ac->contract_terms,
-                           &h_contract_terms))
-      {
-        GNUNET_break (0);
-        return (MHD_YES ==
-                TALER_MHD_reply_with_error (connection,
-                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                            
TALER_EC_ABORT_FAILED_COMPUTE_PROPOSAL_HASH,
-                                            "Failed to hash contract terms"))
-               ? GNUNET_NO
-               : GNUNET_SYSERR;
-      }
       if (0 !=
-          GNUNET_memcmp (&ac->contract_terms,
+          GNUNET_memcmp (&ac->h_contract_terms,
                          &h_contract_terms))
       {
         GNUNET_break_op (0);
@@ -940,48 +925,8 @@ parse_abort (struct MHD_Connection *connection,
     }
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "Handling /abort for order `%s' with contract hash `%s'\n",
-                order_id,
+                ac->hc->infix,
                 GNUNET_h2s (&ac->h_contract_terms));
-
-    /* Check abort is still possible */
-    {
-      struct GNUNET_TIME_Absolute refund_deadline;
-      struct GNUNET_TIME_Absolute wire_transfer_deadline;
-      struct GNUNET_TIME_Absolute now;
-      struct GNUNET_JSON_Specification espec[] = {
-        GNUNET_JSON_spec_absolute_time ("refund_deadline",
-                                        &refund_deadline),
-        GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline",
-                                        &wire_transfer_deadline),
-        GNUNET_JSON_spec_end ()
-      };
-
-      /* FIXME: this is a tad wrong, as IF the contract is
-         malformed, the routine generates an error that blames
-         it on the client (400) instead of on us! */
-      res = TALER_MHD_parse_json_data (connection,
-                                       ac->contract_terms,
-                                       espec);
-      if (GNUNET_YES != res)
-      {
-        GNUNET_break (0);
-        return res;
-      }
-      now = GNUNET_TIME_absolute_get ();
-      if ( (now.abs_value_us < refund_deadline.abs_value_us) &&
-           ( (0 != refund_deadline.abs_value_us) ||
-             (now.abs_value_us < wire_transfer_deadline.abs_value_us) ) )
-      {
-        /* it is most definitively too late for an abort */
-        return (MHD_YES ==
-                TALER_MHD_reply_with_error (connection,
-                                            MHD_HTTP_GONE,
-                                            TALER_EC_ABORT_TOO_LATE,
-                                            "It is too late to abort the 
payment"))
-               ? GNUNET_NO
-               : GNUNET_SYSERR;
-      }
-    }
   }
   return GNUNET_OK;
 }
@@ -1028,7 +973,7 @@ TMH_post_orders_ID_abort (const struct TMH_RequestHandler 
*rh,
 {
   struct AbortContext *ac = hc->ctx;
 
-  if (NULL == *connection_cls)
+  if (NULL == ac)
   {
     ac = GNUNET_new (struct AbortContext);
     GNUNET_CONTAINER_DLL_insert (ac_head,
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index f11154e..46bcaee 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -896,17 +896,16 @@ find_next_exchange (struct PayContext *pc)
  * Function called with information about a coin that was deposited.
  *
  * @param cls closure
- * @param h_contract_terms hashed proposal data
+ * @param exchange_url exchange where @a coin_pub was deposited
  * @param coin_pub public key of the coin
- * @param exchange_url URL of the exchange that issued @a coin_pub
  * @param amount_with_fee amount the exchange will deposit for this coin
  * @param deposit_fee fee the exchange will charge for this coin
  * @param refund_fee fee the exchange will charge for refunding this coin
  * @param wire_fee wire fee the exchange of this coin charges
- * @param exchange_proof proof from exchange that coin was accepted
  */
 static void
 check_coin_paid (void *cls,
+                 const char *exchange_url,
                  const struct TALER_CoinSpendPublicKeyP *coin_pub,
                  const struct TALER_Amount *amount_with_fee,
                  const struct TALER_Amount *deposit_fee,
@@ -924,6 +923,9 @@ check_coin_paid (void *cls,
     /* Get matching coin from results*/
     if ( (0 != GNUNET_memcmp (coin_pub,
                               &dc->coin_pub)) ||
+         (0 !=
+          strcmp (exchange_url,
+                  dc->exchange_url)) ||
          (0 != TALER_amount_cmp (amount_with_fee,
                                  &dc->amount_with_fee)) )
       continue; /* does not match, skip */
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 2e97c86..46929c0 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1551,7 +1551,10 @@ lookup_deposits_cb (void *cls,
     struct TALER_Amount deposit_fee;
     struct TALER_Amount refund_fee;
     struct TALER_Amount wire_fee;
+    const char *exchange_url;
     struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("exchange_url",
+                                    &exchange_url),
       GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
                                             &coin_pub),
       TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
@@ -1576,6 +1579,7 @@ lookup_deposits_cb (void *cls,
     }
     ldc->qs = i + 1;
     ldc->cb (ldc->cb_cls,
+             exchange_url,
              &coin_pub,
              &amount_with_fee,
              &deposit_fee,
@@ -5301,7 +5305,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     /* for postgres_lookup_deposits() */
     GNUNET_PQ_make_prepare ("lookup_deposits",
                             "SELECT"
-                            " coin_pub"
+                            " exchange_url"
+                            ",coin_pub"
                             ",amount_with_fee_val"
                             ",amount_with_fee_frac"
                             ",deposit_fee_val"
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 68efc6c..f995d98 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -303,8 +303,8 @@ typedef void
  * Function called with information about a coin that was deposited.
  *
  * @param cls closure
+ * @param exchange_url exchange where @a coin_pub was deposited
  * @param coin_pub public key of the coin
- * @param exchange_url URL of the exchange that issued the coin
  * @param amount_with_fee amount the exchange will deposit for this coin
  * @param deposit_fee fee the exchange will charge for this coin
  * @param refund_fee fee the exchange will charge for refunding this coin
@@ -313,6 +313,7 @@ typedef void
 typedef void
 (*TALER_MERCHANTDB_DepositsCallback)(
   void *cls,
+  const char *exchange_url,
   const struct TALER_CoinSpendPublicKeyP *coin_pub,
   const struct TALER_Amount *amount_with_fee,
   const struct TALER_Amount *deposit_fee,

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