commit b82f45cd64f87ab7be99096bac9196e830f9a9dc
parent 027129dd07bfb3fd8da742688dcbadb205d22ec9
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 10 Oct 2026 21:18:57 +0200
Assign 'deposited' only for the merchant/contract combination being
aggregated.
Diffstat:
1 file changed, 66 insertions(+), 62 deletions(-)
diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c
@@ -428,7 +428,7 @@ check_transaction_history_for_deposit (
struct TALER_Amount expenditures;
struct TALER_Amount refunds;
struct TALER_Amount spent;
- struct TALER_Amount *deposited = NULL;
+ const struct TALER_Amount *deposited = NULL;
struct TALER_Amount merchant_loss;
const struct TALER_Amount *deposit_fee;
enum GNUNET_DB_QueryStatus qs;
@@ -463,66 +463,70 @@ check_transaction_history_for_deposit (
switch (tl->type)
{
case TALER_EXCHANGEDB_TT_DEPOSIT:
- /* check wire and h_wire are consistent */
- if (NULL != deposited)
{
- struct TALER_AUDITORDB_RowInconsistency ri = {
- .row_id = tl->serial_id,
- .diagnostic = (char *)
- "multiple deposits of the same coin into the same contract detected",
- .row_table = (char *) "deposits"
- };
-
- qs = TALER_AUDITORDB_insert_row_inconsistency (
- TALER_ARL_adb,
- &ri);
-
- if (qs < 0)
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.deposit->amount_with_fee; /* according to exchange*/
+ fee_claimed = &tl->details.deposit->deposit_fee; /* Fee according to exchange DB */
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ /* Check if this deposit is within the remit of the aggregation
+ we are investigating, if so, include it in the totals. */
+ if ((0 == GNUNET_memcmp (merchant_pub,
+ &tl->details.deposit->merchant_pub)) &&
+ (0 == GNUNET_memcmp (h_contract_terms,
+ &tl->details.deposit->h_contract_terms)))
{
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
+ struct TALER_Amount amount_without_fee;
+
+ if (NULL != deposited)
+ {
+ struct TALER_AUDITORDB_RowInconsistency ri = {
+ .row_id = tl->serial_id,
+ .diagnostic = (char *)
+ "multiple deposits of the same coin into the same contract detected",
+ .row_table = (char *) "deposits"
+ };
+
+ qs = TALER_AUDITORDB_insert_row_inconsistency (
+ TALER_ARL_adb,
+ &ri);
+
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ }
+ deposited = amount_with_fee;
+ TALER_ARL_amount_subtract (&amount_without_fee,
+ amount_with_fee,
+ fee_claimed);
+ TALER_ARL_amount_add (merchant_gain,
+ merchant_gain,
+ &amount_without_fee);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Detected applicable deposit of %s\n",
+ TALER_amount2s (&amount_without_fee));
+ deposit_fee = fee_claimed; /* We had a deposit, remember the fee, we may need it */
}
+ /* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.deposit,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between auditor and exchange DB! */
+ qs = report_amount_arithmetic_inconsistency ("deposit fee",
+ 0,
+ fee_claimed,
+ &issue->fees.deposit,
+ 1);
+ if (0 > qs)
+ return qs;
+ }
+ break;
}
- deposited = &tl->details.deposit->amount_with_fee; /* according to exchange*/
- fee_claimed = &tl->details.deposit->deposit_fee; /* Fee according to exchange DB */
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- deposited);
- /* Check if this deposit is within the remit of the aggregation
- we are investigating, if so, include it in the totals. */
- if ((0 == GNUNET_memcmp (merchant_pub,
- &tl->details.deposit->merchant_pub)) &&
- (0 == GNUNET_memcmp (h_contract_terms,
- &tl->details.deposit->h_contract_terms)))
- {
- struct TALER_Amount amount_without_fee;
-
- TALER_ARL_amount_subtract (&amount_without_fee,
- deposited,
- fee_claimed);
- TALER_ARL_amount_add (merchant_gain,
- merchant_gain,
- &amount_without_fee);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Detected applicable deposit of %s\n",
- TALER_amount2s (&amount_without_fee));
- deposit_fee = fee_claimed; /* We had a deposit, remember the fee, we may need it */
- }
- /* Check that the fees given in the transaction list and in dki match */
- if (0 !=
- TALER_amount_cmp (&issue->fees.deposit,
- fee_claimed))
- {
- /* Disagreement in fee structure between auditor and exchange DB! */
- qs = report_amount_arithmetic_inconsistency ("deposit fee",
- 0,
- fee_claimed,
- &issue->fees.deposit,
- 1);
- if (0 > qs)
- return qs;
- }
- break;
case TALER_EXCHANGEDB_TT_MELT:
{
const struct TALER_Amount *amount_with_fee;
@@ -690,13 +694,13 @@ check_transaction_history_for_deposit (
*deposit_gain = *merchant_gain;
if ((NULL != deposited) &&
(NULL != deposit_fee) &&
- (0 == TALER_amount_cmp (&refunds,
+ (0 == TALER_amount_cmp (&merchant_loss,
deposited)))
{
- /* We had a /deposit operation AND /refund operations adding up to the
- total deposited value including deposit fee. Thus, we should not
- subtract the /deposit fee from the merchant gain (as it was also
- refunded). */
+ /* We had a /deposit operation AND /refund operations for the same
+ merchant and contract adding up to the total deposited value
+ including deposit fee. Thus, we should not subtract the /deposit fee
+ from the merchant gain (as it was also refunded). */
TALER_ARL_amount_add (merchant_gain,
merchant_gain,
deposit_fee);