summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-03-05 14:36:49 +0100
committerChristian Grothoff <christian@grothoff.org>2022-03-05 14:36:55 +0100
commit7ff58c3d8f2351c57142b4b65ab75304f355fc4f (patch)
tree4d5de28cbc2cb51b9946c924b7dd228cfe0d0634 /src/exchange
parent8a906bf96c9c418dbd58727284eb5cfdd6fdff24 (diff)
downloadexchange-7ff58c3d8f2351c57142b4b65ab75304f355fc4f.tar.gz
exchange-7ff58c3d8f2351c57142b4b65ab75304f355fc4f.tar.bz2
exchange-7ff58c3d8f2351c57142b4b65ab75304f355fc4f.zip
refactor /wire to include logic to return the wad fee (for W2W payments)
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-aggregator.c12
-rw-r--r--src/exchange/taler-exchange-closer.c8
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_fees.c41
-rw-r--r--src/exchange/taler-exchange-httpd_transfers_get.c12
-rw-r--r--src/exchange/taler-exchange-httpd_wire.c12
5 files changed, 36 insertions, 49 deletions
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index 40653f9b9..abab347fe 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -43,7 +43,7 @@ struct AggregationUnit
struct TALER_MerchantPublicKeyP merchant_pub;
/**
- * Total amount to be transferred, before subtraction of @e wire_fee and rounding down.
+ * Total amount to be transferred, before subtraction of @e fees.wire and rounding down.
*/
struct TALER_Amount total_amount;
@@ -55,7 +55,7 @@ struct AggregationUnit
/**
* Wire fee we charge for @e wp at @e execution_time.
*/
- struct TALER_Amount wire_fee;
+ struct TALER_WireFeeSet fees;
/**
* Wire transfer identifier we use.
@@ -454,7 +454,6 @@ deposit_cb (void *cls,
/* make sure we have current fees */
au->execution_time = GNUNET_TIME_timestamp_get ();
{
- struct TALER_Amount closing_fee;
struct GNUNET_TIME_Timestamp start_date;
struct GNUNET_TIME_Timestamp end_date;
struct TALER_MasterSignatureP master_sig;
@@ -465,8 +464,7 @@ deposit_cb (void *cls,
au->execution_time,
&start_date,
&end_date,
- &au->wire_fee,
- &closing_fee,
+ &au->fees,
&master_sig);
if (0 >= qs)
{
@@ -482,7 +480,7 @@ deposit_cb (void *cls,
"Aggregator starts aggregation for deposit %llu to %s with wire fee %s\n",
(unsigned long long) row_id,
TALER_B2S (&au->wtid),
- TALER_amount2s (&au->wire_fee));
+ TALER_amount2s (&au->fees.wire));
qs = db_plugin->insert_aggregation_tracking (db_plugin->cls,
&au->wtid,
row_id);
@@ -820,7 +818,7 @@ run_aggregation (void *cls)
if ( (0 >=
TALER_amount_subtract (&au_active.final_amount,
&au_active.total_amount,
- &au_active.wire_fee)) ||
+ &au_active.fees.wire)) ||
(GNUNET_SYSERR ==
TALER_amount_round_down (&au_active.final_amount,
&currency_round_unit)) ||
diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c
index 3847e05b2..92ba7babb 100644
--- a/src/exchange/taler-exchange-closer.c
+++ b/src/exchange/taler-exchange-closer.c
@@ -217,6 +217,7 @@ expired_reserve_cb (void *cls,
struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_Amount amount_without_fee;
struct TALER_Amount closing_fee;
+ struct TALER_WireFeeSet fees;
enum TALER_AmountArithmeticResult ret;
enum GNUNET_DB_QueryStatus qs;
const struct TALER_EXCHANGEDB_AccountInfo *wa;
@@ -241,10 +242,9 @@ expired_reserve_cb (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
- /* lookup `closing_fee` from time of actual reserve expiration
+ /* lookup `fees` from time of actual reserve expiration
(we may be lagging behind!) */
{
- struct TALER_Amount wire_fee;
struct GNUNET_TIME_Timestamp start_date;
struct GNUNET_TIME_Timestamp end_date;
struct TALER_MasterSignatureP master_sig;
@@ -255,8 +255,7 @@ expired_reserve_cb (void *cls,
expiration_date,
&start_date,
&end_date,
- &wire_fee,
- &closing_fee,
+ &fees,
&master_sig);
if (0 >= qs)
{
@@ -269,6 +268,7 @@ expired_reserve_cb (void *cls,
}
/* calculate transfer amount */
+ closing_fee = fees.closing;
ret = TALER_amount_subtract (&amount_without_fee,
left,
&closing_fee);
diff --git a/src/exchange/taler-exchange-httpd_management_wire_fees.c b/src/exchange/taler-exchange-httpd_management_wire_fees.c
index c14500e8d..1e96353ca 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_fees.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_fees.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020, 2021 Taler Systems SA
+ Copyright (C) 2020, 2021, 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -58,14 +58,9 @@ struct AddFeeContext
struct GNUNET_TIME_Timestamp end_time;
/**
- * Wire fee amount.
+ * Wire fee amounts.
*/
- struct TALER_Amount wire_fee;
-
- /**
- * Closing fee amount.
- */
- struct TALER_Amount closing_fee;
+ struct TALER_WireFeeSet fees;
};
@@ -91,16 +86,14 @@ add_fee (void *cls,
{
struct AddFeeContext *afc = cls;
enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount wire_fee;
- struct TALER_Amount closing_fee;
+ struct TALER_WireFeeSet fees;
qs = TEH_plugin->lookup_wire_fee_by_time (
TEH_plugin->cls,
afc->wire_method,
afc->start_time,
afc->end_time,
- &wire_fee,
- &closing_fee);
+ &fees);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -115,13 +108,10 @@ add_fee (void *cls,
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
{
if ( (GNUNET_OK ==
- TALER_amount_is_valid (&wire_fee)) &&
- (0 ==
- TALER_amount_cmp (&wire_fee,
- &afc->wire_fee)) &&
+ TALER_amount_is_valid (&fees.wire)) &&
(0 ==
- TALER_amount_cmp (&closing_fee,
- &afc->closing_fee)) )
+ TALER_wire_fee_set_cmp (&fees,
+ &afc->fees)) )
{
/* this will trigger the 'success' response */
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
@@ -142,8 +132,7 @@ add_fee (void *cls,
afc->wire_method,
afc->start_time,
afc->end_time,
- &afc->wire_fee,
- &afc->closing_fee,
+ &afc->fees,
&afc->master_sig);
if (qs < 0)
{
@@ -175,12 +164,15 @@ TEH_handler_management_post_wire_fees (
&afc.start_time),
GNUNET_JSON_spec_timestamp ("fee_end",
&afc.end_time),
+ TALER_JSON_spec_amount ("wire_fee",
+ TEH_currency,
+ &afc.fees.wire),
TALER_JSON_spec_amount ("closing_fee",
TEH_currency,
- &afc.closing_fee),
- TALER_JSON_spec_amount ("wire_fee",
+ &afc.fees.closing),
+ TALER_JSON_spec_amount ("wad_fee",
TEH_currency,
- &afc.wire_fee),
+ &afc.fees.wad),
GNUNET_JSON_spec_end ()
};
@@ -201,8 +193,7 @@ TEH_handler_management_post_wire_fees (
afc.wire_method,
afc.start_time,
afc.end_time,
- &afc.wire_fee,
- &afc.closing_fee,
+ &afc.fees,
&TEH_master_public_key,
&afc.master_sig))
{
diff --git a/src/exchange/taler-exchange-httpd_transfers_get.c b/src/exchange/taler-exchange-httpd_transfers_get.c
index 5b914c417..0a4b1f541 100644
--- a/src/exchange/taler-exchange-httpd_transfers_get.c
+++ b/src/exchange/taler-exchange-httpd_transfers_get.c
@@ -211,9 +211,9 @@ struct WtidTransactionContext
struct TALER_MerchantPublicKeyP merchant_pub;
/**
- * Wire fee applicable at @e exec_time.
+ * Wire fees applicable at @e exec_time.
*/
- struct TALER_Amount wire_fee;
+ struct TALER_WireFeeSet fees;
/**
* Execution time of the wire transfer
@@ -401,7 +401,6 @@ get_transfer_deposits (void *cls,
struct GNUNET_TIME_Timestamp wire_fee_start_date;
struct GNUNET_TIME_Timestamp wire_fee_end_date;
struct TALER_MasterSignatureP wire_fee_master_sig;
- struct TALER_Amount closing_fee;
/* resetting to NULL/0 in case transaction was repeated after
serialization failure */
@@ -457,8 +456,7 @@ get_transfer_deposits (void *cls,
ctx->exec_time,
&wire_fee_start_date,
&wire_fee_end_date,
- &ctx->wire_fee,
- &closing_fee,
+ &ctx->fees,
&wire_fee_master_sig);
GNUNET_free (wire_method);
}
@@ -478,7 +476,7 @@ get_transfer_deposits (void *cls,
if (0 >
TALER_amount_subtract (&ctx->total,
&ctx->total,
- &ctx->wire_fee))
+ &ctx->fees.wire))
{
GNUNET_break (0);
*mhd_ret = TALER_MHD_reply_with_error (connection,
@@ -528,7 +526,7 @@ TEH_handler_transfers_get (struct TEH_RequestContext *rc,
&ctx.total,
&ctx.merchant_pub,
ctx.payto_uri,
- &ctx.wire_fee,
+ &ctx.fees.wire,
ctx.exec_time,
ctx.wdd_head);
free_ctx (&ctx);
diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c
index e80c775ef..e1adde22a 100644
--- a/src/exchange/taler-exchange-httpd_wire.c
+++ b/src/exchange/taler-exchange-httpd_wire.c
@@ -200,8 +200,7 @@ add_wire_account (void *cls,
* Add information about a wire account to @a cls.
*
* @param cls a `json_t *` array to expand with wire account details
- * @param wire_fee the wire fee we charge
- * @param closing_fee the closing fee we charge
+ * @param fees the wire fees we charge
* @param start_date from when are these fees valid (start date)
* @param end_date until when are these fees valid (end date, exclusive)
* @param master_sig master key signature affirming that this is the correct
@@ -209,8 +208,7 @@ add_wire_account (void *cls,
*/
static void
add_wire_fee (void *cls,
- const struct TALER_Amount *wire_fee,
- const struct TALER_Amount *closing_fee,
+ const struct TALER_WireFeeSet *fees,
struct GNUNET_TIME_Timestamp start_date,
struct GNUNET_TIME_Timestamp end_date,
const struct TALER_MasterSignatureP *master_sig)
@@ -222,9 +220,11 @@ add_wire_fee (void *cls,
a,
GNUNET_JSON_PACK (
TALER_JSON_pack_amount ("wire_fee",
- wire_fee),
+ &fees->wire),
+ TALER_JSON_pack_amount ("wad_fee",
+ &fees->wad),
TALER_JSON_pack_amount ("closing_fee",
- closing_fee),
+ &fees->closing),
GNUNET_JSON_pack_timestamp ("start_date",
start_date),
GNUNET_JSON_pack_timestamp ("end_date",