0002-unique_withdraw_blinding_seed.sql (2105B)
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 -- @author Özgür Kesim 17 18 CREATE FUNCTION create_table_unique_withdraw_blinding_seed( 19 IN partition_suffix TEXT DEFAULT NULL 20 ) 21 RETURNS VOID 22 LANGUAGE plpgsql 23 AS $$ 24 DECLARE 25 table_name TEXT DEFAULT 'unique_withdraw_blinding_seed'; 26 BEGIN 27 PERFORM create_partitioned_table( 28 'CREATE TABLE %I' 29 '(unique_withdraw_blinding_seed_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 30 ',blinding_seed BYTEA PRIMARY KEY' 31 ') %s ;' 32 ,table_name 33 ,'PARTITION BY HASH (blinding_seed)' 34 ,partition_suffix 35 ); 36 PERFORM comment_partitioned_table( 37 'Table to ensure uniqueness of the blinding_seed for CS signatures across all withdraw operations. ' 38 ,table_name 39 ,partition_suffix 40 ); 41 END 42 $$; 43 44 45 CREATE FUNCTION constrain_table_unique_withdraw_blinding_seed( 46 IN partition_suffix TEXT 47 ) 48 RETURNS void 49 LANGUAGE plpgsql 50 AS $$ 51 DECLARE 52 table_name TEXT DEFAULT 'unique_withdraw_blinding_seed'; 53 BEGIN 54 table_name = concat_ws('_', table_name, partition_suffix); 55 EXECUTE FORMAT ( 56 'ALTER TABLE ' || table_name || 57 ' ADD CONSTRAINT ' || table_name || '_withdraw_id_key' 58 ' UNIQUE (unique_withdraw_blinding_seed_id);' 59 ); 60 END 61 $$; 62 63 INSERT INTO exchange_tables 64 (name 65 ,version 66 ,action 67 ,partitioned 68 ,by_range) 69 VALUES 70 ('unique_withdraw_blinding_seed', 'exchange-0002', 'create', TRUE ,FALSE), 71 ('unique_withdraw_blinding_seed', 'exchange-0002', 'constrain',TRUE ,FALSE); 72