gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -draft for purse merge command


From: gnunet
Subject: [taler-exchange] branch master updated: -draft for purse merge command
Date: Tue, 12 Apr 2022 16:35:08 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 2299b8b1 -draft for purse merge command
2299b8b1 is described below

commit 2299b8b1935fb5fe8514315a0db7f6e724a96a5a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Apr 12 16:35:05 2022 +0200

    -draft for purse merge command
---
 src/exchange/taler-exchange-httpd_purses_merge.c |   2 +-
 src/lib/exchange_api_purse_create_with_deposit.c |   1 +
 src/testing/Makefile.am                          |   1 +
 src/testing/testing_api_cmd_purse_merge.c        | 329 +++++++++++++++++++++++
 4 files changed, 332 insertions(+), 1 deletion(-)

diff --git a/src/exchange/taler-exchange-httpd_purses_merge.c 
b/src/exchange/taler-exchange-httpd_purses_merge.c
index 52623822..b998a3b1 100644
--- a/src/exchange/taler-exchange-httpd_purses_merge.c
+++ b/src/exchange/taler-exchange-httpd_purses_merge.c
@@ -453,7 +453,7 @@ TEH_handler_purses_merge (
   }
   else
   {
-    char *method = GNUNET_strdup ("FIXME");
+    char *method = GNUNET_strdup ("FIXME-WAD");
 
     /* FIXME: lookup wire method by pcc.provider_url! */
     pcc.wf = TEH_wire_fees_by_time (pcc.exchange_timestamp,
diff --git a/src/lib/exchange_api_purse_create_with_deposit.c 
b/src/lib/exchange_api_purse_create_with_deposit.c
index f5871fa3..48b9aad7 100644
--- a/src/lib/exchange_api_purse_create_with_deposit.c
+++ b/src/lib/exchange_api_purse_create_with_deposit.c
@@ -265,6 +265,7 @@ TALER_EXCHANGE_purse_create_with_deposit (
   pch->exchange = exchange;
   pch->cb = cb;
   pch->cb_cls = cb_cls;
+  // FIXME: get expiration from pay deadline of contract?
   pch->purse_expiration = purse_expiration;
   {
     struct GNUNET_JSON_Specification spec[] = {
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 7b892d94..94b1aadf 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -72,6 +72,7 @@ libtalertesting_la_SOURCES = \
   testing_api_cmd_offline_sign_keys.c \
   testing_api_cmd_offline_sign_extensions.c \
   testing_api_cmd_purse_create_deposit.c \
+  testing_api_cmd_purse_merge.c \
   testing_api_cmd_set_wire_fee.c \
   testing_api_cmd_recoup.c \
   testing_api_cmd_recoup_refresh.c \
diff --git a/src/testing/testing_api_cmd_purse_merge.c 
b/src/testing/testing_api_cmd_purse_merge.c
new file mode 100644
index 00000000..a17f8a9d
--- /dev/null
+++ b/src/testing/testing_api_cmd_purse_merge.c
@@ -0,0 +1,329 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2022 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3, or (at your
+  option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_purse_merge.c
+ * @brief command for testing /purses/$PID/merge
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "purse create deposit" CMD.
+ */
+struct PurseMergeState
+{
+
+  /**
+   * Merge time.
+   */
+  struct GNUNET_TIME_Timestamp merge_timestamp;
+
+  /**
+   * Reserve public key (to be merged into)
+   */
+  struct TALER_ReservePublicKeyP reserve_pub;
+
+  /**
+   * Reserve private key (useful especially if
+   * @e reserve_ref is NULL).
+   */
+  struct TALER_ReservePrivateKeyP reserve_priv;
+
+  /**
+   * Handle while operation is running.
+   */
+  struct TALER_EXCHANGE_AccountMergeHandle *dh;
+
+  /**
+   * Reference to the merge capability.
+   */
+  const char *merge_ref;
+
+  /**
+   * Refernece to the reserve, or NULL (!).
+   */
+  const char *reserve_ref;
+
+  /**
+   * Interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int expected_response_code;
+
+};
+
+
+/**
+ * Callback to analyze the /purses/$PID/merge response, just used to check if
+ * the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param dr merge response details
+ */
+static void
+merge_cb (void *cls,
+          const struct TALER_EXCHANGE_AccountMergeResponse *dr)
+{
+  struct PurseMergeState *ds = cls;
+
+  ds->dh = NULL;
+  if (ds->expected_response_code != dr->hr.http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u to command %s in %s:%u\n",
+                dr->hr.http_status,
+                ds->is->commands[ds->is->ip].label,
+                __FILE__,
+                __LINE__);
+    json_dumpf (dr->hr.reply,
+                stderr,
+                0);
+    TALER_TESTING_interpreter_fail (ds->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (ds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+merge_run (void *cls,
+           const struct TALER_TESTING_Command *cmd,
+           struct TALER_TESTING_Interpreter *is)
+{
+  struct PurseMergeState *ds = cls;
+  const struct TALER_PurseContractPublicKeyP *purse_pub;
+  const struct TALER_PurseMergePrivateKeyP *merge_priv;
+  const json_t *ct;
+  struct TALER_PrivateContractHashP h_contract_terms;
+  uint32_t min_age;
+  struct TALER_Amount value_after_fees;
+  struct GNUNET_TIME_Timestamp purse_expiration;
+  const struct TALER_TESTING_Command *ref;
+
+  (void) cmd;
+  ds->is = is;
+  ref = TALER_TESTING_interpreter_lookup_command (ds->is,
+                                                  ds->merge_ref);
+  GNUNET_assert (NULL != ref);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_merge_priv (ref,
+                                          &merge_priv))
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (ds->is);
+    return;
+  }
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_purse_pub (ref,
+                                         &purse_pub))
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (ds->is);
+    return;
+  }
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_contract_terms (ref,
+                                              &ct))
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (ds->is);
+    return;
+  }
+  if (GNUNET_OK !=
+      TALER_JSON_contract_hash (ct,
+                                &h_contract_terms))
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (ds->is);
+    return;
+  }
+  {
+    struct GNUNET_JSON_Specification spec[] = {
+      TALER_JSON_spec_amount_any ("amount",
+                                  &value_after_fees),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_uint32 ("minimum_age",
+                                 &min_age),
+        NULL),
+      GNUNET_JSON_spec_end ()
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (ct,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ds->is);
+      return;
+    }
+  }
+
+  // FIXME: how to get purse_expiration nicely!?!?
+  // See create_with_deposit FIXME: from pay deadline?
+
+  if (NULL == ds->reserve_ref)
+  {
+    GNUNET_CRYPTO_eddsa_key_create (&ds->reserve_priv.eddsa_priv);
+  }
+  else
+  {
+    const struct TALER_ReservePrivateKeyP *rp;
+
+    ref = TALER_TESTING_interpreter_lookup_command (ds->is,
+                                                    ds->merge_ref);
+    GNUNET_assert (NULL != ref);
+    if (GNUNET_OK !=
+        TALER_TESTING_get_trait_reserve_priv (ref,
+                                              &rp))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ds->is);
+      return;
+    }
+    ds->reserve_priv = *rp;
+  }
+  GNUNET_CRYPTO_eddsa_key_get_public (&ds->reserve_priv.eddsa_priv,
+                                      &ds->reserve_pub.eddsa_pub);
+  ds->merge_timestamp = GNUNET_TIME_timestamp_get ();
+  ds->dh = TALER_EXCHANGE_account_merge (
+    is->exchange,
+    NULL, /* no wad */
+    &ds->reserve_priv,
+    purse_pub,
+    merge_priv,
+    &h_contract_terms,
+    min_age,
+    &value_after_fees,
+    purse_expiration,
+    ds->merge_timestamp,
+    &merge_cb,
+    ds);
+  if (NULL == ds->dh)
+  {
+    GNUNET_break (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Could not merge purse\n");
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+}
+
+
+/**
+ * Free the state of a "merge" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct PurseMergeState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+merge_cleanup (void *cls,
+               const struct TALER_TESTING_Command *cmd)
+{
+  struct PurseMergeState *ds = cls;
+
+  if (NULL != ds->dh)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command %u (%s) did not complete\n",
+                ds->is->ip,
+                cmd->label);
+    TALER_EXCHANGE_account_merge_cancel (ds->dh);
+    ds->dh = NULL;
+  }
+  GNUNET_free (ds);
+}
+
+
+/**
+ * Offer internal data from a "merge" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+merge_traits (void *cls,
+              const void **ret,
+              const char *trait,
+              unsigned int index)
+{
+  struct PurseMergeState *ds = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_timestamp (0,
+                                        &ds->merge_timestamp),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_purse_merge (
+  const char *label,
+  unsigned int expected_http_status,
+  const char *merge_ref,
+  const char *reserve_ref)
+{
+  struct PurseMergeState *ds;
+
+  ds = GNUNET_new (struct PurseMergeState);
+  ds->merge_ref = merge_ref;
+  ds->reserve_ref = reserve_ref;
+  ds->expected_response_code = expected_http_status;
+
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ds,
+      .label = label,
+      .run = &merge_run,
+      .cleanup = &merge_cleanup,
+      .traits = &merge_traits
+    };
+
+    return cmd;
+  }
+}
+
+
+/* end of testing_api_cmd_purse_merge.c */

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