LCOV - code coverage report
Current view: top level - backenddb - pg_lookup_contract_terms2.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 19 94.7 %
Date: 2025-06-23 16:22:09 Functions: 1 1 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 backenddb/pg_lookup_contract_terms2.c
      18             :  * @brief Implementation of the lookup_contract_terms2 function for Postgres
      19             :  * @author Iván Ávalos
      20             :  */
      21             : #include "platform.h"
      22             : #include <taler/taler_error_codes.h>
      23             : #include <taler/taler_dbevents.h>
      24             : #include <taler/taler_pq_lib.h>
      25             : #include "pg_lookup_contract_terms2.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : enum GNUNET_DB_QueryStatus
      29          42 : TMH_PG_lookup_contract_terms2 (
      30             :   void *cls,
      31             :   const char *instance_id,
      32             :   const char *order_id,
      33             :   json_t **contract_terms,
      34             :   uint64_t *order_serial,
      35             :   bool *paid,
      36             :   struct TALER_ClaimTokenP *claim_token,
      37             :   char **pos_key,
      38             :   enum TALER_MerchantConfirmationAlgorithm *pos_algorithm)
      39             : {
      40          42 :   struct PostgresClosure *pg = cls;
      41             :   enum GNUNET_DB_QueryStatus qs;
      42             :   struct TALER_ClaimTokenP ct;
      43          42 :   struct GNUNET_PQ_QueryParam params[] = {
      44          42 :     GNUNET_PQ_query_param_string (instance_id),
      45          42 :     GNUNET_PQ_query_param_string (order_id),
      46             :     GNUNET_PQ_query_param_end
      47             :   };
      48             :   uint32_t pos32;
      49          42 :   struct GNUNET_PQ_ResultSpec rs[] = {
      50             :     /* contract_terms must be first! */
      51          42 :     TALER_PQ_result_spec_json ("contract_terms",
      52             :                                contract_terms),
      53          42 :     GNUNET_PQ_result_spec_uint64 ("order_serial",
      54             :                                   order_serial),
      55          42 :     GNUNET_PQ_result_spec_bool ("paid",
      56             :                                 paid),
      57          42 :     GNUNET_PQ_result_spec_auto_from_type ("claim_token",
      58             :                                           &ct),
      59          42 :     GNUNET_PQ_result_spec_allow_null (
      60             :       GNUNET_PQ_result_spec_string ("pos_key",
      61             :                                     pos_key),
      62             :       NULL),
      63          42 :     GNUNET_PQ_result_spec_allow_null (
      64             :       GNUNET_PQ_result_spec_uint32 ("pos_algorithm",
      65             :                                     &pos32),
      66             :       NULL),
      67             :     GNUNET_PQ_result_spec_end
      68             :   };
      69             : 
      70          42 :   check_connection (pg);
      71          42 :   PREPARE (pg,
      72             :            "lookup_contract_terms2",
      73             :            "SELECT"
      74             :            " contract_terms"
      75             :            ",order_serial"
      76             :            ",claim_token"
      77             :            ",paid"
      78             :            ",pos_key"
      79             :            ",pos_algorithm"
      80             :            " FROM merchant_contract_terms"
      81             :            " WHERE order_id=$2"
      82             :            "   AND merchant_serial="
      83             :            "     (SELECT merchant_serial"
      84             :            "        FROM merchant_instances"
      85             :            "        WHERE merchant_id=$1)");
      86          42 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      87             :                                                  "lookup_contract_terms2",
      88             :                                                  params,
      89             :                                                  (NULL != contract_terms)
      90             :                                                    ? rs
      91             :                                                    : &rs[1]);
      92          42 :   *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32;
      93          42 :   if (NULL != claim_token)
      94           0 :     *claim_token = ct;
      95          42 :   return qs;
      96             : }

Generated by: LCOV version 1.16