aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-09-01 17:37:00 +0200
committerChristian Grothoff <christian@grothoff.org>2024-09-01 17:37:00 +0200
commit0188860eddca95d80d2253c7e2893daf3b3d6dca (patch)
treeb6cc9c5ab4b9d3aad7fd7fe9bdabadd1d2e87345 /src/lib
parent6996910aeee8fad4f0d249590b46570d514d2eb3 (diff)
downloadexchange-0188860eddca95d80d2253c7e2893daf3b3d6dca.tar.xz
introduce zero_limits for #9039/#9040 to signal clients that they must do KYC before even attempting to work with an exchange
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exchange_api_handle.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 329e2c2e6..c39440857 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -813,6 +813,57 @@ parse_hard_limits (const json_t *hard_limits,
/**
+ * Decode the JSON array in @a zero_limits from the /keys response
+ * and store the data in `zero_limits` array the @a key_data.
+ *
+ * @param[in] zero_limits JSON array to parse
+ * @param[out] key_data where to store the results we decoded
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ * (malformed JSON)
+ */
+static enum GNUNET_GenericReturnValue
+parse_zero_limits (const json_t *zero_limits,
+ struct TALER_EXCHANGE_Keys *key_data)
+{
+ json_t *obj;
+ size_t off;
+
+ key_data->zero_limits_length
+ = (unsigned int) json_array_size (zero_limits);
+ if ( ((size_t) key_data->zero_limits_length)
+ != json_array_size (zero_limits))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ key_data->zero_limits
+ = GNUNET_new_array (key_data->zero_limits_length,
+ struct TALER_EXCHANGE_ZeroLimitedOperation);
+
+ json_array_foreach (zero_limits, off, obj)
+ {
+ struct TALER_EXCHANGE_ZeroLimitedOperation *zol
+ = &key_data->zero_limits[off];
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_kycte ("operation_type",
+ &zol->operation_type),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (obj,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Decode the JSON in @a resp_obj from the /keys response
* and store the data in the @a key_data.
*
@@ -976,6 +1027,7 @@ decode_keys_json (const json_t *resp_obj,
}
{
const json_t *hard_limits = NULL;
+ const json_t *zero_limits = NULL;
struct GNUNET_JSON_Specification sspec[] = {
TALER_JSON_spec_currency_specification (
"currency_specification",
@@ -994,6 +1046,11 @@ decode_keys_json (const json_t *resp_obj,
"hard_limits",
&hard_limits),
NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const (
+ "zero_limits",
+ &zero_limits),
+ NULL),
GNUNET_JSON_spec_double (
"stefan_lin",
&key_data->stefan_lin),
@@ -1021,6 +1078,15 @@ decode_keys_json (const json_t *resp_obj,
"Parsing hard limits of /keys failed\n");
EXITIF (1);
}
+ if ( (NULL != zero_limits) &&
+ (GNUNET_OK !=
+ parse_zero_limits (zero_limits,
+ key_data)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Parsing hard limits of /keys failed\n");
+ EXITIF (1);
+ }
}
key_data->currency = GNUNET_strdup (currency);
@@ -1964,6 +2030,9 @@ TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys)
GNUNET_array_grow (keys->hard_limits,
keys->hard_limits_length,
0);
+ GNUNET_array_grow (keys->zero_limits,
+ keys->zero_limits_length,
+ 0);
json_decref (keys->extensions);
GNUNET_free (keys->cspec.name);
json_decref (keys->cspec.map_alt_unit_names);