commit db381f4bea291caec22f9c07f353b030440af8dd
parent c05c3edd1cea2f522b6e4742f8cf86a27bc6f4a7
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 9 Mar 2026 00:04:42 +0100
fix computation of total_amount of batch_deposits table when multiple REST API calls are made to batch-deposit for the same contract and with different coins (#11207)
Diffstat:
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/exchangedb/exchange_do_amount_specific.sql b/src/exchangedb/exchange_do_amount_specific.sql
@@ -41,7 +41,9 @@ LANGUAGE plpgsql
AS $$
BEGIN
sum = (a.val + b.val, a.frac + b.frac);
- CALL amount_normalize(sum ,sum);
+ SELECT *
+ INTO sum
+ FROM amount_normalize(sum);
IF (sum.val > (1<<52))
THEN
diff --git a/src/exchangedb/exchange_do_deposit.sql b/src/exchangedb/exchange_do_deposit.sql
@@ -50,9 +50,12 @@ DECLARE
wtsi INT8; -- wire target serial id
bdsi INT8; -- batch_deposits serial id
i INT4;
+ my_record RECORD;
ini_amount_with_fee taler_amount;
ini_coin_pub BYTEA;
ini_coin_sig BYTEA;
+ my_update BOOL := FALSE;
+ my_total taler_amount;
BEGIN
-- Shards:
-- INSERT wire_targets (by h_payto), ON CONFLICT DO NOTHING;
@@ -141,9 +144,9 @@ THEN
SELECT
exchange_timestamp
,batch_deposit_serial_id
+ ,total_amount
INTO
- out_exchange_timestamp
- ,bdsi
+ my_record
FROM batch_deposits
WHERE shard=in_shard
AND merchant_pub=in_merchant_pub
@@ -164,6 +167,10 @@ THEN
out_conflict=TRUE;
RETURN;
END IF;
+ out_exchange_timestamp = my_record.exchange_timestamp;
+ bdsi = my_record.batch_deposit_serial_id;
+ my_total = my_record.total_amount;
+ my_update = TRUE;
END IF;
out_conflict=FALSE;
@@ -192,6 +199,13 @@ LOOP
IF FOUND
THEN
-- Insert did happen, update balance in known_coins!
+ IF my_update
+ THEN
+ SELECT *
+ INTO my_total
+ FROM amount_add (my_total,
+ ini_amount_with_fee);
+ END IF;
UPDATE known_coins kc
SET
@@ -222,4 +236,13 @@ LOOP
END IF;
END LOOP; -- end FOR all coins
+IF my_update
+THEN
+ UPDATE batch_deposits
+ SET total_amount = my_total
+ WHERE batch_deposit_serial_id = bdsi
+ AND merchant_pub = in_merchant_pub
+ AND h_contract_terms = in_h_contract_terms;
+END IF;
+
END $$;