LCOV - code coverage report
Current view: top level - backenddb - pg_insert_instance.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 36 97.2 %
Date: 2025-08-28 06:06:54 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_instance.c
      18             :  * @brief Implementation of the insert_instance function for Postgres
      19             :  * @author Christian Grothoff
      20             :  * @author Iván Ávalos
      21             :  */
      22             : #include "platform.h"
      23             : #include <taler/taler_error_codes.h>
      24             : #include <taler/taler_dbevents.h>
      25             : #include <taler/taler_pq_lib.h>
      26             : #include "pg_insert_instance.h"
      27             : #include "pg_helper.h"
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30          31 : TMH_PG_insert_instance (
      31             :   void *cls,
      32             :   const struct TALER_MerchantPublicKeyP *merchant_pub,
      33             :   const struct TALER_MerchantPrivateKeyP *merchant_priv,
      34             :   const struct TALER_MERCHANTDB_InstanceSettings *is,
      35             :   const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
      36             :   bool validation_needed)
      37             : {
      38          31 :   struct PostgresClosure *pg = cls;
      39          31 :   struct GNUNET_PQ_QueryParam params[] = {
      40          31 :     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
      41          31 :     GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash),
      42          31 :     GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt),
      43          31 :     GNUNET_PQ_query_param_string (is->id),
      44          31 :     GNUNET_PQ_query_param_string (is->name),
      45          31 :     TALER_PQ_query_param_json (is->address),
      46          31 :     TALER_PQ_query_param_json (is->jurisdiction),
      47          31 :     GNUNET_PQ_query_param_bool (is->use_stefan),
      48          31 :     GNUNET_PQ_query_param_relative_time (
      49             :       &is->default_wire_transfer_delay),
      50          31 :     GNUNET_PQ_query_param_relative_time (&is->default_pay_delay),
      51          31 :     (NULL == is->website)
      52          31 :     ? GNUNET_PQ_query_param_null ()
      53          31 :     : GNUNET_PQ_query_param_string (is->website),
      54          31 :     (NULL == is->email)
      55          31 :     ? GNUNET_PQ_query_param_null ()
      56          31 :     : GNUNET_PQ_query_param_string (is->email),
      57          31 :     (NULL == is->logo)
      58          31 :     ? GNUNET_PQ_query_param_null ()
      59          31 :     : GNUNET_PQ_query_param_string (is->logo),
      60          31 :     (NULL == is->phone)
      61          31 :     ? GNUNET_PQ_query_param_null ()
      62          31 :     : GNUNET_PQ_query_param_string (is->phone),
      63          31 :     GNUNET_PQ_query_param_bool (validation_needed),
      64             :     GNUNET_PQ_query_param_end
      65             :   };
      66          31 :   struct GNUNET_PQ_QueryParam params_priv[] = {
      67          31 :     GNUNET_PQ_query_param_auto_from_type (merchant_priv),
      68          31 :     GNUNET_PQ_query_param_string (is->id),
      69             :     GNUNET_PQ_query_param_end
      70             :   };
      71             :   enum GNUNET_DB_QueryStatus qs;
      72             : 
      73          31 :   check_connection (pg);
      74          31 :   PREPARE (pg,
      75             :            "insert_instance",
      76             :            "INSERT INTO merchant_instances"
      77             :            "(merchant_pub"
      78             :            ",auth_hash"
      79             :            ",auth_salt"
      80             :            ",merchant_id"
      81             :            ",merchant_name"
      82             :            ",address"
      83             :            ",jurisdiction"
      84             :            ",use_stefan"
      85             :            ",default_wire_transfer_delay"
      86             :            ",default_pay_delay"
      87             :            ",website"
      88             :            ",email"
      89             :            ",logo"
      90             :            ",phone_number"
      91             :            ",validation_needed)"
      92             :            "VALUES"
      93             :            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)")
      94             :   ;
      95          31 :   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
      96             :                                            "insert_instance",
      97             :                                            params);
      98          31 :   if (qs <= 0)
      99           0 :     return qs;
     100          31 :   PREPARE (pg,
     101             :            "insert_keys",
     102             :            "INSERT INTO merchant_keys"
     103             :            "(merchant_priv"
     104             :            ",merchant_serial)"
     105             :            " SELECT $1, merchant_serial"
     106             :            " FROM merchant_instances"
     107             :            " WHERE merchant_id=$2");
     108          31 :   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     109             :                                              "insert_keys",
     110             :                                              params_priv);
     111             : }

Generated by: LCOV version 1.16