exchange

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

auditor_do_get_balance.sql (1510B)


      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 -- @author Christian Grothoff
     17 
     18 DROP FUNCTION IF EXISTS auditor_do_get_balance;
     19 CREATE OR REPLACE FUNCTION auditor_do_get_balance(
     20   IN in_keys TEXT[])
     21 RETURNS SETOF taler_amount
     22 LANGUAGE plpgsql
     23 AS $$
     24 DECLARE
     25   my_key TEXT;
     26   my_rec RECORD;
     27   my_val taler_amount;
     28 BEGIN
     29   FOREACH my_key IN ARRAY in_keys
     30   LOOP
     31     SELECT (ab.balance_value).val
     32           ,(ab.balance_value).frac
     33       INTO my_rec
     34       FROM auditor_balances ab
     35       WHERE balance_key=my_key;
     36     IF FOUND
     37     THEN
     38         my_val.val = my_rec.val;
     39         my_val.frac = my_rec.frac;
     40         RETURN NEXT my_val;
     41     ELSE
     42         RETURN NEXT NULL;
     43     END IF;
     44   END LOOP;
     45 END $$;
     46 
     47 COMMENT ON FUNCTION auditor_do_get_balance(TEXT[])
     48   IS 'Finds all balances associated with the array of keys given as the argument and returns them in order';