merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

pg_lookup_expected_transfer.c (4040B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2026 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_lookup_expected_transfer.c
     18  * @brief Implementation of the lookup_expected_transfer function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/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_lookup_expected_transfer.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TMH_PG_lookup_expected_transfer (
     31   void *cls,
     32   const char *instance_id,
     33   uint64_t expected_incoming_serial,
     34   struct GNUNET_TIME_Timestamp *expected_time,
     35   struct TALER_Amount *expected_credit_amount,
     36   struct TALER_WireTransferIdentifierRawP *wtid,
     37   struct TALER_FullPayto *payto_uri,
     38   char **exchange_url,
     39   struct GNUNET_TIME_Timestamp *execution_time,
     40   bool *confirmed,
     41   struct TALER_MasterPublicKeyP *master_pub)
     42 {
     43   struct PostgresClosure *pg = cls;
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_string (instance_id),
     46     GNUNET_PQ_query_param_uint64 (&expected_incoming_serial),
     47     GNUNET_PQ_query_param_end
     48   };
     49   struct GNUNET_PQ_ResultSpec rs[] = {
     50     GNUNET_PQ_result_spec_timestamp ("expected_time",
     51                                      expected_time),
     52     GNUNET_PQ_result_spec_bool ("confirmed",
     53                                 confirmed),
     54     GNUNET_PQ_result_spec_allow_null (
     55       TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount",
     56                                                  expected_credit_amount),
     57       NULL),
     58     GNUNET_PQ_result_spec_string ("exchange_url",
     59                                   exchange_url),
     60     GNUNET_PQ_result_spec_auto_from_type ("wtid",
     61                                           wtid),
     62     GNUNET_PQ_result_spec_string ("payto_uri",
     63                                   &payto_uri->full_payto),
     64     GNUNET_PQ_result_spec_allow_null (
     65       GNUNET_PQ_result_spec_timestamp ("execution_time",
     66                                        execution_time),
     67       NULL),
     68     GNUNET_PQ_result_spec_auto_from_type ("master_pub",
     69                                           master_pub),
     70     GNUNET_PQ_result_spec_end
     71   };
     72 
     73   *execution_time = GNUNET_TIME_UNIT_ZERO_TS;
     74   memset (expected_credit_amount,
     75           0,
     76           sizeof (*expected_credit_amount));
     77   check_connection (pg);
     78   PREPARE (pg,
     79            "lookup_expected_transfer",
     80            "SELECT"
     81            "  met.expected_time"
     82            " ,met.confirmed"
     83            " ,met.expected_credit_amount"
     84            " ,met.exchange_url"
     85            " ,met.wtid"
     86            " ,ma.payto_uri"
     87            " ,mts.execution_time"
     88            " ,esk.master_pub"
     89            " FROM merchant_expected_transfers met"
     90            " JOIN merchant_exchange_signing_keys esk"
     91            "   USING (signkey_serial)"
     92            " JOIN merchant_accounts ma"
     93            "   USING (account_serial)"
     94            " JOIN merchant_instances inst"
     95            "   USING (merchant_serial)"
     96            " LEFT JOIN merchant_transfer_signatures mts"
     97            "   USING (expected_credit_serial)"
     98            " WHERE inst.merchant_id=$1"
     99            "   AND met.expected_credit_serial=$2");
    100   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    101                                                    "lookup_expected_transfer",
    102                                                    params,
    103                                                    rs);
    104 }