summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-11-27 23:42:17 +0100
committerChristian Grothoff <christian@grothoff.org>2017-11-29 20:23:08 +0100
commit499247a4805583dc67b9d6fef850ae86b4be1e32 (patch)
treeabf9bf358bc00149a78d8128101bfc43540af8f2 /src/exchangedb
parent9041840d6e1caa5a0a4f8222b312b547ccd2ab1b (diff)
downloadexchange-499247a4805583dc67b9d6fef850ae86b4be1e32.tar.gz
exchange-499247a4805583dc67b9d6fef850ae86b4be1e32.tar.bz2
exchange-499247a4805583dc67b9d6fef850ae86b4be1e32.zip
fixing #5178
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/perf_taler_exchangedb.c40
-rw-r--r--src/exchangedb/perf_taler_exchangedb_init.c118
-rw-r--r--src/exchangedb/perf_taler_exchangedb_init.h60
-rw-r--r--src/exchangedb/perf_taler_exchangedb_interpreter.c541
-rw-r--r--src/exchangedb/perf_taler_exchangedb_interpreter.h163
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c33
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c1278
-rw-r--r--src/exchangedb/test_exchangedb.c532
8 files changed, 1006 insertions, 1759 deletions
diff --git a/src/exchangedb/perf_taler_exchangedb.c b/src/exchangedb/perf_taler_exchangedb.c
index dcd8a4e2b..e2591c88b 100644
--- a/src/exchangedb/perf_taler_exchangedb.c
+++ b/src/exchangedb/perf_taler_exchangedb.c
@@ -74,7 +74,7 @@ main (int argc, char ** argv)
/* End of initialization */
/* Reserve initialization */
PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("02 - init reserve loop",
- NB_RESERVE_INIT),
+ NB_RESERVE_INIT),
PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_RESERVE ("02 - reserve"),
PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_RESERVE ("02 - insert",
"02 - reserve"),
@@ -131,14 +131,24 @@ main (int argc, char ** argv)
PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("05 - refresh session init loop",
NB_REFRESH_INIT),
PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION (""),
- PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION ("05 - refresh session"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("05 - denomination load",
+ "05 - refresh session init loop",
+ "01 - save denomination"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("05 - reserve load",
+ "05 - refresh session init loop",
+ "02 - save reserve"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_WITHDRAW ("05 - withdraw",
+ "05 - denomination load",
+ "05 - reserve load"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION ("05 - refresh session",
+ "05 - withdraw"),
PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("05 - session array",
- "05 - refresh session init loop",
- "05 - refresh session",
- NB_RESERVE_SAVE),
+ "05 - refresh session init loop",
+ "05 - refresh session",
+ NB_RESERVE_SAVE),
PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION (""),
PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("05 - end",
- "05 - refresh session init loop"),
+ "05 - refresh session init loop"),
/* End of refresh session initialization */
/* Refresh melt initialization */
PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("06 - refresh melt init loop",
@@ -328,9 +338,23 @@ main (int argc, char ** argv)
NB_DEPOSIT_SAVE),
PERF_TALER_EXCHANGEDB_INIT_CMD_GET_TIME ("29 - start"),
PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("29 - insert refresh session",
- NB_REFRESH_SAVE),
+ NB_REFRESH_SAVE),
PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION (""),
- PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION (""),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("29 - denomination load",
+ "29 - insert refresh session",
+ "01 - save denomination"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("29 - reserve load",
+ "29 - insert refresh session",
+ "02 - save reserve"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_WITHDRAW ("29 - withdraw",
+ "29 - denomination load",
+ "29 - reserve load"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION ("29 - refresh session",
+ "29 - withdraw"),
+ PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("29 - session array",
+ "29 - insert refresh session",
+ "29 - refresh session",
+ NB_RESERVE_SAVE),
PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION (""),
PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("",
"29 - insert refresh session"),
diff --git a/src/exchangedb/perf_taler_exchangedb_init.c b/src/exchangedb/perf_taler_exchangedb_init.c
index c46bea22d..412853980 100644
--- a/src/exchangedb/perf_taler_exchangedb_init.c
+++ b/src/exchangedb/perf_taler_exchangedb_init.c
@@ -435,56 +435,14 @@ PERF_TALER_EXCHANGEDB_coin_free (struct PERF_TALER_EXCHANGEDB_Coin *coin)
/**
- * @return a randomly generated refresh session
- */
-struct TALER_EXCHANGEDB_RefreshSession *
-PERF_TALER_EXCHANGEDB_refresh_session_init ()
-{
- struct TALER_EXCHANGEDB_RefreshSession *refresh_session;
-
- GNUNET_assert (NULL !=
- (refresh_session = GNUNET_new (struct TALER_EXCHANGEDB_RefreshSession)));
- refresh_session->noreveal_index = 1;
- refresh_session->num_newcoins = 1;
-
- return refresh_session;
-}
-
-
-/**
- * @return #GNUNET_OK if the copy was successful, #GNUNET_SYSERR if it wasn't
- */
-int
-PERF_TALER_EXCHANGEDB_refresh_session_copy (struct TALER_EXCHANGEDB_RefreshSession *session,
- struct TALER_EXCHANGEDB_RefreshSession *copy)
-{
- *copy = *session;
- return GNUNET_OK;
-}
-
-
-/**
- * Free a refresh session
- */
-int
-PERF_TALER_EXCHANGEDB_refresh_session_free (struct TALER_EXCHANGEDB_RefreshSession *refresh_session)
-{
- if (NULL == refresh_session)
- return GNUNET_OK;
- GNUNET_free (refresh_session);
- return GNUNET_OK;
-}
-
-
-/**
* Create a melt operation
*
- * @param session the refresh session
+ * @param rc the commitment of the refresh session
* @param dki the denomination the melted coin uses
* @return a pointer to a #TALER_EXCHANGEDB_RefreshMelt
*/
struct TALER_EXCHANGEDB_RefreshMelt *
-PERF_TALER_EXCHANGEDB_refresh_melt_init (struct GNUNET_HashCode *session,
+PERF_TALER_EXCHANGEDB_refresh_melt_init (struct TALER_RefreshCommitmentP *rc,
struct PERF_TALER_EXCHANGEDB_Coin *coin)
{
struct TALER_EXCHANGEDB_RefreshMelt *melt;
@@ -496,12 +454,12 @@ PERF_TALER_EXCHANGEDB_refresh_melt_init (struct GNUNET_HashCode *session,
struct
{
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
- struct GNUNET_HashCode session;
+ struct TALER_RefreshCommitmentP rc;
} to_sign;
to_sign.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_TEST;
to_sign.purpose.size = htonl (sizeof (to_sign));
- to_sign.session = *session;
+ to_sign.rc = *rc;
GNUNET_CRYPTO_eddsa_sign (&coin->priv,
&to_sign.purpose,
&coin_sig.eddsa_signature);
@@ -513,16 +471,16 @@ PERF_TALER_EXCHANGEDB_refresh_melt_init (struct GNUNET_HashCode *session,
TALER_string_to_amount (CURRENCY ":0.1",
&amount_with_fee));
melt = GNUNET_new (struct TALER_EXCHANGEDB_RefreshMelt);
- melt->coin.coin_pub = coin->public_info.coin_pub;
- melt->coin.denom_sig.rsa_signature =
+ melt->session.coin.coin_pub = coin->public_info.coin_pub;
+ melt->session.coin.denom_sig.rsa_signature =
GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature);
- melt->coin.denom_pub.rsa_public_key =
+ melt->session.coin.denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_public_key_dup (coin->public_info.denom_pub.rsa_public_key);
- GNUNET_assert (NULL != melt->coin.denom_pub.rsa_public_key);
- GNUNET_assert (NULL != melt->coin.denom_sig.rsa_signature);
- melt->coin_sig = coin_sig;
- melt->session_hash = *session;
- melt->amount_with_fee = amount;
+ GNUNET_assert (NULL != melt->session.coin.denom_pub.rsa_public_key);
+ GNUNET_assert (NULL != melt->session.coin.denom_sig.rsa_signature);
+ melt->session.coin_sig = coin_sig;
+ melt->session.rc = *rc;
+ melt->session.amount_with_fee = amount;
melt->melt_fee = amount_with_fee;
return melt;
}
@@ -541,9 +499,9 @@ PERF_TALER_EXCHANGEDB_refresh_melt_copy (const struct TALER_EXCHANGEDB_RefreshMe
copy = GNUNET_new (struct TALER_EXCHANGEDB_RefreshMelt);
*copy = *melt;
- copy->coin.denom_sig.rsa_signature =
- GNUNET_CRYPTO_rsa_signature_dup (melt->coin.denom_sig.rsa_signature);
- GNUNET_assert (NULL != copy->coin.denom_sig.rsa_signature);
+ copy->session.coin.denom_sig.rsa_signature =
+ GNUNET_CRYPTO_rsa_signature_dup (melt->session.coin.denom_sig.rsa_signature);
+ GNUNET_assert (NULL != copy->session.coin.denom_sig.rsa_signature);
return copy;
}
@@ -558,51 +516,7 @@ PERF_TALER_EXCHANGEDB_refresh_melt_copy (const struct TALER_EXCHANGEDB_RefreshMe
int
PERF_TALER_EXCHANGEDB_refresh_melt_free (struct TALER_EXCHANGEDB_RefreshMelt *melt)
{
- GNUNET_CRYPTO_rsa_signature_free (melt->coin.denom_sig.rsa_signature);
+ GNUNET_CRYPTO_rsa_signature_free (melt->session.coin.denom_sig.rsa_signature);
GNUNET_free (melt);
return GNUNET_OK;
}
-
-
-/**
- * Create a #TALER_EXCHANGEDB_RefreshCommitCoin
- */
-struct TALER_EXCHANGEDB_RefreshCommitCoin *
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_init ()
-{
- struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin;
-
- commit_coin = GNUNET_new (struct TALER_EXCHANGEDB_RefreshCommitCoin);
- commit_coin->coin_ev = "coin_ev";
- commit_coin->coin_ev_size = 8;
- return commit_coin;
-}
-
-
-/**
- * Copies a #TALER_EXCHANGEDB_RefreshCommitCoin
- *
- * @param commit_coin the commit to copy
- * @return a copy of @a commit_coin
- */
-struct TALER_EXCHANGEDB_RefreshCommitCoin *
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_copy (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin)
-{
- struct TALER_EXCHANGEDB_RefreshCommitCoin *copy;
-
- copy = GNUNET_new (struct TALER_EXCHANGEDB_RefreshCommitCoin);
- *copy = *commit_coin;
- return copy;
-}
-
-
-/**
- * Free a #TALER_EXCHANGEDB_RefreshCommitCoin
- *
- * @param commit_coin the coin to free
- */
-void
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_free (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin)
-{
- GNUNET_free (commit_coin);
-}
diff --git a/src/exchangedb/perf_taler_exchangedb_init.h b/src/exchangedb/perf_taler_exchangedb_init.h
index 11b2f1661..a1f2559e2 100644
--- a/src/exchangedb/perf_taler_exchangedb_init.h
+++ b/src/exchangedb/perf_taler_exchangedb_init.h
@@ -44,7 +44,7 @@ struct PERF_TALER_EXCHANGEDB_Reserve
/**
- * All informations about a coin
+ * All informations about a coin
*/
struct PERF_TALER_EXCHANGEDB_Coin
{
@@ -169,42 +169,20 @@ PERF_TALER_EXCHANGEDB_coin_free (struct PERF_TALER_EXCHANGEDB_Coin *coin);
/**
- * @return a randomly generated refresh session
- */
-struct TALER_EXCHANGEDB_RefreshSession *
-PERF_TALER_EXCHANGEDB_refresh_session_init (void);
-
-
-/**
- * @return #GNUNET_OK if the copy was successful, #GNUNET_SYSERR if it wasn't
- */
-int
-PERF_TALER_EXCHANGEDB_refresh_session_copy (struct TALER_EXCHANGEDB_RefreshSession *session,
- struct TALER_EXCHANGEDB_RefreshSession *copy);
-
-
-/**
- * Frees memory of a refresh_session
- */
-int
-PERF_TALER_EXCHANGEDB_refresh_session_free (struct TALER_EXCHANGEDB_RefreshSession *refresh_session);
-
-
-/**
* Create a melt operation
*
- * @param session the refresh session
+ * @param rc the commitment of the refresh session
* @param dki the denomination the melted coin uses
- * @return a pointer to a #TALER_EXCHANGEDB_RefreshMelt
+ * @return a pointer to a #TALER_EXCHANGEDB_RefreshMelt
*/
struct TALER_EXCHANGEDB_RefreshMelt *
-PERF_TALER_EXCHANGEDB_refresh_melt_init (struct GNUNET_HashCode *session,
- struct PERF_TALER_EXCHANGEDB_Coin *coin);
+PERF_TALER_EXCHANGEDB_refresh_melt_init (struct TALER_RefreshCommitmentP *rc,
+ struct PERF_TALER_EXCHANGEDB_Coin *coin);
/**
* Copies the internals of a #TALER_EXCHANGEDB_RefreshMelt
- *
+ *
* @param melt the refresh melt to copy
* @return an copy of @ melt
*/
@@ -221,30 +199,4 @@ PERF_TALER_EXCHANGEDB_refresh_melt_copy (const struct TALER_EXCHANGEDB_RefreshMe
int
PERF_TALER_EXCHANGEDB_refresh_melt_free (struct TALER_EXCHANGEDB_RefreshMelt *melt);
-
-/**
- * Create a #TALER_EXCHANGEDB_RefreshCommitCoin
- */
-struct TALER_EXCHANGEDB_RefreshCommitCoin *
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_init (void);
-
-
-/**
- * Copies a #TALER_EXCHANGEDB_RefreshCommitCoin
- *
- * @param commit_coin the commit to copy
- * @return a copy of @a commit_coin
- */
-struct TALER_EXCHANGEDB_RefreshCommitCoin *
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_copy (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin);
-
-
-/**
- * Free a #TALER_EXCHANGEDB_RefreshCommitCoin
- *
- * @param commit_coin the coin to free
- */
-void
-PERF_TALER_EXCHANGEDB_refresh_commit_coin_free (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin);
-
#endif
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c
index 7ec958c48..eca519527 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.c
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c
@@ -59,50 +59,40 @@ data_free (struct PERF_TALER_EXCHANGEDB_Data *data)
{
switch (data->type)
{
- case PERF_TALER_EXCHANGEDB_TIME:
- if (NULL == data->data.time)
- break;
- GNUNET_free (data->data.time);
- data->data.time = NULL;
- break;
-
- case PERF_TALER_EXCHANGEDB_DEPOSIT:
- if (NULL == data->data.deposit)
- break;
- PERF_TALER_EXCHANGEDB_deposit_free (data->data.deposit);
- data->data.deposit = NULL;
- break;
-
- case PERF_TALER_EXCHANGEDB_COIN:
- if (NULL == data->data.coin)
- break;
- PERF_TALER_EXCHANGEDB_coin_free (data->data.coin);
- data->data.coin = NULL;
+ case PERF_TALER_EXCHANGEDB_TIME:
+ if (NULL == data->data.time)
break;
-
- case PERF_TALER_EXCHANGEDB_RESERVE:
- if (NULL == data->data.reserve)
- break;
- PERF_TALER_EXCHANGEDB_reserve_free (data->data.reserve);
- data->data.reserve = NULL;
+ GNUNET_free (data->data.time);
+ data->data.time = NULL;
+ break;
+ case PERF_TALER_EXCHANGEDB_DEPOSIT:
+ if (NULL == data->data.deposit)
break;
-
- case PERF_TALER_EXCHANGEDB_DENOMINATION_INFO:
- if (NULL == data->data.dki)
- break;
- PERF_TALER_EXCHANGEDB_denomination_free (data->data.dki);
- data->data.dki = NULL;
+ PERF_TALER_EXCHANGEDB_deposit_free (data->data.deposit);
+ data->data.deposit = NULL;
+ break;
+ case PERF_TALER_EXCHANGEDB_COIN:
+ if (NULL == data->data.coin)
break;
-
- case PERF_TALER_EXCHANGEDB_REFRESH_HASH:
- if (NULL == data->data.session_hash)
- break;
- GNUNET_free (data->data.session_hash);
- data->data.session_hash = NULL;
+ GNUNET_free (data->data.coin);
+ data->data.coin = NULL;
+ break;
+ case PERF_TALER_EXCHANGEDB_RESERVE:
+ if (NULL == data->data.reserve)
break;
-
- case PERF_TALER_EXCHANGEDB_NONE:
+ PERF_TALER_EXCHANGEDB_reserve_free (data->data.reserve);
+ data->data.reserve = NULL;
+ break;
+ case PERF_TALER_EXCHANGEDB_DENOMINATION_INFO:
+ if (NULL == data->data.dki)
break;
+ PERF_TALER_EXCHANGEDB_denomination_free (data->data.dki);
+ data->data.dki = NULL;
+ break;
+ case PERF_TALER_EXCHANGEDB_REFRESH_HASH:
+ break;
+ case PERF_TALER_EXCHANGEDB_NONE:
+ break;
}
}
@@ -124,33 +114,25 @@ data_copy (const struct PERF_TALER_EXCHANGEDB_Data *data,
copy->data.time = GNUNET_new (struct GNUNET_TIME_Absolute);
*copy->data.time = *data->data.time;
return;
-
case PERF_TALER_EXCHANGEDB_DEPOSIT:
copy->data.deposit
= PERF_TALER_EXCHANGEDB_deposit_copy (data->data.deposit);
return;
-
case PERF_TALER_EXCHANGEDB_COIN:
copy->data.coin
= PERF_TALER_EXCHANGEDB_coin_copy (data->data.coin);
return;
-
case PERF_TALER_EXCHANGEDB_RESERVE:
copy->data.reserve
= PERF_TALER_EXCHANGEDB_reserve_copy (data->data.reserve);
return;
-
case PERF_TALER_EXCHANGEDB_DENOMINATION_INFO:
copy->data.dki
= PERF_TALER_EXCHANGEDB_denomination_copy (data->data.dki);
return;
-
case PERF_TALER_EXCHANGEDB_REFRESH_HASH:
- copy-> data.session_hash = GNUNET_new (struct GNUNET_HashCode);
- *copy->data.session_hash
- = *data->data.session_hash;
+ copy->data.rc = data->data.rc;
break;
-
case PERF_TALER_EXCHANGEDB_NONE:
break;
}
@@ -210,9 +192,10 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
if (PERF_TALER_EXCHANGEDB_CMD_LOOP != cmd[ret].command)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.end_loop.label_loop);
+ cmd[i].details.end_loop.label_loop,
+ cmd[i].label);
return GNUNET_SYSERR;
}
cmd[i].details.end_loop.index_loop = ret;
@@ -228,17 +211,19 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
+ "%d:Undefined reference to %s at %s\n",
i,
- cmd[i].details.save_array.label_save);
+ cmd[i].details.save_array.label_save,
+ cmd[i].label);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_NONE == cmd[ret].exposed.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.save_array.label_save);
+ cmd[i].details.save_array.label_save,
+ cmd[i].label);
return GNUNET_SYSERR;
}
cmd[i].details.save_array.index_save = ret;
@@ -248,17 +233,19 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
+ "%d:Undefined reference to %s at %s\n",
i,
- cmd[i].details.save_array.label_loop);
+ cmd[i].details.save_array.label_loop,
+ cmd[i].label);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_CMD_LOOP != cmd[ret].command)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.save_array.label_loop);
+ cmd[i].details.save_array.label_loop,
+ cmd[i].label);
return GNUNET_SYSERR;
}
cmd[i].details.save_array.index_loop = ret;
@@ -281,17 +268,19 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
+ "%d:Undefined reference to %s at %s\n",
i,
- cmd[i].details.load_array.label_save);
+ cmd[i].details.load_array.label_save,
+ cmd[i].label);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY != cmd[ret].command)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.load_array.label_save);
+ cmd[i].details.load_array.label_save,
+ cmd[i].label);
return GNUNET_SYSERR;
}
cmd[i].details.load_array.index_save = ret;
@@ -732,188 +721,73 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION:
- {
- int ret;
-
- ret = cmd_find (cmd,
- cmd[i].details.get_refresh_session.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.get_refresh_session.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.get_refresh_session.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.get_refresh_session.index_hash = ret;
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
+ case PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION:
{
int ret;
- ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_order.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.insert_refresh_order.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.insert_refresh_order.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.insert_refresh_order.index_hash = ret;
ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_order.label_denom);
+ cmd[i].details.create_refresh_session.label_coin);
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
+ "%d:Undefined reference to %s at %s\n",
i,
- cmd[i].details.insert_refresh_order.label_denom);
+ cmd[i].details.create_refresh_session.label_coin,
+ cmd[i].label);
return GNUNET_SYSERR;
}
- if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
+ if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.insert_refresh_order.label_denom);
+ cmd[i].details.create_refresh_session.label_coin,
+ cmd[i].label);
return GNUNET_SYSERR;
}
- cmd[i].details.insert_refresh_order.index_denom = ret;
+ cmd[i].details.create_refresh_session.index_coin = ret;
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER:
+ case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION:
{
int ret;
- ret = cmd_find (cmd,
- cmd[i].details.get_refresh_order.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.get_refresh_order.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.get_refresh_order.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.get_refresh_order.index_hash = ret;
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN:
- {
- int ret;
- ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_commit_coin.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.insert_refresh_commit_coin.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.insert_refresh_commit_coin.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.insert_refresh_commit_coin.index_hash = ret;
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN:
- {
- int ret;
- ret = cmd_find (cmd,
- cmd[i].details.get_refresh_commit_coin.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.get_refresh_commit_coin.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.get_refresh_commit_coin.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.get_refresh_commit_coin.index_hash = ret;
- }
- break;
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK:
- {
- int ret;
ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_commit_link.label_hash);
+ cmd[i].details.get_refresh_session.label_hash);
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
+ "%d:Undefined reference to %s at %s\n",
i,
- cmd[i].details.insert_refresh_commit_link.label_hash);
+ cmd[i].details.get_refresh_session.label_hash,
+ cmd[i].label);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
+ "%d:Wrong type reference to %s at %s\n",
i,
- cmd[i].details.insert_refresh_commit_link.label_hash);
+ cmd[i].details.get_refresh_session.label_hash,
+ cmd[i].label);
return GNUNET_SYSERR;
}
- cmd[i].details.insert_refresh_commit_link.index_hash = ret;
+ cmd[i].details.get_refresh_session.index_hash = ret;
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK:
- {
+ case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_REVEAL:
+ {
int ret;
ret = cmd_find (cmd,
- cmd[i].details.get_refresh_commit_link.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_hash);
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Undefined reference to %s\n",
i,
- cmd[i].details.get_refresh_commit_link.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_hash);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
@@ -921,49 +795,44 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Wrong type reference to %s\n",
i,
- cmd[i].details.get_refresh_commit_link.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_hash);
return GNUNET_SYSERR;
}
- cmd[i].details.get_refresh_commit_link.index_hash = ret;
- }
- break;
+ cmd[i].details.insert_refresh_reveal.index_hash = ret;
- case PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT:
- {
- int ret;
ret = cmd_find (cmd,
- cmd[i].details.get_melt_commitment.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_denom);
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Undefined reference to %s\n",
i,
- cmd[i].details.get_melt_commitment.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_denom);
return GNUNET_SYSERR;
}
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
+ if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Wrong type reference to %s\n",
i,
- cmd[i].details.get_melt_commitment.label_hash);
+ cmd[i].details.insert_refresh_reveal.label_denom);
return GNUNET_SYSERR;
}
- cmd[i].details.get_melt_commitment.index_hash = ret;
+ cmd[i].details.insert_refresh_reveal.index_denom = ret;
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT:
- {
+ case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_REVEAL:
+ {
int ret;
ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_out.label_hash);
+ cmd[i].details.get_refresh_reveal.label_hash);
if (GNUNET_SYSERR == ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Undefined reference to %s\n",
i,
- cmd[i].details.insert_refresh_out.label_hash);
+ cmd[i].details.get_refresh_reveal.label_hash);
return GNUNET_SYSERR;
}
if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
@@ -971,14 +840,14 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%d:Wrong type reference to %s\n",
i,
- cmd[i].details.insert_refresh_out.label_hash);
+ cmd[i].details.get_refresh_reveal.label_hash);
return GNUNET_SYSERR;
}
- cmd[i].details.insert_refresh_out.index_hash = ret;
+ cmd[i].details.get_refresh_reveal.index_hash = ret;
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST:
+ case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA:
{
int ret;
ret = cmd_find (cmd,
@@ -1003,31 +872,6 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER:
- {
- int ret;
- ret = cmd_find (cmd,
- cmd[i].details.get_transfer.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.get_transfer.label_hash);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.get_transfer.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.get_transfer.index_hash = ret;
- }
- break;
-
case PERF_TALER_EXCHANGEDB_CMD_END:
case PERF_TALER_EXCHANGEDB_CMD_DEBUG:
case PERF_TALER_EXCHANGEDB_CMD_LOOP:
@@ -1038,7 +882,6 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
case PERF_TALER_EXCHANGEDB_CMD_GET_TIME:
case PERF_TALER_EXCHANGEDB_CMD_CREATE_DENOMINATION:
case PERF_TALER_EXCHANGEDB_CMD_CREATE_RESERVE:
- case PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION:
break;
}
}
@@ -1092,12 +935,11 @@ cmd_clean (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
static void
interpret_end_loop (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
{
- unsigned int i;
int jump;
jump = state->cmd[state->i].details.end_loop.index_loop;
// Cleaning up the memory in the loop
- for (i = jump; i < state->i; i++)
+ for (unsigned int i = jump; i < state->i; i++)
data_free (&state->cmd[i].exposed);
state->cmd[jump].details.loop.curr_iteration++;
@@ -1230,6 +1072,29 @@ interprete_load_random (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
/**
+ * Function called with information about a refresh order.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the row in our database
+ * @param num_newcoins size of the @a rrcs array
+ * @param rrcs array of @a num_newcoins information about coins to be created
+ * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
+ * @param tprivs array of @e num_tprivs transfer private keys
+ * @param tp transfer public key information
+ */
+static void
+refresh_reveal_cb (void *cls,
+ uint32_t num_newcoins,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivs,
+ const struct TALER_TransferPublicKeyP *tp)
+{
+ /* intentionally empty */
+}
+
+
+/**
* Iterate over the commands, acting accordingly at each step
*
* @param state the current state of the interpreter
@@ -1340,10 +1205,11 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
deposit_index = state->cmd[state->i].details.insert_deposit.index_deposit;
deposit = state->cmd[deposit_index].exposed.data.deposit;
qs = state->plugin->insert_deposit (state->plugin->cls,
- state->session,
- deposit);
+ state->session,
+ deposit);
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
- state->cmd[state->i].exposed.data.deposit = deposit;
+ state->cmd[state->i].exposed.data.deposit
+ = PERF_TALER_EXCHANGEDB_deposit_copy (deposit);
}
break;
@@ -1502,8 +1368,8 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
coin_index = state->cmd[state->i].details.insert_withdraw.index_coin;
coin = state->cmd[coin_index].exposed.data.coin;
qs = state->plugin->insert_withdraw_info (state->plugin->cls,
- state->session,
- &coin->blind);
+ state->session,
+ &coin->blind);
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
}
break;
@@ -1546,143 +1412,100 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
case PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION:
{
- struct GNUNET_HashCode *hash;
- struct TALER_EXCHANGEDB_RefreshSession *refresh_session;
+ struct TALER_EXCHANGEDB_RefreshSession refresh_session;
+ unsigned int coin_index;
+ struct PERF_TALER_EXCHANGEDB_Coin *coin;
- hash = GNUNET_new (struct GNUNET_HashCode);
- refresh_session = PERF_TALER_EXCHANGEDB_refresh_session_init ();
+ coin_index = state->cmd[state->i].details.create_refresh_session.index_coin;
+ coin = state->cmd[coin_index].exposed.data.coin;
+
+ refresh_session.coin = coin->public_info;
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &refresh_session.coin_sig,
+ sizeof (refresh_session.coin_sig));
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- hash);
+ &refresh_session.rc.session_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.1",
+ &refresh_session.amount_with_fee));
+ refresh_session.noreveal_index = 1;
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
- state->plugin->create_refresh_session (state->session,
- state->session,
- hash,
- refresh_session));
- state->cmd[state->i].exposed.data.session_hash = hash;
- PERF_TALER_EXCHANGEDB_refresh_session_free (refresh_session);
- GNUNET_free (refresh_session);
+ state->plugin->insert_melt (state->session,
+ state->session,
+ &refresh_session));
+ state->cmd[state->i].exposed.data.rc = refresh_session.rc;
}
break;
case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION:
{
unsigned int hash_index;
- struct GNUNET_HashCode *hash;
- struct TALER_EXCHANGEDB_RefreshSession refresh;
+ const struct TALER_RefreshCommitmentP *rc;
+ struct TALER_EXCHANGEDB_RefreshMelt refresh;
hash_index = state->cmd[state->i].details.get_refresh_session.index_hash;
- hash = state->cmd[hash_index].exposed.data.session_hash;
- state->plugin->get_refresh_session (state->session,
- state->session,
- hash,
- &refresh);
+ rc = &state->cmd[hash_index].exposed.data.rc;
+ state->plugin->get_melt (state->session,
+ state->session,
+ rc,
+ &refresh);
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
+ case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_REVEAL:
{
unsigned int hash_index;
unsigned int denom_index;
- struct GNUNET_HashCode *session_hash;
+ const struct TALER_RefreshCommitmentP *rc;
struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *denom;
+ struct TALER_TransferPublicKeyP tpub;
+ struct TALER_TransferPrivateKeyP tprivs[2];
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin rrc;
- hash_index = state->cmd[state->i].details.insert_refresh_order.index_hash;
- denom_index = state->cmd[state->i].details.insert_refresh_order.index_denom;
- session_hash = state->cmd[hash_index].exposed.data.session_hash;
+ hash_index = state->cmd[state->i].details.insert_refresh_reveal.index_hash;
+ denom_index = state->cmd[state->i].details.insert_refresh_reveal.index_denom;
+ rc = &state->cmd[hash_index].exposed.data.rc;
denom = state->cmd[denom_index].exposed.data.dki;
+ rrc.denom_pub = denom->denom_pub;
+ rrc.coin_ev = "coin_ev";
+ rrc.coin_ev_size = strlen (rrc.coin_ev) + 1;
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &rrc.coin_sig,
+ sizeof (struct TALER_CoinSpendSignatureP));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ tprivs,
+ sizeof (struct TALER_TransferPrivateKeyP) * 2);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &tpub,
+ sizeof (struct TALER_TransferPublicKeyP));
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
- state->plugin->insert_refresh_order (state->plugin->cls,
- state->session,
- session_hash,
- 1,
- &denom->denom_pub));
-
+ state->plugin->insert_refresh_reveal (state->plugin->cls,
+ state->session,
+ rc,
+ 1,
+ &rrc,
+ 2,
+ tprivs,
+ &tpub));
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER:
+ case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_REVEAL:
{
int hash_index;
- struct GNUNET_HashCode *hash;
- struct TALER_DenominationPublicKey denom_pub;
-
- hash_index = state->cmd[state->i].details.get_refresh_order.index_hash;
- hash = state->cmd[hash_index].exposed.data.session_hash;
- state->plugin->get_refresh_order (state->plugin->cls,
- state->session,
- hash,
- 1,
- &denom_pub);
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN:
- {
- enum GNUNET_DB_QueryStatus qs;
- unsigned int hash_index;
- struct TALER_EXCHANGEDB_RefreshCommitCoin *refresh_commit;
-
- hash_index = state->cmd[state->i].details.insert_refresh_commit_coin.index_hash;
- refresh_commit = PERF_TALER_EXCHANGEDB_refresh_commit_coin_init ();
- qs = state->plugin->insert_refresh_commit_coins (state->plugin->cls,
- state->session,
- state->cmd[hash_index].exposed.data.session_hash,
- 1,
- refresh_commit);
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN:
- {
- unsigned int hash_index;
- struct TALER_EXCHANGEDB_RefreshCommitCoin refresh_commit;
-
- hash_index = state->cmd[state->i].details.insert_refresh_commit_coin.index_hash;
- state->plugin->get_refresh_commit_coins (state->plugin->cls,
- state->session,
- state->cmd[hash_index].exposed.data.session_hash,
- 1,
- &refresh_commit);
-
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK:
- {
-// unsigned int hash_index;
-//
-// hash_index = state->cmd[state->i].details.insert_refresh_commit_link.index_hash;
- }
- break;
+ const struct TALER_RefreshCommitmentP *rc;
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK:
- {
- int ret;
- unsigned int hash_index;
- struct TALER_EXCHANGEDB_RefreshCommitCoin commit_coin;
-
- // FIXME: this should go after the public key!
- hash_index = state->cmd[state->i].details.get_refresh_commit_link.index_hash;
- ret = state->plugin->get_refresh_commit_coins(state->plugin->cls,
- state->session,
- state->cmd[hash_index].exposed.data.session_hash,
- 1,
- &commit_coin);
- GNUNET_assert (GNUNET_SYSERR != ret);
+ hash_index = state->cmd[state->i].details.get_refresh_reveal.index_hash;
+ rc = &state->cmd[hash_index].exposed.data.rc;
+ state->plugin->get_refresh_reveal (state->plugin->cls,
+ state->session,
+ rc,
+ &refresh_reveal_cb,
+ state);
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT:
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT:
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST:
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER:
+ case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA:
break;
}
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.h b/src/exchangedb/perf_taler_exchangedb_interpreter.h
index 169811bdd..60e676069 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.h
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.h
@@ -331,7 +331,7 @@
}
/**
- * Inserts informations about a withdrawal in the database
+ * Inserts information about a withdrawal into the database
*
* @exposes #PERF_TALER_EXCHANGEDB_COIN
*
@@ -452,16 +452,18 @@
_label_coin), \
PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_DEPOSIT (_label "insert", \
_label "deposit")
+
/**
* Insert informations about a refresh session
* melts one coin into another
*
* @param _label the label of the command
*/
-#define PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION(_label) \
+#define PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_REFRESH_SESSION(_label, _label_coin) \
{ \
.command = PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION, \
.label = _label, \
+ .details.create_refresh_session.label_coin = _label_coin, \
.exposed.type = PERF_TALER_EXCHANGEDB_REFRESH_HASH \
}
@@ -519,7 +521,7 @@ struct PERF_TALER_EXCHANGEDB_Data
/** #PERF_TALER_EXCHANGEDB_DENOMINATION_INFO */
struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
/** #PERF_TALER_EXCHANGEDB_REFRESH_HASH */
- struct GNUNET_HashCode *session_hash;
+ struct TALER_RefreshCommitmentP rc;
} data;
};
@@ -679,54 +681,19 @@ enum PERF_TALER_EXCHANGEDB_CMD_Name
PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION,
/**
- * Insert a melt refresh order
- */
- PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER,
-
- /**
- * Get informations about a refresh order
- */
- PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER,
-
- /**
- * Insert refresh commit coin
- */
- PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN,
-
- /**
- * Get refresh commit coin
- */
- PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN,
-
- /**
- * Insert refresh commit link
- */
- PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK,
-
- /**
- * Get refresh commit link
- */
- PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK,
-
- /**
- * Get information avout the melt commit
+ * Insert a melt refresh reveal data
*/
- PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT,
+ PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_REVEAL,
/**
- * Insert a new coin into the database after a melt operation
+ * Get informations about a refresh reveal data
*/
- PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT,
+ PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_REVEAL,
/**
* Get the link data list of a coin
*/
- PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST,
-
- /**
- * Get the shared secret and the transfere public key
- */
- PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER
+ PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA
};
@@ -1029,6 +996,18 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
} get_deposit;
/**
+ * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION command
+ */
+ struct PERF_TALER_EXCHANGEDB_CMD_createRefreshSessionDetails
+ {
+ /**
+ * label of the source of the hash of the session
+ */
+ const char *label_coin;
+ unsigned int index_coin;
+ } create_refresh_session;
+
+ /**
* Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION command
*/
struct PERF_TALER_EXCHANGEDB_CMD_getRefreshSessionDetails
@@ -1041,9 +1020,9 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
} get_refresh_session;
/**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER command
+ * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_REVEAL command
*/
- struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshOrderDetails
+ struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshRevealDetails
{
/**
* The refresh session hash
@@ -1056,12 +1035,12 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
*/
const char *label_denom;
unsigned int index_denom;
- } insert_refresh_order;
+ } insert_refresh_reveal;
/**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER command
+ * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_REVEAL command
*/
- struct PERF_TALER_EXCHANGEDB_CMD_getRefreshOrderDetails
+ struct PERF_TALER_EXCHANGEDB_CMD_getRefreshRevealDetails
{
/**
* The session hash
@@ -1069,82 +1048,7 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
const char *label_hash;
unsigned int index_hash;
- } get_refresh_order;
-
- /**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshCommitCoinDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
-
- } insert_refresh_commit_coin;
-
- /**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_getRefreshCommitCoinDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
-
- } get_refresh_commit_coin;
-
- /**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshCommitLinkDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
-
- } insert_refresh_commit_link;
-
- /**
- * Data requiered by the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_getRefreshCommitLinkDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
- } get_refresh_commit_link;
-
- /**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_getMeltCommitmentDaetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
- } get_melt_commitment;
-
- /**
- * Data requiered by the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshOutDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
- } insert_refresh_out;
+ } get_refresh_reveal;
/**
* Data requiered by the #PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST command
@@ -1158,17 +1062,6 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
unsigned int index_hash;
} get_link_data_list;
- /**
- * Data requiered by the #PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_getTransferDetails
- {
- /**
- * The refresh session hash
- */
- const char *label_hash;
- unsigned int index_hash;
- } get_transfer;
};
diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c
index 61c00c14d..e4b832491 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -74,31 +74,6 @@ common_free_reserve_history (void *cls,
/**
- * Free memory of the link data list.
- *
- * @param cls the @e cls of this struct with the plugin-specific state (unused)
- * @param ldl link data list to release
- */
-static void
-common_free_link_data_list (void *cls,
- struct TALER_EXCHANGEDB_LinkDataList *ldl)
-{
- struct TALER_EXCHANGEDB_LinkDataList *next;
-
- while (NULL != ldl)
- {
- next = ldl->next;
- if (NULL != ldl->denom_pub.rsa_public_key)
- GNUNET_CRYPTO_rsa_public_key_free (ldl->denom_pub.rsa_public_key);
- if (NULL != ldl->ev_sig.rsa_signature)
- GNUNET_CRYPTO_rsa_signature_free (ldl->ev_sig.rsa_signature);
- GNUNET_free (ldl);
- ldl = next;
- }
-}
-
-
-/**
* Free linked list of transactions.
*
* @param cls the @e cls of this struct with the plugin-specific state (unused)
@@ -125,10 +100,10 @@ common_free_coin_transaction_list (void *cls,
GNUNET_free (list->details.deposit);
break;
case TALER_EXCHANGEDB_TT_REFRESH_MELT:
- if (NULL != list->details.melt->coin.denom_pub.rsa_public_key)
- GNUNET_CRYPTO_rsa_public_key_free (list->details.melt->coin.denom_pub.rsa_public_key);
- if (NULL != list->details.melt->coin.denom_sig.rsa_signature)
- GNUNET_CRYPTO_rsa_signature_free (list->details.melt->coin.denom_sig.rsa_signature);
+ if (NULL != list->details.melt->session.coin.denom_pub.rsa_public_key)
+ GNUNET_CRYPTO_rsa_public_key_free (list->details.melt->session.coin.denom_pub.rsa_public_key);
+ if (NULL != list->details.melt->session.coin.denom_sig.rsa_signature)
+ GNUNET_CRYPTO_rsa_signature_free (list->details.melt->session.coin.denom_sig.rsa_signature);
GNUNET_free (list->details.melt);
break;
case TALER_EXCHANGEDB_TT_REFUND:
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 93a8c1a8b..b6e862ab9 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -23,6 +23,7 @@
* @author Marcello Stanisci
*/
#include "platform.h"
+#include "taler_error_codes.h"
#include "taler_pq_lib.h"
#include "taler_exchangedb_plugin.h"
#include <pthread.h>
@@ -105,12 +106,10 @@ postgres_drop_tables (void *cls)
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS wire_out CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS wire_fee CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS deposits CASCADE;"),
- GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_out CASCADE;"),
- GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_commit_coin CASCADE;"),
- GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_transfer_public_key CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refunds CASCADE;"),
- GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_order CASCADE;"),
- GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_sessions CASCADE;"),
+ GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_commitments CASCADE;"),
+ GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_revealed_coins CASCADE;"),
+ GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS refresh_transfer_keys CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS known_coins CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS reserves_close CASCADE;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS reserves_out CASCADE;"),
@@ -266,67 +265,46 @@ postgres_create_tables (void *cls)
",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
",denom_sig BYTEA NOT NULL"
");"),
- /**
- * The DB will show negative values for some values of the following fields as
- * we use them as 16 bit unsigned integers
- * @a num_newcoins
- * @a noreveal_index
- * Do not do arithmetic in SQL on these fields.
- * NOTE: maybe we should instead forbid values >= 2^15 categorically?
- */
- GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_sessions "
+
+ /* Table with the commitments made when melting a coin. */
+ GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_commitments "
"(melt_serial_id BIGSERIAL UNIQUE"
- ",session_hash BYTEA PRIMARY KEY CHECK (LENGTH(session_hash)=64)"
+ ",rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)"
",old_coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)"
",amount_with_fee_val INT8 NOT NULL"
",amount_with_fee_frac INT4 NOT NULL"
",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
- ",num_newcoins INT2 NOT NULL"
- ",noreveal_index INT2 NOT NULL"
- ");"),
- GNUNET_PQ_make_try_execute ("CREATE INDEX refresh_sessions_old_coin_pub_index ON "
- "refresh_sessions (old_coin_pub);"),
-
- /* Table with information about the desired denominations to be created
- during a refresh operation; contains the denomination key for each
- of the coins (for a given refresh session) */
- GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_order "
- "(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE"
- ",newcoin_index INT2 NOT NULL "
- ",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
- ",PRIMARY KEY (session_hash, newcoin_index)"
+ ",noreveal_index INT4 NOT NULL"
");"),
- /* Table with the commitments for a refresh operation; includes
- the session_hash for which this is the link information, the
- oldcoin index and the cut-and-choose index (from 0 to #TALER_CNC_KAPPA-1),
- as well as the actual link data (the transfer public key and the encrypted
- link secret) */
- GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_transfer_public_key "
- "(session_hash BYTEA NOT NULL PRIMARY KEY REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE"
- ",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
- ");"),
- /* Table with the commitments for the new coins that are to be created
+ GNUNET_PQ_make_try_execute ("CREATE INDEX refresh_commitments_old_coin_pub_index ON "
+ "refresh_commitments (old_coin_pub);"),
+
+ /* Table with the revelations about the new coins that are to be created
during a melting session. Includes the session, the cut-and-choose
index and the index of the new coin, and the envelope of the new
coin to be signed, as well as the encrypted information about the
private key and the blinding factor for the coin (for verification
in case this newcoin_index is chosen to be revealed) */
- GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_commit_coin "
- "(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE"
- ",newcoin_index INT2 NOT NULL"
+ GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_revealed_coins "
+ "(rc BYTEA NOT NULL REFERENCES refresh_commitments (rc) ON DELETE CASCADE"
+ ",newcoin_index INT4 NOT NULL"
+ ",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
",coin_ev BYTEA NOT NULL"
- ",PRIMARY KEY (session_hash, newcoin_index)"
- ");"),
- /* Table with the signatures over coins generated during a refresh
- operation. Needed to answer /refresh/link queries later. Stores
- the coin signatures under the respective session hash and index. */
- GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_out "
- "(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE"
- ",newcoin_index INT2 NOT NULL"
",ev_sig BYTEA NOT NULL"
- ",PRIMARY KEY (session_hash, newcoin_index)"
+ ",PRIMARY KEY (rc, newcoin_index)"
+ ");"),
+
+ /* Table with the transfer keys of a refresh operation; includes
+ the rc for which this is the link information, the
+ transfer public key (for gamma) and the revealed transfer private
+ keys (array of TALER_CNC_KAPPA - 1 entries, with gamma being skipped) */
+ GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_transfer_keys "
+ "(rc BYTEA NOT NULL PRIMARY KEY REFERENCES refresh_commitments (rc) ON DELETE CASCADE"
+ ",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
+ ",transfer_privs BYTEA NOT NULL"
");"),
+
/* This table contains the wire transfers the exchange is supposed to
execute to transmit funds to the merchants (and manage refunds). */
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS deposits "
@@ -726,64 +704,7 @@ postgres_prepare (PGconn *db_conn)
" WHERE reserve_out_serial_id>=$1"
" ORDER BY reserve_out_serial_id ASC;",
1),
- /* Used in #postgres_get_refresh_session() to fetch
- high-level information about a refresh session */
- GNUNET_PQ_make_prepare ("get_refresh_session",
- "SELECT"
- " old_coin_pub"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",amount_with_fee_curr"
- ",denom.fee_refresh_val "
- ",denom.fee_refresh_frac "
- ",denom.fee_refresh_curr "
- ",num_newcoins"
- ",noreveal_index"
- " FROM refresh_sessions"
- " JOIN known_coins"
- " ON (refresh_sessions.old_coin_pub = known_coins.coin_pub)"
- " JOIN denominations denom"
- " USING (denom_pub_hash)"
- " WHERE session_hash=$1;",
- 1),
- /* Used in #postgres_select_refreshs_above_serial_id() to fetch
- refresh session with id '\geq' the given parameter */
- GNUNET_PQ_make_prepare ("audit_get_refresh_sessions_incr",
- "SELECT"
- " denom.denom_pub"
- ",old_coin_pub"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",amount_with_fee_curr"
- ",num_newcoins"
- ",noreveal_index"
- ",melt_serial_id"
- ",session_hash"
- " FROM refresh_sessions"
- " JOIN known_coins kc"
- " ON (refresh_sessions.old_coin_pub = kc.coin_pub)"
- " JOIN denominations denom"
- " ON (kc.denom_pub_hash = denom.denom_pub_hash)"
- " WHERE melt_serial_id>=$1"
- " ORDER BY melt_serial_id ASC;",
- 1),
- /* Used in #postgres_create_refresh_session() to store
- high-level information about a refresh session */
- GNUNET_PQ_make_prepare ("insert_refresh_session",
- "INSERT INTO refresh_sessions "
- "(session_hash "
- ",old_coin_pub "
- ",old_coin_sig "
- ",amount_with_fee_val "
- ",amount_with_fee_frac "
- ",amount_with_fee_curr "
- ",num_newcoins "
- ",noreveal_index "
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
+
/* Used in #postgres_get_known_coin() to fetch
the denomination public key and signature for
a coin known to the exchange. */
@@ -807,30 +728,68 @@ postgres_prepare (PGconn *db_conn)
") VALUES "
"($1,$2,$3);",
3),
- /* Store information about the desired denominations for a
- refresh operation, used in #postgres_insert_refresh_order() */
- GNUNET_PQ_make_prepare ("insert_refresh_order",
- "INSERT INTO refresh_order "
- "(newcoin_index "
- ",session_hash "
- ",denom_pub_hash "
+
+ /* Used in #postgres_insert_melt() to store
+ high-level information about a melt operation */
+ GNUNET_PQ_make_prepare ("insert_melt",
+ "INSERT INTO refresh_commitments "
+ "(rc "
+ ",old_coin_pub "
+ ",old_coin_sig "
+ ",amount_with_fee_val "
+ ",amount_with_fee_frac "
+ ",amount_with_fee_curr "
+ ",noreveal_index "
") VALUES "
- "($1, $2, $3);",
- 3),
- /* Obtain information about the desired denominations for a
- refresh operation, used in #postgres_get_refresh_order() */
- GNUNET_PQ_make_prepare ("get_refresh_order",
- "SELECT denom_pub"
- " FROM refresh_order"
- " JOIN denominations denom "
- " USING (denom_pub_hash)"
- " WHERE session_hash=$1"
- " AND newcoin_index=$2;",
- 2),
- /* Query the 'refresh_sessions' by coin public key */
+ "($1, $2, $3, $4, $5, $6, $7);",
+ 7),
+ /* Used in #postgres_get_melt() to fetch
+ high-level information about a melt operation */
+ GNUNET_PQ_make_prepare ("get_melt",
+ "SELECT"
+ " denom.denom_pub"
+ ",denom.fee_refresh_val"
+ ",denom.fee_refresh_frac"
+ ",denom.fee_refresh_curr"
+ ",kc.denom_sig"
+ ",old_coin_pub"
+ ",old_coin_sig"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",amount_with_fee_curr"
+ ",noreveal_index"
+ " FROM refresh_commitments"
+ " JOIN known_coins kc"
+ " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denom_pub_hash = denom.denom_pub_hash)"
+ " WHERE rc=$1;",
+ 1),
+ /* Used in #postgres_select_refreshs_above_serial_id() to fetch
+ refresh session with id '\geq' the given parameter */
+ GNUNET_PQ_make_prepare ("audit_get_refresh_commitments_incr",
+ "SELECT"
+ " denom.denom_pub"
+ ",old_coin_pub"
+ ",old_coin_sig"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",amount_with_fee_curr"
+ ",noreveal_index"
+ ",melt_serial_id"
+ ",rc"
+ " FROM refresh_commitments"
+ " JOIN known_coins kc"
+ " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denom_pub_hash = denom.denom_pub_hash)"
+ " WHERE melt_serial_id>=$1"
+ " ORDER BY melt_serial_id ASC;",
+ 1),
+ /* Query the 'refresh_commitments' by coin public key */
GNUNET_PQ_make_prepare ("get_refresh_session_by_coin",
"SELECT"
- " session_hash"
+ " rc"
",old_coin_sig"
",amount_with_fee_val"
",amount_with_fee_frac"
@@ -838,31 +797,75 @@ postgres_prepare (PGconn *db_conn)
",denom.fee_refresh_val "
",denom.fee_refresh_frac "
",denom.fee_refresh_curr "
- " FROM refresh_sessions"
+ " FROM refresh_commitments"
" JOIN known_coins "
- " ON (refresh_sessions.old_coin_pub = known_coins.coin_pub)"
+ " ON (refresh_commitments.old_coin_pub = known_coins.coin_pub)"
" JOIN denominations denom USING (denom_pub_hash)"
" WHERE old_coin_pub=$1;",
1),
- /* Fetch refunds with rowid '\geq' the given parameter */
- GNUNET_PQ_make_prepare ("audit_get_refunds_incr",
- "SELECT"
- " merchant_pub"
- ",merchant_sig"
- ",h_contract_terms"
- ",rtransaction_id"
+
+ /* Store information about the desired denominations for a
+ refresh operation, used in #postgres_insert_refresh_reveal() */
+ GNUNET_PQ_make_prepare ("insert_refresh_revealed_coin",
+ "INSERT INTO refresh_revealed_coins "
+ "(rc "
+ ",newcoin_index "
+ ",denom_pub_hash "
+ ",coin_ev"
+ ",ev_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);",
+ 5),
+ /* Obtain information about the coins created in a refresh
+ operation, used in #postgres_get_refresh_reveal() */
+ GNUNET_PQ_make_prepare ("get_refresh_revealed_coins",
+ "SELECT "
+ " newcoin_index"
",denom.denom_pub"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",amount_with_fee_curr"
- ",refund_serial_id"
- " FROM refunds"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations denom ON (kc.denom_pub_hash = denom.denom_pub_hash)"
- " WHERE refund_serial_id>=$1"
- " ORDER BY refund_serial_id ASC;",
+ ",coin_ev"
+ ",ev_sig"
+ " FROM refresh_revealed_coins"
+ " JOIN denominations denom "
+ " USING (denom_pub_hash)"
+ " WHERE rc=$1"
+ " ORDER BY newcoin_index ASC;",
+ 1),
+
+ /* Used in #postgres_insert_refresh_reveal() to store the transfer
+ keys we learned */
+ GNUNET_PQ_make_prepare ("insert_refresh_transfer_keys",
+ "INSERT INTO refresh_transfer_keys "
+ "(rc"
+ ",transfer_pub"
+ ",transfer_privs"
+ ") VALUES "
+ "($1, $2, $3);",
+ 3),
+ /* Used in #postgres_get_refresh_reveal() to retrieve transfer
+ keys from /refresh/reveal */
+ GNUNET_PQ_make_prepare ("get_refresh_transfer_keys",
+ "SELECT"
+ " transfer_pub"
+ ",transfer_privs"
+ " FROM refresh_transfer_keys"
+ " WHERE rc=$1;",
1),
+
+
+ /* Used in #postgres_insert_refund() to store refund information */
+ GNUNET_PQ_make_prepare ("insert_refund",
+ "INSERT INTO refunds "
+ "(coin_pub "
+ ",merchant_pub "
+ ",merchant_sig "
+ ",h_contract_terms "
+ ",rtransaction_id "
+ ",amount_with_fee_val "
+ ",amount_with_fee_frac "
+ ",amount_with_fee_curr "
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8);",
+ 8),
/* Query the 'refunds' by coin public key */
GNUNET_PQ_make_prepare ("get_refunds_by_coin",
"SELECT"
@@ -881,43 +884,26 @@ postgres_prepare (PGconn *db_conn)
" JOIN denominations denom USING (denom_pub_hash)"
" WHERE coin_pub=$1;",
1),
- /* Used in #postgres_insert_transfer_public_key() to
- store commitments */
- GNUNET_PQ_make_prepare ("insert_transfer_public_key",
- "INSERT INTO refresh_transfer_public_key "
- "(session_hash"
- ",transfer_pub"
- ") VALUES "
- "($1, $2);",
- 2),
- /* Used in #postgres_get_refresh_transfer_public_key() to
- retrieve original commitments during /refresh/reveal */
- GNUNET_PQ_make_prepare ("get_refresh_transfer_public_key",
+ /* Fetch refunds with rowid '\geq' the given parameter */
+ GNUNET_PQ_make_prepare ("audit_get_refunds_incr",
"SELECT"
- " transfer_pub"
- " FROM refresh_transfer_public_key"
- " WHERE session_hash=$1;",
+ " merchant_pub"
+ ",merchant_sig"
+ ",h_contract_terms"
+ ",rtransaction_id"
+ ",denom.denom_pub"
+ ",coin_pub"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",amount_with_fee_curr"
+ ",refund_serial_id"
+ " FROM refunds"
+ " JOIN known_coins kc USING (coin_pub)"
+ " JOIN denominations denom ON (kc.denom_pub_hash = denom.denom_pub_hash)"
+ " WHERE refund_serial_id>=$1"
+ " ORDER BY refund_serial_id ASC;",
1),
- /* Used in #postgres_insert_refresh_commit_coins() to
- store coin commitments. */
- GNUNET_PQ_make_prepare ("insert_refresh_commit_coin",
- "INSERT INTO refresh_commit_coin "
- "(session_hash"
- ",newcoin_index"
- ",coin_ev"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- /* Used in #postgres_get_refresh_commit_coins() to
- retrieve the original coin envelopes, to either be
- verified or signed. */
- GNUNET_PQ_make_prepare ("get_refresh_commit_coin",
- "SELECT"
- " coin_ev"
- " FROM refresh_commit_coin"
- " WHERE session_hash=$1"
- " AND newcoin_index=$2;",
- 2),
+
/* Store information about a /deposit the exchange is to execute.
Used in #postgres_insert_deposit(). */
GNUNET_PQ_make_prepare ("insert_deposit",
@@ -938,20 +924,6 @@ postgres_prepare (PGconn *db_conn)
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
" $11, $12);",
12),
- /* Used in #postgres_insert_refund() to store refund information */
- GNUNET_PQ_make_prepare ("insert_refund",
- "INSERT INTO refunds "
- "(coin_pub "
- ",merchant_pub "
- ",merchant_sig "
- ",h_contract_terms "
- ",rtransaction_id "
- ",amount_with_fee_val "
- ",amount_with_fee_frac "
- ",amount_with_fee_curr "
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
/* Fetch an existing deposit request, used to ensure idempotency
during /deposit processing. Used in #postgres_have_deposit(). */
GNUNET_PQ_make_prepare ("get_deposit",
@@ -1113,68 +1085,22 @@ postgres_prepare (PGconn *db_conn)
" USING (denom_pub_hash)"
" WHERE coin_pub=$1;",
1),
- /* Used in #postgres_insert_refresh_out() to store the
- generated signature(s) for future requests, i.e. /refresh/link */
- GNUNET_PQ_make_prepare ("insert_refresh_out",
- "INSERT INTO refresh_out "
- "(session_hash"
- ",newcoin_index"
- ",ev_sig"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- /* Used in #postgres_get_refresh_out() to test if the
- generated signature(s) already exists */
- GNUNET_PQ_make_prepare ("get_refresh_out",
- "SELECT ev_sig"
- " FROM refresh_out"
- " WHERE session_hash=$1"
- " AND newcoin_index=$2;",
- 2),
- /* Used in #postgres_get_link_data_list(). We use the session_hash
- to obtain the "noreveal_index" for that session, and then select the
- corresponding signatures (ev_sig) and the denomination keys from
- the respective tables (namely refresh_melts and refresh_order)
- using the session_hash as the primary filter (on join) and the
- 'noreveal_index' to constrain the selection on the commitment.
- We also want to get the triplet for each of the newcoins, so we
- have another constraint to ensure we get each triplet with
- matching "newcoin_index" values. NOTE: This may return many
- results, both for different sessions and for the different coins
- being exchangeed in the refresh ops. NOTE: There may be more
- efficient ways to express the same query. */
+
+ /* Used in #postgres_get_link_data(). */
GNUNET_PQ_make_prepare ("get_link",
"SELECT "
- " ev_sig"
+ " tp.transfer_pub"
",denoms.denom_pub"
- " FROM refresh_sessions"
- " JOIN refresh_order ro"
- " USING (session_hash)"
- " JOIN refresh_commit_coin rcc"
- " USING (session_hash)"
- " JOIN refresh_out rc"
- " USING (session_hash)"
+ ",rrc.ev_sig"
+ " FROM refresh_commitments"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (rc)"
+ " JOIN refresh_transfer_keys tp"
+ " USING (rc)"
" JOIN denominations denoms"
- " ON (ro.denom_pub_hash = denoms.denom_pub_hash)"
- " WHERE ro.session_hash=$1"
- " AND ro.newcoin_index=rcc.newcoin_index"
- " AND ro.newcoin_index=rc.newcoin_index;",
- 1),
- /* Used in #postgres_get_transfer(). Given the public key of a
- melted coin, we obtain the corresponding encrypted link secret
- and the transfer public key. This is done by first finding
- the session_hash(es) of all sessions the coin was melted into,
- and then constraining the result to the selected "noreveal_index".
- NOTE: This may (in theory) return multiple results, one per session
- that the old coin was melted into. */
- GNUNET_PQ_make_prepare ("get_transfer",
- "SELECT"
- " transfer_pub"
- ",session_hash"
- " FROM refresh_sessions rs"
- " JOIN refresh_transfer_public_key rcl"
- " USING (session_hash)"
- " WHERE rs.old_coin_pub=$1;",
+ " ON (rrc.denom_pub_hash = denoms.denom_pub_hash)"
+ " WHERE old_coin_pub=$1"
+ " ORDER BY tp.transfer_pub",
1),
/* Used in #postgres_lookup_wire_transfer */
GNUNET_PQ_make_prepare ("lookup_transactions",
@@ -3008,7 +2934,11 @@ ensure_coin_known (struct PostgresClosure *cls,
return GNUNET_SYSERR;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ GNUNET_CRYPTO_rsa_public_key_free (known_coin.denom_pub.rsa_public_key);
+ GNUNET_CRYPTO_rsa_signature_free (known_coin.denom_sig.rsa_signature);
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* no change! */
+ }
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
/* if not known, insert it */
qs = insert_known_coin (cls,
@@ -3101,461 +3031,340 @@ postgres_insert_refund (void *cls,
/**
- * Lookup refresh session data under the given @a session_hash.
+ * Lookup refresh melt commitment data under the given @a rc.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param session database handle to use
- * @param session_hash hash over the melt to use to locate the session
- * @param[out] refresh_session where to store the result
+ * @param rc commitment hash to use to locate the operation
+ * @param[out] refresh_melt where to store the result
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_session (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- struct TALER_EXCHANGEDB_RefreshSession *refresh_session)
+postgres_get_melt (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct TALER_RefreshCommitmentP *rc,
+ struct TALER_EXCHANGEDB_RefreshMelt *refresh_melt)
{
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_auto_from_type (rc),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint16 ("num_newcoins",
- &refresh_session->num_newcoins),
- GNUNET_PQ_result_spec_uint16 ("noreveal_index",
- &refresh_session->noreveal_index),
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
+ &refresh_melt->session.coin.denom_pub.rsa_public_key),
+ TALER_PQ_result_spec_amount ("fee_refresh",
+ &refresh_melt->melt_fee),
+ GNUNET_PQ_result_spec_rsa_signature ("denom_sig",
+ &refresh_melt->session.coin.denom_sig.rsa_signature),
+ GNUNET_PQ_result_spec_uint32 ("noreveal_index",
+ &refresh_melt->session.noreveal_index),
GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &refresh_session->melt.coin.coin_pub),
+ &refresh_melt->session.coin.coin_pub),
GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &refresh_session->melt.coin_sig),
+ &refresh_melt->session.coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
- &refresh_session->melt.amount_with_fee),
- TALER_PQ_result_spec_amount ("fee_refresh",
- &refresh_session->melt.melt_fee),
+ &refresh_melt->session.amount_with_fee),
GNUNET_PQ_result_spec_end
};
enum GNUNET_DB_QueryStatus qs;
- memset (refresh_session,
- 0,
- sizeof (struct TALER_EXCHANGEDB_RefreshSession));
qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
- "get_refresh_session",
+ "get_melt",
params,
rs);
- if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
- (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- (qs = get_known_coin (cls,
- session,
- &refresh_session->melt.coin.coin_pub,
- &refresh_session->melt.coin)) ) )
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- refresh_session->melt.session_hash = *session_hash;
+ refresh_melt->session.rc = *rc;
return qs;
}
/**
- * Store new refresh session data under the given @a session_hash.
+ * Store new refresh melt commitment data.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param session database handle to use
- * @param session_hash hash over the melt to use to locate the session
* @param refresh_session session data to store
* @return query status for the transaction
*/
static enum GNUNET_DB_QueryStatus
-postgres_create_refresh_session (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- const struct TALER_EXCHANGEDB_RefreshSession *refresh_session)
+postgres_insert_melt (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct TALER_EXCHANGEDB_RefreshSession *refresh_session)
{
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_auto_from_type (&refresh_session->melt.coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&refresh_session->melt.coin_sig),
- TALER_PQ_query_param_amount (&refresh_session->melt.amount_with_fee),
- GNUNET_PQ_query_param_uint16 (&refresh_session->num_newcoins),
- GNUNET_PQ_query_param_uint16 (&refresh_session->noreveal_index),
+ GNUNET_PQ_query_param_auto_from_type (&refresh_session->rc),
+ GNUNET_PQ_query_param_auto_from_type (&refresh_session->coin.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refresh_session->coin_sig),
+ TALER_PQ_query_param_amount (&refresh_session->amount_with_fee),
+ GNUNET_PQ_query_param_uint32 (&refresh_session->noreveal_index),
GNUNET_PQ_query_param_end
};
enum GNUNET_DB_QueryStatus qs;
if (0 > (qs = ensure_coin_known (cls,
session,
- &refresh_session->melt.coin)))
+ &refresh_session->coin)))
return qs;
return GNUNET_PQ_eval_prepared_non_select (session->conn,
- "insert_refresh_session",
+ "insert_melt",
params);
}
/**
- * Store in the database which coin(s) we want to create
- * in a given refresh operation.
+ * Store in the database which coin(s) the wallet wanted to create
+ * in a given refresh operation and all of the other information
+ * we learned or created in the /refresh/reveal step.
*
- * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param cls the @e cls of this struct with the plugin-specific state
* @param session database connection
- * @param session_hash hash to identify refresh session
- * @param num_newcoins number of coins to generate, size of the @a denom_pubs array
- * @param denom_pubs array denominations of the coins to create
+ * @param rc identify commitment and thus refresh operation
+ * @param num_rrcs_newcoins number of coins to generate, size of the
+ * @a rrcs array
+ * @param rrcs information about the new coins
+ * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
+ * @param tprivs transfer private keys to store
+ * @param tp public key to store
* @return query status for the transaction
*/
static enum GNUNET_DB_QueryStatus
-postgres_insert_refresh_order (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t num_newcoins,
- const struct TALER_DenominationPublicKey *denom_pubs)
-{
- for (unsigned int i=0;i<(unsigned int) num_newcoins;i++)
- {
- uint16_t newcoin_off = (uint16_t) i;
-
- {
- struct GNUNET_HashCode denom_pub_hash;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint16 (&newcoin_off),
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_auto_from_type (&denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_CRYPTO_rsa_public_key_hash (denom_pubs[i].rsa_public_key,
- &denom_pub_hash);
- qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
- "insert_refresh_order",
- params);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- return qs;
- }
- }
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-
-/**
- * We allocated some @a denom_pubs information, but now need
- * to abort. Free allocated memory.
- *
- * @param denom_pubs data to free (but not the array itself)
- * @param denom_pubs_len length of @a denom_pubs array
- */
-static void
-free_dpk_result (struct TALER_DenominationPublicKey *denom_pubs,
- unsigned int denom_pubs_len)
+postgres_insert_refresh_reveal (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct TALER_RefreshCommitmentP *rc,
+ uint32_t num_rrcs,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivs,
+ const struct TALER_TransferPublicKeyP *tp)
{
- for (unsigned int i=0;i<denom_pubs_len;i++)
+ if (TALER_CNC_KAPPA != num_tprivs + 1)
{
- GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[i].rsa_public_key);
- denom_pubs[i].rsa_public_key = NULL;
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
}
-}
-
-
-/**
- * Lookup in the database the coins that we want to
- * create in the given refresh operation.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param session_hash hash to identify refresh session
- * @param num_newcoins size of the array of the @a denom_pubs array
- * @param denom_pubs where to store the deomination keys
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_order (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t num_newcoins,
- struct TALER_DenominationPublicKey *denom_pubs)
-{
- for (unsigned i=0;i<(unsigned int) num_newcoins;i++)
+ for (uint32_t i=0;i<num_rrcs;i++)
{
- uint16_t newcoin_off = (uint16_t) i;
- enum GNUNET_DB_QueryStatus qs;
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
+ struct GNUNET_HashCode denom_pub_hash;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&newcoin_off),
+ GNUNET_PQ_query_param_auto_from_type (rc),
+ GNUNET_PQ_query_param_uint32 (&i),
+ GNUNET_PQ_query_param_auto_from_type (&denom_pub_hash),
+ GNUNET_PQ_query_param_fixed_size (rrc->coin_ev,
+ rrc->coin_ev_size),
+ GNUNET_PQ_query_param_rsa_signature (rrc->coin_sig.rsa_signature),
GNUNET_PQ_query_param_end
};
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
- &denom_pubs[i].rsa_public_key),
- GNUNET_PQ_result_spec_end
- };
+ enum GNUNET_DB_QueryStatus qs;
- qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
- "get_refresh_order",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- case GNUNET_DB_STATUS_SOFT_ERROR:
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- free_dpk_result (denom_pubs, i);
+ GNUNET_CRYPTO_rsa_public_key_hash (rrc->denom_pub.rsa_public_key,
+ &denom_pub_hash);
+
+ qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
+ "insert_refresh_revealed_coin",
+ params);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
return qs;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- break;
- default:
- GNUNET_break (0);
- break;
- }
}
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-/**
- * Store information about the commitment of the
- * given coin for the given refresh session in the database.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection to use
- * @param session_hash hash to identify refresh session
- * @param num_newcoins coin index size of the @a commit_coins array
- * @param commit_coins array of coin commitments to store
- * @return query transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_refresh_commit_coins (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t num_newcoins,
- const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins)
-{
- for (uint16_t coin_off=0;coin_off<num_newcoins;coin_off++)
{
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&coin_off),
- GNUNET_PQ_query_param_fixed_size (commit_coins[coin_off].coin_ev,
- commit_coins[coin_off].coin_ev_size),
+ GNUNET_PQ_query_param_auto_from_type (rc),
+ GNUNET_PQ_query_param_auto_from_type (tp),
+ GNUNET_PQ_query_param_fixed_size (tprivs,
+ num_tprivs * sizeof (struct TALER_TransferPrivateKeyP)),
GNUNET_PQ_query_param_end
};
- enum GNUNET_DB_QueryStatus qs;
- qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
- "insert_refresh_commit_coin",
- params);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- return qs;
+ return GNUNET_PQ_eval_prepared_non_select (session->conn,
+ "insert_refresh_transfer_keys",
+ params);
}
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
/**
- * We allocated some @a commit_coin information, but now need
- * to abort. Free allocated memory.
- *
- * @param cls unused
- * @param commit_coins_len length of @a commit_coins array
- * @param commit_coins data to free (but not the array itself)
+ * Context where we aggregate data from the database.
+ * Closure for #add_revealed_coins().
*/
-static void
-postgres_free_refresh_commit_coins (void *cls,
- unsigned int commit_coins_len,
- struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins)
+struct GetRevealContext
{
- for (unsigned int i=0;i<commit_coins_len;i++)
- {
- GNUNET_free (commit_coins[i].coin_ev);
- commit_coins[i].coin_ev = NULL;
- commit_coins[i].coin_ev_size = 0;
- }
-}
+ /**
+ * Array of revealed coins we obtained from the DB.
+ */
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs;
+
+ /**
+ * Length of the @a rrcs array.
+ */
+ unsigned int rrcs_len;
+
+ /**
+ * Set to an error code if we ran into trouble.
+ */
+ enum TALER_ErrorCode ec;
+};
/**
- * Obtain information about the commitment of the
- * given coin of the given refresh session from the database.
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
*
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection to use
- * @param session_hash hash to identify refresh session
- * @param num_newcoins size of the @a commit_coins array
- * @param[out] commit_coins array of coin commitments to return
- * @return transaction status
+ * @param cls closure of type `struct GetRevealContext`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
*/
-static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_commit_coins (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t num_newcoins,
- struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins)
+static void
+add_revealed_coins (void *cls,
+ PGresult *result,
+ unsigned int num_results)
{
- for (unsigned int i=0;i<(unsigned int) num_newcoins;i++)
+ struct GetRevealContext *grctx = cls;
+
+ if (0 == num_results)
+ return;
+ grctx->rrcs = GNUNET_new_array (num_results,
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin);
+ grctx->rrcs_len = num_results;
+ for (unsigned int i = 0; i < num_results; i++)
{
- uint16_t newcoin_off = (uint16_t) i;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&newcoin_off),
- GNUNET_PQ_query_param_end
- };
- void *c_buf;
- size_t c_buf_size;
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx->rrcs[i];
+ uint32_t off;
struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("newcoin_index",
+ &off),
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
+ &rrc->denom_pub.rsa_public_key),
GNUNET_PQ_result_spec_variable_size ("coin_ev",
- &c_buf,
- &c_buf_size),
+ (void **) &rrc->coin_ev,
+ &rrc->coin_ev_size),
+ GNUNET_PQ_result_spec_rsa_signature ("ev_sig",
+ &rrc->coin_sig.rsa_signature),
GNUNET_PQ_result_spec_end
};
- enum GNUNET_DB_QueryStatus qs;
- qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
- "get_refresh_commit_coin",
- params,
- rs);
- if (0 >= qs)
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
{
- postgres_free_refresh_commit_coins (cls,
- i,
- commit_coins);
- return qs;
+ GNUNET_break (0);
+ grctx->ec = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if (off != i)
+ {
+ GNUNET_break (0);
+ grctx->ec = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
}
- commit_coins[i].coin_ev = c_buf;
- commit_coins[i].coin_ev_size = c_buf_size;
}
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-
-/**
- * Store the commitment to the given (encrypted) refresh link data
- * for the given refresh session.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection to use
- * @param session_hash hash to identify refresh session
- * @param tp transfer public key to store
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_refresh_transfer_public_key (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- const struct TALER_TransferPublicKeyP *tp)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_auto_from_type (tp),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (session->conn,
- "insert_transfer_public_key",
- params);
}
/**
- * Obtain the commited (encrypted) refresh link data
- * for the given refresh session.
+ * Lookup in the database the coins that we want to
+ * create in the given refresh operation.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection to use
- * @param session_hash hash to identify refresh session
- * @param[out] tp information to return
+ * @param session database connection
+ * @param rc identify commitment and thus refresh operation
+ * @param cb function to call with the results
+ * @param cb_cls closure for @a cb
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_transfer_public_key (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- struct TALER_TransferPublicKeyP *tp)
+postgres_get_refresh_reveal (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct TALER_RefreshCommitmentP *rc,
+ TALER_EXCHANGEDB_RefreshCallback cb,
+ void *cb_cls)
{
+ struct GetRevealContext grctx;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_TransferPublicKeyP tp;
+ void *tpriv;
+ size_t tpriv_size;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_auto_from_type (rc),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
- tp),
+ &tp),
+ GNUNET_PQ_result_spec_variable_size ("transfer_privs",
+ &tpriv,
+ &tpriv_size),
GNUNET_PQ_result_spec_end
};
- return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
- "get_refresh_transfer_public_key",
- params,
- rs);
-}
-
+ /* First get the coins */
+ memset (&grctx,
+ 0,
+ sizeof (grctx));
+ qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
+ "get_refresh_revealed_coins",
+ params,
+ &add_revealed_coins,
+ &grctx);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ goto cleanup;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ default: /* can have more than one result */
+ break;
+ }
-/**
- * Get signature of a new coin generated during refresh into
- * the database indexed by the refresh session and the index
- * of the coin.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param session_hash hash to identify refresh session
- * @param newcoin_index coin index
- * @param ev_sig coin signature
- * @return transaction result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_out (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t newcoin_index,
- struct TALER_DenominationSignature *ev_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&newcoin_index),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_rsa_signature ("ev_sig",
- &ev_sig->rsa_signature),
- GNUNET_PQ_result_spec_end
- };
+ /* now also get the transfer keys (public and private) */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+ "get_refresh_transfer_keys",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ goto cleanup;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ if ( (0 != tpriv_size % sizeof (struct TALER_TransferPrivateKeyP)) ||
+ (TALER_CNC_KAPPA - 1 != tpriv_size / sizeof (struct TALER_TransferPrivateKeyP)) )
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_PQ_cleanup_result (rs);
+ goto cleanup;
+ }
- return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
- "get_refresh_out",
- params,
- rs);
-}
+ /* Pass result back to application */
+ cb (cb_cls,
+ grctx.rrcs_len,
+ grctx.rrcs,
+ tpriv_size / sizeof (struct TALER_TransferPrivateKeyP),
+ (const struct TALER_TransferPrivateKeyP *) tpriv,
+ &tp);
+ GNUNET_PQ_cleanup_result (rs);
+ cleanup:
+ for (unsigned int i = 0; i < grctx.rrcs_len; i++)
+ {
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx.rrcs[i];
-/**
- * Insert signature of a new coin generated during refresh into
- * the database indexed by the refresh session and the index
- * of the coin. This data is later used should an old coin
- * be used to try to obtain the private keys during "/refresh/link".
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param session_hash hash to identify refresh session
- * @param newcoin_index coin index
- * @param ev_sig coin signature
- * @return transaction result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_refresh_out (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t newcoin_index,
- const struct TALER_DenominationSignature *ev_sig)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&newcoin_index),
- GNUNET_PQ_query_param_rsa_signature (ev_sig->rsa_signature),
- GNUNET_PQ_query_param_end
- };
+ if (NULL != rrc->denom_pub.rsa_public_key)
+ GNUNET_CRYPTO_rsa_public_key_free (rrc->denom_pub.rsa_public_key);
+ if (NULL != rrc->coin_sig.rsa_signature)
+ GNUNET_CRYPTO_rsa_signature_free (rrc->coin_sig.rsa_signature);
+ GNUNET_free_non_null (rrc->coin_ev);
+ }
+ GNUNET_free_non_null (grctx.rrcs);
- return GNUNET_PQ_eval_prepared_non_select (session->conn,
- "insert_refresh_out",
- params);
+ return qs;
}
@@ -3565,9 +3374,25 @@ postgres_insert_refresh_out (void *cls,
struct LinkDataContext
{
/**
- * List we are building.
+ * Function to call on each result.
*/
- struct TALER_EXCHANGEDB_LinkDataList *ldl;
+ TALER_EXCHANGEDB_LinkDataCallback ldc;
+
+ /**
+ * Closure for @e ldc.
+ */
+ void *ldc_cls;
+
+ /**
+ * Last transfer public key for which we have information in @e last.
+ * Only valid if @e last is non-NULL.
+ */
+ struct TALER_TransferPublicKeyP transfer_pub;
+
+ /**
+ * Link data for @e transfer_pub
+ */
+ struct TALER_EXCHANGEDB_LinkDataList *last;
/**
* Status, set to #GNUNET_SYSERR on errors,
@@ -3577,6 +3402,31 @@ struct LinkDataContext
/**
+ * Free memory of the link data list.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state (unused)
+ * @param ldl link data list to release
+ */
+static void
+free_link_data_list (void *cls,
+ struct TALER_EXCHANGEDB_LinkDataList *ldl)
+{
+ struct TALER_EXCHANGEDB_LinkDataList *next;
+
+ while (NULL != ldl)
+ {
+ next = ldl->next;
+ if (NULL != ldl->denom_pub.rsa_public_key)
+ GNUNET_CRYPTO_rsa_public_key_free (ldl->denom_pub.rsa_public_key);
+ if (NULL != ldl->ev_sig.rsa_signature)
+ GNUNET_CRYPTO_rsa_signature_free (ldl->ev_sig.rsa_signature);
+ GNUNET_free (ldl);
+ ldl = next;
+ }
+}
+
+
+/**
* Function to be called with the results of a SELECT statement
* that has returned @a num_results results.
*
@@ -3589,21 +3439,22 @@ add_ldl (void *cls,
PGresult *result,
unsigned int num_results)
{
- struct LinkDataContext *ldc = cls;
+ struct LinkDataContext *ldctx = cls;
for (int i = num_results - 1; i >= 0; i--)
{
- struct GNUNET_CRYPTO_RsaPublicKey *denom_pub;
- struct GNUNET_CRYPTO_RsaSignature *sig;
struct TALER_EXCHANGEDB_LinkDataList *pos;
+ struct TALER_TransferPublicKeyP transfer_pub;
pos = GNUNET_new (struct TALER_EXCHANGEDB_LinkDataList);
{
struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
+ &transfer_pub),
GNUNET_PQ_result_spec_rsa_signature ("ev_sig",
- &sig),
+ &pos->ev_sig.rsa_signature),
GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
- &denom_pub),
+ &pos->denom_pub.rsa_public_key),
GNUNET_PQ_result_spec_end
};
@@ -3613,18 +3464,31 @@ add_ldl (void *cls,
i))
{
GNUNET_break (0);
- common_free_link_data_list (cls,
- ldc->ldl);
- ldc->ldl = NULL;
GNUNET_free (pos);
- ldc->status = GNUNET_SYSERR;
+ ldctx->status = GNUNET_SYSERR;
return;
}
}
- pos->next = ldc->ldl;
- pos->denom_pub.rsa_public_key = denom_pub;
- pos->ev_sig.rsa_signature = sig;
- ldc->ldl = pos;
+ if ( (NULL != ldctx->last) &&
+ (0 == memcmp (&transfer_pub,
+ &ldctx->transfer_pub,
+ sizeof (struct TALER_TransferPublicKeyP))) )
+ {
+ pos->next = ldctx->last;
+ }
+ else
+ {
+ if (NULL != ldctx->last)
+ {
+ ldctx->ldc (ldctx->ldc_cls,
+ &ldctx->transfer_pub,
+ ldctx->last);
+ free_link_data_list (cls,
+ ldctx->last);
+ }
+ ldctx->transfer_pub = transfer_pub;
+ }
+ ldctx->last = pos;
}
}
@@ -3635,137 +3499,49 @@ add_ldl (void *cls,
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param session database connection
- * @param session_hash refresh session to get linkage data for
- * @param[out] ldlp set to all known link data for the session
+ * @param coin_pub public key of the coin
+ * @param ldc function to call for each session the coin was melted into
+ * @param ldc_cls closure for @a tdc
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
-postgres_get_link_data_list (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- struct TALER_EXCHANGEDB_LinkDataList **ldlp)
+postgres_get_link_data (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ TALER_EXCHANGEDB_LinkDataCallback ldc,
+ void *ldc_cls)
{
- struct LinkDataContext ldc;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_end
};
enum GNUNET_DB_QueryStatus qs;
+ struct LinkDataContext ldctx;
- ldc.status = GNUNET_OK;
- ldc.ldl = NULL;
+ ldctx.ldc = ldc;
+ ldctx.ldc_cls = ldc_cls;
+ ldctx.last = NULL;
+ ldctx.status = GNUNET_OK;
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
"get_link",
params,
&add_ldl,
- &ldc);
- *ldlp = ldc.ldl;
- if (GNUNET_OK != ldc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #add_link().
- */
-struct AddLinkContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_TransferDataCallback tdc;
-
- /**
- * Closure for @e tdc.
- */
- void *tdc_cls;
-
- /**
- * Status code, set to #GNUNET_SYSERR on errors.
- */
- int status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct AddLinkContext *`
- * @param result the postgres result
- * @param num_result the number of results in @a result
- */
-static void
-add_link (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AddLinkContext *alc = cls;
-
- for (unsigned int i=0;i<num_results;i++)
+ &ldctx);
+ if (NULL != ldctx.last)
{
- struct GNUNET_HashCode session_hash;
- struct TALER_TransferPublicKeyP transfer_pub;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("transfer_pub", &transfer_pub),
- GNUNET_PQ_result_spec_auto_from_type ("session_hash", &session_hash),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
+ if (GNUNET_OK == ldctx.status)
{
- GNUNET_break (0);
- alc->status = GNUNET_SYSERR;
- return;
+ /* call callback one more time! */
+ ldc (ldc_cls,
+ &ldctx.transfer_pub,
+ ldctx.last);
}
- alc->tdc (alc->tdc_cls,
- &session_hash,
- &transfer_pub);
+ free_link_data_list (cls,
+ ldctx.last);
+ ldctx.last = NULL;
}
-}
-
-
-/**
- * Obtain shared secret and transfer public key from the public key of
- * the coin. This information and the link information returned by
- * #postgres_get_link_data_list() enable the owner of an old coin to
- * determine the private keys of the new coins after the melt.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param coin_pub public key of the coin
- * @param tdc function to call for each session the coin was melted into
- * @param tdc_cls closure for @a tdc
- * @return statement execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_transfer (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- TALER_EXCHANGEDB_TransferDataCallback tdc,
- void *tdc_cls)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- struct AddLinkContext al_ctx;
- enum GNUNET_DB_QueryStatus qs;
-
- al_ctx.tdc = tdc;
- al_ctx.tdc_cls = tdc_cls;
- al_ctx.status = GNUNET_OK;
- qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
- "get_transfer",
- params,
- &add_link,
- &al_ctx);
- if (GNUNET_OK != al_ctx.status)
- qs = GNUNET_DB_STATUS_HARD_ERROR;
+ if (GNUNET_OK != ldctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
return qs;
}
@@ -3905,13 +3681,13 @@ add_coin_melt (void *cls,
melt = GNUNET_new (struct TALER_EXCHANGEDB_RefreshMelt);
{
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("session_hash",
- &melt->session_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("rc",
+ &melt->session.rc),
/* oldcoin_index not needed */
GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &melt->coin_sig),
+ &melt->session.coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
- &melt->amount_with_fee),
+ &melt->session.amount_with_fee),
TALER_PQ_result_spec_amount ("fee_refresh",
&melt->melt_fee),
GNUNET_PQ_result_spec_end
@@ -3927,16 +3703,17 @@ add_coin_melt (void *cls,
chc->status = GNUNET_DB_STATUS_HARD_ERROR;
return;
}
- melt->coin.coin_pub = *chc->coin_pub;
+ melt->session.coin.coin_pub = *chc->coin_pub;
}
tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
tl->next = chc->head;
tl->type = TALER_EXCHANGEDB_TT_REFRESH_MELT;
tl->details.melt = melt;
+ /* FIXME: integrate via JOIN in main select, instead of using separate query */
qs = get_known_coin (chc->db_cls,
chc->session,
chc->coin_pub,
- &melt->coin);
+ &melt->session.coin);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -5184,10 +4961,9 @@ refreshs_serial_helper_cb (void *cls,
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_CoinSpendSignatureP coin_sig;
struct TALER_Amount amount_with_fee;
- uint16_t num_newcoins;
- uint16_t noreveal_index;
+ uint32_t noreveal_index;
uint64_t rowid;
- struct GNUNET_HashCode session_hash;
+ struct TALER_RefreshCommitmentP rc;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pub.rsa_public_key),
@@ -5197,14 +4973,12 @@ refreshs_serial_helper_cb (void *cls,
&coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
&amount_with_fee),
- GNUNET_PQ_result_spec_uint16 ("num_newcoins",
- &num_newcoins),
- GNUNET_PQ_result_spec_uint16 ("noreveal_index",
+ GNUNET_PQ_result_spec_uint32 ("noreveal_index",
&noreveal_index),
GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
&rowid),
- GNUNET_PQ_result_spec_auto_from_type ("session_hash",
- &session_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("rc",
+ &rc),
GNUNET_PQ_result_spec_end
};
int ret;
@@ -5224,9 +4998,8 @@ refreshs_serial_helper_cb (void *cls,
&coin_pub,
&coin_sig,
&amount_with_fee,
- num_newcoins,
noreveal_index,
- &session_hash);
+ &rc);
GNUNET_PQ_cleanup_result (rs);
if (GNUNET_OK != ret)
break;
@@ -5264,7 +5037,7 @@ postgres_select_refreshs_above_serial_id (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
- "audit_get_refresh_sessions_incr",
+ "audit_get_refresh_commitments_incr",
params,
&refreshs_serial_helper_cb,
&rsc);
@@ -6451,20 +6224,11 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->iterate_matching_deposits = &postgres_iterate_matching_deposits;
plugin->insert_deposit = &postgres_insert_deposit;
plugin->insert_refund = &postgres_insert_refund;
- plugin->get_refresh_session = &postgres_get_refresh_session;
- plugin->create_refresh_session = &postgres_create_refresh_session;
- plugin->insert_refresh_order = &postgres_insert_refresh_order;
- plugin->get_refresh_order = &postgres_get_refresh_order;
- plugin->insert_refresh_commit_coins = &postgres_insert_refresh_commit_coins;
- plugin->get_refresh_commit_coins = &postgres_get_refresh_commit_coins;
- plugin->free_refresh_commit_coins = &postgres_free_refresh_commit_coins;
- plugin->insert_refresh_transfer_public_key = &postgres_insert_refresh_transfer_public_key;
- plugin->get_refresh_transfer_public_key = &postgres_get_refresh_transfer_public_key;
- plugin->get_refresh_out = &postgres_get_refresh_out;
- plugin->insert_refresh_out = &postgres_insert_refresh_out;
- plugin->get_link_data_list = &postgres_get_link_data_list;
- plugin->free_link_data_list = &common_free_link_data_list;
- plugin->get_transfer = &postgres_get_transfer;
+ plugin->insert_melt = &postgres_insert_melt;
+ plugin->get_melt = &postgres_get_melt;
+ plugin->insert_refresh_reveal = &postgres_insert_refresh_reveal;
+ plugin->get_refresh_reveal = &postgres_get_refresh_reveal;
+ plugin->get_link_data = &postgres_get_link_data;
plugin->get_coin_transactions = &postgres_get_coin_transactions;
plugin->free_coin_transaction_list = &common_free_coin_transaction_list;
plugin->lookup_wire_transfer = &postgres_lookup_wire_transfer;
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index f04eaf129..33dc74cd6 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -308,162 +308,85 @@ static struct TALER_Amount amount_with_fee;
*/
#define MELT_NOREVEAL_INDEX 1
-
-static struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins;
-
/**
- * Test APIs related to the "insert_refresh_commit_coins" function.
- *
- * @param session database sesison to use
- * @param refresh_session details about the refresh session to use
- * @param session_hash refresh melt session hash to use
- * @return #GNUNET_OK on success
+ * How big do we make the coin envelopes?
*/
-static int
-test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
- const struct TALER_EXCHANGEDB_RefreshSession *refresh_session,
- const struct GNUNET_HashCode *session_hash)
-{
- struct TALER_EXCHANGEDB_RefreshCommitCoin *ret_commit_coins;
- struct TALER_EXCHANGEDB_RefreshCommitCoin *a_ccoin;
- struct TALER_EXCHANGEDB_RefreshCommitCoin *b_ccoin;
- unsigned int cnt;
- int ret;
-
#define COIN_ENC_MAX_SIZE 512
- ret = GNUNET_SYSERR;
- ret_commit_coins = NULL;
- commit_coins
- = GNUNET_new_array (MELT_NEW_COINS,
- struct TALER_EXCHANGEDB_RefreshCommitCoin);
- for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
- {
- struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin;
- ccoin = &commit_coins[cnt];
- ccoin->coin_ev_size = GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_WEAK, COIN_ENC_MAX_SIZE);
- ccoin->coin_ev = GNUNET_malloc (ccoin->coin_ev_size);
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- ccoin->coin_ev,
- ccoin->coin_ev_size);
- }
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_refresh_commit_coins (plugin->cls,
- session,
- session_hash,
- MELT_NEW_COINS,
- commit_coins));
- ret_commit_coins = GNUNET_new_array (MELT_NEW_COINS,
- struct TALER_EXCHANGEDB_RefreshCommitCoin);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_refresh_commit_coins (plugin->cls,
- session,
- session_hash,
- MELT_NEW_COINS,
- ret_commit_coins));
- /* compare the refresh commit coin arrays */
- for (cnt = 0; cnt < MELT_NEW_COINS; cnt++)
- {
- a_ccoin = &commit_coins[cnt];
- b_ccoin = &ret_commit_coins[cnt];
- FAILIF (a_ccoin->coin_ev_size != b_ccoin->coin_ev_size);
- FAILIF (0 != memcmp (a_ccoin->coin_ev,
- a_ccoin->coin_ev,
- a_ccoin->coin_ev_size));
- GNUNET_free (ret_commit_coins[cnt].coin_ev);
- }
- GNUNET_free (ret_commit_coins);
- ret_commit_coins = NULL;
- ret = GNUNET_OK;
- drop:
- if (NULL != ret_commit_coins)
- {
- plugin->free_refresh_commit_coins (plugin->cls,
- MELT_NEW_COINS,
- ret_commit_coins);
- GNUNET_free (ret_commit_coins);
- }
- return ret;
-}
+static struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coins;
+static struct TALER_TransferPrivateKeyP tprivs[TALER_CNC_KAPPA];
-static struct TALER_TransferPublicKeyP rctp[TALER_CNC_KAPPA];
+static struct TALER_TransferPublicKeyP tpub;
/**
- * Test APIs related to the "insert_refresh_commit_coins" function.
+ * Function called with information about a refresh order. This
+ * one should not be called in a successful test.
*
- * @param session database sesison to use
- * @param refresh_session details about the refresh session to use
- * @param session_hash refresh melt session hash to use
- * @return #GNUNET_OK on success
+ * @param cls closure
+ * @param rowid unique serial ID for the row in our database
+ * @param num_newcoins size of the @a rrcs array
+ * @param rrcs array of @a num_newcoins information about coins to be created
+ * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
+ * @param tprivs array of @e num_tprivs transfer private keys
+ * @param tp transfer public key information
*/
-static int
-test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session,
- const struct TALER_EXCHANGEDB_RefreshSession *refresh_session,
- const struct GNUNET_HashCode *session_hash)
+static void
+never_called_cb (void *cls,
+ uint32_t num_newcoins,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivs,
+ const struct TALER_TransferPublicKeyP *tp)
{
- int ret;
- struct TALER_TransferPublicKeyP tp;
- unsigned int i;
-
- ret = GNUNET_SYSERR;
- FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
- plugin->get_refresh_transfer_public_key (plugin->cls,
- session,
- session_hash,
- &tp));
- for (i=0;i<TALER_CNC_KAPPA;i++)
- RND_BLK (&rctp[i]);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_refresh_transfer_public_key (plugin->cls,
- session,
- session_hash,
- &rctp[MELT_NOREVEAL_INDEX]));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_refresh_transfer_public_key (plugin->cls,
- session,
- session_hash,
- &tp));
- FAILIF (0 !=
- memcmp (&rctp[MELT_NOREVEAL_INDEX],
- &tp,
- sizeof (struct TALER_TransferPublicKeyP)));
- ret = GNUNET_OK;
- drop:
- return ret;
+ GNUNET_assert (0); /* should never be called! */
}
-static struct GNUNET_HashCode session_hash;
-
-
/**
- * Function called with the session hashes and transfer secret
- * information for a given coin. Checks if they are as expected.
+ * Function called with information about a refresh order.
+ * Checks that the response matches what we expect to see.
*
* @param cls closure
- * @param sh a session the coin was melted in
- * @param transfer_pub public transfer key for the session
+ * @param rowid unique serial ID for the row in our database
+ * @param num_newcoins size of the @a rrcs array
+ * @param rrcs array of @a num_newcoins information about coins to be created
+ * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
+ * @param tprivsr array of @e num_tprivs transfer private keys
+ * @param tpr transfer public key information
*/
static void
-check_transfer_data (void *cls,
- const struct GNUNET_HashCode *sh,
- const struct TALER_TransferPublicKeyP *transfer_pub)
+check_refresh_reveal_cb (void *cls,
+ uint32_t num_newcoins,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivsr,
+ const struct TALER_TransferPublicKeyP *tpr)
{
- int *ok = cls;
-
- FAILIF (0 != memcmp (&rctp[MELT_NOREVEAL_INDEX],
- transfer_pub,
- sizeof (struct TALER_TransferPublicKeyP)));
- FAILIF (0 != memcmp (&session_hash,
- sh,
- sizeof (struct GNUNET_HashCode)));
- *ok = GNUNET_OK;
- return;
- drop:
- *ok = GNUNET_SYSERR;
+ /* compare the refresh commit coin arrays */
+ for (unsigned int cnt = 0; cnt < num_newcoins; cnt++)
+ {
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *acoin = &revealed_coins[cnt];
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *bcoin = &rrcs[cnt];
+
+ GNUNET_assert (acoin->coin_ev_size == bcoin->coin_ev_size);
+ GNUNET_assert (0 ==
+ memcmp (acoin->coin_ev,
+ bcoin->coin_ev,
+ acoin->coin_ev_size));
+ GNUNET_assert (0 ==
+ GNUNET_CRYPTO_rsa_public_key_cmp (acoin->denom_pub.rsa_public_key,
+ bcoin->denom_pub.rsa_public_key));
+ }
+ GNUNET_assert (0 ==
+ memcmp (&tpub,
+ tpr,
+ sizeof (tpub)));
+ GNUNET_assert (0 ==
+ memcmp (tprivs,
+ tprivsr,
+ sizeof (struct TALER_TransferPrivateKeyP) * (TALER_CNC_KAPPA - 1)));
}
@@ -487,7 +410,7 @@ static unsigned int auditor_row_cnt;
* @param amount_with_fee amount that was deposited including fee
* @param num_newcoins how many coins were issued
* @param noreveal_index which index was picked by the exchange in cut-and-choose
- * @param session_hash what is the session hash
+ * @param rc what is the session hash
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
static int
@@ -497,9 +420,8 @@ audit_refresh_session_cb (void *cls,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_Amount *amount_with_fee,
- uint16_t num_newcoins,
- uint16_t noreveal_index,
- const struct GNUNET_HashCode *session_hash)
+ uint32_t noreveal_index,
+ const struct TALER_RefreshCommitmentP *rc)
{
auditor_row_cnt++;
return GNUNET_OK;
@@ -507,6 +429,51 @@ audit_refresh_session_cb (void *cls,
/**
+ * Denomination keys used for fresh coins in melt test.
+ */
+static struct DenomKeyPair **new_dkp;
+
+
+/**
+ * Function called with the session hashes and transfer secret
+ * information for a given coin.
+ *
+ * @param cls closure
+ * @param transfer_pub public transfer key for the session
+ * @param ldl link data for @a transfer_pub
+ */
+static void
+handle_link_data_cb (void *cls,
+ const struct TALER_TransferPublicKeyP *transfer_pub,
+ const struct TALER_EXCHANGEDB_LinkDataList *ldl)
+{
+ for (const struct TALER_EXCHANGEDB_LinkDataList *ldlp = ldl;
+ NULL != ldlp;
+ ldlp = ldlp->next)
+ {
+ int found;
+
+ found = GNUNET_NO;
+ for (unsigned int cnt=0;cnt < MELT_NEW_COINS;cnt++)
+ {
+ GNUNET_assert (NULL != ldlp->ev_sig.rsa_signature);
+ if ( (0 ==
+ GNUNET_CRYPTO_rsa_public_key_cmp (ldlp->denom_pub.rsa_public_key,
+ new_dkp[cnt]->pub.rsa_public_key)) &&
+ (0 ==
+ GNUNET_CRYPTO_rsa_signature_cmp (ldlp->ev_sig.rsa_signature,
+ revealed_coins[cnt].coin_sig.rsa_signature)) )
+ {
+ found = GNUNET_YES;
+ break;
+ }
+ }
+ GNUNET_assert (GNUNET_NO != found);
+ }
+}
+
+
+/**
* Function to test melting of coins as part of a refresh session
*
* @param session the database session
@@ -517,30 +484,20 @@ static int
test_melting (struct TALER_EXCHANGEDB_Session *session)
{
struct TALER_EXCHANGEDB_RefreshSession refresh_session;
- struct TALER_EXCHANGEDB_RefreshSession ret_refresh_session;
+ struct TALER_EXCHANGEDB_RefreshMelt ret_refresh_session;
struct DenomKeyPair *dkp;
- struct DenomKeyPair **new_dkp;
- /* struct TALER_CoinPublicInfo *coins; */
- struct TALER_EXCHANGEDB_RefreshMelt *meltp;
struct TALER_DenominationPublicKey *new_denom_pubs;
struct TALER_DenominationPublicKey *ret_denom_pubs;
- struct TALER_EXCHANGEDB_LinkDataList *ldl;
- struct TALER_EXCHANGEDB_LinkDataList *ldlp;
- struct TALER_DenominationSignature ev_sigs[MELT_NEW_COINS];
- unsigned int cnt;
int ret;
enum GNUNET_DB_QueryStatus qs;
ret = GNUNET_SYSERR;
- memset (ev_sigs, 0, sizeof (ev_sigs));
RND_BLK (&refresh_session);
- RND_BLK (&session_hash);
dkp = NULL;
new_dkp = NULL;
new_denom_pubs = NULL;
ret_denom_pubs = NULL;
/* create and test a refresh session */
- refresh_session.num_newcoins = MELT_NEW_COINS;
refresh_session.noreveal_index = MELT_NOREVEAL_INDEX;
/* create a denomination (value: 1; fraction: 100) */
dkp = create_denom_key_pair (512,
@@ -556,33 +513,62 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
{
struct GNUNET_HashCode hc;
- meltp = &refresh_session.melt;
- RND_BLK (&meltp->coin.coin_pub);
- GNUNET_CRYPTO_hash (&meltp->coin.coin_pub,
- sizeof (meltp->coin.coin_pub),
+ RND_BLK (&refresh_session.coin.coin_pub);
+ GNUNET_CRYPTO_hash (&refresh_session.coin.coin_pub,
+ sizeof (refresh_session.coin.coin_pub),
&hc);
- meltp->coin.denom_sig.rsa_signature =
+ refresh_session.coin.denom_sig.rsa_signature =
GNUNET_CRYPTO_rsa_sign_fdh (dkp->priv.rsa_private_key,
&hc);
- GNUNET_assert (NULL != meltp->coin.denom_sig.rsa_signature);
- meltp->coin.denom_pub = dkp->pub;
- RND_BLK (&meltp->coin_sig);
- meltp->session_hash = session_hash;
- meltp->amount_with_fee = amount_with_fee;
- meltp->melt_fee = fee_refresh;
+ GNUNET_assert (NULL != refresh_session.coin.denom_sig.rsa_signature);
+ refresh_session.coin.denom_pub = dkp->pub;
+ refresh_session.amount_with_fee = amount_with_fee;
}
+ /* test insert_melt & get_melt */
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->get_melt (plugin->cls,
+ session,
+ &refresh_session.rc,
+ &ret_refresh_session));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->create_refresh_session (plugin->cls,
- session,
- &session_hash,
- &refresh_session));
+ plugin->insert_melt (plugin->cls,
+ session,
+ &refresh_session));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_refresh_session (plugin->cls,
- session,
- &session_hash,
- &ret_refresh_session));
+ plugin->get_melt (plugin->cls,
+ session,
+ &refresh_session.rc,
+ &ret_refresh_session));
+ FAILIF (refresh_session.noreveal_index !=
+ ret_refresh_session.session.noreveal_index);
+ FAILIF (0 !=
+ TALER_amount_cmp (&refresh_session.amount_with_fee,
+ &ret_refresh_session.session.amount_with_fee));
+ FAILIF (0 !=
+ TALER_amount_cmp (&fee_refresh,
+ &ret_refresh_session.melt_fee));
+ FAILIF (0 !=
+ memcmp (&refresh_session.rc,
+ &ret_refresh_session.session.rc,
+ sizeof (struct TALER_RefreshCommitmentP)));
+ FAILIF (0 !=
+ memcmp (&refresh_session.coin_sig,
+ &ret_refresh_session.session.coin_sig,
+ sizeof (struct TALER_CoinSpendSignatureP)));
+ FAILIF (0 !=
+ GNUNET_CRYPTO_rsa_signature_cmp (refresh_session.coin.denom_sig.rsa_signature,
+ ret_refresh_session.session.coin.denom_sig.rsa_signature));
+ FAILIF (0 != memcmp (&refresh_session.coin.coin_pub,
+ &ret_refresh_session.session.coin.coin_pub,
+ sizeof (refresh_session.coin.coin_pub)));
+ FAILIF (0 !=
+ GNUNET_CRYPTO_rsa_public_key_cmp (refresh_session.coin.denom_pub.rsa_public_key,
+ ret_refresh_session.session.coin.denom_pub.rsa_public_key));
+ GNUNET_CRYPTO_rsa_signature_free (ret_refresh_session.session.coin.denom_sig.rsa_signature);
+ GNUNET_CRYPTO_rsa_public_key_free (ret_refresh_session.session.coin.denom_pub.rsa_public_key);
+ /* test 'select_refreshs_above_serial_id' */
auditor_row_cnt = 0;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_refreshs_above_serial_id (plugin->cls,
@@ -591,41 +577,19 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
&audit_refresh_session_cb,
NULL));
FAILIF (1 != auditor_row_cnt);
- FAILIF (ret_refresh_session.num_newcoins != refresh_session.num_newcoins);
- FAILIF (ret_refresh_session.noreveal_index != refresh_session.noreveal_index);
- /* check refresh session melt data */
- {
- struct TALER_EXCHANGEDB_RefreshMelt *ret_melt;
-
- ret_melt = &ret_refresh_session.melt;
- FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp
- (ret_melt->coin.denom_sig.rsa_signature,
- meltp->coin.denom_sig.rsa_signature));
- FAILIF (0 != memcmp (&ret_melt->coin.coin_pub,
- &meltp->coin.coin_pub,
- sizeof (ret_melt->coin.coin_pub)));
- FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
- (ret_melt->coin.denom_pub.rsa_public_key,
- meltp->coin.denom_pub.rsa_public_key));
- FAILIF (0 != memcmp (&ret_melt->coin_sig,
- &meltp->coin_sig,
- sizeof (ret_melt->coin_sig)));
- FAILIF (0 != memcmp (&ret_melt->session_hash,
- &meltp->session_hash,
- sizeof (ret_melt->session_hash)));
- FAILIF (0 != TALER_amount_cmp (&ret_melt->amount_with_fee,
- &meltp->amount_with_fee));
- FAILIF (0 != TALER_amount_cmp (&ret_melt->melt_fee,
- &meltp->melt_fee));
- GNUNET_CRYPTO_rsa_signature_free (ret_melt->coin.denom_sig.rsa_signature);
- GNUNET_CRYPTO_rsa_public_key_free (ret_melt->coin.denom_pub.rsa_public_key);
- }
- new_dkp = GNUNET_new_array (MELT_NEW_COINS, struct DenomKeyPair *);
+ new_dkp = GNUNET_new_array (MELT_NEW_COINS,
+ struct DenomKeyPair *);
new_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_DenominationPublicKey);
- for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
+ revealed_coins
+ = GNUNET_new_array (MELT_NEW_COINS,
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin);
+ for (unsigned int cnt=0; cnt < MELT_NEW_COINS; cnt++)
{
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *ccoin;
+ struct GNUNET_HashCode hc;
+
new_dkp[cnt] = create_denom_key_pair (1024,
session,
GNUNET_TIME_absolute_get (),
@@ -636,100 +600,50 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
&fee_refund);
GNUNET_assert (NULL != new_dkp[cnt]);
new_denom_pubs[cnt] = new_dkp[cnt]->pub;
- }
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_refresh_order (plugin->cls,
- session,
- &session_hash,
- MELT_NEW_COINS,
- new_denom_pubs));
- ret_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
- struct TALER_DenominationPublicKey);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_refresh_order (plugin->cls,
- session,
- &session_hash,
- MELT_NEW_COINS,
- ret_denom_pubs));
- for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
- {
- FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
- (ret_denom_pubs[cnt].rsa_public_key,
- new_denom_pubs[cnt].rsa_public_key));
- }
- FAILIF (GNUNET_OK !=
- test_refresh_commit_coins (session,
- &refresh_session,
- &session_hash));
- FAILIF (GNUNET_OK !=
- test_refresh_commit_links (session,
- &refresh_session,
- &session_hash));
-
- for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
- {
- struct GNUNET_HashCode hc;
- struct TALER_DenominationSignature test_sig;
-
+ ccoin = &revealed_coins[cnt];
+ ccoin->coin_ev_size = (size_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ COIN_ENC_MAX_SIZE);
+ ccoin->coin_ev = GNUNET_malloc (ccoin->coin_ev_size);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ ccoin->coin_ev,
+ ccoin->coin_ev_size);
RND_BLK (&hc);
- ev_sigs[cnt].rsa_signature
+ ccoin->denom_pub = new_dkp[cnt]->pub;
+ ccoin->coin_sig.rsa_signature
= GNUNET_CRYPTO_rsa_sign_fdh (new_dkp[cnt]->priv.rsa_private_key,
&hc);
- GNUNET_assert (NULL != ev_sigs[cnt].rsa_signature);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
- plugin->get_refresh_out (plugin->cls,
- session,
- &session_hash,
- cnt,
- &test_sig));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_refresh_out (plugin->cls,
- session,
- &session_hash,
- cnt,
- &ev_sigs[cnt]));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_refresh_out (plugin->cls,
- session,
- &session_hash,
- cnt,
- &test_sig));
- FAILIF (0 !=
- GNUNET_CRYPTO_rsa_signature_cmp (test_sig.rsa_signature,
- ev_sigs[cnt].rsa_signature));
- GNUNET_CRYPTO_rsa_signature_free (test_sig.rsa_signature);
}
+ RND_BLK (&tprivs);
+ RND_BLK (&tpub);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->get_refresh_reveal (plugin->cls,
+ session,
+ &refresh_session.rc,
+ &never_called_cb,
+ NULL));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_refresh_reveal (plugin->cls,
+ session,
+ &refresh_session.rc,
+ MELT_NEW_COINS,
+ revealed_coins,
+ TALER_CNC_KAPPA - 1,
+ tprivs,
+ &tpub));
+ FAILIF (0 >=
+ plugin->get_refresh_reveal (plugin->cls,
+ session,
+ &refresh_session.rc,
+ &check_refresh_reveal_cb,
+ NULL));
- qs = plugin->get_link_data_list (plugin->cls,
- session,
- &session_hash,
- &ldl);
- FAILIF (0 >= qs);
- FAILIF (NULL == ldl);
- for (ldlp = ldl; NULL != ldlp; ldlp = ldlp->next)
- {
- int found;
-
- found = GNUNET_NO;
- for (cnt=0;cnt < MELT_NEW_COINS;cnt++)
- {
- FAILIF (NULL == ldlp->ev_sig.rsa_signature);
- if ( (0 ==
- GNUNET_CRYPTO_rsa_public_key_cmp (ldlp->denom_pub.rsa_public_key,
- new_dkp[cnt]->pub.rsa_public_key)) &&
- (0 ==
- GNUNET_CRYPTO_rsa_signature_cmp (ldlp->ev_sig.rsa_signature,
- ev_sigs[cnt].rsa_signature)) )
- {
- found = GNUNET_YES;
- break;
- }
- }
- FAILIF (GNUNET_NO == found);
- }
- plugin->free_link_data_list (plugin->cls,
- ldl);
+ qs = plugin->get_link_data (plugin->cls,
+ session,
+ &refresh_session.coin.coin_pub,
+ &handle_link_data_cb,
+ NULL);
+ FAILIF (0 >= qs);
{
/* Just to test fetching a coin with melt history */
struct TALER_EXCHANGEDB_TransactionList *tl;
@@ -737,7 +651,7 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
qs = plugin->get_coin_transactions (plugin->cls,
session,
- &meltp->coin.coin_pub,
+ &refresh_session.coin.coin_pub,
&tl);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs);
plugin->free_coin_transaction_list (plugin->cls,
@@ -745,42 +659,29 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
}
- {
- int ok;
-
- ok = GNUNET_NO;
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_transfer (plugin->cls,
- session,
- &meltp->coin.coin_pub,
- &check_transfer_data,
- &ok));
- FAILIF (GNUNET_OK != ok);
- }
-
ret = GNUNET_OK;
drop:
- for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
- if (NULL != ev_sigs[cnt].rsa_signature)
- GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature);
- if (NULL != commit_coins)
+ if (NULL != revealed_coins)
{
- plugin->free_refresh_commit_coins (plugin->cls,
- MELT_NEW_COINS,
- commit_coins);
- GNUNET_free (commit_coins);
- commit_coins = NULL;
+ for (unsigned int cnt=0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ if (NULL != revealed_coins[cnt].coin_sig.rsa_signature)
+ GNUNET_CRYPTO_rsa_signature_free (revealed_coins[cnt].coin_sig.rsa_signature);
+ GNUNET_free (revealed_coins[cnt].coin_ev);
+ }
+ GNUNET_free (revealed_coins);
+ revealed_coins = NULL;
}
destroy_denom_key_pair (dkp);
- GNUNET_CRYPTO_rsa_signature_free (meltp->coin.denom_sig.rsa_signature);
- for (cnt = 0;
+ GNUNET_CRYPTO_rsa_signature_free (refresh_session.coin.denom_sig.rsa_signature);
+ for (unsigned int cnt = 0;
(NULL != ret_denom_pubs) && (cnt < MELT_NEW_COINS)
&& (NULL != ret_denom_pubs[cnt].rsa_public_key);
cnt++)
GNUNET_CRYPTO_rsa_public_key_free (ret_denom_pubs[cnt].rsa_public_key);
GNUNET_free_non_null (ret_denom_pubs);
GNUNET_free_non_null (new_denom_pubs);
- for (cnt = 0;
+ for (unsigned int cnt = 0;
(NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]);
cnt++)
destroy_denom_key_pair (new_dkp[cnt]);
@@ -1439,7 +1340,7 @@ wire_missing_cb (void *cls,
/* bool? */ int tiny,
/* bool? */ int done)
{
- struct TALER_EXCHANGEDB_Deposit *deposit = cls;
+ const struct TALER_EXCHANGEDB_Deposit *deposit = cls;
struct GNUNET_HashCode h_wire;
if (NULL != wire)
@@ -1615,6 +1516,7 @@ run (void *cls)
session,
&rr,
&rr_size));
+ GNUNET_free (rr);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls,
session,