LCOV - code coverage report
Current view: top level - exchangedb - pg_select_account_merges_above_serial_id.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 36 36.1 %
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_account_merges_above_serial_id.c
      18             :  * @brief Implementation of the select_account_merges_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_account_merges_above_serial_id.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : /**
      30             :  * Closure for #account_merge_serial_helper_cb().
      31             :  */
      32             : struct AccountMergeSerialContext
      33             : {
      34             : 
      35             :   /**
      36             :    * Callback to call.
      37             :    */
      38             :   TALER_EXCHANGEDB_AccountMergeCallback 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 AccountMergeSerialContext`
      62             :  * @param result the postgres result
      63             :  * @param num_results the number of results in @a result
      64             :  */
      65             : static void
      66         148 : account_merge_serial_helper_cb (void *cls,
      67             :                                 PGresult *result,
      68             :                                 unsigned int num_results)
      69             : {
      70         148 :   struct AccountMergeSerialContext *dsc = cls;
      71         148 :   struct PostgresClosure *pg = dsc->pg;
      72             : 
      73         148 :   for (unsigned int i = 0; i<num_results; i++)
      74             :   {
      75             :     struct TALER_ReservePublicKeyP reserve_pub;
      76             :     struct TALER_PurseContractPublicKeyP purse_pub;
      77             :     struct TALER_PrivateContractHashP h_contract_terms;
      78             :     struct GNUNET_TIME_Timestamp purse_expiration;
      79             :     struct TALER_Amount amount;
      80             :     uint32_t min_age;
      81             :     uint32_t flags32;
      82             :     enum TALER_WalletAccountMergeFlags flags;
      83             :     struct TALER_Amount purse_fee;
      84             :     struct GNUNET_TIME_Timestamp merge_timestamp;
      85             :     struct TALER_ReserveSignatureP reserve_sig;
      86             :     uint64_t rowid;
      87           0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      88           0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
      89             :                                    &amount),
      90           0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
      91             :                                    &purse_fee),
      92           0 :       GNUNET_PQ_result_spec_uint32 ("flags",
      93             :                                     &flags32),
      94           0 :       GNUNET_PQ_result_spec_uint32 ("age_limit",
      95             :                                     &min_age),
      96           0 :       GNUNET_PQ_result_spec_timestamp ("purse_expiration",
      97             :                                        &purse_expiration),
      98           0 :       GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
      99             :                                        &merge_timestamp),
     100           0 :       GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
     101             :                                             &h_contract_terms),
     102           0 :       GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
     103             :                                             &purse_pub),
     104           0 :       GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
     105             :                                             &reserve_sig),
     106           0 :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
     107             :                                             &reserve_pub),
     108           0 :       GNUNET_PQ_result_spec_uint64 ("account_merge_request_serial_id",
     109             :                                     &rowid),
     110             :       GNUNET_PQ_result_spec_end
     111             :     };
     112             :     enum GNUNET_GenericReturnValue ret;
     113             : 
     114           0 :     if (GNUNET_OK !=
     115           0 :         GNUNET_PQ_extract_result (result,
     116             :                                   rs,
     117             :                                   i))
     118             :     {
     119           0 :       GNUNET_break (0);
     120           0 :       dsc->status = GNUNET_SYSERR;
     121           0 :       return;
     122             :     }
     123           0 :     flags = (enum TALER_WalletAccountMergeFlags) flags32;
     124           0 :     ret = dsc->cb (dsc->cb_cls,
     125             :                    rowid,
     126             :                    &reserve_pub,
     127             :                    &purse_pub,
     128             :                    &h_contract_terms,
     129             :                    purse_expiration,
     130             :                    &amount,
     131             :                    min_age,
     132             :                    flags,
     133             :                    &purse_fee,
     134             :                    merge_timestamp,
     135             :                    &reserve_sig);
     136           0 :     GNUNET_PQ_cleanup_result (rs);
     137           0 :     if (GNUNET_OK != ret)
     138           0 :       break;
     139             :   }
     140             : }
     141             : 
     142             : 
     143             : enum GNUNET_DB_QueryStatus
     144         148 : TEH_PG_select_account_merges_above_serial_id (
     145             :   void *cls,
     146             :   uint64_t serial_id,
     147             :   TALER_EXCHANGEDB_AccountMergeCallback cb,
     148             :   void *cb_cls)
     149             : {
     150         148 :   struct PostgresClosure *pg = cls;
     151         148 :   struct GNUNET_PQ_QueryParam params[] = {
     152         148 :     GNUNET_PQ_query_param_uint64 (&serial_id),
     153             :     GNUNET_PQ_query_param_end
     154             :   };
     155         148 :   struct AccountMergeSerialContext dsc = {
     156             :     .cb = cb,
     157             :     .cb_cls = cb_cls,
     158             :     .pg = pg,
     159             :     .status = GNUNET_OK
     160             :   };
     161             :   enum GNUNET_DB_QueryStatus qs;
     162             : 
     163         148 :   PREPARE (pg,
     164             :            "audit_get_account_merge_incr",
     165             :            "SELECT"
     166             :            " am.account_merge_request_serial_id"
     167             :            ",am.reserve_pub"
     168             :            ",am.purse_pub"
     169             :            ",pr.h_contract_terms"
     170             :            ",pr.purse_expiration"
     171             :            ",pr.amount_with_fee"
     172             :            ",pr.age_limit"
     173             :            ",pr.flags"
     174             :            ",pr.purse_fee"
     175             :            ",pm.merge_timestamp"
     176             :            ",am.reserve_sig"
     177             :            " FROM account_merges am"
     178             :            " JOIN purse_requests pr USING (purse_pub)"
     179             :            " JOIN purse_merges pm USING (purse_pub)"
     180             :            " WHERE ("
     181             :            "  (account_merge_request_serial_id>=$1)"
     182             :            " )"
     183             :            " ORDER BY account_merge_request_serial_id ASC;");
     184         148 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     185             :                                              "audit_get_account_merge_incr",
     186             :                                              params,
     187             :                                              &account_merge_serial_helper_cb,
     188             :                                              &dsc);
     189         148 :   if (GNUNET_OK != dsc.status)
     190           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     191         148 :   return qs;
     192             : }

Generated by: LCOV version 1.16