anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

do_insert_recdoc_payment.c (2617B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020-2026 Anastasis SARL
      4 
      5   Anastasis 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   Anastasis 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   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file stasis/do_insert_recdoc_payment.c
     18  * @brief Anastasis database: record the start of a recovery document payment
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "anastasis-db_pg.h"
     23 #include "anastasis/anastasis-database/do_insert_recdoc_payment.h"
     24 #include "anastasis/anastasis-database/preflight.h"
     25 #include <taler/taler_pq_lib.h>
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 ANASTASIS_DB_do_insert_recdoc_payment (
     30   const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub,
     31   uint32_t post_counter,
     32   const struct ANASTASIS_PaymentSecretP *payment_secret,
     33   const struct TALER_Amount *amount)
     34 {
     35   struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
     36   struct GNUNET_TIME_Timestamp transient_expiration
     37     = GNUNET_TIME_relative_to_timestamp (TRANSIENT_LIFETIME);
     38   struct GNUNET_PQ_QueryParam params[] = {
     39     GNUNET_PQ_query_param_auto_from_type (account_pub),
     40     GNUNET_PQ_query_param_uint32 (&post_counter),
     41     TALER_PQ_query_param_amount (pg->conn,
     42                                  amount),
     43     GNUNET_PQ_query_param_auto_from_type (payment_secret),
     44     GNUNET_PQ_query_param_timestamp (&now),
     45     GNUNET_PQ_query_param_timestamp (&transient_expiration),
     46     GNUNET_PQ_query_param_end
     47   };
     48 
     49   GNUNET_break (GNUNET_OK ==
     50                 ANASTASIS_DB_preflight ());
     51   /* Creating the account and recording the payment happen in one statement:
     52      they must not be separated, since the payment row references the account
     53      and two concurrent first uploads would otherwise collide. */
     54   PREPARE ("do_insert_recdoc_payment",
     55            "SELECT anastasis_do_insert_recdoc_payment"
     56            " ($1, $2, $3, $4, $5, $6);");
     57   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     58                                              "do_insert_recdoc_payment",
     59                                              params);
     60 }
     61 
     62 
     63 /* end of do_insert_recdoc_payment.c */