[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-exchange] branch master updated: add STEFAN support to exchange
From: |
gnunet |
Subject: |
[taler-exchange] branch master updated: add STEFAN support to exchange |
Date: |
Fri, 11 Aug 2023 16:30:36 +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 1b373474 add STEFAN support to exchange
1b373474 is described below
commit 1b37347422f00edb648dfa78cd83083a2f80a9e8
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Aug 11 16:30:32 2023 +0200
add STEFAN support to exchange
---
src/exchange/taler-exchange-httpd.c | 71 ++++++++++++++++++++++++++++++++
src/exchange/taler-exchange-httpd.h | 21 ++++++++++
src/exchange/taler-exchange-httpd_keys.c | 8 ++++
src/include/taler_exchange_service.h | 21 ++++++++++
src/lib/exchange_api_handle.c | 39 ++++++++++++++++--
5 files changed, 156 insertions(+), 4 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd.c
b/src/exchange/taler-exchange-httpd.c
index 7d599293..194ec6da 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -149,6 +149,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.
*/
@@ -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 9fcfcd6c..9e18f9e6 100644
--- a/src/exchange/taler-exchange-httpd.h
+++ b/src/exchange/taler-exchange-httpd.h
@@ -97,6 +97,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.
*/
diff --git a/src/exchange/taler-exchange-httpd_keys.c
b/src/exchange/taler-exchange-httpd_keys.c
index 9623a5a3..0bb5c813 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 c390bd63..471263f7 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -516,6 +516,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.
*/
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 016f7bf6..9c5e1278 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",
¤cy),
+ 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);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-exchange] branch master updated: add STEFAN support to exchange,
gnunet <=