LCOV - code coverage report
Current view: top level - exchangedb - persist_aml_program_result.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 49.0 % 51 25
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 Affero 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 Affero General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU Affero General Public License along with
      14              :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15              : */
      16              : /**
      17              :  * @file persist_aml_program_result.c
      18              :  * @brief helper function store results of AML programs
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_exchangedb_lib.h"
      22              : #include "taler/taler_kyclogic_lib.h"
      23              : #include "exchange-database/insert_aml_decision.h"
      24              : #include "exchange-database/insert_aml_program_failure.h"
      25              : #include "exchange-database/insert_successor_measure.h"
      26              : #include "exchange-database/persist_aml_program_result.h"
      27              : #include "helper.h"
      28              : #include <gnunet/gnunet_common.h>
      29              : 
      30              : 
      31              : enum GNUNET_DB_QueryStatus
      32           10 : TALER_EXCHANGEDB_persist_aml_program_result (
      33              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      34              :   uint64_t process_row,
      35              :   const struct TALER_NormalizedPaytoHashP *account_id,
      36              :   const struct TALER_KYCLOGIC_AmlProgramResult *apr,
      37              :   enum TALER_EXCHANGEDB_PersistProgramResultStatus *ret_pprs)
      38              : {
      39              :   enum GNUNET_DB_QueryStatus qs;
      40           10 :   json_t *jmeasures = NULL;
      41           10 :   struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs = NULL;
      42              : 
      43           10 :   GNUNET_assert (NULL != ret_pprs);
      44              : 
      45           10 :   *ret_pprs = TALER_EXCHANGEDB_PPRS_OK;
      46              : 
      47           10 :   if ( (TALER_KYCLOGIC_AMLR_SUCCESS == apr->status) &&
      48           10 :        (NULL != apr->details.success.new_measures) )
      49              :   {
      50            0 :     lrs = TALER_KYCLOGIC_rules_parse (apr->details.success.new_rules);
      51            0 :     if (NULL == lrs)
      52              :     {
      53            0 :       qs = TALER_EXCHANGEDB_insert_aml_program_failure (
      54              :         pg,
      55              :         process_row,
      56              :         account_id,
      57              :         "Failed to parse AML program output",
      58              :         TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
      59            0 :       GNUNET_break (qs > 0);
      60            0 :       return qs;
      61              :     }
      62            0 :     jmeasures = TALER_KYCLOGIC_get_jmeasures (
      63              :       lrs,
      64            0 :       apr->details.success.new_measures);
      65            0 :     if (NULL == jmeasures)
      66              :     {
      67              :       char *err;
      68              : 
      69            0 :       GNUNET_break (0);
      70            0 :       GNUNET_asprintf (&err,
      71              :                        "Failed to find measures `%s' specified in AML program output",
      72            0 :                        apr->details.success.new_measures);
      73            0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      74              :                   "AML program specified invalid measures `%s'\n",
      75              :                   apr->details.success.new_measures);
      76            0 :       qs = TALER_EXCHANGEDB_insert_aml_program_failure (
      77              :         pg,
      78              :         process_row,
      79              :         account_id,
      80              :         err,
      81              :         TALER_EC_EXCHANGE_KYC_AML_PROGRAM_MALFORMED_RESULT);
      82            0 :       *ret_pprs = TALER_EXCHANGEDB_PPRS_BAD_OUTCOME;
      83            0 :       TALER_KYCLOGIC_rules_free (lrs);
      84            0 :       GNUNET_free (err);
      85            0 :       GNUNET_break (qs > 0);
      86            0 :       return qs;
      87              :     }
      88              :   }
      89              : 
      90           10 :   qs = TALER_EXCHANGEDB_clear_aml_lock (
      91              :     pg,
      92              :     account_id);
      93           10 :   switch (apr->status)
      94              :   {
      95            0 :   case TALER_KYCLOGIC_AMLR_FAILURE:
      96            0 :     qs = TALER_EXCHANGEDB_insert_aml_program_failure (
      97              :       pg,
      98              :       process_row,
      99              :       account_id,
     100            0 :       apr->details.failure.error_message,
     101            0 :       apr->details.failure.ec);
     102            0 :     GNUNET_break (qs > 0);
     103            0 :     goto cleanup;
     104           10 :   case TALER_KYCLOGIC_AMLR_SUCCESS:
     105              :     {
     106           10 :       struct TALER_FullPayto null_payto_uri = { 0 };
     107              :       bool invalid_officer;
     108              :       bool unknown_account;
     109              :       struct GNUNET_TIME_Timestamp last_date;
     110              :       uint64_t legitimization_measure_serial_id;
     111              :       bool is_wallet;
     112              : 
     113           10 :       qs = TALER_EXCHANGEDB_insert_aml_decision (
     114              :         pg,
     115              :         null_payto_uri,
     116              :         account_id,
     117              :         GNUNET_TIME_timestamp_get (),
     118              :         apr->details.success.expiration_time,
     119           10 :         apr->details.success.account_properties,
     120           10 :         apr->details.success.new_rules,
     121           10 :         apr->details.success.to_investigate,
     122           10 :         apr->details.success.new_measures,
     123              :         jmeasures,
     124              :         NULL, /* justification */
     125              :         NULL, /* decider_pub */
     126              :         NULL, /* decider_sig */
     127           10 :         apr->details.success.num_events,
     128           10 :         apr->details.success.events,
     129              :         NULL, /* form ID */
     130              :         0, /* enc_attributes_size*/
     131              :         NULL, /* enc_attributes*/
     132              :         NULL, /* attributes_hash */
     133           10 :         GNUNET_TIME_UNIT_ZERO_TS, /* attributes_expiration_time */
     134              :         &invalid_officer,
     135              :         &unknown_account,
     136              :         &last_date,
     137              :         &legitimization_measure_serial_id,
     138              :         &is_wallet);
     139           10 :       GNUNET_break (qs > 0);
     140           10 :       goto cleanup;
     141              :     }
     142              :   }
     143            0 :   GNUNET_break (0);
     144            0 :   qs = GNUNET_DB_STATUS_HARD_ERROR;
     145           10 : cleanup:
     146           10 :   TALER_KYCLOGIC_rules_free (lrs);
     147           10 :   json_decref (jmeasures);
     148           10 :   return qs;
     149              : }
        

Generated by: LCOV version 2.0-1