LCOV - code coverage report
Current view: top level - exchangedb - get_wire_accounts.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 40 32
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022, 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              :  * @file exchangedb/get_wire_accounts.c
      18              :  * @brief Implementation of the get_wire_accounts function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/get_wire_accounts.h"
      23              : #include "helper.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Closure for #get_wire_accounts_cb().
      28              :  */
      29              : struct GetWireAccountsContext
      30              : {
      31              :   /**
      32              :    * Function to call per result.
      33              :    */
      34              :   TALER_EXCHANGEDB_WireAccountCallback cb;
      35              : 
      36              :   /**
      37              :    * Closure for @e cb.
      38              :    */
      39              :   void *cb_cls;
      40              : 
      41              :   /**
      42              :    * Flag set to #GNUNET_OK as long as everything is fine.
      43              :    */
      44              :   enum GNUNET_GenericReturnValue status;
      45              : 
      46              : };
      47              : 
      48              : 
      49              : /**
      50              :  * Invoke the callback for each result.
      51              :  *
      52              :  * @param cls a `struct MissingWireContext *`
      53              :  * @param result SQL result
      54              :  * @param num_results number of rows in @a result
      55              :  */
      56              : static void
      57           19 : get_wire_accounts_cb (void *cls,
      58              :                       PGresult *result,
      59              :                       unsigned int num_results)
      60              : {
      61           19 :   struct GetWireAccountsContext *ctx = cls;
      62              : 
      63           40 :   for (unsigned int i = 0; i < num_results; i++)
      64              :   {
      65              :     struct TALER_FullPayto payto_uri;
      66           21 :     char *conversion_url = NULL;
      67           21 :     char *open_banking_gateway = NULL;
      68           21 :     char *wire_transfer_gateway = NULL;
      69           21 :     json_t *debit_restrictions = NULL;
      70           21 :     json_t *credit_restrictions = NULL;
      71              :     struct TALER_MasterSignatureP master_sig;
      72           21 :     char *bank_label = NULL;
      73              :     int64_t priority;
      74           21 :     struct GNUNET_PQ_ResultSpec rs[] = {
      75           21 :       GNUNET_PQ_result_spec_string ("payto_uri",
      76              :                                     &payto_uri.full_payto),
      77           21 :       GNUNET_PQ_result_spec_allow_null (
      78              :         GNUNET_PQ_result_spec_string ("conversion_url",
      79              :                                       &conversion_url),
      80              :         NULL),
      81           21 :       GNUNET_PQ_result_spec_allow_null (
      82              :         GNUNET_PQ_result_spec_string ("open_banking_gateway",
      83              :                                       &open_banking_gateway),
      84              :         NULL),
      85           21 :       GNUNET_PQ_result_spec_allow_null (
      86              :         GNUNET_PQ_result_spec_string ("wire_transfer_gateway",
      87              :                                       &wire_transfer_gateway),
      88              :         NULL),
      89           21 :       GNUNET_PQ_result_spec_allow_null (
      90              :         GNUNET_PQ_result_spec_string ("bank_label",
      91              :                                       &bank_label),
      92              :         NULL),
      93           21 :       GNUNET_PQ_result_spec_int64 ("priority",
      94              :                                    &priority),
      95           21 :       GNUNET_PQ_result_spec_allow_null (
      96              :         TALER_PQ_result_spec_json ("debit_restrictions",
      97              :                                    &debit_restrictions),
      98              :         NULL),
      99           21 :       GNUNET_PQ_result_spec_allow_null (
     100              :         TALER_PQ_result_spec_json ("credit_restrictions",
     101              :                                    &credit_restrictions),
     102              :         NULL),
     103           21 :       GNUNET_PQ_result_spec_auto_from_type ("master_sig",
     104              :                                             &master_sig),
     105              :       GNUNET_PQ_result_spec_end
     106              :     };
     107              : 
     108           21 :     if (GNUNET_OK !=
     109           21 :         GNUNET_PQ_extract_result (result,
     110              :                                   rs,
     111              :                                   i))
     112              :     {
     113            0 :       GNUNET_break (0);
     114            0 :       ctx->status = GNUNET_SYSERR;
     115            0 :       return;
     116              :     }
     117           21 :     if (NULL == debit_restrictions)
     118              :     {
     119            0 :       debit_restrictions = json_array ();
     120            0 :       GNUNET_assert (NULL != debit_restrictions);
     121              :     }
     122           21 :     if (NULL == credit_restrictions)
     123              :     {
     124            0 :       credit_restrictions = json_array ();
     125            0 :       GNUNET_assert (NULL != credit_restrictions);
     126              :     }
     127           21 :     ctx->cb (ctx->cb_cls,
     128              :              payto_uri,
     129              :              conversion_url,
     130              :              open_banking_gateway,
     131              :              wire_transfer_gateway,
     132              :              debit_restrictions,
     133              :              credit_restrictions,
     134              :              &master_sig,
     135              :              bank_label,
     136              :              priority);
     137           21 :     GNUNET_PQ_cleanup_result (rs);
     138              :   }
     139              : }
     140              : 
     141              : 
     142              : enum GNUNET_DB_QueryStatus
     143           19 : TALER_EXCHANGEDB_get_wire_accounts (struct TALER_EXCHANGEDB_PostgresContext *pg,
     144              :                                     TALER_EXCHANGEDB_WireAccountCallback cb,
     145              :                                     void *cb_cls)
     146              : {
     147           19 :   struct GetWireAccountsContext ctx = {
     148              :     .cb = cb,
     149              :     .cb_cls = cb_cls,
     150              :     .status = GNUNET_OK
     151              :   };
     152           19 :   struct GNUNET_PQ_QueryParam params[] = {
     153              :     GNUNET_PQ_query_param_end
     154              :   };
     155              :   enum GNUNET_DB_QueryStatus qs;
     156              : 
     157           19 :   PREPARE (pg,
     158              :            "get_wire_accounts",
     159              :            "SELECT"
     160              :            " payto_uri"
     161              :            ",conversion_url"
     162              :            ",open_banking_gateway"
     163              :            ",wire_transfer_gateway"
     164              :            ",debit_restrictions::TEXT"
     165              :            ",credit_restrictions::TEXT"
     166              :            ",master_sig"
     167              :            ",bank_label"
     168              :            ",priority"
     169              :            " FROM wire_accounts"
     170              :            " WHERE is_active");
     171           19 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     172              :                                              "get_wire_accounts",
     173              :                                              params,
     174              :                                              &get_wire_accounts_cb,
     175              :                                              &ctx);
     176           19 :   if (GNUNET_OK != ctx.status)
     177            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     178           19 :   return qs;
     179              : }
        

Generated by: LCOV version 2.0-1