diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-11-11 23:59:18 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-11-12 00:01:30 +0100 |
commit | 1fa05639288928cfdb3fa245a0156c425a1edb6d (patch) | |
tree | a462f2969257f6544fd30858734ba07ed261e4d2 | |
parent | a269dd82029a51086bab66e63357bef3a2d0d000 (diff) |
fix very bad amount subtraction that created free money under certain circumstances, plus some SQL code cleanup
-rw-r--r-- | src/exchangedb/exchange_do_purse_merge.sql | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/exchangedb/exchange_do_purse_merge.sql b/src/exchangedb/exchange_do_purse_merge.sql index 946fd7e97..25b752fcd 100644 --- a/src/exchangedb/exchange_do_purse_merge.sql +++ b/src/exchangedb/exchange_do_purse_merge.sql @@ -39,7 +39,7 @@ DECLARE DECLARE rval RECORD; DECLARE - reserve RECORD; + reserve_bal RECORD; DECLARE balance taler_amount; BEGIN @@ -64,7 +64,7 @@ ELSE partner_serial_id INTO my_partner_serial_id - FROM exchange.partners + FROM partners WHERE partner_base_url=in_partner_url AND start_date <= in_merge_timestamp AND end_date > in_merge_timestamp; @@ -204,28 +204,28 @@ ELSE my_amount.val = my_amount.val + my_amount.frac / 100000000; my_amount.frac = my_amount.frac % 100000000; - SELECT * - INTO reserve - FROM exchange.reserves - WHERE reserve_pub=in_reserve_pub; + SELECT current_balance + INTO reserve_bal + FROM reserves + WHERE reserve_pub=in_reserve_pub; - balance = reserve.current_balance; - balance.frac=balance.frac+my_amount.frac - - CASE - WHEN balance.frac + my_amount.frac >= 100000000 - THEN 100000000 - ELSE 0 - END; + balance = reserve_bal.current_balance; balance.val=balance.val+my_amount.val + CASE WHEN balance.frac + my_amount.frac >= 100000000 THEN 1 ELSE 0 END; + balance.frac=balance.frac+my_amount.frac + - CASE + WHEN balance.frac + my_amount.frac >= 100000000 + THEN 100000000 + ELSE 0 + END; - UPDATE exchange.reserves - SET current_balance=balance - WHERE reserve_pub=in_reserve_pub; + UPDATE reserves + SET current_balance=balance + WHERE reserve_pub=in_reserve_pub; END IF; |