0002-cs_nonce_locks.sql (2641B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2014--2022 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_cs_nonce_locks( 18 partition_suffix TEXT DEFAULT NULL 19 ) 20 RETURNS VOID 21 LANGUAGE plpgsql 22 AS $$ 23 BEGIN 24 PERFORM create_partitioned_table( 25 'CREATE TABLE %I' 26 '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 27 ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)' 28 ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)' 29 ',max_denomination_serial INT8 NOT NULL' 30 ') %s ;' 31 ,'cs_nonce_locks' 32 ,'PARTITION BY HASH (nonce)' 33 ,partition_suffix 34 ); 35 PERFORM comment_partitioned_table( 36 'ensures a Clause Schnorr client nonce is locked for use with an operation identified by a hash' 37 ,'cs_nonce_locks' 38 ,partition_suffix 39 ); 40 PERFORM comment_partitioned_column( 41 'actual nonce submitted by the client' 42 ,'nonce' 43 ,'cs_nonce_locks' 44 ,partition_suffix 45 ); 46 PERFORM comment_partitioned_column( 47 'hash (RC for refresh, blind coin hash for withdraw) the nonce may be used with' 48 ,'op_hash' 49 ,'cs_nonce_locks' 50 ,partition_suffix 51 ); 52 PERFORM comment_partitioned_column( 53 'Maximum number of a CS denomination serial the nonce could be used with, for GC' 54 ,'max_denomination_serial' 55 ,'cs_nonce_locks' 56 ,partition_suffix 57 ); 58 END 59 $$; 60 61 62 CREATE FUNCTION constrain_table_cs_nonce_locks( 63 IN partition_suffix TEXT 64 ) 65 RETURNS VOID 66 LANGUAGE plpgsql 67 AS $$ 68 DECLARE 69 table_name TEXT DEFAULT 'cs_nonce_locks'; 70 BEGIN 71 table_name = concat_ws('_', table_name, partition_suffix); 72 EXECUTE FORMAT ( 73 'ALTER TABLE ' || table_name || 74 ' ADD CONSTRAINT ' || table_name || '_cs_nonce_lock_serial_id_key' 75 ' UNIQUE (cs_nonce_lock_serial_id)' 76 ); 77 END 78 $$; 79 80 81 INSERT INTO exchange_tables 82 (name 83 ,version 84 ,action 85 ,partitioned 86 ,by_range) 87 VALUES 88 ('cs_nonce_locks' 89 ,'exchange-0002' 90 ,'create' 91 ,TRUE 92 ,FALSE), 93 ('cs_nonce_locks' 94 ,'exchange-0002' 95 ,'constrain' 96 ,TRUE 97 ,FALSE);