commit 2c27aef23b605d3a631adf6717083e0bc082f4b0
parent 8ad98a3370781ca341498e002e926c8bf8835047
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 14 Dec 2025 23:28:30 +0100
combine multiple coins in wire transfer reports (#10745)
Diffstat:
1 file changed, 69 insertions(+), 12 deletions(-)
diff --git a/src/backenddb/pg_lookup_transfer_details_by_order.c b/src/backenddb/pg_lookup_transfer_details_by_order.c
@@ -55,7 +55,10 @@ struct LookupTransferDetailsByOrderContext
/**
* Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
+ * that has returned @a num_results results. We SELECT by coin,
+ * but because that's not useful for the UI, we combine all coins
+ * that were deposited in the same wire transfer into a single
+ * record before calling the callback.
*
* @param cls of type `struct LookupTransferDetailsByOrderContext *`
* @param result the postgres result
@@ -67,19 +70,22 @@ lookup_transfer_details_by_order_cb (void *cls,
unsigned int num_results)
{
struct LookupTransferDetailsByOrderContext *ltdo = cls;
+ struct TALER_WireTransferIdentifierRawP last_wtid;
+ char *last_exchange_url = NULL;
+ struct GNUNET_TIME_Timestamp last_execution_time;
+ struct TALER_Amount last_deposit_value;
+ struct TALER_Amount last_deposit_fee;
+ bool last_confirmed;
for (unsigned int i = 0; i<num_results; i++)
{
struct TALER_WireTransferIdentifierRawP wtid;
char *exchange_url;
- uint64_t deposit_serial;
struct GNUNET_TIME_Timestamp execution_time;
struct TALER_Amount deposit_value;
struct TALER_Amount deposit_fee;
bool confirmed;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("deposit_serial",
- &deposit_serial),
GNUNET_PQ_result_spec_timestamp ("deposit_timestamp",
&execution_time),
GNUNET_PQ_result_spec_string ("exchange_url",
@@ -104,15 +110,65 @@ lookup_transfer_details_by_order_cb (void *cls,
ltdo->qs = GNUNET_DB_STATUS_HARD_ERROR;
return;
}
+ if (0 == i)
+ {
+ last_wtid = wtid;
+ last_exchange_url = exchange_url;
+ last_execution_time = execution_time;
+ last_deposit_value = deposit_value;
+ last_deposit_fee = deposit_fee;
+ last_confirmed = confirmed;
+ continue;
+ }
+ if ( (0 ==
+ GNUNET_memcmp (&wtid,
+ &last_wtid)) &&
+ (0 == strcmp (exchange_url,
+ last_exchange_url)) &&
+ (GNUNET_TIME_timestamp_cmp (execution_time,
+ ==,
+ last_execution_time)) &&
+ (last_confirmed == confirmed) &&
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (&deposit_value,
+ &last_deposit_value)) )
+ {
+ GNUNET_assert (0 <=
+ TALER_amount_add (&last_deposit_value,
+ &last_deposit_value,
+ &deposit_value));
+ GNUNET_assert (0 <=
+ TALER_amount_add (&last_deposit_fee,
+ &last_deposit_fee,
+ &deposit_fee));
+ continue;
+ }
+ ltdo->cb (ltdo->cb_cls,
+ &last_wtid,
+ last_exchange_url,
+ last_execution_time,
+ &last_deposit_value,
+ &last_deposit_fee,
+ last_confirmed);
+ GNUNET_free (exchange_url);
+ last_wtid = wtid;
+ last_exchange_url = exchange_url;
+ last_execution_time = execution_time;
+ last_deposit_value = deposit_value;
+ last_deposit_fee = deposit_fee;
+ last_confirmed = confirmed;
+ }
+ if (num_results > 0)
+ {
ltdo->cb (ltdo->cb_cls,
- &wtid,
- exchange_url,
- execution_time,
- &deposit_value,
- &deposit_fee,
- confirmed);
- GNUNET_PQ_cleanup_result (rs); /* technically useless here */
+ &last_wtid,
+ last_exchange_url,
+ last_execution_time,
+ &last_deposit_value,
+ &last_deposit_fee,
+ last_confirmed);
}
+ GNUNET_free (last_exchange_url);
ltdo->qs = num_results;
}
@@ -159,7 +215,8 @@ TMH_PG_lookup_transfer_details_by_order (
/* Check that all this is for the same instance */
" JOIN merchant_contract_terms contracts"
" USING (merchant_serial, order_serial)"
- " WHERE mcon.order_serial=$1");
+ " WHERE mcon.order_serial=$1"
+ " ORDER BY met.wtid");
qs = GNUNET_PQ_eval_prepared_multi_select (
pg->conn,