exchange

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

exchange_do_insert_aml_officer.sql (2068B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2023 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 OR REPLACE FUNCTION exchange_do_insert_aml_officer(
     18   IN in_decider_pub BYTEA,
     19   IN in_master_sig BYTEA,
     20   IN in_decider_name TEXT,
     21   IN in_is_active BOOLEAN,
     22   IN in_read_only BOOLEAN,
     23   IN in_last_change INT8,
     24   OUT out_last_change INT8)
     25 LANGUAGE plpgsql
     26 AS $$
     27 BEGIN
     28 INSERT INTO exchange.aml_staff
     29   (decider_pub
     30   ,master_sig
     31   ,decider_name
     32   ,is_active
     33   ,read_only
     34   ,last_change
     35   ) VALUES
     36   (in_decider_pub
     37   ,in_master_sig
     38   ,in_decider_name
     39   ,in_is_active
     40   ,in_read_only
     41   ,in_last_change)
     42  ON CONFLICT DO NOTHING;
     43 IF FOUND
     44 THEN
     45   out_last_change=0;
     46   RETURN;
     47 END IF;
     48 
     49 -- Check update is most recent...
     50 SELECT last_change
     51   INTO out_last_change
     52   FROM exchange.aml_staff
     53   WHERE decider_pub=in_decider_pub;
     54 ASSERT FOUND, 'cannot have INSERT conflict but no AML staff record';
     55 
     56 IF out_last_change >= in_last_change
     57 THEN
     58   -- Refuse to insert older status
     59  RETURN;
     60 END IF;
     61 
     62 -- We are more recent, update existing record.
     63 UPDATE exchange.aml_staff
     64   SET master_sig=in_master_sig
     65      ,decider_name=in_decider_name
     66      ,is_active=in_is_active
     67      ,read_only=in_read_only
     68      ,last_change=in_last_change
     69   WHERE decider_pub=in_decider_pub;
     70 END $$;
     71 
     72 
     73 COMMENT ON FUNCTION exchange_do_insert_aml_officer(BYTEA, BYTEA, TEXT, BOOL, BOOL, INT8)
     74   IS 'Inserts or updates AML staff record, making sure the update is more recent than the previous change';