exchange

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

exchange_trigger_purse_decision_insert.sql (1616B)


      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 CREATE OR REPLACE FUNCTION purse_decision_insert_trigger()
     18   RETURNS trigger
     19   LANGUAGE plpgsql
     20   AS $$
     21 BEGIN
     22   UPDATE exchange.purse_requests
     23      SET was_decided=TRUE
     24    WHERE purse_pub=NEW.purse_pub;
     25   IF NEW.refunded
     26   THEN
     27     INSERT INTO exchange.coin_history
     28       (coin_pub
     29       ,table_name
     30       ,serial_id)
     31     SELECT
     32       pd.coin_pub
     33      ,'purse_decision'
     34      ,NEW.purse_decision_serial_id
     35     FROM exchange.purse_deposits pd
     36     WHERE purse_pub = NEW.purse_pub;
     37   ELSE
     38     INSERT INTO exchange.reserve_history
     39       (reserve_pub
     40       ,table_name
     41       ,serial_id)
     42     SELECT
     43       reserve_pub
     44      ,'purse_decision'
     45      ,NEW.purse_decision_serial_id
     46     FROM exchange.purse_merges
     47     WHERE purse_pub=NEW.purse_pub;
     48   END IF;
     49   RETURN NEW;
     50 END $$;
     51 COMMENT ON FUNCTION purse_decision_insert_trigger()
     52   IS 'Automatically generate coin history entry and update decision status for the purse.';
     53 
     54