aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/plugin_exchangedb_postgres.c
diff options
context:
space:
mode:
authorJoseph <Joseph.xu@efrei.net>2022-11-08 07:28:17 -0500
committerJoseph <Joseph.xu@efrei.net>2022-11-08 07:28:17 -0500
commite43e2a9b29540d37b37d5539c8d0087ce89b501f (patch)
tree2f010e1b1624db643b1be169153b4a07de4e452c /src/exchangedb/plugin_exchangedb_postgres.c
parent55f1217a3313876a8c5f5ea24be9bd81dc922910 (diff)
downloadexchange-e43e2a9b29540d37b37d5539c8d0087ce89b501f.tar.xz
-move two more functions
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c181
1 files changed, 9 insertions, 172 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index e7e9ff0ec..75e70493c 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;
}