LCOV - code coverage report
Current view: top level - backenddb - pg_update_contract_session.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 14 14
Test Date: 2025-12-11 17:58:06 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2025 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_update_contract_session.c
      18              :  * @brief Implementation of the update_contract_session function for Postgres
      19              :  * @author Christian Grothoff
      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_update_contract_session.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30            4 : TMH_PG_update_contract_session (
      31              :   void *cls,
      32              :   const char *instance_id,
      33              :   const struct TALER_PrivateContractHashP *h_contract_terms,
      34              :   const char *session_id,
      35              :   char **fulfillment_url,
      36              :   bool *refunded)
      37              : {
      38            4 :   struct PostgresClosure *pg = cls;
      39            4 :   struct GNUNET_PQ_QueryParam params[] = {
      40            4 :     GNUNET_PQ_query_param_string (instance_id),
      41            4 :     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
      42            4 :     GNUNET_PQ_query_param_string (session_id),
      43              :     GNUNET_PQ_query_param_end
      44              :   };
      45            4 :   struct GNUNET_PQ_ResultSpec rs[] = {
      46            4 :     GNUNET_PQ_result_spec_allow_null (
      47              :       GNUNET_PQ_result_spec_string ("fulfillment_url",
      48              :                                     fulfillment_url),
      49              :       NULL),
      50            4 :     GNUNET_PQ_result_spec_bool ("refunded",
      51              :                                 refunded),
      52              :     GNUNET_PQ_result_spec_end
      53              :   };
      54              : 
      55              :   /* Session ID must always be given by the caller. */
      56            4 :   GNUNET_assert (NULL != session_id);
      57              : 
      58              :   /* no preflight check here, run in transaction by caller! */
      59            4 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      60              :               "Updating session for h_contract_terms '%s' of `%s' to `%s'\n",
      61              :               GNUNET_h2s (&h_contract_terms->hash),
      62              :               instance_id,
      63              :               session_id);
      64            4 :   PREPARE (pg,
      65              :            "update_contract_session",
      66              :            "UPDATE merchant_contract_terms mct SET"
      67              :            " session_id=$3"
      68              :            " WHERE h_contract_terms=$2"
      69              :            "   AND merchant_serial="
      70              :            "     (SELECT merchant_serial"
      71              :            "        FROM merchant_instances"
      72              :            "       WHERE merchant_id=$1)"
      73              :            " RETURNING"
      74              :            "  contract_terms->>'fulfillment_url' AS fulfillment_url"
      75              :            " ,EXISTS (SELECT 1"
      76              :            "            FROM merchant_refunds mr"
      77              :            "           WHERE order_serial=mct.order_serial"
      78              :            " ) AS refunded");
      79            4 :   *fulfillment_url = NULL;
      80            4 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      81              :                                                    "update_contract_session",
      82              :                                                    params,
      83              :                                                    rs);
      84              : }
        

Generated by: LCOV version 2.0-1