gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: refactor order claiming


From: gnunet
Subject: [taler-merchant] branch master updated: refactor order claiming
Date: Thu, 22 Jul 2021 15:54:53 +0200

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

dold pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 2f4a05e7 refactor order claiming
2f4a05e7 is described below

commit 2f4a05e7a2f947372f97d11ac8c08fc705c79e59
Author: Florian Dold <florian@dold.me>
AuthorDate: Thu Jul 22 15:53:37 2021 +0200

    refactor order claiming
---
 contrib/merchant-backoffice                        |  2 +-
 .../taler-merchant-httpd_post-orders-ID-claim.c    | 77 ++++++++++++++--------
 src/backenddb/plugin_merchantdb_postgres.c         |  8 +--
 3 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/contrib/merchant-backoffice b/contrib/merchant-backoffice
index 1732185a..4320467d 160000
--- a/contrib/merchant-backoffice
+++ b/contrib/merchant-backoffice
@@ -1 +1 @@
-Subproject commit 1732185ac1d1dcc783b8f2489f2ce333b5254d92
+Subproject commit 4320467db1392e5f48a4acd079f7e2a253cf9984
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
index b764c7d7..1d201ce1 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
@@ -83,7 +83,46 @@ claim_order (const char *instance_id,
     return qs;
   }
 
-  if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+  if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+  {
+    /* We already have claimed contract terms for this order_id */
+    const char *stored_nonce;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_string ("nonce",
+                               &stored_nonce),
+      GNUNET_JSON_spec_end ()
+    };
+    enum GNUNET_GenericReturnValue res;
+
+    TMH_db->rollback (TMH_db->cls);
+    GNUNET_assert (NULL != *contract_terms);
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (*contract_terms,
+                           spec,
+                           NULL,
+                           NULL))
+    {
+      /* this should not be possible: contract_terms should always
+         have a nonce! */
+      GNUNET_break (0);
+      return GNUNET_DB_STATUS_HARD_ERROR;
+    }
+
+    if (0 != strcmp (stored_nonce,
+                     nonce))
+    {
+      GNUNET_JSON_parse_free (spec);
+      return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+    }
+    GNUNET_JSON_parse_free (spec);
+    return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+  }
+
+  GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
+
+  /* Now we need to claim the order. */
+
   {
     struct GNUNET_HashCode unused;
 
@@ -99,13 +138,13 @@ claim_order (const char *instance_id,
       TMH_db->rollback (TMH_db->cls);
       return qs;
     }
-    GNUNET_assert (NULL != contract_terms);
+    GNUNET_assert (NULL != *contract_terms);
     GNUNET_assert (0 ==
                    json_object_set_new (*contract_terms,
                                         "nonce",
                                         json_string (nonce)));
-    if (0 != GNUNET_memcmp (&order_ct,
-                            claim_token))
+    if (0 != GNUNET_memcmp_priv (&order_ct,
+                                 claim_token))
     {
       TMH_db->rollback (TMH_db->cls);
       json_decref (*contract_terms);
@@ -128,29 +167,6 @@ claim_order (const char *instance_id,
       return qs;
     return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
   }
-  else
-  {
-    const char *stored_nonce;
-
-    TMH_db->rollback (TMH_db->cls);
-    GNUNET_assert (NULL != *contract_terms);
-    stored_nonce
-      = json_string_value (json_object_get (*contract_terms,
-                                            "nonce"));
-    if (NULL == stored_nonce)
-    {
-      /* this should not be possible: contract_terms should always
-         have a nonce! */
-      GNUNET_break (0);
-      return GNUNET_DB_STATUS_HARD_ERROR;
-    }
-    if (0 != strcmp (stored_nonce,
-                     nonce))
-    {
-      return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
-    }
-    return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-  }
 }
 
 
@@ -225,13 +241,18 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler 
*rh,
     break; /* Good! return signature (below) */
   }
 
-  /* create proposal signature */
+  /* create contract signature */
   {
     struct GNUNET_CRYPTO_EddsaSignature merchant_sig;
     struct TALER_ProposalDataPS pdps = {
       .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT),
       .purpose.size = htonl (sizeof (pdps))
     };
+    /**
+     * Hash of the JSON contract in UTF-8 including 0-termination,
+     * using JSON_COMPACT | JSON_SORT_KEYS
+     */
+    struct GNUNET_HashCode hash;
 
     if (GNUNET_OK !=
         TALER_JSON_contract_hash (contract_terms,
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index bc3af1bb..6970233c 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1749,7 +1749,7 @@ postgres_update_contract_terms (void *cls,
   struct PostgresClosure *pg = cls;
   struct GNUNET_TIME_Absolute pay_deadline;
   struct GNUNET_TIME_Absolute refund_deadline;
-  const char *fulfillment_url;
+  const char *fulfillment_url = NULL;
   struct GNUNET_HashCode h_contract_terms;
 
   if (GNUNET_OK !=
@@ -1766,6 +1766,9 @@ postgres_update_contract_terms (void *cls,
                                      &pay_deadline),
       TALER_JSON_spec_absolute_time ("refund_deadline",
                                      &refund_deadline),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_string ("fulfillment_url",
+                                 &fulfillment_url)),
       GNUNET_JSON_spec_end ()
     };
     enum GNUNET_GenericReturnValue res;
@@ -1780,9 +1783,6 @@ postgres_update_contract_terms (void *cls,
     }
   }
 
-  fulfillment_url =
-    json_string_value (json_object_get (contract_terms,
-                                        "fulfillment_url"));
   check_connection (pg);
   {
     struct GNUNET_PQ_QueryParam params[] = {

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