aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange_do_age_withdraw.sql
diff options
context:
space:
mode:
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
commit6dedca0fa36bd30bbeb26be012ce3ac9d967065a (patch)
treebd87d5ee2b4f7309e552928bf68e10e84c32c2b1 /src/exchangedb/exchange_do_age_withdraw.sql
parenta1dae0199f3bc3e9f66fc1375c652c6f99b26b2c (diff)
downloadexchange-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_age_withdraw.sql')
-rw-r--r--src/exchangedb/exchange_do_age_withdraw.sql36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/exchangedb/exchange_do_age_withdraw.sql b/src/exchangedb/exchange_do_age_withdraw.sql
index 756c00851..184a3e49a 100644
--- a/src/exchangedb/exchange_do_age_withdraw.sql
+++ b/src/exchangedb/exchange_do_age_withdraw.sql
@@ -36,10 +36,9 @@ CREATE OR REPLACE FUNCTION exchange_do_age_withdraw(
LANGUAGE plpgsql
AS $$
DECLARE
- reserve_gc INT8;
+ reserve RECORD;
difference RECORD;
balance taler_amount;
- new_balance taler_amount;
not_before date;
earliest_date date;
BEGIN
@@ -49,15 +48,8 @@ BEGIN
-- reserves_in by reserve_pub (SELECT)
-- wire_targets by wire_target_h_payto
-SELECT
- current_balance
- ,gc_date
- ,birthday
- INTO
- balance.val
- ,balance.frac
- ,reserve_gc
- ,reserve_birthday
+SELECT *
+ INTO reserve
FROM exchange.reserves
WHERE reserves.reserve_pub=rpub;
@@ -74,10 +66,13 @@ END IF;
reserve_found = TRUE;
conflict=FALSE; -- not really yet determined
+balance = reserve.current_balance;
+reserve_birthday = reserve.birthday;
+
-- Check age requirements
-IF (reserve_birthday <> 0)
+IF (reserve.birthday <> 0)
THEN
- not_before=date '1970-01-01' + reserve_birthday;
+ not_before=date '1970-01-01' + reserve.birthday;
earliest_date = current_date - make_interval(maximum_age_committed);
--
-- 1970-01-01 + birthday == not_before now
@@ -103,12 +98,9 @@ required_age=0;
-- Check reserve balance is sufficient.
SELECT *
-INTO
- difference
-FROM
- amount_left_minus_right(
- balance
- ,amount_with_fee);
+INTO difference
+FROM amount_left_minus_right(balance
+ ,amount_with_fee);
balance_ok = difference.ok;
@@ -117,15 +109,15 @@ THEN
RETURN;
END IF;
-new_balance = difference.diff;
+balance = difference.diff;
-- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
+min_reserve_gc=GREATEST(min_reserve_gc,reserve.gc_date);
-- Update reserve balance.
UPDATE reserves SET
gc_date=min_reserve_gc
- ,current_balance=new_balance
+ ,current_balance=balance
WHERE
reserves.reserve_pub=rpub;