summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-08-11 16:30:32 +0200
committerChristian Grothoff <christian@grothoff.org>2023-08-11 16:30:32 +0200
commit1b37347422f00edb648dfa78cd83083a2f80a9e8 (patch)
tree56a8c34ae3864ec25aa5c1d0e40e2e845f324998
parent8d3934c7fa6224092781a2400d68e9efa94a497d (diff)
downloadexchange-1b37347422f00edb648dfa78cd83083a2f80a9e8.tar.gz
exchange-1b37347422f00edb648dfa78cd83083a2f80a9e8.tar.bz2
exchange-1b37347422f00edb648dfa78cd83083a2f80a9e8.zip
add STEFAN support to exchange
-rw-r--r--src/exchange/taler-exchange-httpd.c71
-rw-r--r--src/exchange/taler-exchange-httpd.h21
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c8
-rw-r--r--src/include/taler_exchange_service.h21
-rw-r--r--src/lib/exchange_api_handle.c39
5 files changed, 156 insertions, 4 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 7d5992935..194ec6dae 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -150,6 +150,27 @@ struct TALER_AttributeEncryptionKeyP TEH_attribute_key;
struct TALER_EXCHANGEDB_Plugin *TEH_plugin;
/**
+ * Absolute STEFAN parameter.
+ */
+struct TALER_Amount TEH_stefan_abs;
+
+/**
+ * Logarithmic STEFAN parameter.
+ */
+struct TALER_Amount TEH_stefan_log;
+
+/**
+ * Linear STEFAN parameter.
+ */
+struct TALER_Amount TEH_stefan_lin;
+
+/**
+ * Default number of fractional digits to render
+ * amounts with.
+ */
+unsigned int TEH_currency_fraction_digits;
+
+/**
* Our currency.
*/
char *TEH_currency;
@@ -1925,6 +1946,25 @@ exchange_serve_process_config (void)
"CURRENCY");
return GNUNET_SYSERR;
}
+ {
+ unsigned long long cfd;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (TEH_cfg,
+ "exchange",
+ "CURRENCY_FRACTION_DIGITS",
+ &cfd))
+ cfd = 0;
+ if (cfd > 8)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "taler",
+ "CURRENCY_FRACTION_DIGITS",
+ "Value must be below 8");
+ return GNUNET_SYSERR;
+ }
+ TEH_currency_fraction_digits = (unsigned int) cfd;
+ }
if (GNUNET_OK !=
TALER_config_get_amount (TEH_cfg,
"exchange",
@@ -1935,6 +1975,37 @@ exchange_serve_process_config (void)
"Need amount in section `exchange' under `AML_THRESHOLD'\n");
return GNUNET_SYSERR;
}
+ if (GNUNET_OK !=
+ TALER_config_get_amount (TEH_cfg,
+ "exchange",
+ "STEFAN_ABS",
+ &TEH_stefan_abs))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &TEH_stefan_abs));
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (TEH_cfg,
+ "exchange",
+ "STEFAN_LOG",
+ &TEH_stefan_log))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &TEH_stefan_log));
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (TEH_cfg,
+ "exchange",
+ "STEFAN_LIN",
+ &TEH_stefan_lin))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &TEH_stefan_lin));
+ }
+
if (0 != strcmp (TEH_currency,
TEH_aml_threshold.currency))
{
diff --git a/src/exchange/taler-exchange-httpd.h b/src/exchange/taler-exchange-httpd.h
index 9fcfcd6c1..9e18f9e69 100644
--- a/src/exchange/taler-exchange-httpd.h
+++ b/src/exchange/taler-exchange-httpd.h
@@ -98,6 +98,27 @@ extern struct TALER_AttributeEncryptionKeyP TEH_attribute_key;
extern struct TALER_EXCHANGEDB_Plugin *TEH_plugin;
/**
+ * Absolute STEFAN parameter.
+ */
+extern struct TALER_Amount TEH_stefan_abs;
+
+/**
+ * Logarithmic STEFAN parameter.
+ */
+extern struct TALER_Amount TEH_stefan_log;
+
+/**
+ * Linear STEFAN parameter.
+ */
+extern struct TALER_Amount TEH_stefan_lin;
+
+/**
+ * Default number of fractional digits to render
+ * amounts with.
+ */
+extern unsigned int TEH_currency_fraction_digits;
+
+/**
* Our currency.
*/
extern char *TEH_currency;
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index 9623a5a30..0bb5c8138 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -2525,6 +2525,14 @@ create_krd (struct TEH_KeyStateHandle *ksh,
TEH_base_url),
GNUNET_JSON_pack_string ("currency",
TEH_currency),
+ GNUNET_JSON_pack_uint64 ("currency_fraction_digits",
+ TEH_currency_fraction_digits),
+ TALER_JSON_pack_amount ("stefan_abs",
+ &TEH_stefan_abs),
+ TALER_JSON_pack_amount ("stefan_log",
+ &TEH_stefan_log),
+ TALER_JSON_pack_amount ("stefan_lin",
+ &TEH_stefan_lin),
GNUNET_JSON_pack_string ("asset_type",
asset_type),
// FIXME: legacy, remove soon!
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index c390bd63b..471263f78 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -517,6 +517,27 @@ struct TALER_EXCHANGE_Keys
struct TALER_AgeMask age_mask;
/**
+ * Absolute STEFAN parameter.
+ */
+ struct TALER_Amount stefan_abs;
+
+ /**
+ * Logarithmic STEFAN parameter.
+ */
+ struct TALER_Amount stefan_log;
+
+ /**
+ * Linear STEFAN parameter.
+ */
+ struct TALER_Amount stefan_lin;
+
+ /**
+ * Default number of fractional digits to render
+ * amounts with.
+ */
+ uint32_t currency_fraction_digits;
+
+ /**
* Length of @e accounts array.
*/
unsigned int accounts_len;
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 016f7bf6b..9c5e12785 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -155,12 +155,14 @@ free_fees (struct TALER_EXCHANGE_WireFeesByMethod *wfm,
* Parse wire @a fees and return array.
*
* @param master_pub master public key to use to check signatures
+ * @param currency currency amounts are expected in
* @param fees json AggregateTransferFee to parse
* @param[out] fees_len set to length of returned array
* @return NULL on error
*/
static struct TALER_EXCHANGE_WireFeesByMethod *
parse_fees (const struct TALER_MasterPublicKeyP *master_pub,
+ const char *currency,
const json_t *fees,
unsigned int *fees_len)
{
@@ -187,10 +189,12 @@ parse_fees (const struct TALER_MasterPublicKeyP *master_pub,
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("sig",
&wa->master_sig),
- TALER_JSON_spec_amount_any ("wire_fee",
- &wa->fees.wire),
- TALER_JSON_spec_amount_any ("closing_fee",
- &wa->fees.closing),
+ TALER_JSON_spec_amount ("wire_fee",
+ currency,
+ &wa->fees.wire),
+ TALER_JSON_spec_amount ("closing_fee",
+ currency,
+ &wa->fees.closing),
GNUNET_JSON_spec_timestamp ("start_date",
&wa->start_date),
GNUNET_JSON_spec_timestamp ("end_date",
@@ -741,6 +745,9 @@ decode_keys_json (const json_t *resp_obj,
GNUNET_JSON_spec_string (
"currency",
&currency),
+ GNUNET_JSON_spec_uint32 (
+ "currency_fraction_digits",
+ &key_data->currency_fraction_digits),
GNUNET_JSON_spec_string (
"asset_type",
&asset_type),
@@ -787,6 +794,29 @@ decode_keys_json (const json_t *resp_obj,
GNUNET_JSON_parse (resp_obj,
(check_sig) ? mspec : &mspec[2],
NULL, NULL));
+ {
+ struct GNUNET_JSON_Specification sspec[] = {
+ TALER_JSON_spec_amount (
+ "stefan_abs",
+ currency,
+ &key_data->stefan_abs),
+ TALER_JSON_spec_amount (
+ "stefan_log",
+ currency,
+ &key_data->stefan_log),
+ TALER_JSON_spec_amount (
+ "stefan_lin",
+ currency,
+ &key_data->stefan_lin),
+ GNUNET_JSON_spec_end ()
+ };
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_JSON_parse (resp_obj,
+ sspec,
+ NULL, NULL));
+ }
+
key_data->currency = GNUNET_strdup (currency);
key_data->asset_type = GNUNET_strdup (asset_type);
if (! no_extensions)
@@ -862,6 +892,7 @@ decode_keys_json (const json_t *resp_obj,
/* Parse wire accounts */
key_data->fees = parse_fees (&key_data->master_pub,
+ key_data->currency,
fees,
&key_data->fees_len);
EXITIF (NULL == key_data->fees);