LCOV - code coverage report
Current view: top level - backenddb - pg_insert_exchange_keys.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 16 100.0 %
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_insert_exchange_keys.c
      18             :  * @brief Implementation of the insert_exchange_keys 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_insert_exchange_keys.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30          23 : TMH_PG_insert_exchange_keys (
      31             :   void *cls,
      32             :   const struct TALER_EXCHANGE_Keys *keys,
      33             :   struct GNUNET_TIME_Absolute first_retry)
      34             : {
      35          23 :   struct PostgresClosure *pg = cls;
      36          23 :   json_t *jkeys = TALER_EXCHANGE_keys_to_json (keys);
      37          23 :   struct GNUNET_PQ_QueryParam params[] = {
      38          23 :     TALER_PQ_query_param_json (jkeys),
      39          23 :     GNUNET_PQ_query_param_absolute_time (&first_retry),
      40          23 :     GNUNET_PQ_query_param_timestamp (&keys->last_denom_issue_date),
      41          23 :     GNUNET_PQ_query_param_string (keys->exchange_url),
      42             :     GNUNET_PQ_query_param_end
      43             :   };
      44             :   enum GNUNET_DB_QueryStatus qs;
      45             : 
      46          23 :   check_connection (pg);
      47          23 :   PREPARE (pg,
      48             :            "insert_exchange_keys",
      49             :            "INSERT INTO merchant_exchange_keys"
      50             :            "(keys_json"
      51             :            ",first_retry"
      52             :            ",expiration_time"
      53             :            ",exchange_url"
      54             :            ") VALUES ($1, $2, $3, $4);");
      55          23 :   PREPARE (pg,
      56             :            "update_exchange_keys",
      57             :            "UPDATE merchant_exchange_keys SET"
      58             :            " keys_json=$1"
      59             :            ",first_retry=$2"
      60             :            ",expiration_time=$3"
      61             :            " WHERE"
      62             :            " exchange_url=$4;");
      63          23 :   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      64             :                                            "update_exchange_keys",
      65             :                                            params);
      66          23 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      67          23 :     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      68             :                                              "insert_exchange_keys",
      69             :                                              params);
      70          23 :   json_decref (jkeys);
      71          23 :   return qs;
      72             : }

Generated by: LCOV version 1.16