gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: -expand data returned from /conf


From: gnunet
Subject: [taler-merchant] branch master updated: -expand data returned from /config by merchant backend
Date: Sun, 17 Dec 2023 15:17:09 +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 21f67e82 -expand data returned from /config by merchant backend
21f67e82 is described below

commit 21f67e8241e451a593b44562237cf9ae754c4eef
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sun Dec 17 22:17:02 2023 +0800

    -expand data returned from /config by merchant backend
---
 contrib/wallet-core                          |  2 +-
 doc/prebuilt                                 |  2 +-
 src/backend/taler-merchant-httpd_config.c    | 38 +++++++++++++++++++++++
 src/backend/taler-merchant-httpd_exchanges.c |  8 +++++
 src/backend/taler-merchant-httpd_exchanges.h | 13 ++++++++
 src/include/taler_merchant_service.h         | 34 +++++++++++++++++++++
 src/lib/merchant_api_get_config.c            | 45 ++++++++++++++++++++++++++++
 7 files changed, 140 insertions(+), 2 deletions(-)

diff --git a/contrib/wallet-core b/contrib/wallet-core
index ec95723a..2347be69 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit ec95723a68d36620aa66109c329437612383830b
+Subproject commit 2347be694c713959528ad59f3f157d866d7ad424
diff --git a/doc/prebuilt b/doc/prebuilt
index 5e47a72e..09a33a50 160000
--- a/doc/prebuilt
+++ b/doc/prebuilt
@@ -1 +1 @@
-Subproject commit 5e47a72e8a2b5086dfdae4078f695155f5ed7af8
+Subproject commit 09a33a50d9b3b400f8a515082c888918cbf4e1b5
diff --git a/src/backend/taler-merchant-httpd_config.c 
b/src/backend/taler-merchant-httpd_config.c
index 448b3dec..d53554f6 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -45,6 +45,38 @@
 #define MERCHANT_PROTOCOL_VERSION "6:0:2"
 
 
+
+/**
+ * Callback on an exchange known to us. Does not warrant
+ * that the "keys" information is actually available for
+ * @a exchange.
+ *
+ * @param cls closure with `json_t *` array to expand
+ * @param url base URL of the exchange
+ * @param exchange internal handle for the exchange
+ */
+static void
+add_exchange (void *cls,
+              const char *url,
+              const struct TMH_Exchange *exchange)
+{
+  json_t *xa = cls;
+  json_t *xi;
+
+  xi = GNUNET_JSON_PACK (
+    GNUNET_JSON_pack_data_auto ("master_pub",
+                                TMH_EXCHANGES_get_master_pub (exchange)),
+    GNUNET_JSON_pack_string ("currency",
+                             TMH_EXCHANGES_get_currency (exchange)),
+    GNUNET_JSON_pack_string ("base_url",
+                             url));
+  GNUNET_assert (NULL != xi);
+  GNUNET_assert (0 ==
+                 json_array_append_new (xa,
+                                        xi));
+}
+
+
 MHD_RESULT
 MH_handler_config (struct TMH_RequestHandler *rh,
                    struct MHD_Connection *connection,
@@ -57,8 +89,12 @@ MH_handler_config (struct TMH_RequestHandler *rh,
   if (NULL == response)
   {
     json_t *specs = json_object ();
+    json_t *exchanges = json_array ();
 
     GNUNET_assert (NULL != specs);
+    GNUNET_assert (NULL != exchanges);
+    TMH_exchange_get_trusted (&add_exchange,
+                              exchanges);
     for (unsigned int i=0;i<TMH_num_cspecs;i++)
     {
       const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i];
@@ -74,6 +110,8 @@ MH_handler_config (struct TMH_RequestHandler *rh,
                                TMH_currency),
       GNUNET_JSON_pack_object_steal ("currencies",
                                      specs),
+      GNUNET_JSON_pack_array_steal ("exchanges",
+                                    exchanges),
       GNUNET_JSON_pack_string ("name",
                                "taler-merchant"),
       GNUNET_JSON_pack_string ("version",
diff --git a/src/backend/taler-merchant-httpd_exchanges.c 
b/src/backend/taler-merchant-httpd_exchanges.c
index 8a89235a..260a725a 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -372,6 +372,14 @@ TMH_EXCHANGES_get_master_pub (
 }
 
 
+const char *
+TMH_EXCHANGES_get_currency (
+  const struct TMH_Exchange *exchange)
+{
+  return exchange->currency;
+}
+
+
 /**
  * Free data structures within @a ea, but not @a ea
  * pointer itself.
diff --git a/src/backend/taler-merchant-httpd_exchanges.h 
b/src/backend/taler-merchant-httpd_exchanges.h
index 86c8374d..892843f6 100644
--- a/src/backend/taler-merchant-httpd_exchanges.h
+++ b/src/backend/taler-merchant-httpd_exchanges.h
@@ -139,6 +139,19 @@ TMH_EXCHANGES_get_master_pub (
   const struct TMH_Exchange *exchange);
 
 
+/**
+ * Return the currency of the given @a exchange.
+ * Will be returned from configuration for trusted
+ * exchanges.
+ *
+ * @param exchange exchange to get master public key for
+ * @return the currency of @a exchange
+ */
+const char *
+TMH_EXCHANGES_get_currency (
+  const struct TMH_Exchange *exchange);
+
+
 /**
  * Lookup current wire fee by @a exchange_url and @a wire_method.
  *
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index e8aad3d0..aeddefc8 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -309,6 +309,29 @@ struct TALER_MERCHANT_ConfigInformation
 };
 
 
+/**
+ * Information about an exchange the merchant backend trusts.
+ */
+struct TALER_MERCHANT_ExchangeConfigInfo
+{
+  /**
+   * Base URL of the exchange REST API.
+   */
+  const char *base_url;
+
+  /**
+   * Currency for which the merchant is configured to
+   * trust the exchange.
+   */
+  const char *currency;
+
+  /**
+   * Master public key of the exchange.
+   */
+  struct TALER_MasterPublicKeyP master_pub;
+  
+};
+
 /**
  * Response to /config request.
  */
@@ -351,6 +374,17 @@ struct TALER_MERCHANT_ConfigResponse
        */
       const struct TALER_CurrencySpecification *cspecs;
 
+      /**
+       * Length of the @e exchanges array.
+       */
+      unsigned int num_exchanges;
+
+      /**
+       * Array details about exchanges trusted 
+       * by this merchant backend.
+       */
+      const struct TALER_MERCHANT_ExchangeConfigInfo *exchanges;
+      
     } ok;
   } details;
 };
diff --git a/src/lib/merchant_api_get_config.c 
b/src/lib/merchant_api_get_config.c
index 1b289a9a..401d4829 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -105,10 +105,19 @@ handle_config_finished (void *cls,
   case MHD_HTTP_OK:
     {
       const json_t *jcs;
+      const json_t *exchanges = NULL;
+      struct TALER_MERCHANT_ExchangeConfigInfo *eci = NULL;
+      unsigned int num_eci = 0;
       struct TALER_JSON_ProtocolVersion pv;
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_object_const ("currencies",
                                        &jcs),
+        /* Optional for v5 compatibility, remove
+           once we reduce age! */
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_array_const ("exchanges",
+                                        &exchanges),
+        NULL),
         GNUNET_JSON_spec_string ("currency",
                                  &cr.details.ok.ci.currency),
         TALER_JSON_spec_version ("version",
@@ -124,6 +133,7 @@ handle_config_finished (void *cls,
                              spec,
                              NULL, NULL))
       {
+        GNUNET_break_op (0);
         cr.hr.http_status = 0;
         cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
       }
@@ -143,6 +153,38 @@ handle_config_finished (void *cls,
             cr.details.ok.compat |= TALER_MERCHANT_VC_INCOMPATIBLE;
         }
       }
+      if (NULL != exchanges)
+      {
+        num_eci = json_object_size (exchanges);
+        eci = GNUNET_new_array (num_eci,
+                                struct TALER_MERCHANT_ExchangeConfigInfo);
+        for (unsigned int i=0;i<num_eci;i++)
+        {
+          struct TALER_MERCHANT_ExchangeConfigInfo *ei = &eci[i];
+          const json_t *ej = json_array_get (exchanges,
+                                             i);
+          struct GNUNET_JSON_Specification ispec[] = {
+            GNUNET_JSON_spec_string ("currency",
+                                     &ei->currency),
+            GNUNET_JSON_spec_string ("base_url",
+                                     &ei->base_url),
+            GNUNET_JSON_spec_fixed_auto ("master_pub",
+                                         &ei->master_pub),
+            GNUNET_JSON_spec_end ()
+          };
+
+          if (GNUNET_OK !=
+              GNUNET_JSON_parse (ej,
+                                 ispec,
+                                 NULL, NULL))
+          {
+            GNUNET_break_op (0);
+            cr.hr.http_status = 0;
+            cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+            break;
+          }
+        }
+      }
       {
         unsigned int nspec = json_object_size (jcs);
         struct TALER_CurrencySpecification *cspecs;
@@ -154,6 +196,8 @@ handle_config_finished (void *cls,
                                    struct TALER_CurrencySpecification);
         cr.details.ok.num_cspecs = nspec;
         cr.details.ok.cspecs = cspecs;
+        cr.details.ok.num_exchanges = num_eci;
+        cr.details.ok.exchanges = eci;
         json_object_foreach ((json_t *) jcs, curr, obj)
         {
           struct TALER_CurrencySpecification *cs = &cspecs[off++];
@@ -168,6 +212,7 @@ handle_config_finished (void *cls,
                                  cspec,
                                  NULL, NULL))
           {
+            GNUNET_break_op (0);
             cr.hr.http_status = 0;
             cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
             break;

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