LCOV - code coverage report
Current view: top level - exchangedb - get_wire_hash_for_contract.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 13 13
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 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 exchangedb/get_wire_hash_for_contract.c
      18              :  * @brief Implementation of the get_wire_hash_for_contract function for Postgres
      19              :  * @author Özgür Kesim
      20              :  */
      21              : #include "taler/taler_exchangedb_lib.h"
      22              : #include "taler/taler_pq_lib.h"
      23              : #include "exchange-database/get_wire_hash_for_contract.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28            4 : TALER_EXCHANGEDB_get_wire_hash_for_contract (
      29              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      30              :   const struct TALER_MerchantPublicKeyP *merchant_pub,
      31              :   const struct TALER_PrivateContractHashP *h_contract_terms,
      32              :   struct TALER_MerchantWireHashP *h_wire)
      33              : {
      34              :   enum GNUNET_DB_QueryStatus qs;
      35            4 :   struct GNUNET_PQ_QueryParam params[] = {
      36            4 :     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
      37            4 :     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
      38              :     GNUNET_PQ_query_param_end
      39              :   };
      40              :   struct TALER_FullPayto payto_uri;
      41              :   struct TALER_WireSaltP wire_salt;
      42            4 :   struct GNUNET_PQ_ResultSpec rs[] = {
      43            4 :     GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
      44              :                                           &wire_salt),
      45            4 :     GNUNET_PQ_result_spec_string ("payto_uri",
      46              :                                   &payto_uri.full_payto),
      47              :     GNUNET_PQ_result_spec_end
      48              :   };
      49              : 
      50              :   /* check if the necessary records exist and get them */
      51            4 :   PREPARE (pg,
      52              :            "get_wire_hash_for_contract",
      53              :            "SELECT"
      54              :            "  bdep.wire_salt"
      55              :            " ,wt.payto_uri"
      56              :            " FROM coin_deposits"
      57              :            " JOIN batch_deposits bdep"
      58              :            "   USING (batch_deposit_serial_id)"
      59              :            " JOIN wire_targets wt"
      60              :            "   USING (wire_target_h_payto)"
      61              :            " WHERE bdep.merchant_pub=$1"
      62              :            "   AND bdep.h_contract_terms=$2");
      63              :   /* NOTE: above query might be more efficient if we computed the shard
      64              :      from the merchant_pub and included that in the query */
      65            4 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      66              :                                                  "get_wire_hash_for_contract",
      67              :                                                  params,
      68              :                                                  rs);
      69            4 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
      70              :   {
      71            4 :     TALER_merchant_wire_signature_hash (payto_uri,
      72              :                                         &wire_salt,
      73              :                                         h_wire);
      74            4 :     GNUNET_PQ_cleanup_result (rs);
      75              :   }
      76            4 :   return qs;
      77              : }
        

Generated by: LCOV version 2.0-1