exchange

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

0002-purse_actions.sql (2721B)


      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 
     18 CREATE OR REPLACE FUNCTION create_table_purse_actions(
     19   IN partition_suffix TEXT DEFAULT NULL
     20 )
     21 RETURNS VOID
     22 LANGUAGE plpgsql
     23 AS $$
     24 DECLARE
     25   table_name TEXT DEFAULT 'purse_actions';
     26 BEGIN
     27   PERFORM create_partitioned_table(
     28     'CREATE TABLE IF NOT EXISTS %I'
     29       '(purse_pub BYTEA NOT NULL PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
     30       ',action_date INT8 NOT NULL'
     31       ',partner_serial_id INT8'
     32     ') %s ;'
     33     ,table_name
     34     ,'PARTITION BY HASH (purse_pub)'
     35     ,partition_suffix
     36   );
     37   PERFORM comment_partitioned_table(
     38      'purses awaiting some action by the router'
     39     ,table_name
     40     ,partition_suffix
     41   );
     42   PERFORM comment_partitioned_column(
     43      'public (contract) key of the purse'
     44     ,'purse_pub'
     45     ,table_name
     46     ,partition_suffix
     47   );
     48   PERFORM comment_partitioned_column(
     49      'when is the purse ready for action'
     50     ,'action_date'
     51     ,table_name
     52     ,partition_suffix
     53   );
     54   PERFORM comment_partitioned_column(
     55      'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown'
     56     ,'partner_serial_id'
     57     ,table_name
     58     ,partition_suffix
     59   );
     60 END $$;
     61 
     62 
     63 CREATE OR REPLACE FUNCTION master_table_purse_actions()
     64 RETURNS VOID
     65 LANGUAGE plpgsql
     66 AS $$
     67 DECLARE
     68   table_name TEXT DEFAULT 'purse_actions';
     69 BEGIN
     70   -- Create global index
     71   CREATE INDEX IF NOT EXISTS purse_action_by_target
     72     ON purse_actions
     73     (partner_serial_id,action_date);
     74 
     75   -- Setup trigger
     76   CREATE TRIGGER purse_requests_on_insert
     77     AFTER INSERT
     78     ON purse_requests
     79     FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
     80   COMMENT ON TRIGGER purse_requests_on_insert
     81           ON purse_requests
     82     IS 'Here we install an entry for the purse expiration.';
     83 END $$;
     84 
     85 
     86 INSERT INTO exchange_tables
     87     (name
     88     ,version
     89     ,action
     90     ,partitioned
     91     ,by_range)
     92   VALUES
     93     ('purse_actions'
     94     ,'exchange-0002'
     95     ,'create'
     96     ,TRUE
     97     ,FALSE),
     98     ('purse_actions'
     99     ,'exchange-0002'
    100     ,'master'
    101     ,TRUE
    102     ,FALSE);