gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated: work on new tipping


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: work on new tipping test logic, also refactoring to match latest exchange API (as that was changed to support tipping test logic better)
Date: Tue, 31 Oct 2017 14:03:32 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new f637ee5  work on new tipping test logic, also refactoring to match 
latest exchange API (as that was changed to support tipping test logic better)
f637ee5 is described below

commit f637ee51760a2315c3386431fd56a14e5d918184
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Oct 31 14:03:30 2017 +0100

    work on new tipping test logic, also refactoring to match latest exchange 
API (as that was changed to support tipping test logic better)
---
 src/include/taler_merchant_service.h               |  26 +--
 src/lib/merchant_api_tip_pickup.c                  |   4 +-
 src/lib/test_merchant_api.c                        | 193 +++++++++++++++------
 .../taler-merchant-generate-payments.c             |  30 +---
 4 files changed, 145 insertions(+), 108 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index b9a6a8d..48c44e6 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -24,6 +24,7 @@
 
 #include <taler/taler_util.h>
 #include <taler/taler_error_codes.h>
+#include <taler/taler_exchange_service.h>
 #include <gnunet/gnunet_curl_lib.h>
 #include <jansson.h>
 
@@ -870,29 +871,6 @@ typedef void
 
 
 /**
- * Details about a planchet that the customer wants to obtain
- * a withdrawal authorization for to obtain a tip.
- */
-struct TALER_MERCHANT_PlanchetDetail
-{
-  /**
-   * Hash of the denomination public key.
-   */
-  struct GNUNET_HashCode denom_pub_hash;
-
-  /**
-   * Blinded coin (see GNUNET_CRYPTO_rsa_blind()).
-   */
-  const char *coin_ev;
-
-  /**
-   * Number of bytes in @a coin_ev.
-   */
-  size_t coin_ev_size;
-};
-
-
-/**
  * Issue a /tip-pickup request to the backend.  Informs the backend
  * that a customer wants to pick up a tip.
  *
@@ -910,7 +888,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx,
                            const char *backend_uri,
                            const struct GNUNET_HashCode *tip_id,
                            unsigned int num_planchets,
-                           struct TALER_MERCHANT_PlanchetDetail *planchets,
+                           struct TALER_PlanchetDetail *planchets,
                            TALER_MERCHANT_TipPickupCallback pickup_cb,
                            void *pickup_cb_cls);
 
diff --git a/src/lib/merchant_api_tip_pickup.c 
b/src/lib/merchant_api_tip_pickup.c
index 02b8878..ec46c0f 100644
--- a/src/lib/merchant_api_tip_pickup.c
+++ b/src/lib/merchant_api_tip_pickup.c
@@ -215,7 +215,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx,
                            const char *backend_uri,
                            const struct GNUNET_HashCode *tip_id,
                            unsigned int num_planchets,
-                           struct TALER_MERCHANT_PlanchetDetail *planchets,
+                           struct TALER_PlanchetDetail *planchets,
                            TALER_MERCHANT_TipPickupCallback pickup_cb,
                            void *pickup_cb_cls)
 {
@@ -227,7 +227,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx,
   pa = json_array ();
   for (unsigned int i=0;i<num_planchets;i++)
   {
-    const struct TALER_MERCHANT_PlanchetDetail *planchet = &planchets[i];
+    const struct TALER_PlanchetDetail *planchet = &planchets[i];
     json_t *p;
 
     p = json_pack ("{"
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 162557c..80f4fb8 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -253,33 +253,6 @@ struct MeltDetails
 
 
 /**
- * Information about a fresh coin generated by the refresh operation.
- */
-struct FreshCoin
-{
-
-  /**
-   * If @e amount is NULL, this specifies the denomination key to
-   * use.  Otherwise, this will be set (by the interpreter) to the
-   * denomination PK matching @e amount.
-   */
-  const struct TALER_EXCHANGE_DenomPublicKey *pk;
-
-  /**
-   * Set (by the interpreter) to the exchange's signature over the
-   * coin's public key.
-   */
-  struct TALER_DenominationSignature sig;
-
-  /**
-   * Set (by the interpreter) to the coin's private key.
-   */
-  struct TALER_CoinSpendPrivateKeyP coin_priv;
-
-};
-
-
-/**
  * Details for a exchange operation to execute.
  */
 struct Command
@@ -425,14 +398,9 @@ struct Command
       struct TALER_DenominationSignature sig;
 
       /**
-       * Set (by the interpreter) to the coin's private key.
+       * Set (by the interpreter) to the planchet's secrets.
        */
-      struct TALER_CoinSpendPrivateKeyP coin_priv;
-
-      /**
-       * Blinding key used for the operation.
-       */
-      struct TALER_DenominationBlindingKeyP blinding_key;
+      struct TALER_PlanchetSecretsP ps;
 
       /**
        * Withdraw handle (while operation is running).
@@ -806,15 +774,17 @@ struct Command
        */
       struct TALER_MERCHANT_TipPickupOperation *tpo;
 
-      /* FIXME: will need some other temporary data structure here
-         to store the blinding keys while the pickup operation
-         runs. */
+      /**
+       * Temporary data structure to store the blinding keys while the
+       * pickup operation runs.
+       */
+      struct TALER_PlanchetSecretsP *psa;
 
       /**
        * Set (by the interpreter) to an array of @a num_coins coins
        * created from the (successful) tip operation.
        */
-      struct FreshCoin *coins;
+      struct TALER_FreshCoin *coins;
 
       /**
        * EC expected for the operation.
@@ -1488,7 +1458,7 @@ refund_lookup_cb (void *cls,
     GNUNET_assert (NULL != (icoin =
                            find_command (is,
                                          icoin_ref)));
-    GNUNET_CRYPTO_eddsa_key_get_public 
(&icoin->details.reserve_withdraw.coin_priv.eddsa_priv,
+    GNUNET_CRYPTO_eddsa_key_get_public 
(&icoin->details.reserve_withdraw.ps.coin_priv.eddsa_priv,
                                         &icoin_pub.eddsa_pub);
     GNUNET_CRYPTO_hash (&icoin_pub,
                         sizeof (struct TALER_CoinSpendPublicKeyP),
@@ -1829,6 +1799,83 @@ tip_authorize_cb (void *cls,
 
 
 /**
+ * Create a planchet for tipping.
+ *
+ * @param keys the exchange's denominations
+ * @param amount the desired amount
+ * @param[out] pd blinded planchet (to be set)
+ * @param[out] ps secret details needed to extract the coin later (set)
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if @a amount is not in @a keys
+ */
+static int
+make_planchet (const struct TALER_EXCHANGE_Keys *keys,
+               const char *amount,
+               struct TALER_PlanchetDetail *pd,
+               struct TALER_PlanchetSecretsP *ps)
+{
+  struct TALER_Amount a;
+  const struct TALER_EXCHANGE_DenomPublicKey *dk;
+
+  if (GNUNET_OK !=
+      TALER_string_to_amount (amount,
+                              &a))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  dk = NULL;
+  for (unsigned int i=0;i<keys->num_denom_keys;i++)
+  {
+    if (0 ==
+        TALER_amount_cmp (&a,
+                          &keys->denom_keys[i].value))
+    {
+      dk = &keys->denom_keys[i];
+      break;
+    }
+  }
+  if (NULL == dk)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return TALER_planchet_prepare (&dk->key,
+                                 ps,
+                                 pd);
+}
+
+
+/**
+ * Callback for a /tip-pickup request.  Returns the result of
+ * the operation.
+ *
+ * @param cls closure
+ * @param http_status HTTP status returned by the merchant backend, "200 OK" 
on success
+ * @param ec taler-specific error code
+ * @param reserve_pub public key of the reserve that made the @a reserve_sigs, 
NULL on error
+ * @param num_reserve_sigs length of the @a reserve_sigs array, 0 on error
+ * @param reserve_sigs array of signatures authorizing withdrawals, NULL on 
error
+ * @param json original json response
+ */
+static void
+pickup_cb (void *cls,
+           unsigned int http_status,
+           enum TALER_ErrorCode ec,
+           const struct TALER_ReservePublicKeyP *reserve_pub,
+           unsigned int num_reserve_sigs,
+           const struct TALER_ReserveSignatureP *reserve_sigs,
+           const json_t *json)
+{
+  struct InterpreterState *is = cls;
+  struct Command *cmd = &is->commands[is->ip];
+
+  cmd->details.tip_pickup.tpo = NULL;
+  // FIXME: implement!
+  next_command (is);
+}
+
+
+/**
  * Find denomination key matching the given amount.
  *
  * @param keys array of keys to search
@@ -2053,6 +2100,11 @@ cleanup_state (struct InterpreterState *is)
         TALER_MERCHANT_tip_pickup_cancel (cmd->details.tip_pickup.tpo);
         cmd->details.tip_pickup.tpo = NULL;
       }
+      if (NULL != cmd->details.tip_pickup.psa)
+      {
+        GNUNET_free (cmd->details.tip_pickup.psa);
+        cmd->details.tip_pickup.psa = NULL;
+      }
       break;
     default:
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2079,7 +2131,6 @@ interpreter_run (void *cls)
   struct Command *cmd = &is->commands[is->ip];
   const struct Command *ref;
   struct TALER_ReservePublicKeyP reserve_pub;
-  struct TALER_CoinSpendPublicKeyP coin_pub;
   struct TALER_Amount amount;
   struct GNUNET_TIME_Absolute execution_date;
   json_t *sender_details;
@@ -2268,27 +2319,14 @@ interpreter_run (void *cls)
     GNUNET_assert (NULL != (cmd->details.reserve_withdraw.pk
       = find_pk (is->keys,
                  &amount)));
-    /* create coin's private key */
-    {
-      struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
-
-      priv = GNUNET_CRYPTO_eddsa_key_create ();
-      cmd->details.reserve_withdraw.coin_priv.eddsa_priv = *priv;
-      GNUNET_free (priv);
-    }
-    GNUNET_CRYPTO_eddsa_key_get_public 
(&cmd->details.reserve_withdraw.coin_priv.eddsa_priv,
-                                        &coin_pub.eddsa_pub);
-    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                                &cmd->details.reserve_withdraw.blinding_key,
-                                sizeof 
(cmd->details.reserve_withdraw.blinding_key));
 
+    TALER_planchet_setup_random (&cmd->details.reserve_withdraw.ps);
     cmd->details.reserve_withdraw.wsh
       = TALER_EXCHANGE_reserve_withdraw
         (exchange,
          cmd->details.reserve_withdraw.pk,
          &ref->details.admin_add_incoming.reserve_priv,
-         &cmd->details.reserve_withdraw.coin_priv,
-         &cmd->details.reserve_withdraw.blinding_key,
+         &cmd->details.reserve_withdraw.ps,
          &reserve_withdraw_cb,
          is);
     if (NULL == cmd->details.reserve_withdraw.wsh)
@@ -2404,7 +2442,7 @@ interpreter_run (void *cls)
         switch (coin_ref->oc)
         {
         case OC_WITHDRAW_SIGN:
-          icoin->coin_priv = coin_ref->details.reserve_withdraw.coin_priv;
+          icoin->coin_priv = coin_ref->details.reserve_withdraw.ps.coin_priv;
           icoin->denom_pub = coin_ref->details.reserve_withdraw.pk->key;
           icoin->denom_sig = coin_ref->details.reserve_withdraw.sig;
           icoin->denom_value = coin_ref->details.reserve_withdraw.pk->value;
@@ -2587,7 +2625,8 @@ interpreter_run (void *cls)
     {
       struct TALER_Amount refund_amount;
 
-      GNUNET_assert (GNUNET_OK == TALER_string_to_amount
+      GNUNET_assert (GNUNET_OK ==
+                     TALER_string_to_amount
                      (cmd->details.refund_increase.refund_amount,
                       &refund_amount));
       if (NULL == (cmd->details.refund_increase.rio
@@ -2633,6 +2672,7 @@ interpreter_run (void *cls)
         ref = find_command (is,
                             cmd->details.tip_enable.admin_add_incoming_ref);
         GNUNET_assert (NULL != ref);
+        GNUNET_assert (OC_ADMIN_ADD_INCOMING == ref->oc);
       }
       else
       {
@@ -2717,6 +2757,45 @@ interpreter_run (void *cls)
       }
       break;
     }
+  case OC_TIP_PICKUP:
+    {
+      unsigned int num_planchets = cmd->details.tip_pickup.num_coins;
+      struct TALER_PlanchetDetail planchets[num_planchets];
+
+      ref = find_command (is,
+                          cmd->details.tip_pickup.authorize_ref);
+      GNUNET_assert (NULL != ref);
+      GNUNET_assert (OC_TIP_AUTHORIZE == ref->oc);
+      cmd->details.tip_pickup.psa = GNUNET_new_array (num_planchets,
+                                                      struct 
TALER_PlanchetSecretsP);
+
+      for (unsigned int i=0;i<num_planchets;i++)
+        if (GNUNET_OK !=
+            make_planchet (is->keys,
+                           cmd->details.tip_pickup.amounts[i],
+                           &planchets[i],
+                           &cmd->details.tip_pickup.psa[i]))
+        {
+          GNUNET_break (0);
+          fail (is);
+          return;
+        }
+
+      if (NULL == (cmd->details.tip_pickup.tpo
+                   = TALER_MERCHANT_tip_pickup
+                   (ctx,
+                    MERCHANT_URI,
+                    &ref->details.tip_authorize.tip_id,
+                    num_planchets,
+                    planchets,
+                    &pickup_cb,
+                    is)))
+      {
+        GNUNET_break (0);
+        fail (is);
+      }
+      break;
+    }
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unknown instruction %d at %u (%s)\n",
diff --git a/src/merchant-tools/taler-merchant-generate-payments.c 
b/src/merchant-tools/taler-merchant-generate-payments.c
index bf5ecad..ab5406e 100644
--- a/src/merchant-tools/taler-merchant-generate-payments.c
+++ b/src/merchant-tools/taler-merchant-generate-payments.c
@@ -251,14 +251,9 @@ struct Command
       struct TALER_DenominationSignature sig;
 
       /**
-       * Set (by the interpreter) to the coin's private key.
+       * Secrets of the planchet. Set by the interpreter.
        */
-      struct TALER_CoinSpendPrivateKeyP coin_priv;
-
-      /**
-       * Blinding key used for the operation.
-       */
-      struct TALER_DenominationBlindingKeyP blinding_key;
+      struct TALER_PlanchetSecretsP ps;
 
       /**
        * Withdraw handle (while operation is running).
@@ -951,7 +946,6 @@ interpreter_run (void *cls)
   struct Command *cmd = &is->commands[is->ip];
   const struct Command *ref;
   struct TALER_ReservePublicKeyP reserve_pub;
-  struct TALER_CoinSpendPublicKeyP coin_pub;
   struct TALER_Amount amount;
   struct GNUNET_TIME_Absolute execution_date;
   json_t *sender_details;
@@ -1056,7 +1050,7 @@ interpreter_run (void *cls)
           switch (coin_ref->oc)
           {
           case OC_WITHDRAW_SIGN:
-            pc.coin_priv = coin_ref->details.reserve_withdraw.coin_priv;
+            pc.coin_priv = coin_ref->details.reserve_withdraw.ps.coin_priv;
             pc.denom_pub = coin_ref->details.reserve_withdraw.pk->key;
             pc.denom_sig = coin_ref->details.reserve_withdraw.sig;
             pc.denom_value = coin_ref->details.reserve_withdraw.pk->value;
@@ -1275,26 +1269,12 @@ interpreter_run (void *cls)
         return;
       }
 
-      /* create coin's private key */
-      {
-        struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
-
-        priv = GNUNET_CRYPTO_eddsa_key_create ();
-        cmd->details.reserve_withdraw.coin_priv.eddsa_priv = *priv;
-        GNUNET_free (priv);
-      }
-      GNUNET_CRYPTO_eddsa_key_get_public 
(&cmd->details.reserve_withdraw.coin_priv.eddsa_priv,
-                                          &coin_pub.eddsa_pub);
-      GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                                  &cmd->details.reserve_withdraw.blinding_key,
-                                  sizeof 
(cmd->details.reserve_withdraw.blinding_key));
-
+      TALER_planchet_setup_random (&cmd->details.reserve_withdraw.ps);
       cmd->details.reserve_withdraw.wsh
         = TALER_EXCHANGE_reserve_withdraw (exchange,
                                            cmd->details.reserve_withdraw.pk,
                                            
&ref->details.admin_add_incoming.reserve_priv,
-                                           
&cmd->details.reserve_withdraw.coin_priv,
-                                           
&cmd->details.reserve_withdraw.blinding_key,
+                                           &cmd->details.reserve_withdraw.ps,
                                            &reserve_withdraw_cb,
                                            is);
       if (NULL == cmd->details.reserve_withdraw.wsh)

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]