gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: [policy] mark deposit as blocked


From: gnunet
Subject: [taler-exchange] branch master updated: [policy] mark deposit as blocked, when policy is not fulfilled
Date: Mon, 04 Dec 2023 13:02:32 +0100

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

oec pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new dbc4b71b [policy] mark deposit as blocked, when policy is not fulfilled
dbc4b71b is described below

commit dbc4b71bc1a94e42de20e330627567675e78cae5
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Mon Dec 4 13:02:27 2023 +0100

    [policy] mark deposit as blocked, when policy is not fulfilled
---
 src/exchange/taler-exchange-httpd_batch-deposit.c | 17 +++++++++++------
 src/extensions/extensions.c                       | 15 ++++++++++++++-
 src/include/taler_extensions.h                    |  2 ++
 src/include/taler_extensions_policy.h             | 15 ++++++++++-----
 4 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c 
b/src/exchange/taler-exchange-httpd_batch-deposit.c
index baf2b964..9f66a99a 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.c
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.c
@@ -28,6 +28,7 @@
 #include <jansson.h>
 #include <microhttpd.h>
 #include <pthread.h>
+#include "taler_extensions_policy.h"
 #include "taler_json_lib.h"
 #include "taler_mhd_lib.h"
 #include "taler-exchange-httpd_batch-deposit.h"
@@ -168,7 +169,7 @@ batch_deposit_transaction (void *cls,
 {
   struct BatchDepositContext *dc = cls;
   const struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc->bd;
-  enum GNUNET_DB_QueryStatus qs = GNUNET_SYSERR;
+  enum GNUNET_DB_QueryStatus qs = GNUNET_DB_STATUS_HARD_ERROR;
   uint32_t bad_balance_coin_index = UINT32_MAX;
   bool balance_ok;
   bool in_conflict;
@@ -185,8 +186,9 @@ batch_deposit_transaction (void *cls,
       &dc->policy_details.fulfillment_state);
     if (qs < 0)
       return qs;
-    /* FIXME-Oec: dc->bd.policy_blocked not initialized,
-       likely should be set based on fulfillment_state!?*/
+
+    dc->bd.policy_blocked =
+      dc->policy_details.fulfillment_state != TALER_PolicyFulfillmentSuccess;
   }
 
   /* FIXME: replace by batch insert! */
@@ -523,9 +525,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
       return MHD_YES; /* failure */
     }
   }
-  GNUNET_assert (GNUNET_OK ==
-                 TALER_amount_set_zero (TEH_currency,
-                                        &dc.policy_details.accumulated_total));
+
   /* validate merchant's wire details (as far as we can) */
   {
     char *emsg;
@@ -578,13 +578,18 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
 
     if (GNUNET_OK !=
         TALER_extensions_create_policy_details (
+          TEH_currency,
           dc.policy_json,
           &dc.policy_details,
           &error_hint))
+    {
+      GNUNET_break_op (0);
+      GNUNET_JSON_parse_free (spec);
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_BAD_REQUEST,
                                          
TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
                                          error_hint);
+    }
 
     TALER_deposit_policy_hash (dc.policy_json,
                                &dc.h_policy);
diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c
index fbbe874f..999e9317 100644
--- a/src/extensions/extensions.c
+++ b/src/extensions/extensions.c
@@ -19,6 +19,7 @@
  * @author Özgür Kesim
  */
 #include "platform.h"
+#include "taler_extensions_policy.h"
 #include "taler_util.h"
 #include "taler_signatures.h"
 #include "taler_extensions.h"
@@ -366,6 +367,7 @@ TALER_extensions_load_manifests (
  */
 
 static char *fulfillment2str[] =  {
+  [TALER_PolicyFulfillmentInitial]      = "<init>",
   [TALER_PolicyFulfillmentReady]        = "Ready",
   [TALER_PolicyFulfillmentSuccess]      = "Success",
   [TALER_PolicyFulfillmentFailure]      = "Failure",
@@ -384,6 +386,7 @@ TALER_policy_fulfillment_state_str (
 
 enum GNUNET_GenericReturnValue
 TALER_extensions_create_policy_details (
+  const char *currency,
   const json_t *policy_options,
   struct TALER_PolicyDetails *details,
   const char **error_hint)
@@ -427,8 +430,18 @@ TALER_extensions_create_policy_details (
     return GNUNET_NO;
   }
 
+  /* Set state fields in the policy details to initial values. */
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_amount_set_zero (currency,
+                                        &details->accumulated_total));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_amount_set_zero (currency,
+                                        &details->policy_fee));
   details->deadline = GNUNET_TIME_UNIT_FOREVER_TS;
-  ret = extension->create_policy_details (policy_options,
+  details->fulfillment_state = TALER_PolicyFulfillmentInitial;
+  details->no_policy_fulfillment_id = true;
+  ret = extension->create_policy_details (currency,
+                                          policy_options,
                                           details,
                                           error_hint);
   return ret;
diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h
index fe1eac27..1eb567f7 100644
--- a/src/include/taler_extensions.h
+++ b/src/include/taler_extensions.h
@@ -162,6 +162,7 @@ struct TALER_Extension
    * (see https://docs.taler.net/core/api-exchange.html#deposit), this handler
    * will be called before the deposit transaction.
    *
+   * @param[in]  currency Currency used in the exchange
    * @param[in]  policy_json Details about the policy, provided by the client
    *             during a deposit request.
    * @param[out] details On success, will contain the details to the policy,
@@ -170,6 +171,7 @@ struct TALER_Extension
    * @return     GNUNET_OK if the data was accepted by the extension.
    */
   enum GNUNET_GenericReturnValue (*create_policy_details)(
+    const char *currency,
     const json_t *policy_json,
     struct TALER_PolicyDetails *details,
     const char **error_hint);
diff --git a/src/include/taler_extensions_policy.h 
b/src/include/taler_extensions_policy.h
index 97fc509b..7750f58f 100644
--- a/src/include/taler_extensions_policy.h
+++ b/src/include/taler_extensions_policy.h
@@ -31,21 +31,24 @@
  */
 enum TALER_PolicyFulfillmentState
 {
+  /* Initial state of an fulfillment, before any other state. */
+  TALER_PolicyFulfillmentInitial = 0,
+
   /* General error state of an fulfillment. */
-  TALER_PolicyFulfillmentFailure = 0,
+  TALER_PolicyFulfillmentFailure = 1,
 
   /* The policy is not yet ready due to insufficient funding. More deposits are
    * necessary for it to become ready . */
-  TALER_PolicyFulfillmentInsufficient = 1,
+  TALER_PolicyFulfillmentInsufficient = 2,
 
   /* The policy is funded and ready, pending */
-  TALER_PolicyFulfillmentReady = 2,
+  TALER_PolicyFulfillmentReady = 3,
 
   /* Policy is provably fulfilled. */
-  TALER_PolicyFulfillmentSuccess = 3,
+  TALER_PolicyFulfillmentSuccess = 4,
 
   /* Policy fulfillment has timed out */
-  TALER_PolicyFulfillmentTimeout = 4,
+  TALER_PolicyFulfillmentTimeout = 5,
 
   TALER_PolicyFulfillmentStateCount = TALER_PolicyFulfillmentTimeout + 1
 };
@@ -143,6 +146,7 @@ struct TALER_PolicyFulfillmentTransactionData
 /*
  * @brief Extracts policy details from the deposit's policy options and the 
policy extensions
  *
+ * @param[in]  currency Currency used in the exchange
  * @param[in]  policy_options JSON of the policy options from a deposit request
  * @param[out] details On GNUNET_OK, the parsed details
  * @param[out] error_hint On GNUNET_SYSERR, will contain a hint for the reason 
why it failed
@@ -151,6 +155,7 @@ struct TALER_PolicyFulfillmentTransactionData
  */
 enum GNUNET_GenericReturnValue
 TALER_extensions_create_policy_details (
+  const char *currency,
   const json_t *policy_options,
   struct TALER_PolicyDetails *details,
   const char **error_hint);

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