From a1dae0199f3bc3e9f66fc1375c652c6f99b26b2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= <oec-taler@kesim.org>
Date: Fri, 28 Jul 2023 19:01:57 +0200
Subject: FAILING attempt to make echange.reserve use taler_amount

Fails with

> TALER_PREFIX=/usr/local ./test-exchangedb-postgres
2023-07-28T19:02:25.150845+0200 /home/oec/projects/taler/exchange/src/exchangedb/.libs/test-exchangedb-postgres-2559159 WARNING Could not run PSQL on file /usr/local/share/taler//sql/exchange/drop.sql: psql exit code was 3
2023-07-28T19:02:32.488085+0200 pq-2559159 ERROR Query `call_withdraw' failed with result: invalid input syntax for type bigint:
"(1,1000)"/(null)/ERROR:  invalid input syntax for type bigint: "(1,1000)"
CONTEXT:  PL/pgSQL function exchange_do_withdraw(bytea,taler_amount,bytea,bytea,bytea,bytea,bytea,bigint,bigint,boolean) line 23 at SQL statement
/PGRES_FATAL_ERROR/ERROR:  invalid input syntax for type bigint: "(1,1000)"
CONTEXT:  PL/pgSQL function exchange_do_withdraw(bytea,taler_amount,bytea,bytea,bytea,bytea,bytea,bigint,bigint,boolean) line 23 at SQL statement
2023-07-28T19:02:32.488146+0200 /home/oec/projects/taler/exchange/src/exchangedb/.libs/test-exchangedb-postgres-2559159 ERROR Assertion failed at test_exchangedb.c:1428.
---
 src/exchangedb/exchange_do_purse_deposit.sql | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

(limited to 'src/exchangedb/exchange_do_purse_deposit.sql')

diff --git a/src/exchangedb/exchange_do_purse_deposit.sql b/src/exchangedb/exchange_do_purse_deposit.sql
index d710e9002..5e9f71bb5 100644
--- a/src/exchangedb/exchange_do_purse_deposit.sql
+++ b/src/exchangedb/exchange_do_purse_deposit.sql
@@ -32,17 +32,10 @@ LANGUAGE plpgsql
 AS $$
 DECLARE
   was_merged BOOLEAN;
-DECLARE
   psi INT8; -- partner's serial ID (set if merged)
-DECLARE
-  my_amount_val INT8; -- total in purse
-DECLARE
-  my_amount_frac INT4; -- total in purse
-DECLARE
+  my_amount taler_amount; -- total in purse
   was_paid BOOLEAN;
-DECLARE
   my_in_reserve_quota BOOLEAN;
-DECLARE
   my_reserve_pub BYTEA;
 BEGIN
 
@@ -174,8 +167,8 @@ SELECT
    ,amount_with_fee_frac
    ,in_reserve_quota
   INTO
-    my_amount_val
-   ,my_amount_frac
+    my_amount.val
+   ,my_amount.frac
    ,my_in_reserve_quota
   FROM exchange.purse_requests
   WHERE (purse_pub=in_purse_pub)
@@ -231,14 +224,12 @@ ELSE
   -- This is a local reserve, update balance immediately.
   INSERT INTO reserves
     (reserve_pub
-    ,current_balance_frac
-    ,current_balance_val
+    ,current_balance
     ,expiration_date
     ,gc_date)
   VALUES
     (my_reserve_pub
-    ,my_amount_frac
-    ,my_amount_val
+    ,my_amount
     ,in_reserve_expiration
     ,in_reserve_expiration)
   ON CONFLICT DO NOTHING;
@@ -248,15 +239,15 @@ ELSE
     -- Reserve existed, thus UPDATE instead of INSERT.
     UPDATE reserves
       SET
-       current_balance_frac=current_balance_frac+my_amount_frac
+       current_balance.frac=current_balance.frac+my_amount.frac
         - CASE
-          WHEN current_balance_frac + my_amount_frac >= 100000000
+          WHEN current_balance.frac + my_amount.frac >= 100000000
             THEN 100000000
           ELSE 0
           END
-      ,current_balance_val=current_balance_val+my_amount_val
+      ,current_balance.val=current.balance_val+my_amount.val
         + CASE
-          WHEN current_balance_frac + my_amount_frac >= 100000000
+          WHEN current_balance.frac + my_amount.frac >= 100000000
             THEN 1
           ELSE 0
           END
-- 
cgit v1.2.3

