diff options
Diffstat (limited to 'src/exchangedb')
| -rw-r--r-- | src/exchangedb/Makefile.am | 2 | ||||
| -rw-r--r-- | src/exchangedb/pg_get_purse_request.c | 83 | ||||
| -rw-r--r-- | src/exchangedb/pg_get_purse_request.h | 57 | ||||
| -rw-r--r-- | src/exchangedb/pg_insert_purse_request.c | 109 | ||||
| -rw-r--r-- | src/exchangedb/pg_insert_purse_request.h | 61 | ||||
| -rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 181 | 
6 files changed, 321 insertions, 172 deletions
| diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index 4145c13c..f8182b76 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -72,11 +72,13 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \    pg_do_reserve_open.c pg_do_reserve_open.h \    pg_get_coin_transactions.c pg_get_coin_transactions.h \    pg_get_expired_reserves.c pg_get_expired_reserves.h \ +  pg_get_purse_request.c pg_get_purse_request.h \    pg_get_reserve_history.c pg_get_reserve_history.h \    pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \    pg_insert_close_request.c pg_insert_close_request.h \    pg_delete_aggregation_transient.h pg_delete_aggregation_transient.c \    pg_get_link_data.h pg_get_link_data.c \ +  pg_insert_purse_request.h pg_insert_purse_request.c \    pg_insert_records_by_table.c pg_insert_records_by_table.h \    pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h \    pg_iterate_kyc_reference.c pg_iterate_kyc_reference.h \ diff --git a/src/exchangedb/pg_get_purse_request.c b/src/exchangedb/pg_get_purse_request.c new file mode 100644 index 00000000..ba818285 --- /dev/null +++ b/src/exchangedb/pg_get_purse_request.c @@ -0,0 +1,83 @@ +/* +   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_template.c + * @brief Implementation of the template 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_get_purse_request.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TEH_PG_get_purse_request ( +  void *cls, +  const struct TALER_PurseContractPublicKeyP *purse_pub, +  struct TALER_PurseMergePublicKeyP *merge_pub, +  struct GNUNET_TIME_Timestamp *purse_expiration, +  struct TALER_PrivateContractHashP *h_contract_terms, +  uint32_t *age_limit, +  struct TALER_Amount *target_amount, +  struct TALER_Amount *balance, +  struct TALER_PurseContractSignatureP *purse_sig) +{ +  struct PostgresClosure *pg = cls; +  struct GNUNET_PQ_QueryParam params[] = { +    GNUNET_PQ_query_param_auto_from_type (purse_pub), +    GNUNET_PQ_query_param_end +  }; +  struct GNUNET_PQ_ResultSpec rs[] = { +    GNUNET_PQ_result_spec_auto_from_type ("merge_pub", +                                          merge_pub), +    GNUNET_PQ_result_spec_timestamp ("purse_expiration", +                                     purse_expiration), +    GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", +                                          h_contract_terms), +    GNUNET_PQ_result_spec_uint32 ("age_limit", +                                  age_limit), +    TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", +                                 target_amount), +    TALER_PQ_RESULT_SPEC_AMOUNT ("balance", +                                 balance), +    GNUNET_PQ_result_spec_auto_from_type ("purse_sig", +                                          purse_sig), +    GNUNET_PQ_result_spec_end +  }; +   +  PREPARE (pg, +           "get_purse_request", +           "SELECT " +           " merge_pub" +           ",purse_expiration" +           ",h_contract_terms" +           ",age_limit" +           ",amount_with_fee_val" +           ",amount_with_fee_frac" +           ",balance_val" +           ",balance_frac" +           ",purse_sig" +           " FROM purse_requests" +           " WHERE purse_pub=$1;"); + +  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, +                                                   "get_purse_request", +                                                   params, +                                                   rs); +} + diff --git a/src/exchangedb/pg_get_purse_request.h b/src/exchangedb/pg_get_purse_request.h new file mode 100644 index 00000000..24620e1b --- /dev/null +++ b/src/exchangedb/pg_get_purse_request.h @@ -0,0 +1,57 @@ +/* +   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_get_purse_request.h + * @brief implementation of the get_purse_request function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_GET_PURSE_REQUEST_H +#define PG_GET_PURSE_REQUEST_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_exchangedb_plugin.h" + +/** + * Function called to return meta data about a purse by the + * purse public key. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param purse_pub public key of the purse + * @param[out] merge_pub public key representing the merge capability + * @param[out] purse_expiration when would an unmerged purse expire + * @param[out] h_contract_terms contract associated with the purse + * @param[out] age_limit the age limit for deposits into the purse + * @param[out] target_amount amount to be put into the purse + * @param[out] balance amount put so far into the purse + * @param[out] purse_sig signature of the purse over the initialization data + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_get_purse_request ( +  void *cls, +  const struct TALER_PurseContractPublicKeyP *purse_pub, +  struct TALER_PurseMergePublicKeyP *merge_pub, +  struct GNUNET_TIME_Timestamp *purse_expiration, +  struct TALER_PrivateContractHashP *h_contract_terms, +  uint32_t *age_limit, +  struct TALER_Amount *target_amount, +  struct TALER_Amount *balance, +  struct TALER_PurseContractSignatureP *purse_sig); + +#endif diff --git a/src/exchangedb/pg_insert_purse_request.c b/src/exchangedb/pg_insert_purse_request.c new file mode 100644 index 00000000..88ce36ea --- /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; +  } +} + + diff --git a/src/exchangedb/pg_insert_purse_request.h b/src/exchangedb/pg_insert_purse_request.h new file mode 100644 index 00000000..37cce2a9 --- /dev/null +++ b/src/exchangedb/pg_insert_purse_request.h @@ -0,0 +1,61 @@ +/* +   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.h + * @brief implementation of the insert_purse_request function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_INSERT_PURSE_REQUEST_H +#define PG_INSERT_PURSE_REQUEST_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_exchangedb_plugin.h" + +/** + * Function called to create a new purse with certain meta data. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param purse_pub public key of the new purse + * @param merge_pub public key providing the merge capability + * @param purse_expiration time when the purse will expire + * @param h_contract_terms hash of the contract for the purse + * @param age_limit age limit to enforce for payments into the purse + * @param flags flags for the operation + * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags) + * @param amount target amount (with fees) to be put into the purse + * @param purse_sig signature with @a purse_pub's private key affirming the above + * @param[out] in_conflict set to true if the meta data + *             conflicts with an existing purse; + *             in this case, the return value will be + *             #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure + * @return transaction status code + */ +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); + +#endif diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index e7e9ff0e..75e70493 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -36,6 +36,7 @@  #include "pg_do_reserve_open.h"  #include "pg_get_coin_transactions.h"  #include "pg_get_expired_reserves.h" +#include "pg_get_purse_request.h"  #include "pg_get_reserve_history.h"  #include "pg_get_unfinished_close_requests.h"  #include "pg_insert_close_request.h" @@ -58,6 +59,9 @@  #include <pthread.h>  #include <libpq-fe.h> +/**WHAT I ADD**/ +#include "pg_insert_purse_request.h" +  /**   * Set to 1 to enable Postgres auto_explain module. This will @@ -2139,21 +2143,6 @@ prepare_statements (struct PostgresClosure *pg)        "  ) VALUES "        "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"        "  ON CONFLICT DO NOTHING;"), -    /* Used in #postgres_get_purse_request */ -    GNUNET_PQ_make_prepare ( -      "get_purse_request", -      "SELECT " -      " merge_pub" -      ",purse_expiration" -      ",h_contract_terms" -      ",age_limit" -      ",amount_with_fee_val" -      ",amount_with_fee_frac" -      ",balance_val" -      ",balance_frac" -      ",purse_sig" -      " FROM purse_requests" -      " WHERE purse_pub=$1;"),      /* Used in #postgres_select_purse_by_merge_pub */      GNUNET_PQ_make_prepare (        "select_purse_by_merge_pub", @@ -10684,159 +10673,6 @@ postgres_insert_contract (  } -/** - * Function called to return meta data about a purse by the - * purse public key. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param purse_pub public key of the purse - * @param[out] merge_pub public key representing the merge capability - * @param[out] purse_expiration when would an unmerged purse expire - * @param[out] h_contract_terms contract associated with the purse - * @param[out] age_limit the age limit for deposits into the purse - * @param[out] target_amount amount to be put into the purse - * @param[out] balance amount put so far into the purse - * @param[out] purse_sig signature of the purse over the initialization data - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_get_purse_request ( -  void *cls, -  const struct TALER_PurseContractPublicKeyP *purse_pub, -  struct TALER_PurseMergePublicKeyP *merge_pub, -  struct GNUNET_TIME_Timestamp *purse_expiration, -  struct TALER_PrivateContractHashP *h_contract_terms, -  uint32_t *age_limit, -  struct TALER_Amount *target_amount, -  struct TALER_Amount *balance, -  struct TALER_PurseContractSignatureP *purse_sig) -{ -  struct PostgresClosure *pg = cls; -  struct GNUNET_PQ_QueryParam params[] = { -    GNUNET_PQ_query_param_auto_from_type (purse_pub), -    GNUNET_PQ_query_param_end -  }; -  struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_auto_from_type ("merge_pub", -                                          merge_pub), -    GNUNET_PQ_result_spec_timestamp ("purse_expiration", -                                     purse_expiration), -    GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", -                                          h_contract_terms), -    GNUNET_PQ_result_spec_uint32 ("age_limit", -                                  age_limit), -    TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", -                                 target_amount), -    TALER_PQ_RESULT_SPEC_AMOUNT ("balance", -                                 balance), -    GNUNET_PQ_result_spec_auto_from_type ("purse_sig", -                                          purse_sig), -    GNUNET_PQ_result_spec_end -  }; -  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, -                                                   "get_purse_request", -                                                   params, -                                                   rs); -} - - -/** - * Function called to create a new purse with certain meta data. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param purse_pub public key of the new purse - * @param merge_pub public key providing the merge capability - * @param purse_expiration time when the purse will expire - * @param h_contract_terms hash of the contract for the purse - * @param age_limit age limit to enforce for payments into the purse - * @param flags flags for the operation - * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags) - * @param amount target amount (with fees) to be put into the purse - * @param purse_sig signature with @a purse_pub's private key affirming the above - * @param[out] in_conflict set to true if the meta data - *             conflicts with an existing purse; - *             in this case, the return value will be - *             #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_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 = postgres_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; -  } -}  /** @@ -12422,10 +12258,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)      = &postgres_select_contract;    plugin->select_contract_by_purse      = &postgres_select_contract_by_purse; -  plugin->insert_purse_request -    = &postgres_insert_purse_request; -  plugin->get_purse_request -    = &postgres_get_purse_request;    plugin->expire_purse      = &postgres_expire_purse;    plugin->select_purse_by_merge_pub @@ -12483,6 +12315,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)      = &TEH_PG_get_coin_transactions;    plugin->get_expired_reserves      = &TEH_PG_get_expired_reserves; +  plugin->get_purse_request +    = &TEH_PG_get_purse_request;    plugin->get_reserve_history      = &TEH_PG_get_reserve_history;    plugin->get_reserve_status @@ -12525,6 +12359,9 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)      = &TEH_PG_select_reserve_closed_above_serial_id;    plugin->select_reserve_open_above_serial_id      = &TEH_PG_select_reserve_open_above_serial_id; +  plugin->insert_purse_request +    = &TEH_PG_insert_purse_request; +     return plugin;  } | 
