exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

exchange-0006.sql (2189B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2025 Taler Systems SA
      4 --
      5 -- TALER is free software; you can redistribute it and/or modify it under the
      6 -- terms of the GNU General Public License as published by the Free Software
      7 -- Foundation; either version 3, or (at your option) any later version.
      8 --
      9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 -- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 --
     13 -- You should have received a copy of the GNU General Public License along with
     14 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 --
     16 
     17 BEGIN;
     18 
     19 SELECT _v.register_patch('exchange-0006', NULL, NULL);
     20 
     21 SET search_path TO exchange;
     22 
     23 CREATE PROCEDURE patch_table_kyc_targets()
     24 LANGUAGE plpgsql
     25 AS $$
     26 DECLARE
     27   my_rec RECORD;
     28   my_payto TEXT;
     29   my_is_wallet BOOL;
     30   my_setup_extension BOOL;
     31   wtc CURSOR FOR
     32    SELECT
     33      h_normalized_payto
     34     ,payto_uri
     35      FROM exchange.wire_targets;
     36 BEGIN
     37 
     38 PERFORM
     39   FROM pg_tables
     40  WHERE schemaname = 'exchange'
     41    AND tablename  = 'wire_targets';
     42 IF FOUND
     43 THEN
     44 
     45   -- Fix any remaining NULL columns in wire_targets
     46   CREATE EXTENSION IF NOT EXISTS pgcrypto;
     47   my_setup_extension = FOUND;
     48   UPDATE wire_targets
     49        SET h_normalized_payto=substring(digest(convert_to(payto_uri, 'UTF8') || E'\\000'::bytea, 'sha512') FROM 1 FOR 32)
     50    WHERE h_normalized_payto IS NULL;
     51   IF my_setup_extension
     52   THEN
     53     DROP EXTENSION pgcrypto;
     54   END IF;
     55 END IF;
     56 
     57 -- Only run the migration if the tables already exist.
     58 PERFORM
     59   FROM pg_tables
     60  WHERE schemaname = 'exchange'
     61    AND tablename  = 'kyc_targets';
     62 
     63 IF FOUND
     64 THEN
     65 
     66   FOR my_rec IN wtc
     67   LOOP
     68     my_payto = my_rec.payto_uri;
     69     my_is_wallet
     70       = (LOWER (SUBSTRING (my_payto, 0, 23)) =
     71          'payto://taler-reserve/') OR
     72         (LOWER (SUBSTRING (my_payto, 0, 28)) =
     73          'payto://taler-reserve-http/');
     74     UPDATE kyc_targets
     75       SET is_wallet=my_is_wallet
     76      WHERE h_normalized_payto=my_rec.h_normalized_payto;
     77   END LOOP;
     78 END IF;
     79 
     80 END $$;
     81 
     82 CALL patch_table_kyc_targets();
     83 
     84 DROP PROCEDURE patch_table_kyc_targets;
     85 
     86 COMMIT;