LCOV - code coverage report
Current view: top level - exchangedb - pg_insert_aml_decision.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.3 % 60 56
Test Date: 2025-12-28 14:06:02 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 exchangedb/pg_insert_aml_decision.c
      18              :  * @brief Implementation of the insert_aml_decision 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_insert_aml_decision.h"
      26              : #include "pg_helper.h"
      27              : #include <gnunet/gnunet_pq_lib.h>
      28              : 
      29              : 
      30              : enum GNUNET_DB_QueryStatus
      31           13 : TEH_PG_insert_aml_decision (
      32              :   void *cls,
      33              :   const struct TALER_FullPayto payto_uri,
      34              :   const struct TALER_NormalizedPaytoHashP *h_payto,
      35              :   struct GNUNET_TIME_Timestamp decision_time,
      36              :   struct GNUNET_TIME_Timestamp expiration_time,
      37              :   const json_t *properties,
      38              :   const json_t *new_rules,
      39              :   bool to_investigate,
      40              :   const char *new_measure_name,
      41              :   const json_t *jmeasures,
      42              :   const char *justification,
      43              :   const struct TALER_AmlOfficerPublicKeyP *decider_pub,
      44              :   const struct TALER_AmlOfficerSignatureP *decider_sig,
      45              :   size_t num_events,
      46              :   const char *events[static num_events],
      47              :   const char *form_name,
      48              :   size_t enc_attributes_size,
      49              :   const void *enc_attributes,
      50              :   struct GNUNET_HashCode *attributes_hash,
      51              :   struct GNUNET_TIME_Timestamp attributes_expiration_time,
      52              :   bool *invalid_officer,
      53              :   bool *unknown_account,
      54              :   struct GNUNET_TIME_Timestamp *last_date,
      55              :   uint64_t *legitimization_measure_serial_id,
      56              :   bool *is_wallet)
      57           13 : {
      58           13 :   struct PostgresClosure *pg = cls;
      59           13 :   struct TALER_KycCompletedEventP rep = {
      60           13 :     .header.size = htons (sizeof (rep)),
      61           13 :     .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
      62              :     .h_payto = *h_payto
      63              :   };
      64              :   struct TALER_FullPaytoHashP h_full_payto;
      65              :   char *notify_s
      66           13 :     = GNUNET_PQ_get_event_notify_channel (&rep.header);
      67              :   bool account_unknown;
      68           13 :   struct GNUNET_PQ_QueryParam params[] = {
      69              :     /* $1: in_payto_uri */
      70           13 :     NULL == payto_uri.full_payto
      71           13 :       ? GNUNET_PQ_query_param_null ()
      72           13 :       : GNUNET_PQ_query_param_string (payto_uri.full_payto),
      73              :     /* $2: in_h_normalized_payto */
      74           13 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
      75              :     /* $3: in_h_full_payto */
      76           13 :     NULL == payto_uri.full_payto
      77           13 :       ? GNUNET_PQ_query_param_null ()
      78           13 :       : GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
      79              :     /* $4: in_decision_time */
      80           13 :     GNUNET_PQ_query_param_timestamp (&decision_time),
      81              :     /* $5: in_expiration_time*/
      82           13 :     GNUNET_PQ_query_param_timestamp (&expiration_time),
      83              :     /* $6: in_properties */
      84              :     NULL != properties
      85            3 :       ? TALER_PQ_query_param_json (properties)
      86           13 :       : GNUNET_PQ_query_param_null (),
      87              :     /* $7: in_kyc_attributes_enc */
      88              :     NULL != enc_attributes
      89            0 :       ? GNUNET_PQ_query_param_fixed_size (enc_attributes,
      90              :                                           enc_attributes_size)
      91           13 :       : GNUNET_PQ_query_param_null (),
      92              :     /* $8: in_kyc_attributes_hash */
      93              :     NULL != attributes_hash
      94            0 :         ? GNUNET_PQ_query_param_auto_from_type (attributes_hash)
      95           13 :         : GNUNET_PQ_query_param_null (),
      96              :     /* $9: in_kyc_attributes_expiration */
      97           13 :     GNUNET_PQ_query_param_timestamp (&attributes_expiration_time),
      98              :     /* $10: in_new_rules */
      99           13 :     TALER_PQ_query_param_json (new_rules),
     100              :     /* $11: in_to_investigate */
     101           13 :     GNUNET_PQ_query_param_bool (to_investigate),
     102              :     /* $12: in_new_measure_name */
     103              :     NULL != new_measure_name
     104            1 :       ? GNUNET_PQ_query_param_string (new_measure_name)
     105           13 :       : GNUNET_PQ_query_param_null (),
     106              :     /* $13: in_jmeasures */
     107              :     NULL != jmeasures
     108            1 :       ? TALER_PQ_query_param_json (jmeasures)
     109           13 :       : GNUNET_PQ_query_param_null (),
     110              :     /* $14: in_justification */
     111              :     NULL != justification
     112            3 :       ? GNUNET_PQ_query_param_string (justification)
     113           13 :       : GNUNET_PQ_query_param_null (),
     114              :     /* $15: in_decider_pub */
     115              :     NULL != decider_pub
     116            3 :       ? GNUNET_PQ_query_param_auto_from_type (decider_pub)
     117           13 :       : GNUNET_PQ_query_param_null (),
     118              :     /* $16: in_decider_sig */
     119              :     NULL != decider_sig
     120            3 :       ? GNUNET_PQ_query_param_auto_from_type (decider_sig)
     121           13 :       : GNUNET_PQ_query_param_null (),
     122              :     /* $17: in_notify_s*/
     123           13 :     GNUNET_PQ_query_param_string (notify_s),
     124              :     /* $18: ina_events */
     125           13 :     GNUNET_PQ_query_param_array_ptrs_string (num_events,
     126              :                                              events,
     127              :                                              pg->conn),
     128              :     (NULL == form_name)
     129           13 :     ? GNUNET_PQ_query_param_null ()
     130           13 :     : GNUNET_PQ_query_param_string (form_name),
     131              :     GNUNET_PQ_query_param_end
     132              :   };
     133           13 :   struct GNUNET_PQ_ResultSpec rs[] = {
     134           13 :     GNUNET_PQ_result_spec_bool ("out_invalid_officer",
     135              :                                 invalid_officer),
     136           13 :     GNUNET_PQ_result_spec_bool ("out_account_unknown",
     137              :                                 unknown_account),
     138           13 :     GNUNET_PQ_result_spec_timestamp ("out_last_date",
     139              :                                      last_date),
     140           13 :     GNUNET_PQ_result_spec_uint64 ("out_legitimization_measure_serial_id",
     141              :                                   legitimization_measure_serial_id),
     142           13 :     GNUNET_PQ_result_spec_allow_null (
     143              :       GNUNET_PQ_result_spec_bool ("out_is_wallet",
     144              :                                   is_wallet),
     145              :       &account_unknown),
     146              :     GNUNET_PQ_result_spec_end
     147              :   };
     148              :   enum GNUNET_DB_QueryStatus qs;
     149              : 
     150           13 :   *is_wallet = false;
     151           13 :   GNUNET_assert ( ( (NULL == decider_pub) &&
     152              :                     (NULL == decider_sig) &&
     153              :                     (NULL == justification) ) ||
     154              :                   ( (NULL != decider_pub) &&
     155              :                     (NULL != decider_sig) &&
     156              :                     (NULL != justification) ) );
     157              : 
     158           13 :   if (NULL != payto_uri.full_payto)
     159            0 :     TALER_full_payto_hash (payto_uri,
     160              :                            &h_full_payto);
     161           13 :   PREPARE (pg,
     162              :            "do_insert_aml_decision",
     163              :            "SELECT"
     164              :            " out_invalid_officer"
     165              :            ",out_account_unknown"
     166              :            ",out_last_date"
     167              :            ",out_legitimization_measure_serial_id"
     168              :            ",out_is_wallet"
     169              :            " FROM exchange_do_insert_aml_decision"
     170              :            "($1,$2,$3,$4,$5,$6::TEXT::JSONB,$7,$8,$9,$10::TEXT::JSONB"
     171              :            ",$11,$12,$13::TEXT::JSONB,$14,$15,$16,$17,$18,$19);");
     172           13 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     173              :                                                  "do_insert_aml_decision",
     174              :                                                  params,
     175              :                                                  rs);
     176           13 :   GNUNET_PQ_cleanup_query_params_closures (params);
     177           13 :   GNUNET_free (notify_s);
     178           13 :   GNUNET_PQ_event_do_poll (pg->conn);
     179           13 :   if (qs <= 0)
     180            0 :     return qs;
     181           13 :   if (account_unknown)
     182              :   {
     183            1 :     GNUNET_assert ((*invalid_officer) || (*unknown_account));
     184              :   }
     185           13 :   return qs;
     186              : }
        

Generated by: LCOV version 2.0-1