exchange

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

get_fee_time_inconsistency.c (4681B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 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 #include "taler/taler_pq_lib.h"
     17 #include "pg_helper.h"
     18 #include "auditor-database/get_fee_time_inconsistency.h"
     19 
     20 
     21 /**
     22  * Closure for #feetimeinconsistency_cb().
     23  */
     24 struct FeeTimeInconsistencyContext
     25 {
     26 
     27   /**
     28    * Function to call for each fee time inconsistency
     29    */
     30   TALER_AUDITORDB_FeeTimeInconsistencyCallback cb;
     31 
     32   /**
     33    * Closure for @e cb
     34    */
     35   void *cb_cls;
     36 
     37   /**
     38    * Plugin context.
     39    */
     40   struct TALER_AUDITORDB_PostgresContext *pg;
     41 
     42   /**
     43    * Query status to return.
     44    */
     45   enum GNUNET_DB_QueryStatus qs;
     46 };
     47 
     48 
     49 /**
     50  * Helper function for #TALER_AUDITORDB_get_emergency().
     51  * To be called with the results of a SELECT statement
     52  * that has returned @a num_results results.
     53  *
     54  * @param cls closure of type `struct Emergency *`
     55  * @param result the postgres result
     56  * @param num_results the number of results in @a result
     57  */
     58 static void
     59 fee_time_inconsistency_cb (void *cls,
     60                            PGresult *result,
     61                            unsigned int num_results)
     62 {
     63   struct FeeTimeInconsistencyContext *dcc = cls;
     64   for (unsigned int i = 0; i < num_results; i++)
     65   {
     66     struct TALER_AUDITORDB_FeeTimeInconsistency dc;
     67     struct GNUNET_PQ_ResultSpec rs[] = {
     68       GNUNET_PQ_result_spec_uint64 ("row_id",
     69                                     &dc.row_id),
     70       GNUNET_PQ_result_spec_uint64 ("problem_row_id",
     71                                     &dc.problem_row_id),
     72       GNUNET_PQ_result_spec_string ("fee_type",
     73                                     &dc.type),
     74       GNUNET_PQ_result_spec_absolute_time ("fee_time",
     75                                            &dc.time),
     76       GNUNET_PQ_result_spec_string ("diagnostic",
     77                                     &dc.diagnostic),
     78       GNUNET_PQ_result_spec_end
     79     };
     80     enum GNUNET_GenericReturnValue rval;
     81 
     82     if (GNUNET_OK !=
     83         GNUNET_PQ_extract_result (result,
     84                                   rs,
     85                                   i))
     86     {
     87       GNUNET_break (0);
     88       dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
     89       return;
     90     }
     91     dcc->qs = i + 1;
     92     rval = dcc->cb (dcc->cb_cls,
     93                     &dc);
     94     GNUNET_PQ_cleanup_result (rs);
     95     if (GNUNET_OK != rval)
     96       break;
     97   }
     98 }
     99 
    100 
    101 enum GNUNET_DB_QueryStatus
    102 TALER_AUDITORDB_get_fee_time_inconsistency (
    103   struct TALER_AUDITORDB_PostgresContext *pg,
    104   int64_t limit,
    105   uint64_t offset,
    106   bool return_suppressed,
    107   TALER_AUDITORDB_FeeTimeInconsistencyCallback cb,
    108   void *cb_cls)
    109 {
    110   uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
    111   struct GNUNET_PQ_QueryParam params[] = {
    112     GNUNET_PQ_query_param_uint64 (&offset),
    113     GNUNET_PQ_query_param_bool (return_suppressed),
    114     GNUNET_PQ_query_param_uint64 (&plimit),
    115     GNUNET_PQ_query_param_end
    116   };
    117   struct FeeTimeInconsistencyContext dcc = {
    118     .cb = cb,
    119     .cb_cls = cb_cls,
    120     .pg = pg
    121   };
    122   enum GNUNET_DB_QueryStatus qs;
    123 
    124   PREPARE (pg,
    125            "auditor_fee_time_inconsistency_get_desc",
    126            "SELECT"
    127            " row_id"
    128            ",problem_row_id"
    129            ",fee_type"
    130            ",fee_time"
    131            ",diagnostic"
    132            " FROM auditor_fee_time_inconsistency"
    133            " WHERE (row_id < $1)"
    134            " AND ($2 OR NOT suppressed)"
    135            " ORDER BY row_id DESC"
    136            " LIMIT $3"
    137            );
    138   PREPARE (pg,
    139            "auditor_fee_time_inconsistency_get_asc",
    140            "SELECT"
    141            " row_id"
    142            ",problem_row_id"
    143            ",fee_type"
    144            ",fee_time"
    145            ",diagnostic"
    146            " FROM auditor_fee_time_inconsistency"
    147            " WHERE (row_id > $1)"
    148            " AND ($2 OR NOT suppressed)"
    149            " ORDER BY row_id ASC"
    150            " LIMIT $3"
    151            );
    152   qs = GNUNET_PQ_eval_prepared_multi_select (
    153     pg->conn,
    154     (limit > 0)
    155     ? "auditor_fee_time_inconsistency_get_asc"
    156     : "auditor_fee_time_inconsistency_get_desc",
    157     params,
    158     &fee_time_inconsistency_cb,
    159     &dcc);
    160   if (qs > 0)
    161     return dcc.qs;
    162   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
    163   return qs;
    164 }