exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

get_wire_hash_for_contract.c (3006B)


      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 "exchangedb_lib.h"
     22 #include "taler/taler_pq_lib.h"
     23 #include "exchange-database/get_wire_hash_for_contract.h"
     24 #include "exchange-database/compute_shard.h"
     25 #include "helper.h"
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 TALER_EXCHANGEDB_get_wire_hash_for_contract (
     30   struct TALER_EXCHANGEDB_PostgresContext *pg,
     31   const struct TALER_MerchantPublicKeyP *merchant_pub,
     32   const struct TALER_PrivateContractHashP *h_contract_terms,
     33   struct TALER_MerchantWireHashP *h_wire)
     34 {
     35   enum GNUNET_DB_QueryStatus qs;
     36   uint64_t deposit_shard = TALER_EXCHANGEDB_compute_shard (merchant_pub);
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_uint64 (&deposit_shard),
     39     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     40     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
     41     GNUNET_PQ_query_param_end
     42   };
     43   struct TALER_FullPayto payto_uri;
     44   struct TALER_WireSaltP wire_salt;
     45   struct GNUNET_PQ_ResultSpec rs[] = {
     46     GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
     47                                           &wire_salt),
     48     GNUNET_PQ_result_spec_string ("payto_uri",
     49                                   &payto_uri.full_payto),
     50     GNUNET_PQ_result_spec_end
     51   };
     52 
     53   /* (shard, merchant_pub, h_contract_terms) is unique in batch_deposits */
     54   PREPARE (pg,
     55            "get_wire_hash_for_contract",
     56            "SELECT"
     57            "  bdep.wire_salt"
     58            " ,wt.payto_uri"
     59            " FROM batch_deposits bdep"
     60            " JOIN wire_targets wt"
     61            "   USING (wire_target_h_payto)"
     62            " WHERE bdep.shard=$1"
     63            "   AND bdep.merchant_pub=$2"
     64            "   AND bdep.h_contract_terms=$3");
     65   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     66                                                  "get_wire_hash_for_contract",
     67                                                  params,
     68                                                  rs);
     69   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     70   {
     71     TALER_merchant_wire_signature_hash (payto_uri,
     72                                         &wire_salt,
     73                                         h_wire);
     74     GNUNET_PQ_cleanup_result (rs);
     75   }
     76   return qs;
     77 }