move a few more functions
This commit is contained in:
parent
354bbfa1e5
commit
4394079a5e
@ -71,6 +71,8 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
|
|||||||
plugin_exchangedb_postgres.c pg_helper.h \
|
plugin_exchangedb_postgres.c pg_helper.h \
|
||||||
pg_do_reserve_open.c pg_do_reserve_open.h \
|
pg_do_reserve_open.c pg_do_reserve_open.h \
|
||||||
pg_do_withdraw.h pg_do_withdraw.c \
|
pg_do_withdraw.h pg_do_withdraw.c \
|
||||||
|
pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
|
||||||
|
pg_commit.h pg_commit.c \
|
||||||
pg_get_coin_transactions.c pg_get_coin_transactions.h \
|
pg_get_coin_transactions.c pg_get_coin_transactions.h \
|
||||||
pg_get_expired_reserves.c pg_get_expired_reserves.h \
|
pg_get_expired_reserves.c pg_get_expired_reserves.h \
|
||||||
pg_get_purse_request.c pg_get_purse_request.h \
|
pg_get_purse_request.c pg_get_purse_request.h \
|
||||||
|
58
src/exchangedb/pg_commit.c
Normal file
58
src/exchangedb/pg_commit.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
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_commit.c
|
||||||
|
* @brief Implementation of the commit 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_commit.h"
|
||||||
|
#include "pg_helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit the current transaction of a database connection.
|
||||||
|
*
|
||||||
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
|
* @return final transaction status
|
||||||
|
*/
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_commit (void *cls)
|
||||||
|
{
|
||||||
|
struct PostgresClosure *pg = cls;
|
||||||
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
|
GNUNET_PQ_query_param_end
|
||||||
|
};
|
||||||
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
|
||||||
|
GNUNET_break (NULL != pg->transaction_name);
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
|
"Committing transaction `%s'\n",
|
||||||
|
pg->transaction_name);
|
||||||
|
/* used in #postgres_commit */
|
||||||
|
PREPARE (pg,
|
||||||
|
"do_commit",
|
||||||
|
"COMMIT");
|
||||||
|
|
||||||
|
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||||
|
"do_commit",
|
||||||
|
params);
|
||||||
|
pg->transaction_name = NULL;
|
||||||
|
return qs;
|
||||||
|
}
|
37
src/exchangedb/pg_commit.h
Normal file
37
src/exchangedb/pg_commit.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
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_commit.h
|
||||||
|
* @brief implementation of the commit function for Postgres
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
#ifndef PG_COMMIT_H
|
||||||
|
#define PG_COMMIT_H
|
||||||
|
|
||||||
|
#include "taler_util.h"
|
||||||
|
#include "taler_json_lib.h"
|
||||||
|
#include "taler_exchangedb_plugin.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit the current transaction of a database connection.
|
||||||
|
*
|
||||||
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
|
* @return final transaction status
|
||||||
|
*/
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_commit (void *cls);
|
||||||
|
|
||||||
|
#endif
|
86
src/exchangedb/pg_do_withdraw.c
Normal file
86
src/exchangedb/pg_do_withdraw.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
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_do_withdraw.c
|
||||||
|
* @brief Implementation of the do_withdraw 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_do_withdraw.h"
|
||||||
|
#include "pg_helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_do_withdraw (
|
||||||
|
void *cls,
|
||||||
|
const struct TALER_CsNonce *nonce,
|
||||||
|
const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
|
||||||
|
struct GNUNET_TIME_Timestamp now,
|
||||||
|
bool *found,
|
||||||
|
bool *balance_ok,
|
||||||
|
bool *nonce_ok,
|
||||||
|
uint64_t *ruuid)
|
||||||
|
{
|
||||||
|
struct PostgresClosure *pg = cls;
|
||||||
|
struct GNUNET_TIME_Timestamp gc;
|
||||||
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
|
NULL == nonce
|
||||||
|
? GNUNET_PQ_query_param_null ()
|
||||||
|
: GNUNET_PQ_query_param_auto_from_type (nonce),
|
||||||
|
TALER_PQ_query_param_amount (&collectable->amount_with_fee),
|
||||||
|
GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash),
|
||||||
|
GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
|
||||||
|
GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
|
||||||
|
GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
|
||||||
|
TALER_PQ_query_param_blinded_denom_sig (&collectable->sig),
|
||||||
|
GNUNET_PQ_query_param_timestamp (&now),
|
||||||
|
GNUNET_PQ_query_param_timestamp (&gc),
|
||||||
|
GNUNET_PQ_query_param_end
|
||||||
|
};
|
||||||
|
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||||
|
GNUNET_PQ_result_spec_bool ("reserve_found",
|
||||||
|
found),
|
||||||
|
GNUNET_PQ_result_spec_bool ("balance_ok",
|
||||||
|
balance_ok),
|
||||||
|
GNUNET_PQ_result_spec_bool ("nonce_ok",
|
||||||
|
nonce_ok),
|
||||||
|
GNUNET_PQ_result_spec_uint64 ("ruuid",
|
||||||
|
ruuid),
|
||||||
|
GNUNET_PQ_result_spec_end
|
||||||
|
};
|
||||||
|
|
||||||
|
PREPARE (pg,
|
||||||
|
"call_withdraw",
|
||||||
|
"SELECT "
|
||||||
|
" reserve_found"
|
||||||
|
",balance_ok"
|
||||||
|
",nonce_ok"
|
||||||
|
",ruuid"
|
||||||
|
" FROM exchange_do_withdraw"
|
||||||
|
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
|
||||||
|
gc = GNUNET_TIME_absolute_to_timestamp (
|
||||||
|
GNUNET_TIME_absolute_add (now.abs_time,
|
||||||
|
pg->legal_reserve_expiration_time));
|
||||||
|
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||||
|
"call_withdraw",
|
||||||
|
params,
|
||||||
|
rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
53
src/exchangedb/pg_do_withdraw.h
Normal file
53
src/exchangedb/pg_do_withdraw.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
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_do_withdraw.h
|
||||||
|
* @brief implementation of the do_withdraw function for Postgres
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
#ifndef PG_DO_WITHDRAW_H
|
||||||
|
#define PG_DO_WITHDRAW_H
|
||||||
|
|
||||||
|
#include "taler_util.h"
|
||||||
|
#include "taler_json_lib.h"
|
||||||
|
#include "taler_exchangedb_plugin.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform withdraw operation, checking for sufficient balance
|
||||||
|
* and possibly persisting the withdrawal details.
|
||||||
|
*
|
||||||
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
|
* @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
|
||||||
|
* @param[in,out] collectable corresponding collectable coin (blind signature) if a coin is found; possibly updated if a (different) signature exists already
|
||||||
|
* @param now current time (rounded)
|
||||||
|
* @param[out] found set to true if the reserve was found
|
||||||
|
* @param[out] balance_ok set to true if the balance was sufficient
|
||||||
|
* @param[out] nonce_ok set to false if the nonce was reused
|
||||||
|
* @param[out] ruuid set to the reserve's UUID (reserves table row)
|
||||||
|
* @return query execution status
|
||||||
|
*/
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_do_withdraw (
|
||||||
|
void *cls,
|
||||||
|
const struct TALER_CsNonce *nonce,
|
||||||
|
const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
|
||||||
|
struct GNUNET_TIME_Timestamp now,
|
||||||
|
bool *found,
|
||||||
|
bool *balance_ok,
|
||||||
|
bool *nonce_ok,
|
||||||
|
uint64_t *ruuid);
|
||||||
|
|
||||||
|
#endif
|
145
src/exchangedb/pg_iterate_active_signkeys.c
Normal file
145
src/exchangedb/pg_iterate_active_signkeys.c
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
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_iterate_active_signkeys.c
|
||||||
|
* @brief Implementation of the iterate_active_signkeys 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_iterate_active_signkeys.h"
|
||||||
|
#include "pg_helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closure for #signkeys_cb_helper()
|
||||||
|
*/
|
||||||
|
struct SignkeysIteratorContext
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Function to call with the results.
|
||||||
|
*/
|
||||||
|
TALER_EXCHANGEDB_ActiveSignkeysCallback cb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closure to pass to @e cb
|
||||||
|
*/
|
||||||
|
void *cb_cls;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for #postgres_iterate_active_signkeys().
|
||||||
|
* Calls the callback with each signkey.
|
||||||
|
*
|
||||||
|
* @param cls a `struct SignkeysIteratorContext`
|
||||||
|
* @param result db results
|
||||||
|
* @param num_results number of results in @a result
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
signkeys_cb_helper (void *cls,
|
||||||
|
PGresult *result,
|
||||||
|
unsigned int num_results)
|
||||||
|
{
|
||||||
|
struct SignkeysIteratorContext *dic = cls;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i<num_results; i++)
|
||||||
|
{
|
||||||
|
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
|
||||||
|
struct TALER_ExchangePublicKeyP exchange_pub;
|
||||||
|
struct TALER_MasterSignatureP master_sig;
|
||||||
|
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||||
|
GNUNET_PQ_result_spec_auto_from_type ("master_sig",
|
||||||
|
&master_sig),
|
||||||
|
GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
|
||||||
|
&exchange_pub),
|
||||||
|
GNUNET_PQ_result_spec_timestamp ("valid_from",
|
||||||
|
&meta.start),
|
||||||
|
GNUNET_PQ_result_spec_timestamp ("expire_sign",
|
||||||
|
&meta.expire_sign),
|
||||||
|
GNUNET_PQ_result_spec_timestamp ("expire_legal",
|
||||||
|
&meta.expire_legal),
|
||||||
|
GNUNET_PQ_result_spec_end
|
||||||
|
};
|
||||||
|
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
GNUNET_PQ_extract_result (result,
|
||||||
|
rs,
|
||||||
|
i))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dic->cb (dic->cb_cls,
|
||||||
|
&exchange_pub,
|
||||||
|
&meta,
|
||||||
|
&master_sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function called to invoke @a cb on every non-revoked exchange signing key
|
||||||
|
* that has been signed by the master key. Revoked and (for signing!)
|
||||||
|
* expired keys are skipped. Runs in its own read-only transaction.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param cb function to call on each signing key
|
||||||
|
* @param cb_cls closure for @a cb
|
||||||
|
* @return transaction status code
|
||||||
|
*/
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_iterate_active_signkeys (void *cls,
|
||||||
|
TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
|
||||||
|
void *cb_cls)
|
||||||
|
{
|
||||||
|
struct PostgresClosure *pg = cls;
|
||||||
|
struct GNUNET_TIME_Absolute now = {0};
|
||||||
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
|
GNUNET_PQ_query_param_absolute_time (&now),
|
||||||
|
GNUNET_PQ_query_param_end
|
||||||
|
};
|
||||||
|
struct SignkeysIteratorContext dic = {
|
||||||
|
.cb = cb,
|
||||||
|
.cb_cls = cb_cls,
|
||||||
|
};
|
||||||
|
|
||||||
|
PREPARE (pg,
|
||||||
|
"select_signkeys",
|
||||||
|
"SELECT"
|
||||||
|
" master_sig"
|
||||||
|
",exchange_pub"
|
||||||
|
",valid_from"
|
||||||
|
",expire_sign"
|
||||||
|
",expire_legal"
|
||||||
|
" FROM exchange_sign_keys esk"
|
||||||
|
" WHERE"
|
||||||
|
" expire_sign > $1"
|
||||||
|
" AND NOT EXISTS "
|
||||||
|
" (SELECT esk_serial "
|
||||||
|
" FROM signkey_revocations skr"
|
||||||
|
" WHERE esk.esk_serial = skr.esk_serial);");
|
||||||
|
now = GNUNET_TIME_absolute_get ();
|
||||||
|
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
|
||||||
|
"select_signkeys",
|
||||||
|
params,
|
||||||
|
&signkeys_cb_helper,
|
||||||
|
&dic);
|
||||||
|
}
|
43
src/exchangedb/pg_iterate_active_signkeys.h
Normal file
43
src/exchangedb/pg_iterate_active_signkeys.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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_iterate_active_signkeys.h
|
||||||
|
* @brief implementation of the iterate_active_signkeys function for Postgres
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
#ifndef PG_ITERATE_ACTIVE_SIGNKEYS_H
|
||||||
|
#define PG_ITERATE_ACTIVE_SIGNKEYS_H
|
||||||
|
|
||||||
|
#include "taler_util.h"
|
||||||
|
#include "taler_json_lib.h"
|
||||||
|
#include "taler_exchangedb_plugin.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function called to invoke @a cb on every non-revoked exchange signing key
|
||||||
|
* that has been signed by the master key. Revoked and (for signing!)
|
||||||
|
* expired keys are skipped. Runs in its own read-only transaction.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param cb function to call on each signing key
|
||||||
|
* @param cb_cls closure for @a cb
|
||||||
|
* @return transaction status code
|
||||||
|
*/
|
||||||
|
enum GNUNET_DB_QueryStatus
|
||||||
|
TEH_PG_iterate_active_signkeys (void *cls,
|
||||||
|
TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
|
||||||
|
void *cb_cls);
|
||||||
|
|
||||||
|
#endif
|
@ -62,6 +62,9 @@
|
|||||||
|
|
||||||
/**WHAT I ADD**/
|
/**WHAT I ADD**/
|
||||||
#include "pg_insert_purse_request.h"
|
#include "pg_insert_purse_request.h"
|
||||||
|
#include "pg_iterate_active_signkeys.h"
|
||||||
|
|
||||||
|
#include "pg_commit.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -427,22 +430,7 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" FROM denominations"
|
" FROM denominations"
|
||||||
" LEFT JOIN "
|
" LEFT JOIN "
|
||||||
" denomination_revocations USING (denominations_serial);"),
|
" denomination_revocations USING (denominations_serial);"),
|
||||||
/* Used in #postgres_iterate_active_signkeys() */
|
|
||||||
GNUNET_PQ_make_prepare (
|
|
||||||
"select_signkeys",
|
|
||||||
"SELECT"
|
|
||||||
" master_sig"
|
|
||||||
",exchange_pub"
|
|
||||||
",valid_from"
|
|
||||||
",expire_sign"
|
|
||||||
",expire_legal"
|
|
||||||
" FROM exchange_sign_keys esk"
|
|
||||||
" WHERE"
|
|
||||||
" expire_sign > $1"
|
|
||||||
" AND NOT EXISTS "
|
|
||||||
" (SELECT esk_serial "
|
|
||||||
" FROM signkey_revocations skr"
|
|
||||||
" WHERE esk.esk_serial = skr.esk_serial);"),
|
|
||||||
/* Used in #postgres_iterate_auditor_denominations() */
|
/* Used in #postgres_iterate_auditor_denominations() */
|
||||||
GNUNET_PQ_make_prepare (
|
GNUNET_PQ_make_prepare (
|
||||||
"select_auditor_denoms",
|
"select_auditor_denoms",
|
||||||
@ -1952,11 +1940,7 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" FROM global_fee"
|
" FROM global_fee"
|
||||||
" WHERE end_date > $1"
|
" WHERE end_date > $1"
|
||||||
" AND start_date < $2;"),
|
" AND start_date < $2;"),
|
||||||
/* used in #postgres_commit */
|
/* Used in #postgres_begin_shard() */
|
||||||
GNUNET_PQ_make_prepare (
|
|
||||||
"do_commit",
|
|
||||||
"COMMIT"),
|
|
||||||
/* Used in #postgres_begin_shard() */
|
|
||||||
GNUNET_PQ_make_prepare (
|
GNUNET_PQ_make_prepare (
|
||||||
"get_open_shard",
|
"get_open_shard",
|
||||||
"SELECT"
|
"SELECT"
|
||||||
@ -2591,31 +2575,6 @@ postgres_rollback (void *cls)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit the current transaction of a database connection.
|
|
||||||
*
|
|
||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
|
||||||
* @return final transaction status
|
|
||||||
*/
|
|
||||||
static enum GNUNET_DB_QueryStatus
|
|
||||||
postgres_commit (void *cls)
|
|
||||||
{
|
|
||||||
struct PostgresClosure *pg = cls;
|
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
|
||||||
GNUNET_PQ_query_param_end
|
|
||||||
};
|
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
|
||||||
|
|
||||||
GNUNET_break (NULL != pg->transaction_name);
|
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
||||||
"Committing transaction `%s'\n",
|
|
||||||
pg->transaction_name);
|
|
||||||
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
|
||||||
"do_commit",
|
|
||||||
params);
|
|
||||||
pg->transaction_name = NULL;
|
|
||||||
return qs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3072,109 +3031,6 @@ postgres_iterate_denominations (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closure for #signkeys_cb_helper()
|
|
||||||
*/
|
|
||||||
struct SignkeysIteratorContext
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Function to call with the results.
|
|
||||||
*/
|
|
||||||
TALER_EXCHANGEDB_ActiveSignkeysCallback cb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closure to pass to @e cb
|
|
||||||
*/
|
|
||||||
void *cb_cls;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function for #postgres_iterate_active_signkeys().
|
|
||||||
* Calls the callback with each signkey.
|
|
||||||
*
|
|
||||||
* @param cls a `struct SignkeysIteratorContext`
|
|
||||||
* @param result db results
|
|
||||||
* @param num_results number of results in @a result
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
signkeys_cb_helper (void *cls,
|
|
||||||
PGresult *result,
|
|
||||||
unsigned int num_results)
|
|
||||||
{
|
|
||||||
struct SignkeysIteratorContext *dic = cls;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i<num_results; i++)
|
|
||||||
{
|
|
||||||
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
|
|
||||||
struct TALER_ExchangePublicKeyP exchange_pub;
|
|
||||||
struct TALER_MasterSignatureP master_sig;
|
|
||||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
|
||||||
GNUNET_PQ_result_spec_auto_from_type ("master_sig",
|
|
||||||
&master_sig),
|
|
||||||
GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
|
|
||||||
&exchange_pub),
|
|
||||||
GNUNET_PQ_result_spec_timestamp ("valid_from",
|
|
||||||
&meta.start),
|
|
||||||
GNUNET_PQ_result_spec_timestamp ("expire_sign",
|
|
||||||
&meta.expire_sign),
|
|
||||||
GNUNET_PQ_result_spec_timestamp ("expire_legal",
|
|
||||||
&meta.expire_legal),
|
|
||||||
GNUNET_PQ_result_spec_end
|
|
||||||
};
|
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
|
||||||
GNUNET_PQ_extract_result (result,
|
|
||||||
rs,
|
|
||||||
i))
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dic->cb (dic->cb_cls,
|
|
||||||
&exchange_pub,
|
|
||||||
&meta,
|
|
||||||
&master_sig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function called to invoke @a cb on every non-revoked exchange signing key
|
|
||||||
* that has been signed by the master key. Revoked and (for signing!)
|
|
||||||
* expired keys are skipped. Runs in its own read-only transaction.
|
|
||||||
*
|
|
||||||
* @param cls the @e cls of this struct with the plugin-specific state
|
|
||||||
* @param cb function to call on each signing key
|
|
||||||
* @param cb_cls closure for @a cb
|
|
||||||
* @return transaction status code
|
|
||||||
*/
|
|
||||||
static enum GNUNET_DB_QueryStatus
|
|
||||||
postgres_iterate_active_signkeys (void *cls,
|
|
||||||
TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
|
|
||||||
void *cb_cls)
|
|
||||||
{
|
|
||||||
struct PostgresClosure *pg = cls;
|
|
||||||
struct GNUNET_TIME_Absolute now = {0};
|
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
|
||||||
GNUNET_PQ_query_param_absolute_time (&now),
|
|
||||||
GNUNET_PQ_query_param_end
|
|
||||||
};
|
|
||||||
struct SignkeysIteratorContext dic = {
|
|
||||||
.cb = cb,
|
|
||||||
.cb_cls = cb_cls,
|
|
||||||
};
|
|
||||||
|
|
||||||
now = GNUNET_TIME_absolute_get ();
|
|
||||||
return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
|
|
||||||
"select_signkeys",
|
|
||||||
params,
|
|
||||||
&signkeys_cb_helper,
|
|
||||||
&dic);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closure for #auditors_cb_helper()
|
* Closure for #auditors_cb_helper()
|
||||||
*/
|
*/
|
||||||
@ -3677,7 +3533,7 @@ postgres_reserves_in_insert (void *cls,
|
|||||||
(We are only run in a larger transaction for performance.) */
|
(We are only run in a larger transaction for performance.) */
|
||||||
enum GNUNET_DB_QueryStatus cs;
|
enum GNUNET_DB_QueryStatus cs;
|
||||||
|
|
||||||
cs = postgres_commit (pg);
|
cs = TEH_PG_commit(pg);
|
||||||
if (cs < 0)
|
if (cs < 0)
|
||||||
return cs;
|
return cs;
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
@ -3758,7 +3614,7 @@ postgres_reserves_in_insert (void *cls,
|
|||||||
{
|
{
|
||||||
enum GNUNET_DB_QueryStatus cs;
|
enum GNUNET_DB_QueryStatus cs;
|
||||||
|
|
||||||
cs = postgres_commit (pg);
|
cs = TEH_PG_commit (pg);
|
||||||
if (cs < 0)
|
if (cs < 0)
|
||||||
return cs;
|
return cs;
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
@ -9986,7 +9842,7 @@ commit:
|
|||||||
{
|
{
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
|
||||||
qs = postgres_commit (pg);
|
qs = TEH_PG_commit (pg);
|
||||||
switch (qs)
|
switch (qs)
|
||||||
{
|
{
|
||||||
case GNUNET_DB_STATUS_HARD_ERROR:
|
case GNUNET_DB_STATUS_HARD_ERROR:
|
||||||
@ -10256,7 +10112,7 @@ postgres_begin_revolving_shard (void *cls,
|
|||||||
{
|
{
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
|
||||||
qs = postgres_commit (pg);
|
qs = TEH_PG_commit (pg);
|
||||||
switch (qs)
|
switch (qs)
|
||||||
{
|
{
|
||||||
case GNUNET_DB_STATUS_HARD_ERROR:
|
case GNUNET_DB_STATUS_HARD_ERROR:
|
||||||
@ -12008,7 +11864,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
|||||||
plugin->start = &postgres_start;
|
plugin->start = &postgres_start;
|
||||||
plugin->start_read_committed = &postgres_start_read_committed;
|
plugin->start_read_committed = &postgres_start_read_committed;
|
||||||
plugin->start_read_only = &postgres_start_read_only;
|
plugin->start_read_only = &postgres_start_read_only;
|
||||||
plugin->commit = &postgres_commit;
|
|
||||||
plugin->preflight = &postgres_preflight;
|
plugin->preflight = &postgres_preflight;
|
||||||
plugin->rollback = &postgres_rollback;
|
plugin->rollback = &postgres_rollback;
|
||||||
plugin->event_listen = &postgres_event_listen;
|
plugin->event_listen = &postgres_event_listen;
|
||||||
@ -12018,7 +11874,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
|||||||
plugin->get_denomination_info = &postgres_get_denomination_info;
|
plugin->get_denomination_info = &postgres_get_denomination_info;
|
||||||
plugin->iterate_denomination_info = &postgres_iterate_denomination_info;
|
plugin->iterate_denomination_info = &postgres_iterate_denomination_info;
|
||||||
plugin->iterate_denominations = &postgres_iterate_denominations;
|
plugin->iterate_denominations = &postgres_iterate_denominations;
|
||||||
plugin->iterate_active_signkeys = &postgres_iterate_active_signkeys;
|
|
||||||
plugin->iterate_active_auditors = &postgres_iterate_active_auditors;
|
plugin->iterate_active_auditors = &postgres_iterate_active_auditors;
|
||||||
plugin->iterate_auditor_denominations =
|
plugin->iterate_auditor_denominations =
|
||||||
&postgres_iterate_auditor_denominations;
|
&postgres_iterate_auditor_denominations;
|
||||||
@ -12280,7 +12136,10 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
|||||||
= &TEH_PG_select_reserve_open_above_serial_id;
|
= &TEH_PG_select_reserve_open_above_serial_id;
|
||||||
plugin->insert_purse_request
|
plugin->insert_purse_request
|
||||||
= &TEH_PG_insert_purse_request;
|
= &TEH_PG_insert_purse_request;
|
||||||
|
plugin->iterate_active_signkeys
|
||||||
|
= &TEH_PG_iterate_active_signkeys;
|
||||||
|
plugin->commit
|
||||||
|
= &TEH_PG_commit;
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user