aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-12-17 22:17:02 +0800
committerChristian Grothoff <grothoff@gnunet.org>2023-12-17 22:17:02 +0800
commit21f67e8241e451a593b44562237cf9ae754c4eef (patch)
treec18377379da20e3951f4a20116bfc4d60a36a830
parent7891e62bf98bd884c8c993ae698f9a985dbacfbd (diff)
-expand data returned from /config by merchant backend
m---------contrib/wallet-core0
m---------doc/prebuilt0
-rw-r--r--src/backend/taler-merchant-httpd_config.c38
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.c8
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.h13
-rw-r--r--src/include/taler_merchant_service.h34
-rw-r--r--src/lib/merchant_api_get_config.c45
7 files changed, 138 insertions, 0 deletions
diff --git a/contrib/wallet-core b/contrib/wallet-core
-Subproject ec95723a68d36620aa66109c329437612383830
+Subproject 2347be694c713959528ad59f3f157d866d7ad42
diff --git a/doc/prebuilt b/doc/prebuilt
-Subproject 5e47a72e8a2b5086dfdae4078f695155f5ed7af
+Subproject 09a33a50d9b3b400f8a515082c888918cbf4e1b
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
@@ -140,6 +140,19 @@ TMH_EXCHANGES_get_master_pub (
/**
+ * 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.
*
* @param exchange the exchange to check
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
@@ -310,6 +310,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.
*/
struct TALER_MERCHANT_ConfigResponse
@@ -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;