aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange_do_batch_withdraw.sql
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-06-26 00:01:31 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-06-26 00:01:31 +0200
commitddedf03a816e5139b235a3ebdf5b600508c5ed5f (patch)
treea65179048fc764ec82ddf645a8982186b0157448 /src/exchangedb/exchange_do_batch_withdraw.sql
parent70bfe0ed1b9a5dbb6cc487465ef3c3df4cdb0436 (diff)
downloadexchange-ddedf03a816e5139b235a3ebdf5b600508c5ed5f.tar.xz
[age-withdraw] age-withdraw commit- and reveal-handlers implemented, 12/n
The handlers for the commit- and reveal-phases of the age-withdraw HTTP-endpoints are implemented, yet not active. Still missing: - support for age-withdraw is missing in lib/. - tests
Diffstat (limited to 'src/exchangedb/exchange_do_batch_withdraw.sql')
-rw-r--r--src/exchangedb/exchange_do_batch_withdraw.sql48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/exchangedb/exchange_do_batch_withdraw.sql b/src/exchangedb/exchange_do_batch_withdraw.sql
index 64777bb38..6d3b9a11d 100644
--- a/src/exchangedb/exchange_do_batch_withdraw.sql
+++ b/src/exchangedb/exchange_do_batch_withdraw.sql
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
+-- Copyright (C) 2014--2023 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -13,6 +13,8 @@
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
+-- @author Christian Grothoff
+-- @author Özgür Kesim
CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
IN amount_val INT8,
@@ -20,18 +22,20 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
IN rpub BYTEA,
IN now INT8,
IN min_reserve_gc INT8,
--- TODO[oec]: add [IN] parameter for maximum age and [OUT] parameter for required age
+ IN do_age_check BOOLEAN,
OUT reserve_found BOOLEAN,
OUT balance_ok BOOLEAN,
- OUT ruuid INT8)
+ OUT age_ok BOOLEAN,
+ OUT allowed_maximum_age INT4, -- in years
+ OUT ruuid INT8
LANGUAGE plpgsql
AS $$
DECLARE
reserve_gc INT8;
-DECLARE
reserve_val INT8;
-DECLARE
reserve_frac INT4;
+ reserve_birthday INT4;
+ not_before date;
BEGIN
-- Shards: reserves by reserve_pub (SELECT)
-- reserves_out (INSERT, with CONFLICT detection) by wih
@@ -44,12 +48,13 @@ SELECT
current_balance_val
,current_balance_frac
,gc_date
+ ,birthday
,reserve_uuid
--- TODO[oec]: get age requirements
INTO
reserve_val
,reserve_frac
,reserve_gc
+ ,reserve_birthday
,ruuid
FROM exchange.reserves
WHERE reserves.reserve_pub=rpub;
@@ -59,11 +64,32 @@ THEN
-- reserve unknown
reserve_found=FALSE;
balance_ok=FALSE;
+ age_ok=FALSE;
+ allowed_maximum_age=0;
ruuid=2;
RETURN;
END IF;
--- TODO[oec]: check age requirements
+
+-- Check if age requirements are present
+IF ((NOT do_age_check) OR (reserve_birthday = 0))
+THEN
+ age_ok = OK;
+ required_age = 0;
+ELSE
+ -- Age requirements are formally not met: The exchange is setup to support
+ -- age restrictions (do_age_check == TRUE) and the reserve has a
+ -- birthday set (reserve_birthday != 0), but the client called the
+ -- batch-withdraw endpoint instead of the age-withdraw endpoint, which it
+ -- should have.
+ not_before=date '1970-01-01' + reserve_birthday;
+ allowed_maximum_age = extract(year from age(current_date, not_before));
+
+ reserve_found=TRUE;
+ balance_ok=FALSE;
+ age_ok = FALSE;
+ RETURN;
+END IF;
-- Check reserve balance is sufficient.
IF (reserve_val > amount_val)
@@ -82,7 +108,6 @@ ELSE
reserve_val=0;
reserve_frac=reserve_frac - amount_frac;
ELSE
- reserve_found=TRUE;
balance_ok=FALSE;
RETURN;
END IF;
@@ -104,9 +129,6 @@ balance_ok=TRUE;
END $$;
--- TODO[oec]: Update comment re: age requirements are implemented
-COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8)
- IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.';
-
-
+COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8, BOOLEAN)
+ IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and that age requirements are formally met. If so updates the database with the result. Excludes storing the planchets.';