From a1dae0199f3bc3e9f66fc1375c652c6f99b26b2c Mon Sep 17 00:00:00 2001
From: Özgür Kesim <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_batch_reserves_update.sql | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

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

diff --git a/src/exchangedb/exchange_do_batch_reserves_update.sql b/src/exchangedb/exchange_do_batch_reserves_update.sql
index 39920629..da7f4508 100644
--- a/src/exchangedb/exchange_do_batch_reserves_update.sql
+++ b/src/exchangedb/exchange_do_batch_reserves_update.sql
@@ -18,8 +18,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_reserves_update(
   IN in_reserve_pub BYTEA,
   IN in_expiration_date INT8,
   IN in_wire_ref INT8,
-  IN in_credit_val INT8,
-  IN in_credit_frac INT4,
+  IN in_credit taler_amount,
   IN in_exchange_account_name VARCHAR,
   IN in_wire_source_h_payto BYTEA,
   IN in_notify text,
@@ -38,8 +37,8 @@ BEGIN
     VALUES
     (in_reserve_pub
     ,in_wire_ref
-    ,in_credit_val
-    ,in_credit_frac
+    ,in_credit.val
+    ,in_credit.frac
     ,in_exchange_account_name
     ,in_wire_source_h_payto
     ,in_expiration_date)
@@ -50,15 +49,15 @@ BEGIN
     out_duplicate = FALSE;
     UPDATE reserves
       SET
-         current_balance_frac = current_balance_frac+in_credit_frac
+         current_balance.frac = current_balance.frac+in_credit.frac
            - CASE
-             WHEN current_balance_frac + in_credit_frac >= 100000000
+             WHEN current_balance.frac + in_credit.frac >= 100000000
                THEN 100000000
              ELSE 1
              END
-            ,current_balance_val = current_balance_val+in_credit_val
+            ,current_balance.val = current_balance.val+in_credit.val
            + CASE
-             WHEN current_balance_frac + in_credit_frac >= 100000000
+             WHEN current_balance.frac + in_credit.frac >= 100000000
                THEN 1
              ELSE 0
              END
-- 
cgit v1.2.3

