sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

syncdb_store_payment_TR.c (2919B)


      1 /*
      2   This file is part of TALER
      3   (C) 2014--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 Lesser 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 syncdb/syncdb_store_payment_TR.c
     18  * @brief store payment for sync database
     19  * @author Christian Grothoff
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 
     24 enum SYNC_DB_QueryStatus
     25 SYNCDB_store_payment_TR (
     26   const struct SYNC_AccountPublicKeyP *account_pub,
     27   const char *order_id,
     28   const struct TALER_ClaimTokenP *token,
     29   const struct TALER_Amount *amount,
     30   struct GNUNET_TIME_Relative lifetime)
     31 {
     32   struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
     33   /* all-zero claim token means "no claim token" */
     34   struct TALER_ClaimTokenP tok = { 0 };
     35   bool inserted;
     36   struct GNUNET_PQ_QueryParam params[] = {
     37     GNUNET_PQ_query_param_auto_from_type (account_pub),
     38     GNUNET_PQ_query_param_string (order_id),
     39     GNUNET_PQ_query_param_auto_from_type (&tok),
     40     GNUNET_PQ_query_param_timestamp (&now),
     41     TALER_PQ_query_param_amount (pg->conn,
     42                                  amount),
     43     GNUNET_PQ_query_param_relative_time (&lifetime),
     44     GNUNET_PQ_query_param_timestamp (&now),
     45     GNUNET_PQ_query_param_end
     46   };
     47   struct GNUNET_PQ_ResultSpec rs[] = {
     48     GNUNET_PQ_result_spec_bool ("out_inserted",
     49                                 &inserted),
     50     GNUNET_PQ_result_spec_end
     51   };
     52   enum GNUNET_DB_QueryStatus qs;
     53 
     54   if (NULL != token)
     55     tok = *token;
     56   SYNCDB_preflight ();
     57   PREPARE ("do_store_payment",
     58            "SELECT"
     59            " out_inserted"
     60            " FROM sync_do_store_payment"
     61            " ($1,$2,$3,$4,$5,$6,$7)");
     62   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     63                                                  "do_store_payment",
     64                                                  params,
     65                                                  rs);
     66   switch (qs)
     67   {
     68   case GNUNET_DB_STATUS_HARD_ERROR:
     69     return SYNC_DB_HARD_ERROR;
     70   case GNUNET_DB_STATUS_SOFT_ERROR:
     71     GNUNET_break (0);
     72     return SYNC_DB_SOFT_ERROR;
     73   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     74     GNUNET_break (0);
     75     return SYNC_DB_HARD_ERROR;
     76   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     77     if (! inserted)
     78     {
     79       GNUNET_break (0);
     80       return SYNC_DB_NO_RESULTS;
     81     }
     82     return SYNC_DB_ONE_RESULT;
     83   default:
     84     GNUNET_break (0);
     85     return SYNC_DB_HARD_ERROR;
     86   }
     87 }
     88 
     89 
     90 /* end of syncdb_store_payment_TR.c */