aboutsummaryrefslogtreecommitdiff
path: root/src/mintdb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-18 18:53:12 +0200
committerChristian Grothoff <christian@grothoff.org>2015-05-18 18:53:12 +0200
commit7b4623706c3a87b444362ca27027d9bfb1aa25ae (patch)
treee546a3407f4465be9110fffeaab3ae38c5f8c3b2 /src/mintdb
parentcb68cc7e5b03a03f335e121def044034978adf17 (diff)
parent17985453c560300dba044617bafdb8f682d29e4c (diff)
Merge branch 'master' of git+ssh://taler.net/var/git/mint
Diffstat (limited to 'src/mintdb')
-rw-r--r--src/mintdb/mintdb_plugin.c3
-rw-r--r--src/mintdb/plugin_mintdb_postgres.c393
-rw-r--r--src/mintdb/test-mint-db-postgres.conf2
-rw-r--r--src/mintdb/test_mintdb.c8
4 files changed, 213 insertions, 193 deletions
diff --git a/src/mintdb/mintdb_plugin.c b/src/mintdb/mintdb_plugin.c
index 4480e27c5..2e8d206fd 100644
--- a/src/mintdb/mintdb_plugin.c
+++ b/src/mintdb/mintdb_plugin.c
@@ -20,7 +20,6 @@
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
#include "platform.h"
-#include "taler_mintdb_lib.h"
#include "taler_mintdb_plugin.h"
#include <ltdl.h>
@@ -112,7 +111,7 @@ plugin_init ()
opath = lt_dlgetsearchpath ();
if (NULL != opath)
old_dlsearchpath = GNUNET_strdup (opath);
- path = TALER_os_installation_get_path (GNUNET_OS_IPK_LIBDIR);
+ path = TALER_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
if (NULL != path)
{
if (NULL != opath)
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c
index 7d3a3e870..3800f03b2 100644
--- a/src/mintdb/plugin_mintdb_postgres.c
+++ b/src/mintdb/plugin_mintdb_postgres.c
@@ -23,7 +23,6 @@
*/
#include "platform.h"
#include "taler_pq_lib.h"
-#include "taler_signatures.h"
#include "taler_mintdb_plugin.h"
#include <pthread.h>
#include <libpq-fe.h>
@@ -62,6 +61,12 @@
PQclear (result); result = NULL; \
} while (0)
+#define SQLEXEC_IGNORE_ERROR_(conn, sql, result) \
+ do { \
+ result = PQexec (conn, sql); \
+ PQclear (result); result = NULL; \
+ } while (0)
+
/**
* Handle for a database session (per-thread, for transactions).
@@ -172,6 +177,7 @@ postgres_create_tables (void *cls,
return GNUNET_SYSERR;
}
#define SQLEXEC(sql) SQLEXEC_(conn, sql, result);
+#define SQLEXEC_INDEX(sql) SQLEXEC_IGNORE_ERROR_(conn, sql, result);
/* Denomination table for holding the publicly available information of
denominations keys. The denominations are to be referred to by using
foreign keys. The denominations are deleted by a housekeeping tool;
@@ -216,15 +222,15 @@ postgres_create_tables (void *cls,
",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",details VARCHAR NOT NULL "
",expiration_date INT8 NOT NULL"
- " CONSTRAINT unique_details PRIMARY KEY (reserve_pub,details)"
+ ",PRIMARY KEY (reserve_pub,details)"
");");
/* Create indices on reserves_in */
- SQLEXEC ("CREATE INDEX reserves_in_reserve_pub_index"
- " ON reserves_in (reserve_pub);");
- SQLEXEC ("CREATE INDEX reserves_in_reserve_pub_details_index"
- " ON reserves_in (reserve_pub,details);");
- SQLEXEC ("CREATE INDEX expiration_index"
- " ON reserves_in (expiration_date);");
+ SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_index"
+ " ON reserves_in (reserve_pub);");
+ SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_details_index"
+ " ON reserves_in (reserve_pub,details);");
+ SQLEXEC_INDEX ("CREATE INDEX expiration_index"
+ " ON reserves_in (expiration_date);");
/* Table with the withdraw operations that have been performed on a reserve.
TODO: maybe rename to "reserves_out"?
TODO: is blind_ev really a _primary key_? Is this constraint useful? */
@@ -237,8 +243,8 @@ postgres_create_tables (void *cls,
",reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)"
");");
/* Index blindcoins(reserve_pub) for get_reserves_blindcoins statement */
- SQLEXEC ("CREATE INDEX collectable_blindcoins_reserve_pub_index ON"
- " collectable_blindcoins (reserve_pub)");
+ SQLEXEC_INDEX ("CREATE INDEX collectable_blindcoins_reserve_pub_index ON"
+ " collectable_blindcoins (reserve_pub)");
/* Table with coins that have been (partially) spent, used to detect
double-spending.
TODO: maybe rename to "spent_coins"?
@@ -302,7 +308,7 @@ postgres_create_tables (void *cls,
")");
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_melt"
"("
- " session_hash BYTEA NOT NULL CHECK(LENGTH(session_hash=64)) REFERENCES refresh_sessions (session_hash) "
+ " session_hash BYTEA NOT NULL CHECK(LENGTH(session_hash)=64) REFERENCES refresh_sessions (session_hash) "
",coin_pub BYTEA NOT NULL CHECK(LENGTH(coin_pub)=32) REFERENCES known_coins (coin_pub) "
",coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)"
",denom_pub BYTEA NOT NULL "
@@ -421,10 +427,10 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("update_reserve",
"UPDATE reserves "
"SET"
- "expiration_date=$1 "
+ " expiration_date=$1 "
",current_balance_val=$2 "
",current_balance_frac=$3 "
- "WHERE current_balance_curr=$4 AND reserve_pub=$5 ",
+ "WHERE current_balance_curr=$4 AND reserve_pub=$5",
5, NULL);
PREPARE ("create_reserves_in_transaction",
"INSERT INTO reserves_in ("
@@ -841,7 +847,7 @@ postgres_commit (void *cls,
* Insert a denomination key
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param sesssion connection to use
+ * @param session connection to use
* @param dki the denomination key information
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
@@ -855,15 +861,15 @@ postgres_insert_denomination (void *cls,
int ret;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (dki->denom_pub.rsa_public_key),
- TALER_PQ_QUERY_PARAM_PTR (&issue->start.abs_value_us__),
- TALER_PQ_QUERY_PARAM_PTR (&issue->expire_withdraw.abs_value_us__),
- TALER_PQ_QUERY_PARAM_PTR (&issue->expire_spend.abs_value_us__),
- TALER_PQ_QUERY_PARAM_PTR (&issue->expire_legal.abs_value_us__),
- TALER_PQ_QUERY_PARAM_AMOUNT_NBO (&issue->value),
- TALER_PQ_QUERY_PARAM_AMOUNT_NBO (&issue->fee_withdraw),
- TALER_PQ_QUERY_PARAM_AMOUNT_NBO (&issue->fee_refresh),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_rsa_public_key (dki->denom_pub.rsa_public_key),
+ TALER_PQ_query_param_auto_from_type (&issue->start.abs_value_us__),
+ TALER_PQ_query_param_auto_from_type (&issue->expire_withdraw.abs_value_us__),
+ TALER_PQ_query_param_auto_from_type (&issue->expire_spend.abs_value_us__),
+ TALER_PQ_query_param_auto_from_type (&issue->expire_legal.abs_value_us__),
+ TALER_PQ_query_param_amount_nbo (&issue->value),
+ TALER_PQ_query_param_amount_nbo (&issue->fee_withdraw),
+ TALER_PQ_query_param_amount_nbo (&issue->fee_refresh),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"insert_denomination",
@@ -899,13 +905,13 @@ postgres_reserve_get (void *cls,
{
PGresult *result;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(&reserve->pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(&reserve->pub),
+ TALER_PQ_query_param_end
};
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT("current_balance", &reserve->balance),
- TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME("expiration_date", &reserve->expiry),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
+ TALER_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
+ TALER_PQ_result_spec_end
};
result = TALER_PQ_exec_prepared (session->conn,
@@ -914,7 +920,7 @@ postgres_reserve_get (void *cls,
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
QUERY_ERR (result);
- PQclear (resultE);
+ PQclear (result);
return GNUNET_SYSERR;
}
if (0 == PQntuples (result))
@@ -955,10 +961,10 @@ postgres_reserves_update (void *cls,
if (NULL == reserve)
return GNUNET_SYSERR;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (reserve->expiry),
- TALER_PQ_QUERY_PARAM_AMOUNT (&reserve->balance),
- TALER_PQ_QUERY_PARAM_PTR (&reserve->pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_absolute_time (&reserve->expiry),
+ TALER_PQ_query_param_amount (&reserve->balance),
+ TALER_PQ_query_param_auto_from_type (&reserve->pub),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"update_reserve",
@@ -979,7 +985,8 @@ postgres_reserves_update (void *cls,
/**
* Insert a incoming transaction into reserves. New reserves are also created
- * through this function.
+ * through this function. Note that this API call starts (and stops) its
+ * own transaction scope (so the application must not do so).
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param session the database connection handle
@@ -995,10 +1002,10 @@ postgres_reserves_update (void *cls,
static int
postgres_reserves_in_insert (void *cls,
struct TALER_MINTDB_Session *session,
- struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance,
const char *details,
- const struct GNUNET_TIME_Absolute expiry)
+ struct GNUNET_TIME_Absolute expiry)
{
PGresult *result;
int reserve_exists;
@@ -1018,19 +1025,18 @@ postgres_reserves_in_insert (void *cls,
&reserve);
if (GNUNET_SYSERR == reserve_exists)
{
- postgres_rollback (cls,
- session);
- return GNUNET_SYSERR;
+ GNUNET_break (0);
+ goto rollback;
}
if (GNUNET_NO == reserve_exists)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Reserve does not exist; creating a new one\n");
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (reserve_pub),
- TALER_PQ_QUERY_PARAM_AMOUNT (balance),
- TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (expiry),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_absolute_time (&expiry),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"create_reserve",
@@ -1044,11 +1050,11 @@ postgres_reserves_in_insert (void *cls,
else
{
/* Update reserve */
- updated_reserve.pub = reserve->pub;
+ updated_reserve.pub = reserve.pub;
if (GNUNET_OK !=
TALER_amount_add (&updated_reserve.balance,
- &reserve->balance,
+ &reserve.balance,
balance))
{
/* currency overflow or incompatible currency */
@@ -1057,7 +1063,7 @@ postgres_reserves_in_insert (void *cls,
goto rollback;
}
updated_reserve.expiry = GNUNET_TIME_absolute_max (expiry,
- reserve->expiry);
+ reserve.expiry);
}
if (NULL != result)
@@ -1066,17 +1072,32 @@ postgres_reserves_in_insert (void *cls,
/* create new incoming transaction, SQL "primary key" logic
is used to guard against duplicates! */
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (&reserve->pub),
- TALER_PQ_QUERY_PARAM_AMOUNT (balance),
- TALER_PQ_QUERY_PARAM_PTR_SIZED (details, strlen (details)),
- TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (expiry),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (&reserve.pub),
+ TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_fixed_size (details, strlen (details)),
+ TALER_PQ_query_param_absolute_time (&expiry),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"create_reserves_in_transaction",
params);
if (PGRES_COMMAND_OK != PQresultStatus(result))
{
+ const char *efield;
+
+ efield = PQresultErrorField (result,
+ PG_DIAG_SQLSTATE);
+ if ( (PGRES_FATAL_ERROR == PQresultStatus(result)) &&
+ (NULL != strstr ("23505", /* unique violation */
+ efield)) )
+ {
+ /* This means we had the same reserve/justification/details
+ before */
+ PQclear (result);
+ postgres_rollback (cls,
+ session);
+ return GNUNET_NO;
+ }
QUERY_ERR (result);
goto rollback;
}
@@ -1121,8 +1142,8 @@ postgres_get_collectable_blindcoin (void *cls,
{
PGresult *result;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (h_blind),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (h_blind),
+ TALER_PQ_query_param_end
};
struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
struct GNUNET_CRYPTO_rsa_Signature *denom_sig;
@@ -1144,11 +1165,11 @@ postgres_get_collectable_blindcoin (void *cls,
goto cleanup;
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", &denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("denom_sig", &denom_sig),
- TALER_PQ_RESULT_SPEC("reserve_sig", &collectable->reserve_sig),
- TALER_PQ_RESULT_SPEC("reserve_pub", &collectable->reserve_pub),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_rsa_public_key("denom_pub", &denom_pub),
+ TALER_PQ_result_spec_rsa_signature("denom_sig", &denom_sig),
+ TALER_PQ_result_spec_auto_from_type("reserve_sig", &collectable->reserve_sig),
+ TALER_PQ_result_spec_auto_from_type("reserve_pub", &collectable->reserve_pub),
+ TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
@@ -1194,12 +1215,12 @@ postgres_insert_collectable_blindcoin (void *cls,
struct TALER_MINTDB_Reserve reserve;
int ret = GNUNET_SYSERR;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (h_blind),
- TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (collectable->denom_pub.rsa_public_key),
- TALER_PQ_QUERY_PARAM_RSA_SIGNATURE (collectable->sig.rsa_signature),
- TALER_PQ_QUERY_PARAM_PTR (&collectable->reserve_pub),
- TALER_PQ_QUERY_PARAM_PTR (&collectable->reserve_sig),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (h_blind),
+ TALER_PQ_query_param_rsa_public_key (collectable->denom_pub.rsa_public_key),
+ TALER_PQ_query_param_rsa_signature (collectable->sig.rsa_signature),
+ TALER_PQ_query_param_auto_from_type (&collectable->reserve_pub),
+ TALER_PQ_query_param_auto_from_type (&collectable->reserve_sig),
+ TALER_PQ_query_param_end
};
if (GNUNET_OK != postgres_start (cls,
@@ -1272,8 +1293,8 @@ postgres_get_reserve_history (void *cls,
{
struct TALER_MINTDB_BankTransfer *bt;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (reserve_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
@@ -1329,8 +1350,8 @@ postgres_get_reserve_history (void *cls,
struct GNUNET_CRYPTO_rsa_Signature *denom_sig;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (reserve_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"get_reserves_blindcoins",
@@ -1346,11 +1367,11 @@ postgres_get_reserve_history (void *cls,
goto cleanup;
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC ("blind_ev", &blind_ev),
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("denom_pub", &denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE ("denom_sig", &denom_sig),
- TALER_PQ_RESULT_SPEC ("reserve_sig", &reserve_sig),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_auto_from_type ("blind_ev", &blind_ev),
+ TALER_PQ_result_spec_rsa_public_key ("denom_pub", &denom_pub),
+ TALER_PQ_result_spec_rsa_signature ("denom_sig", &denom_sig),
+ TALER_PQ_result_spec_auto_from_type ("reserve_sig", &reserve_sig),
+ TALER_PQ_result_spec_end
};
GNUNET_assert (NULL != rh);
GNUNET_assert (NULL != rh_head);
@@ -1405,10 +1426,10 @@ postgres_have_deposit (void *cls,
const struct TALER_MINTDB_Deposit *deposit)
{
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (&deposit->coin.coin_pub),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->transaction_id),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->merchant_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
+ TALER_PQ_query_param_auto_from_type (&deposit->transaction_id),
+ TALER_PQ_query_param_auto_from_type (&deposit->merchant_pub),
+ TALER_PQ_query_param_end
};
PGresult *result;
int ret;
@@ -1458,18 +1479,18 @@ postgres_insert_deposit (void *cls,
ret = GNUNET_SYSERR;
json_wire_enc = json_dumps (deposit->wire, JSON_COMPACT);
struct TALER_PQ_QueryParam params[]= {
- TALER_PQ_QUERY_PARAM_PTR (&deposit->coin.coin_pub),
- TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (deposit->coin.denom_pub.rsa_public_key),
- TALER_PQ_QUERY_PARAM_RSA_SIGNATURE (deposit->coin.denom_sig.rsa_signature),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->transaction_id),
- TALER_PQ_QUERY_PARAM_AMOUNT (&deposit->amount_with_fee),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->merchant_pub),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->h_contract),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->h_wire),
- TALER_PQ_QUERY_PARAM_PTR (&deposit->csig),
- TALER_PQ_QUERY_PARAM_PTR_SIZED (json_wire_enc,
+ TALER_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
+ TALER_PQ_query_param_rsa_public_key (deposit->coin.denom_pub.rsa_public_key),
+ TALER_PQ_query_param_rsa_signature (deposit->coin.denom_sig.rsa_signature),
+ TALER_PQ_query_param_auto_from_type (&deposit->transaction_id),
+ TALER_PQ_query_param_amount (&deposit->amount_with_fee),
+ TALER_PQ_query_param_auto_from_type (&deposit->merchant_pub),
+ TALER_PQ_query_param_auto_from_type (&deposit->h_contract),
+ TALER_PQ_query_param_auto_from_type (&deposit->h_wire),
+ TALER_PQ_query_param_auto_from_type (&deposit->csig),
+ TALER_PQ_query_param_fixed_size (json_wire_enc,
strlen (json_wire_enc)),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn, "insert_deposit", params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -1505,8 +1526,8 @@ postgres_get_refresh_session (void *cls,
{
PGresult *result;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_end
};
int ret;
uint16_t num_oldcoins;
@@ -1537,10 +1558,10 @@ postgres_get_refresh_session (void *cls,
}
memset (refresh_session, 0, sizeof (struct TALER_MINTDB_RefreshSession));
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC("num_oldcoins", &num_oldcoins),
- TALER_PQ_RESULT_SPEC("num_newcoins", &num_newcoins),
- TALER_PQ_RESULT_SPEC("noreveal_index", &noreveal_index),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_auto_from_type("num_oldcoins", &num_oldcoins),
+ TALER_PQ_result_spec_auto_from_type("num_newcoins", &num_newcoins),
+ TALER_PQ_result_spec_auto_from_type("noreveal_index", &noreveal_index),
+ TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
{
@@ -1580,11 +1601,11 @@ postgres_create_refresh_session (void *cls,
uint16_t num_newcoins;
uint16_t noreveal_index;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&num_oldcoins),
- TALER_PQ_QUERY_PARAM_PTR(&num_newcoins),
- TALER_PQ_QUERY_PARAM_PTR(&noreveal_index),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&num_oldcoins),
+ TALER_PQ_query_param_auto_from_type(&num_newcoins),
+ TALER_PQ_query_param_auto_from_type(&noreveal_index),
+ TALER_PQ_query_param_end
};
num_oldcoins = htons (refresh_session->num_oldcoins);
num_newcoins = htons (refresh_session->num_newcoins);
@@ -1626,11 +1647,11 @@ postgres_insert_refresh_melt (void *cls,
{
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(&melt->session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&oldcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&melt->coin.coin_pub),
- TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY(melt->coin.denom_pub.rsa_public_key),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(&melt->session_hash),
+ TALER_PQ_query_param_auto_from_type(&oldcoin_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&melt->coin.coin_pub),
+ TALER_PQ_query_param_rsa_public_key(melt->coin.denom_pub.rsa_public_key),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"insert_refresh_melt",
@@ -1669,18 +1690,18 @@ postgres_get_refresh_melt (void *cls,
// FIXME: check logic!
uint16_t oldcoin_index_nbo = htons (oldcoin_index);
struct TALER_PQ_Query params[] = {
- TALER_PQ_QUERY_PARAM_PTR (session_hash),
- TALER_PQ_QUERY_PARAM_PTR (&oldcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (session_hash),
+ TALER_PQ_query_param_auto_from_type (&oldcoin_index_nbo),
+ TALER_PQ_query_param_end
};
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC ("coin_pub", &melt->coin),
- TALER_PQ_RESULT_SPEC ("coin_sig", &melt->coin_sig),
- TALER_PQ_RESULT_SPEC ("denom_pub", &melt->coin),
- TALER_PQ_RESULT_SPEC ("denom_sig", &melt->coin),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount", melt->amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee", melt->melt_fee),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_auto_from_type ("coin_pub", &melt->coin),
+ TALER_PQ_result_spec_auto_from_type ("coin_sig", &melt->coin_sig),
+ TALER_PQ_result_spec_auto_from_type ("denom_pub", &melt->coin),
+ TALER_PQ_result_spec_auto_from_type ("denom_sig", &melt->coin),
+ TALER_PQ_result_spec_amount ("amount", melt->amount_with_fee),
+ TALER_PQ_result_spec_amount ("fee", melt->melt_fee),
+ TALER_PQ_result_spec_end
};
result = TALER_PQ_exec_prepared (session->conn,
@@ -1730,10 +1751,10 @@ postgres_insert_refresh_order (void *cls,
{
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (&newcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR (session_hash),
- TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (denom_pubs->rsa_public_key),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (&newcoin_index_nbo),
+ TALER_PQ_query_param_auto_from_type (session_hash),
+ TALER_PQ_query_param_rsa_public_key (denom_pubs->rsa_public_key),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"insert_refresh_order",
@@ -1778,9 +1799,9 @@ postgres_get_refresh_order (void *cls,
uint16_t newcoin_index_nbo = htons (num_newcoins);
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&newcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&newcoin_index_nbo),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn,
@@ -1801,8 +1822,8 @@ postgres_get_refresh_order (void *cls,
}
GNUNET_assert (1 == PQntuples (result));
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("denom_pub", &denom_pubs->rsa_public_key),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_rsa_public_key ("denom_pub", &denom_pubs->rsa_public_key),
+ TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
{
@@ -1841,14 +1862,14 @@ postgres_insert_refresh_commit_coins (void *cls,
uint16_t cnc_index_nbo = htons (i);
uint16_t newcoin_index_nbo = htons (num_newcoins);
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR_SIZED(commit_coins->coin_ev, commit_coins->coin_ev_size),
- TALER_PQ_QUERY_PARAM_PTR(&cnc_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&newcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR_SIZED (commit_coins->refresh_link->coin_priv_enc,
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_fixed_size(commit_coins->coin_ev, commit_coins->coin_ev_size),
+ TALER_PQ_query_param_auto_from_type(&cnc_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&newcoin_index_nbo),
+ TALER_PQ_query_param_fixed_size (commit_coins->refresh_link->coin_priv_enc,
commit_coins->refresh_link->blinding_key_enc_size +
- sizeof (union TALER_CoinSpendPrivateKeyP)),
- TALER_PQ_QUERY_PARAM_END
+ sizeof (struct TALER_CoinSpendPrivateKeyP)),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn,
@@ -1899,10 +1920,10 @@ postgres_get_refresh_commit_coins (void *cls,
uint16_t cnc_index_nbo = htons (cnc_index);
uint16_t newcoin_index_nbo = htons (newcoin_index);
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&cnc_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&newcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&cnc_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&newcoin_index_nbo),
+ TALER_PQ_query_param_end
};
void *c_buf;
size_t c_buf_size;
@@ -1928,9 +1949,9 @@ postgres_get_refresh_commit_coins (void *cls,
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_VAR("coin_ev", &c_buf, &c_buf_size),
- TALER_PQ_RESULT_SPEC_VAR("link_vector_enc", &rl_buf, &rl_buf_size),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_variable_size("coin_ev", &c_buf, &c_buf_size),
+ TALER_PQ_result_spec_variable_size("link_vector_enc", &rl_buf, &rl_buf_size),
+ TALER_PQ_result_spec_end
};
if (GNUNET_YES != TALER_PQ_extract_result (result, rs, 0))
{
@@ -1938,7 +1959,7 @@ postgres_get_refresh_commit_coins (void *cls,
return GNUNET_SYSERR;
}
PQclear (result);
- if (rl_buf_size < sizeof (union TALER_CoinSpendPrivateKeyP))
+ if (rl_buf_size < sizeof (struct TALER_CoinSpendPrivateKeyP))
{
GNUNET_free (c_buf);
GNUNET_free (rl_buf);
@@ -1978,12 +1999,12 @@ postgres_insert_refresh_commit_links (void *cls,
uint16_t cnc_index_nbo = htons (i);
uint16_t oldcoin_index_nbo = htons (j);
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&commit_link->transfer_pub),
- TALER_PQ_QUERY_PARAM_PTR(&cnc_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&oldcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&commit_link->shared_secret_enc),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&commit_link->transfer_pub),
+ TALER_PQ_query_param_auto_from_type(&cnc_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&oldcoin_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&commit_link->shared_secret_enc),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn,
@@ -2034,10 +2055,10 @@ postgres_get_refresh_commit_links (void *cls,
uint16_t oldcoin_index_nbo = htons (num_links);
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&cnc_index_nbo),
- TALER_PQ_QUERY_PARAM_PTR(&oldcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&cnc_index_nbo),
+ TALER_PQ_query_param_auto_from_type(&oldcoin_index_nbo),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn,
@@ -2057,9 +2078,9 @@ postgres_get_refresh_commit_links (void *cls,
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC("transfer_pub", &links->transfer_pub),
- TALER_PQ_RESULT_SPEC("link_secret_enc", &links->shared_secret_enc),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_auto_from_type("transfer_pub", &links->transfer_pub),
+ TALER_PQ_result_spec_auto_from_type("link_secret_enc", &links->shared_secret_enc),
+ TALER_PQ_result_spec_end
};
if (GNUNET_YES != TALER_PQ_extract_result (result, rs, 0))
@@ -2077,14 +2098,14 @@ postgres_get_refresh_commit_links (void *cls,
* Get all of the information from the given melt commit operation.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param sesssion database connection to use
+ * @param session database connection to use
* @param session_hash hash to identify refresh session
* @return NULL if the @a session_hash does not correspond to any known melt
* operation
*/
static struct TALER_MINTDB_MeltCommitment *
postgres_get_melt_commitment (void *cls,
- struct TALER_MINTDB_Session *sesssion,
+ struct TALER_MINTDB_Session *session,
const struct GNUNET_HashCode *session_hash)
{
// FIXME: needs to be implemented!
@@ -2145,10 +2166,10 @@ postgres_insert_refresh_collectable (void *cls,
{
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(session_hash),
- TALER_PQ_QUERY_PARAM_PTR(&newcoin_index_nbo),
- TALER_PQ_QUERY_PARAM_RSA_SIGNATURE(ev_sig->rsa_signature),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(session_hash),
+ TALER_PQ_query_param_auto_from_type(&newcoin_index_nbo),
+ TALER_PQ_query_param_rsa_signature(ev_sig->rsa_signature),
+ TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"insert_refresh_collectable",
@@ -2177,14 +2198,14 @@ postgres_insert_refresh_collectable (void *cls,
static struct TALER_MINTDB_LinkDataList *
postgres_get_link_data_list (void *cls,
struct TALER_MINTDB_Session *session,
- const union TALER_CoinSpendPublicKeyP *coin_pub)
+ const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
// FIXME: check logic!
struct TALER_MINTDB_LinkDataList *ldl;
struct TALER_MINTDB_LinkDataList *pos;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(coin_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(coin_pub),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn, "get_link", params);
@@ -2211,10 +2232,10 @@ postgres_get_link_data_list (void *cls,
void *ld_buf;
size_t ld_buf_size;
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_VAR("link_vector_enc", &ld_buf, &ld_buf_size),
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", &denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("ev_sig", &sig),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_variable_size("link_vector_enc", &ld_buf, &ld_buf_size),
+ TALER_PQ_result_spec_rsa_public_key("denom_pub", &denom_pub),
+ TALER_PQ_result_spec_rsa_signature("ev_sig", &sig),
+ TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, i))
@@ -2225,7 +2246,7 @@ postgres_get_link_data_list (void *cls,
ldl);
return NULL;
}
- if (ld_buf_size < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
+ if (ld_buf_size < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))
{
PQclear (result);
GNUNET_free (ld_buf);
@@ -2235,9 +2256,9 @@ postgres_get_link_data_list (void *cls,
}
// FIXME: use util API for this!
link_enc = GNUNET_malloc (sizeof (struct TALER_RefreshLinkEncrypted) +
- ld_buf_size - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
+ ld_buf_size - sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
link_enc->blinding_key_enc = (const char *) &link_enc[1];
- link_enc->blinding_key_enc_size = ld_buf_size - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
+ link_enc->blinding_key_enc_size = ld_buf_size - sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
memcpy (link_enc->coin_priv_enc,
ld_buf,
ld_buf_size);
@@ -2271,14 +2292,14 @@ postgres_get_link_data_list (void *cls,
static int
postgres_get_transfer (void *cls,
struct TALER_MINTDB_Session *session,
- const union TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct TALER_TransferPublicKeyP *transfer_pub,
struct TALER_EncryptedLinkSecretP *shared_secret_enc)
{
// FIXME: check logic!
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR(coin_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type(coin_pub),
+ TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn, "get_transfer", params);
@@ -2306,9 +2327,9 @@ postgres_get_transfer (void *cls,
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC("transfer_pub", transfer_pub),
- TALER_PQ_RESULT_SPEC("link_secret_enc", shared_secret_enc),
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_auto_from_type("transfer_pub", transfer_pub),
+ TALER_PQ_result_spec_auto_from_type("link_secret_enc", shared_secret_enc),
+ TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
@@ -2335,7 +2356,7 @@ postgres_get_transfer (void *cls,
static struct TALER_MINTDB_TransactionList *
postgres_get_coin_transactions (void *cls,
struct TALER_MINTDB_Session *session,
- const union TALER_CoinSpendPublicKeyP *coin_pub)
+ const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
PGresult *result;
struct TALER_MINTDB_TransactionList *head;
@@ -2353,8 +2374,8 @@ postgres_get_coin_transactions (void *cls,
{
struct TALER_MINTDB_Deposit *deposit;
struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_QUERY_PARAM_PTR (&coin_pub->ecdsa_pub),
- TALER_PQ_QUERY_PARAM_END
+ TALER_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
+ TALER_PQ_query_param_end
};
json_error_t json_error;
void *json_wire_enc;
@@ -2373,19 +2394,19 @@ postgres_get_coin_transactions (void *cls,
{
deposit = GNUNET_new (struct TALER_MINTDB_Deposit);
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC ("coin_pub", &deposit->coin),
- TALER_PQ_RESULT_SPEC ("coin_sig", &deposit->csig),
- TALER_PQ_RESULT_SPEC ("merchant_pub", &deposit->merchant_pub),
- TALER_PQ_RESULT_SPEC ("h_contract", &deposit->h_contract),
- TALER_PQ_RESULT_SPEC ("h_wire", &deposit->h_wire),
- TALER_PQ_RESULT_SPEC_VAR ("wire", &json_wire_enc, &json_wire_enc_size),
- TALER_PQ_RESULT_SPEC ("transaction_id", &deposit->transaction_id),
+ TALER_PQ_result_spec_auto_from_type ("coin_pub", &deposit->coin),
+ TALER_PQ_result_spec_auto_from_type ("coin_sig", &deposit->csig),
+ TALER_PQ_result_spec_auto_from_type ("merchant_pub", &deposit->merchant_pub),
+ TALER_PQ_result_spec_auto_from_type ("h_contract", &deposit->h_contract),
+ TALER_PQ_result_spec_auto_from_type ("h_wire", &deposit->h_wire),
+ TALER_PQ_result_spec_variable_size ("wire", &json_wire_enc, &json_wire_enc_size),
+ TALER_PQ_result_spec_auto_from_type ("transaction_id", &deposit->transaction_id),
/** FIXME:
- * TALER_PQ_RESULT_SPEC ("timestamp", &deposit->timestamp),
- * TALER_PQ_RESULT_SPEC ("refund_deadline", &deposit->refund_deadline),
+ * TALER_PQ_result_spec_auto_from_type ("timestamp", &deposit->timestamp),
+ * TALER_PQ_result_spec_auto_from_type ("refund_deadline", &deposit->refund_deadline),
* TALER_PQ_RESULT_AMOUNT_NBO ("deposit_fee", &deposit->deposit_fee)
*/
- TALER_PQ_RESULT_SPEC_END
+ TALER_PQ_result_spec_end
};
if ((GNUNET_OK != TALER_PQ_extract_result (result, rs, i)) ||
(GNUNET_OK != TALER_PQ_extract_amount (result,
diff --git a/src/mintdb/test-mint-db-postgres.conf b/src/mintdb/test-mint-db-postgres.conf
index a5a738e49..07f8a0e58 100644
--- a/src/mintdb/test-mint-db-postgres.conf
+++ b/src/mintdb/test-mint-db-postgres.conf
@@ -3,4 +3,4 @@
DB = postgres
#The connection string the plugin has to use for connecting to the database
-DB_CONN_STR = postgres:///taler
+DB_CONN_STR = postgres:///talercheck
diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c
index a35809e3e..212e763bc 100644
--- a/src/mintdb/test_mintdb.c
+++ b/src/mintdb/test_mintdb.c
@@ -127,7 +127,6 @@ run (void *cls,
{
struct TALER_MINTDB_Session *session;
struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_MINTDB_Reserve reserve;
struct GNUNET_TIME_Absolute expiry;
struct TALER_Amount amount;
struct DenomKeyPair *dkp;
@@ -178,7 +177,6 @@ run (void *cls,
goto drop;
}
RND_BLK (&reserve_pub);
- reserve.pub = reserve_pub;
amount.value = 1;
amount.fraction = 1;
strcpy (amount.currency, CURRENCY);
@@ -188,8 +186,9 @@ run (void *cls,
FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls,
session,
- &reserve,
+ &reserve_pub,
&amount,
+ "justification 1",
expiry));
FAILIF (GNUNET_OK !=
check_reserve (session,
@@ -201,8 +200,9 @@ run (void *cls,
FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls,
session,
- &reserve,
+ &reserve_pub,
&amount,
+ "justification 2",
expiry));
FAILIF (GNUNET_OK !=
check_reserve (session,