From 6dedca0fa36bd30bbeb26be012ce3ac9d967065a Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Fri, 28 Jul 2023 23:27:02 +0200 Subject: 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. --- src/exchangedb/exchange_do_age_withdraw.sql | 36 +++++++++++------------------ 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'src/exchangedb/exchange_do_age_withdraw.sql') diff --git a/src/exchangedb/exchange_do_age_withdraw.sql b/src/exchangedb/exchange_do_age_withdraw.sql index 756c0085..184a3e49 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; -- cgit v1.2.3