gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (7025139 -> c9b8f98)


From: gnunet
Subject: [taler-anastasis] branch master updated (7025139 -> c9b8f98)
Date: Thu, 03 Sep 2020 14:36:59 +0200

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

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from 7025139  added template
     new f02d0fb  fix issue with payment identifier
     new cfa008e  added prepared statement
     new df92c37  fixed some payment issues
     new c9b8f98  Merge branch 'master' of ssh://git.taler.net/anastasis into 
master

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/anastasis-httpd_policy_upload.c | 34 +++++++++++++++-
 src/include/anastasis_database_plugin.h     | 18 +++++++++
 src/stasis/plugin_anastasis_postgres.c      | 61 +++++++++++++++++++++++++++++
 src/stasis/test_anastasis_db.c              | 14 +++++++
 4 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index ca7f33b..b0fbee2 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -345,7 +345,7 @@ proposal_cb (void *cls,
   {
     GNUNET_break (0);
     puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CREATE_DB_ERROR,
-                                      "Failed to persist payment request in 
sync database");
+                                      "Failed to persist payment request in 
anastasis database");
     puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     return;
   }
@@ -877,12 +877,42 @@ AH_handler_policy_post (struct MHD_Connection *connection,
                                            "Payment-Identifier does not 
include a base32-encoded Payment-Identifier");
       }
       if (pay_id)
+      {
+        // check if payment identifier is valid (existing and paid)
+        bool paid;
+        bool valid_counter;
+
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                     "At %s:%d Payment-Identifier from header is: %s\n",
                     __FILE__,
                     __LINE__,
                     TALER_B2S (&puc->payment_identifier));
 
+        qs = db->check_payment_identifier (db->cls,
+                                           &puc->payment_identifier,
+                                           &paid,
+                                           &valid_counter);
+        if (qs < 0)
+          return handle_database_error (puc,
+                                        qs);
+
+        if ((qs >= 0)&& (! paid || ! valid_counter))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                      "At %s:%d paid is: '%d' and valid_counter is '%d'\n",
+                      __FILE__,
+                      __LINE__,
+                      paid,
+                      valid_counter);
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "At %s:%d Payment is required, starting payment 
process.\n",
+                      __FILE__,
+                      __LINE__);
+          return begin_payment (puc,
+                                GNUNET_YES);
+        }
+      }
+
       if (! pay_id)
       {
         // generate new payment identifier
@@ -925,7 +955,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
                       __FILE__,
                       __LINE__);
           return begin_payment (puc,
-                                GNUNET_NO);
+                                GNUNET_YES);
         }
       }
 
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index c725be4..4ef5947 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -316,6 +316,7 @@ struct ANASTASIS_DatabasePlugin
  * @param anastasis_pub account to look for pending payment under
  * @param it iterator to call on all pending payments
  * @param it_cls closure for @a it
+ * @return transaction status
  */
   enum ANASTASIS_DB_QueryStatus
   (*lookup_pending_payments_by_account)(void *cls,
@@ -325,6 +326,23 @@ struct ANASTASIS_DatabasePlugin
                                         ANASTASIS_DB_PaymentPendingIterator it,
                                         void *it_cls);
 
+/**
+ * Check payment identifier. Used to check if a payment identifier given by
+ * the user is valid (existing and paid).
+ *
+ * @param cls closure
+ * @param payment_secret payment secret which the user must provide with every 
upload
+ * @param paid bool value to show if payment is paid
+ * @param valid_counter bool value to show if post_counter is > 0
+ * @return transaction status
+ */
+  enum ANASTASIS_DB_QueryStatus
+  (*check_payment_identifier)(void *cls,
+                              const struct
+                              ANASTASIS_PaymentSecretP *payment_secret,
+                              bool *paid,
+                              bool *valid_counter);
+
   /**
    * Increment account lifetime.
    *
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 412b2f4..e09aac5 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -978,6 +978,56 @@ postgres_record_payment (void *cls,
 }
 
 
+/**
+ * Check payment identifier. Used to check if a payment identifier given by
+ * the user is valid (existing and paid).
+ *
+ * @param cls closure
+ * @param payment_secret payment secret which the user must provide with every 
upload
+ * @param paid[OUT] bool value to show if payment is paid
+ * @param valid_counter[OUT] bool value to show if post_counter is > 0
+ * @return transaction status
+ */
+static enum ANASTASIS_DB_QueryStatus
+postgres_check_payment_identifier (void *cls,
+                                   const struct
+                                   ANASTASIS_PaymentSecretP *payment_secret,
+                                   bool *paid,
+                                   bool *valid_counter)
+{
+  struct PostgresClosure *pg = cls;
+  enum ANASTASIS_DB_QueryStatus qs;
+  uint32_t counter;
+
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (payment_secret),
+    GNUNET_PQ_query_param_end
+  };
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    GNUNET_PQ_result_spec_auto_from_type ("paid",
+                                          paid),
+    GNUNET_PQ_result_spec_uint32 ("post_counter",
+                                  &counter),
+    GNUNET_PQ_result_spec_end
+  };
+  check_connection (pg);
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "payment_select",
+                                                 params,
+                                                 rs);
+
+  if (qs == ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT)
+  {
+    if (counter > 0)
+      *valid_counter = true;
+    else
+      *valid_counter = false;
+  }
+
+  return qs;
+}
+
+
 /**
  * Upload Truth, which contains the Truth and the KeyShare.
  *
@@ -1461,6 +1511,16 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             " AND"
                             "  paid=FALSE;",
                             2),
+    GNUNET_PQ_make_prepare ("payment_select",
+                            "SELECT"
+                            " timestamp"
+                            ",post_counter"
+                            ",amount_val"
+                            ",amount_frac"
+                            ",paid"
+                            " FROM anastasis_payment"
+                            " WHERE payment_identifier=$1;",
+                            1),
     GNUNET_PQ_make_prepare ("payments_select",
                             "SELECT"
                             " user_id"
@@ -1629,6 +1689,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
   plugin->get_latest_recovery_document = 
&postgres_get_latest_recovery_document;
   plugin->get_recovery_document = &postgres_get_recovery_document;
   plugin->lookup_account = &postgres_lookup_account;
+  plugin->check_payment_identifier = &postgres_check_payment_identifier;
   plugin->lookup_pending_payments_by_account =
     &postgres_lookup_pending_payments_by_account;
   plugin->increment_lifetime = &postgres_increment_lifetime;
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index e57c8cf..e158607 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -207,6 +207,8 @@ run (void *cls)
   unsigned char aes_gcm_tag[16];
   RND_BLK (&aes_gcm_tag);
 
+  bool paid;
+  bool valid_counter;
   post_counter = 2;
   mime_type = "Picture";
   method = "Methode";
@@ -230,6 +232,12 @@ run (void *cls)
                  TALER_string_to_amount ("EUR:1",
                                          &amount));
 
+  FAILIF (ANASTASIS_DB_STATUS_NO_RESULTS !=
+          plugin->check_payment_identifier (plugin->cls,
+                                            &paymentSecretP,
+                                            &paid,
+                                            &valid_counter));
+
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->record_payment (plugin->cls,
                                   &accountPubP,
@@ -243,6 +251,12 @@ run (void *cls)
                                       &paymentSecretP,
                                       rel_time));
 
+  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+          plugin->check_payment_identifier (plugin->cls,
+                                            &paymentSecretP,
+                                            &paid,
+                                            &valid_counter));
+
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->store_truth (plugin->cls,
                                &truth_public_key,

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