exchange_do_set_aml_lock.sql (1613B)
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 DROP FUNCTION IF EXISTS exchange_do_set_aml_lock; 18 CREATE FUNCTION exchange_do_set_aml_lock ( 19 IN in_h_payto BYTEA, 20 IN in_now INT8, 21 IN in_expiration INT8, 22 OUT out_aml_program_lock_timeout INT8) -- set if we have an existing lock 23 LANGUAGE plpgsql 24 AS $$ 25 BEGIN 26 27 UPDATE kyc_targets 28 SET aml_program_lock_timeout=in_expiration 29 WHERE h_normalized_payto=in_h_payto 30 AND ( (aml_program_lock_timeout IS NULL) 31 OR (aml_program_lock_timeout < in_now) ); 32 IF NOT FOUND 33 THEN 34 SELECT aml_program_lock_timeout 35 INTO out_aml_program_lock_timeout 36 FROM kyc_targets 37 WHERE h_normalized_payto=in_h_payto; 38 ELSE 39 out_aml_program_lock_timeout = 0; 40 END IF; 41 42 END $$; 43 44 45 COMMENT ON FUNCTION exchange_do_set_aml_lock(BYTEA, INT8, INT8) 46 IS 'Tries to lock an account for running an AML program. Returns the timeout of the existing lock, 0 if there is no existing lock, and NULL if we do not know the account.';