diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-07-28 23:27:02 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-07-28 23:27:02 +0200 |
commit | 6dedca0fa36bd30bbeb26be012ce3ac9d967065a (patch) | |
tree | bd87d5ee2b4f7309e552928bf68e10e84c32c2b1 /src/exchangedb/exchange_do_recoup_to_reserve.sql | |
parent | a1dae0199f3bc3e9f66fc1375c652c6f99b26b2c (diff) | |
download | exchange-6dedca0fa36bd30bbeb26be012ce3ac9d967065a.tar.xz |
taler_amount type introduced in reserves table and corresponding functions
- current_balance is now a taler_amount
- all C-functions, SQL-statements and stored procedures adjusted accordingly.
=> make check passes all tests in testing.
Diffstat (limited to 'src/exchangedb/exchange_do_recoup_to_reserve.sql')
-rw-r--r-- | src/exchangedb/exchange_do_recoup_to_reserve.sql | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/exchangedb/exchange_do_recoup_to_reserve.sql b/src/exchangedb/exchange_do_recoup_to_reserve.sql index 72942e8c5..71c1d51b9 100644 --- a/src/exchangedb/exchange_do_recoup_to_reserve.sql +++ b/src/exchangedb/exchange_do_recoup_to_reserve.sql @@ -32,6 +32,9 @@ LANGUAGE plpgsql AS $$ DECLARE tmp taler_amount; -- amount recouped + balance taler_amount; -- current balance of the reserve + new_balance taler_amount; -- new balance of the reserve + reserve RECORD; BEGIN -- Shards: SELECT known_coins (by coin_pub) -- SELECT recoup (by coin_pub) @@ -81,22 +84,31 @@ UPDATE known_coins ,remaining_val=0 WHERE coin_pub=in_coin_pub; +-- Get current balance +SELECT * + INTO reserve + FROM reserves + WHERE reserve_pub=in_reserve_pub; + +balance = reserve.current_balance; +new_balance.frac=balance.frac+tmp.frac + - CASE + WHEN balance.frac+tmp.frac >= 100000000 + THEN 100000000 + ELSE 0 + END; + +new_balance.val=balance.val+tmp.val + + CASE + WHEN balance.frac+tmp.frac >= 100000000 + THEN 1 + ELSE 0 + END; -- Credit the reserve and update reserve timers. UPDATE reserves SET - current_balance.frac=current_balance.frac+tmp.frac - - CASE - WHEN current_balance.frac+tmp.frac >= 100000000 - THEN 100000000 - ELSE 0 - END, - current_balance.val=current_balance.val+tmp.val - + CASE - WHEN current_balance.frac+tmp.frac >= 100000000 - THEN 1 - ELSE 0 - END, + current_balance = new_balance, gc_date=GREATEST(gc_date, in_reserve_gc), expiration_date=GREATEST(expiration_date, in_reserve_expiration) WHERE reserve_pub=in_reserve_pub; |