exchange

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

0002-kycauths_in.sql (3012B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024 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 CREATE FUNCTION create_table_kycauths_in(
     18   IN partition_suffix TEXT DEFAULT NULL
     19 )
     20 RETURNS VOID
     21 LANGUAGE plpgsql
     22 AS $$
     23 DECLARE
     24   table_name TEXT default 'kycauths_in';
     25 BEGIN
     26   PERFORM create_partitioned_table(
     27     'CREATE TABLE %I'
     28       '(kycauth_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
     29       ',account_pub BYTEA CHECK (LENGTH(account_pub)=32)'
     30       ',wire_reference INT8 NOT NULL'
     31       ',credit taler_amount NOT NULL'
     32       ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
     33       ',exchange_account_section TEXT NOT NULL'
     34       ',execution_date INT8 NOT NULL'
     35       ',PRIMARY KEY(wire_source_h_payto, wire_reference)'
     36     ') %s ;'
     37     ,table_name
     38     ,'PARTITION BY HASH (wire_source_h_payto)'
     39     ,partition_suffix
     40   );
     41   PERFORM comment_partitioned_table(
     42      'list of transfers to register a key for KYC authentication, one per incoming wire transfer'
     43     ,table_name
     44     ,partition_suffix
     45   );
     46   -- FIXME: check that the *full* payto URI is indeed the best choice here,
     47   -- given that this is mostly used for KYC, we may prefer the normalized
     48   -- payto URI instead! Not sure, to be checked!
     49   PERFORM comment_partitioned_column(
     50      'Identifies the debited bank account and KYC status by the hash over the full payto URI'
     51     ,'wire_source_h_payto'
     52     ,table_name
     53     ,partition_suffix
     54   );
     55   PERFORM comment_partitioned_column(
     56      'Public key to be associated with the account.'
     57     ,'account_pub'
     58     ,table_name
     59     ,partition_suffix
     60   );
     61   PERFORM comment_partitioned_column(
     62      'Amount that was transferred into the account'
     63     ,'credit'
     64     ,table_name
     65     ,partition_suffix
     66   );
     67 END $$;
     68 
     69 
     70 CREATE FUNCTION constrain_table_kycauths_in(
     71   IN partition_suffix TEXT
     72 )
     73 RETURNS void
     74 LANGUAGE plpgsql
     75 AS $$
     76 DECLARE
     77   table_name TEXT default 'kycauths_in';
     78 BEGIN
     79   table_name = concat_ws('_', table_name, partition_suffix);
     80   EXECUTE FORMAT (
     81     'ALTER TABLE ' || table_name ||
     82     ' ADD CONSTRAINT ' || table_name || '_kycauth_in_serial_id_key'
     83     ' UNIQUE (kycauth_in_serial_id)'
     84   );
     85 END
     86 $$;
     87 
     88 INSERT INTO exchange_tables
     89     (name
     90     ,version
     91     ,action
     92     ,partitioned
     93     ,by_range)
     94   VALUES
     95     ('kycauths_in'
     96     ,'exchange-0002'
     97     ,'create'
     98     ,TRUE
     99     ,FALSE),
    100     ('kycauths_in'
    101     ,'exchange-0002'
    102     ,'constrain'
    103     ,TRUE
    104     ,FALSE);