LCOV - code coverage report
Current view: top level - exchangedb - pg_select_purse_requests_above_serial_id.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 33 39.4 %
Date: 2025-06-05 21:03:14 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 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             :  * @file pg_select_purse_requests_above_serial_id.c
      18             :  * @brief Implementation of the select_purse_requests_above_serial_id function for Postgres
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_error_codes.h"
      23             : #include "taler_dbevents.h"
      24             : #include "taler_pq_lib.h"
      25             : #include "pg_select_purse_requests_above_serial_id.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : /**
      30             :  * Closure for #purse_deposit_serial_helper_cb().
      31             :  */
      32             : struct PurseRequestsSerialContext
      33             : {
      34             : 
      35             :   /**
      36             :    * Callback to call.
      37             :    */
      38             :   TALER_EXCHANGEDB_PurseRequestCallback cb;
      39             : 
      40             :   /**
      41             :    * Closure for @e cb.
      42             :    */
      43             :   void *cb_cls;
      44             : 
      45             :   /**
      46             :    * Plugin context.
      47             :    */
      48             :   struct PostgresClosure *pg;
      49             : 
      50             :   /**
      51             :    * Status code, set to #GNUNET_SYSERR on hard errors.
      52             :    */
      53             :   enum GNUNET_GenericReturnValue status;
      54             : };
      55             : 
      56             : 
      57             : /**
      58             :  * Helper function to be called with the results of a SELECT statement
      59             :  * that has returned @a num_results results.
      60             :  *
      61             :  * @param cls closure of type `struct PurseRequestsSerialContext`
      62             :  * @param result the postgres result
      63             :  * @param num_results the number of results in @a result
      64             :  */
      65             : static void
      66          74 : purse_requests_serial_helper_cb (void *cls,
      67             :                                  PGresult *result,
      68             :                                  unsigned int num_results)
      69             : {
      70          74 :   struct PurseRequestsSerialContext *dsc = cls;
      71          74 :   struct PostgresClosure *pg = dsc->pg;
      72             : 
      73          74 :   for (unsigned int i = 0; i<num_results; i++)
      74             :   {
      75             :     uint64_t rowid;
      76             :     struct TALER_Amount target_amount;
      77             :     uint32_t age_limit;
      78             :     struct TALER_PurseMergePublicKeyP merge_pub;
      79             :     struct TALER_PurseContractPublicKeyP purse_pub;
      80             :     struct TALER_PrivateContractHashP h_contract_terms;
      81             :     struct TALER_PurseContractSignatureP purse_sig;
      82             :     struct GNUNET_TIME_Timestamp purse_creation;
      83             :     struct GNUNET_TIME_Timestamp purse_expiration;
      84           0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      85           0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
      86             :                                    &target_amount),
      87           0 :       GNUNET_PQ_result_spec_uint32 ("age_limit",
      88             :                                     &age_limit),
      89           0 :       GNUNET_PQ_result_spec_timestamp ("purse_creation",
      90             :                                        &purse_creation),
      91           0 :       GNUNET_PQ_result_spec_timestamp ("purse_expiration",
      92             :                                        &purse_expiration),
      93           0 :       GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
      94             :                                             &purse_pub),
      95           0 :       GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
      96             :                                             &h_contract_terms),
      97           0 :       GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
      98             :                                             &purse_sig),
      99           0 :       GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
     100             :                                             &merge_pub),
     101           0 :       GNUNET_PQ_result_spec_uint64 ("purse_requests_serial_id",
     102             :                                     &rowid),
     103             :       GNUNET_PQ_result_spec_end
     104             :     };
     105             :     enum GNUNET_GenericReturnValue ret;
     106             : 
     107           0 :     if (GNUNET_OK !=
     108           0 :         GNUNET_PQ_extract_result (result,
     109             :                                   rs,
     110             :                                   i))
     111             :     {
     112           0 :       GNUNET_break (0);
     113           0 :       dsc->status = GNUNET_SYSERR;
     114           0 :       return;
     115             :     }
     116           0 :     ret = dsc->cb (dsc->cb_cls,
     117             :                    rowid,
     118             :                    &purse_pub,
     119             :                    &merge_pub,
     120             :                    purse_creation,
     121             :                    purse_expiration,
     122             :                    &h_contract_terms,
     123             :                    age_limit,
     124             :                    &target_amount,
     125             :                    &purse_sig);
     126           0 :     GNUNET_PQ_cleanup_result (rs);
     127           0 :     if (GNUNET_OK != ret)
     128           0 :       break;
     129             :   }
     130             : }
     131             : 
     132             : 
     133             : enum GNUNET_DB_QueryStatus
     134          74 : TEH_PG_select_purse_requests_above_serial_id (
     135             :   void *cls,
     136             :   uint64_t serial_id,
     137             :   TALER_EXCHANGEDB_PurseRequestCallback cb,
     138             :   void *cb_cls)
     139             : {
     140          74 :   struct PostgresClosure *pg = cls;
     141          74 :   struct GNUNET_PQ_QueryParam params[] = {
     142          74 :     GNUNET_PQ_query_param_uint64 (&serial_id),
     143             :     GNUNET_PQ_query_param_end
     144             :   };
     145          74 :   struct PurseRequestsSerialContext dsc = {
     146             :     .cb = cb,
     147             :     .cb_cls = cb_cls,
     148             :     .pg = pg,
     149             :     .status = GNUNET_OK
     150             :   };
     151             :   enum GNUNET_DB_QueryStatus qs;
     152             : 
     153          74 :   PREPARE (pg,
     154             :            "audit_get_purse_requests_incr",
     155             :            "SELECT"
     156             :            " purse_requests_serial_id"
     157             :            ",purse_pub"
     158             :            ",amount_with_fee"
     159             :            ",age_limit"
     160             :            ",h_contract_terms"
     161             :            ",purse_creation"
     162             :            ",purse_expiration"
     163             :            ",merge_pub"
     164             :            ",purse_sig"
     165             :            " FROM purse_requests"
     166             :            " WHERE ("
     167             :            "  (purse_requests_serial_id>=$1)"
     168             :            " )"
     169             :            " ORDER BY purse_requests_serial_id ASC;");
     170          74 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     171             :                                              "audit_get_purse_requests_incr",
     172             :                                              params,
     173             :                                              &purse_requests_serial_helper_cb,
     174             :                                              &dsc);
     175          74 :   if (GNUNET_OK != dsc.status)
     176           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     177          74 :   return qs;
     178             : }

Generated by: LCOV version 1.16