LCOV - code coverage report
Current view: top level - backenddb - pg_insert_deposit_confirmation.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 26 26
Test Date: 2025-11-06 19:31:41 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022, 2023, 2024 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_deposit_confirmation.c
      18              :  * @brief Implementation of the insert_deposit_confirmation 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_deposit_confirmation.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30           29 : TMH_PG_insert_deposit_confirmation (
      31              :   void *cls,
      32              :   const char *instance_id,
      33              :   struct GNUNET_TIME_Timestamp deposit_timestamp,
      34              :   const struct TALER_PrivateContractHashP *h_contract_terms,
      35              :   const char *exchange_url,
      36              :   struct GNUNET_TIME_Timestamp wire_transfer_deadline,
      37              :   const struct TALER_Amount *total_without_fees,
      38              :   const struct TALER_Amount *wire_fee,
      39              :   const struct TALER_MerchantWireHashP *h_wire,
      40              :   const struct TALER_ExchangeSignatureP *exchange_sig,
      41              :   const struct TALER_ExchangePublicKeyP *exchange_pub,
      42              :   uint64_t *deposit_confirmation_serial_id)
      43              : {
      44           29 :   struct GNUNET_DB_EventHeaderP es = {
      45           29 :     .size = htons (sizeof (es)),
      46           29 :     .type = htons (TALER_DBEVENT_MERCHANT_NEW_WIRE_DEADLINE)
      47              :   };
      48           29 :   struct PostgresClosure *pg = cls;
      49           29 :   struct GNUNET_PQ_QueryParam params[] = {
      50           29 :     GNUNET_PQ_query_param_string (instance_id),
      51           29 :     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
      52           29 :     GNUNET_PQ_query_param_timestamp (&deposit_timestamp),
      53           29 :     GNUNET_PQ_query_param_string (exchange_url),
      54           29 :     TALER_PQ_query_param_amount_with_currency (pg->conn,
      55              :                                                total_without_fees),
      56           29 :     TALER_PQ_query_param_amount_with_currency (pg->conn,
      57              :                                                wire_fee),
      58           29 :     GNUNET_PQ_query_param_auto_from_type (h_wire), /* 7 */
      59           29 :     GNUNET_PQ_query_param_auto_from_type (exchange_sig),
      60           29 :     GNUNET_PQ_query_param_auto_from_type (exchange_pub),
      61           29 :     GNUNET_PQ_query_param_timestamp (&wire_transfer_deadline),
      62              :     GNUNET_PQ_query_param_end
      63              :   };
      64           29 :   struct GNUNET_PQ_ResultSpec rs[] = {
      65           29 :     GNUNET_PQ_result_spec_uint64 ("deposit_confirmation_serial",
      66              :                                   deposit_confirmation_serial_id),
      67              :     GNUNET_PQ_result_spec_end
      68              :   };
      69              :   enum GNUNET_DB_QueryStatus qs;
      70              : 
      71              :   /* no preflight check here, run in transaction by caller! */
      72           29 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      73              :               "Storing deposit confirmation for instance `%s' h_contract_terms `%s', total_without_fees: %s and wire transfer deadline in %s\n",
      74              :               instance_id,
      75              :               GNUNET_h2s (&h_contract_terms->hash),
      76              :               TALER_amount2s (total_without_fees),
      77              :               GNUNET_TIME_relative2s (
      78              :                 GNUNET_TIME_absolute_get_remaining (
      79              :                   wire_transfer_deadline.abs_time),
      80              :                 true));
      81           29 :   check_connection (pg);
      82           29 :   PREPARE (pg,
      83              :            "insert_deposit_confirmation",
      84              :            "WITH md AS"
      85              :            "  (SELECT account_serial, merchant_serial"
      86              :            "   FROM merchant_accounts"
      87              :            "   WHERE h_wire=$7"
      88              :            "    AND merchant_serial="
      89              :            "     (SELECT merchant_serial"
      90              :            "        FROM merchant_instances"
      91              :            "        WHERE merchant_id=$1))"
      92              :            ", ed AS"
      93              :            "  (SELECT signkey_serial"
      94              :            "   FROM merchant_exchange_signing_keys"
      95              :            "   WHERE exchange_pub=$9"
      96              :            "   ORDER BY start_date DESC"
      97              :            "   LIMIT 1)"
      98              :            "INSERT INTO merchant_deposit_confirmations"
      99              :            "(order_serial"
     100              :            ",deposit_timestamp"
     101              :            ",exchange_url"
     102              :            ",total_without_fee"
     103              :            ",wire_fee"
     104              :            ",exchange_sig"
     105              :            ",wire_transfer_deadline"
     106              :            ",signkey_serial"
     107              :            ",account_serial)"
     108              :            " SELECT "
     109              :            "   order_serial"
     110              :            "  ,$3, $4, $5, $6, $8, $10"
     111              :            "  ,ed.signkey_serial"
     112              :            "  ,md.account_serial"
     113              :            "  FROM merchant_contract_terms"
     114              :            "   JOIN md USING (merchant_serial)"
     115              :            "   FULL OUTER JOIN ed ON TRUE"
     116              :            "  WHERE h_contract_terms=$2"
     117              :            " RETURNING deposit_confirmation_serial");
     118           29 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     119              :                                                  "insert_deposit_confirmation",
     120              :                                                  params,
     121              :                                                  rs);
     122           29 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     123              :   {
     124              :     /* inform taler-merchant-depositcheck about new deadline */
     125              :     struct GNUNET_TIME_AbsoluteNBO nbo;
     126              : 
     127           29 :     nbo = GNUNET_TIME_absolute_hton (wire_transfer_deadline.abs_time);
     128           29 :     GNUNET_PQ_event_notify (pg->conn,
     129              :                             &es,
     130              :                             &nbo,
     131              :                             sizeof (nbo));
     132              :   }
     133           29 :   return qs;
     134              : }
        

Generated by: LCOV version 2.0-1