diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-08 15:15:39 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-08 15:15:39 +0100 |
commit | 0c32c48ac5628b2068fada9fc43fa0fa94d1c002 (patch) | |
tree | 64710d4bdb4b934a6dec972aa1bfaf07bc3859fb /src/exchangedb/pg_insert_purse_request.c | |
parent | fe18c104d8a8d3667b3c872078549c7e78c71db0 (diff) | |
parent | 354bbfa1e5475e3fbf5c885c4ff6fc513968bebd (diff) | |
download | exchange-0c32c48ac5628b2068fada9fc43fa0fa94d1c002.tar.xz |
Merge branch 'master' of git+ssh://git.taler.net/exchange
Diffstat (limited to 'src/exchangedb/pg_insert_purse_request.c')
-rw-r--r-- | src/exchangedb/pg_insert_purse_request.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/exchangedb/pg_insert_purse_request.c b/src/exchangedb/pg_insert_purse_request.c new file mode 100644 index 000000000..88ce36ead --- /dev/null +++ b/src/exchangedb/pg_insert_purse_request.c @@ -0,0 +1,109 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_insert_purse_request.c + * @brief Implementation of the insert_purse_request function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_insert_purse_request.h" +#include "pg_get_purse_request.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TEH_PG_insert_purse_request ( + void *cls, + const struct TALER_PurseContractPublicKeyP *purse_pub, + const struct TALER_PurseMergePublicKeyP *merge_pub, + struct GNUNET_TIME_Timestamp purse_expiration, + const struct TALER_PrivateContractHashP *h_contract_terms, + uint32_t age_limit, + enum TALER_WalletAccountMergeFlags flags, + const struct TALER_Amount *purse_fee, + const struct TALER_Amount *amount, + const struct TALER_PurseContractSignatureP *purse_sig, + bool *in_conflict) +{ + struct PostgresClosure *pg = cls; + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); + uint32_t flags32 = (uint32_t) flags; + bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA + == (flags & TALER_WAMF_MERGE_MODE_MASK)); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (purse_pub), + GNUNET_PQ_query_param_auto_from_type (merge_pub), + GNUNET_PQ_query_param_timestamp (&now), + GNUNET_PQ_query_param_timestamp (&purse_expiration), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_uint32 (&age_limit), + GNUNET_PQ_query_param_uint32 (&flags32), + GNUNET_PQ_query_param_bool (in_reserve_quota), + TALER_PQ_query_param_amount (amount), + TALER_PQ_query_param_amount (purse_fee), + GNUNET_PQ_query_param_auto_from_type (purse_sig), + GNUNET_PQ_query_param_end + }; + + *in_conflict = false; + qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_purse_request", + params); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs) + return qs; + { + struct TALER_PurseMergePublicKeyP merge_pub2; + struct GNUNET_TIME_Timestamp purse_expiration2; + struct TALER_PrivateContractHashP h_contract_terms2; + uint32_t age_limit2; + struct TALER_Amount amount2; + struct TALER_Amount balance; + struct TALER_PurseContractSignatureP purse_sig2; + + qs = TEH_PG_get_purse_request (pg, + purse_pub, + &merge_pub2, + &purse_expiration2, + &h_contract_terms2, + &age_limit2, + &amount2, + &balance, + &purse_sig2); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + if ( (age_limit2 == age_limit) && + (0 == TALER_amount_cmp (amount, + &amount2)) && + (0 == GNUNET_memcmp (&h_contract_terms2, + h_contract_terms)) && + (0 == GNUNET_memcmp (&merge_pub2, + merge_pub)) ) + { + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + } + *in_conflict = true; + return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; + } +} + + |