aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-05-16 11:55:47 +0200
committerChristian Grothoff <christian@grothoff.org>2016-05-16 11:55:47 +0200
commitc8b9370413d6a330f3b457359ed309ac9e964533 (patch)
tree5ae6cc04d2d04731fdf802704ab2570dc3587040 /src/exchangedb
parent068dbf020b1f762d4364ca378c1396d16fa6eb1a (diff)
downloadexchange-c8b9370413d6a330f3b457359ed309ac9e964533.tar.xz
fixing #3814 by removing ability to melt multiple oldcoins at the same time
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/perf_taler_exchangedb.c5
-rw-r--r--src/exchangedb/perf_taler_exchangedb_init.c3
-rw-r--r--src/exchangedb/perf_taler_exchangedb_interpreter.c121
-rw-r--r--src/exchangedb/perf_taler_exchangedb_interpreter.h77
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c10
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c483
-rw-r--r--src/exchangedb/test_exchangedb.c120
7 files changed, 200 insertions, 619 deletions
diff --git a/src/exchangedb/perf_taler_exchangedb.c b/src/exchangedb/perf_taler_exchangedb.c
index bac8f4cb8..49f6ca080 100644
--- a/src/exchangedb/perf_taler_exchangedb.c
+++ b/src/exchangedb/perf_taler_exchangedb.c
@@ -144,7 +144,7 @@ main (int argc, char ** argv)
PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("06 - refresh melt init loop",
NB_MELT_INIT),
PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION (""),
- /* TODO: initialize using coins & sessions created localy
+ /* TODO: initialize using coins & sessions created localy
* in order to make sure the same coin are not melted twice*/
PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("06 - session hash",
"06 - refresh melt init loop",
@@ -152,9 +152,6 @@ main (int argc, char ** argv)
PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("06 - coin",
"06 - refresh melt init loop",
"03 - save coin"),
- PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_REFRESH_MELT ("06 - refresh melt",
- "06 - session hash",
- "06 - coin"),
PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION (""),
PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("06 - end",
"06 - refresh melt init loop"),
diff --git a/src/exchangedb/perf_taler_exchangedb_init.c b/src/exchangedb/perf_taler_exchangedb_init.c
index 2d018bdf0..988014a11 100644
--- a/src/exchangedb/perf_taler_exchangedb_init.c
+++ b/src/exchangedb/perf_taler_exchangedb_init.c
@@ -447,7 +447,6 @@ PERF_TALER_EXCHANGEDB_refresh_session_init ()
GNUNET_assert (NULL !=
(refresh_session = GNUNET_new (struct TALER_EXCHANGEDB_RefreshSession)));
refresh_session->noreveal_index = 1;
- refresh_session->num_oldcoins = 1;
refresh_session->num_newcoins = 1;
return refresh_session;
@@ -459,7 +458,7 @@ PERF_TALER_EXCHANGEDB_refresh_session_init ()
*/
int
PERF_TALER_EXCHANGEDB_refresh_session_copy (struct TALER_EXCHANGEDB_RefreshSession *session,
- struct TALER_EXCHANGEDB_RefreshSession *copy)
+ struct TALER_EXCHANGEDB_RefreshSession *copy)
{
*copy = *session;
return GNUNET_OK;
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c
index cb805a0b3..661cfeef3 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.c
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c
@@ -101,13 +101,6 @@ data_free (struct PERF_TALER_EXCHANGEDB_Data *data)
data->data.session_hash = NULL;
break;
- case PERF_TALER_EXCHANGEDB_REFRESH_MELT:
- if (NULL == data->data.refresh_melt)
- break;
- PERF_TALER_EXCHANGEDB_refresh_melt_free (data->data.refresh_melt);
- data->data.refresh_melt = NULL;
- break;
-
case PERF_TALER_EXCHANGEDB_NONE:
break;
}
@@ -158,11 +151,6 @@ data_copy (const struct PERF_TALER_EXCHANGEDB_Data *data,
= *data->data.session_hash;
break;
- case PERF_TALER_EXCHANGEDB_REFRESH_MELT:
- copy->data.refresh_melt
- = PERF_TALER_EXCHANGEDB_refresh_melt_copy (data->data.refresh_melt);
- break;
-
case PERF_TALER_EXCHANGEDB_NONE:
break;
}
@@ -770,75 +758,6 @@ cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_MELT:
- {
- int ret;
-
- ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_melt.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.insert_refresh_melt.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_melt.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.insert_refresh_melt.index_hash = ret;
- ret = cmd_find (cmd,
- cmd[i].details.insert_refresh_melt.label_coin);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.insert_refresh_melt.label_coin);
- return GNUNET_SYSERR;
- }
- if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Wrong type reference to %s\n",
- i,
- cmd[i].details.insert_refresh_melt.label_coin);
- return GNUNET_SYSERR;
- }
- cmd[i].details.insert_refresh_melt.index_coin = ret; }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_MELT:
- {
- int ret;
- ret = cmd_find (cmd,
- cmd[i].details.get_refresh_melt.label_hash);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%d:Undefined reference to %s\n",
- i,
- cmd[i].details.get_refresh_melt.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_melt.label_hash);
- return GNUNET_SYSERR;
- }
- cmd[i].details.get_refresh_melt.index_hash = ret;
- }
- break;
-
case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
{
int ret;
@@ -1645,46 +1564,6 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
}
break;
- case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_MELT:
- {
- unsigned int hash_index;
- unsigned int coin_index;
- struct GNUNET_HashCode *hash;
- struct TALER_EXCHANGEDB_RefreshMelt *melt;
- struct PERF_TALER_EXCHANGEDB_Coin *coin;
-
- hash_index = state->cmd[state->i].details.insert_refresh_melt.index_hash;
- coin_index = state->cmd[state->i].details.insert_refresh_melt.index_coin;
- hash = state->cmd[hash_index].exposed.data.session_hash;
- coin = state->cmd[coin_index].exposed.data.coin;
- melt = PERF_TALER_EXCHANGEDB_refresh_melt_init (hash,
- coin);
- state->plugin->insert_refresh_melt (state->plugin->cls,
- state->session,
- 1,
- melt);
- }
- break;
-
- case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_MELT:
- {
- int ret;
- unsigned int hash_index;
- struct GNUNET_HashCode *hash;
- struct TALER_EXCHANGEDB_RefreshMelt melt;
-
- hash_index = cmd_find (state->cmd,
- state->cmd[state->i].details.get_refresh_melt.label_hash);
- hash = state->cmd[hash_index].exposed.data.session_hash;
- ret = state->plugin->get_refresh_melt (state->plugin->cls,
- state->session,
- hash,
- 1,
- &melt);
- GNUNET_assert (GNUNET_SYSERR != ret);
- }
- break;
-
case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
{
unsigned int hash_index;
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.h b/src/exchangedb/perf_taler_exchangedb_interpreter.h
index 1c2659dd1..cf4f0bfd7 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.h
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.h
@@ -479,38 +479,6 @@
.exposed.type = PERF_TALER_EXCHANGEDB_NONE \
}
-/**
- * Insert a melt operation in the database
- *
- * @param _label the label of the command
- * @param _label_hash the label of the hash of the session
- * @param _label_coin the label of the coin to melt
- */
-#define PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_REFRESH_MELT(_label, \
- _label_hash, \
- _label_coin) \
-{ \
- .command = PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_MELT, \
- .label = _label, \
- .details.insert_refresh_melt.label_hash = _label_hash, \
- .details.insert_refresh_melt.label_coin = _label_coin, \
- .exposed.type = PERF_TALER_EXCHANGEDB_NONE \
-}
-
-/**
- * Get informations about a melt operation
- *
- * @param _label the label of the command
- * @param _label_hash the label of the hash of the refresh session
- */
-#define PERF_TALER_EXCHANGEDB_INIT_CMD_GET_REFRESH_MELT(_label, \
- _label_hash) \
-{ \
- .command = PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_MELT, \
- .label = _label, \
- .detail.get_refresh_melt.label_hash = _label_hash, \
- .exposed.type = PERF_TALER_EXCHANGEDB_NONE \
-}
/**
* The type of data stored in #PERF_TALER_EXCHANGEDB_Memory
@@ -523,8 +491,7 @@ enum PERF_TALER_EXCHANGEDB_Type
PERF_TALER_EXCHANGEDB_RESERVE,
PERF_TALER_EXCHANGEDB_COIN,
PERF_TALER_EXCHANGEDB_DEPOSIT,
- PERF_TALER_EXCHANGEDB_REFRESH_HASH,
- PERF_TALER_EXCHANGEDB_REFRESH_MELT
+ PERF_TALER_EXCHANGEDB_REFRESH_HASH
};
@@ -553,8 +520,6 @@ struct PERF_TALER_EXCHANGEDB_Data
struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
/** #PERF_TALER_EXCHANGEDB_REFRESH_HASH */
struct GNUNET_HashCode *session_hash;
- /** #PERF_TALER_EXCHANGEDB_REFRESH_MELT */
- struct TALER_EXCHANGEDB_RefreshMelt *refresh_melt;
} data;
};
@@ -714,16 +679,6 @@ enum PERF_TALER_EXCHANGEDB_CMD_Name
PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION,
/**
- * Insert a refresh melt
- */
- PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_MELT,
-
- /**
- * Get informations about a refresh melt operation
- */
- PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_MELT,
-
- /**
* Insert a melt refresh order
*/
PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER,
@@ -1086,36 +1041,6 @@ union PERF_TALER_EXCHANGEDB_CMD_Details
} get_refresh_session;
/**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_MELT command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshMeltDetails
- {
- /**
- * The label of the hash of the refresh session
- */
- const char *label_hash;
- unsigned int index_hash;
-
- /**
- * The label of the coin to melt
- */
- const char *label_coin;
- unsigned int index_coin;
- } insert_refresh_melt;
-
- /**
- * Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_MELT command
- */
- struct PERF_TALER_EXCHANGEDB_CMD_getRefreshMeltDetails
- {
- /**
- * The label of the hash of the session
- */
- const char *label_hash;
- unsigned int index_hash;
- } get_refresh_melt;
-
- /**
* Data requiered for the #PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER command
*/
struct PERF_TALER_EXCHANGEDB_CMD_insertRefreshOrderDetails
diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c
index 8bb214efb..9b62d688f 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -132,15 +132,6 @@ common_free_melt_commitment (void *cls,
unsigned int i;
unsigned int k;
- if (NULL != mc->melts)
- {
- for (i=0;i<mc->num_oldcoins;i++)
- {
- GNUNET_CRYPTO_rsa_signature_free (mc->melts[i].coin.denom_sig.rsa_signature);
- GNUNET_CRYPTO_rsa_public_key_free (mc->melts[i].coin.denom_pub.rsa_public_key);
- }
- GNUNET_free (mc->melts);
- }
if (NULL != mc->denom_pubs)
{
for (i=0;i<mc->num_newcoins;i++)
@@ -161,7 +152,6 @@ common_free_melt_commitment (void *cls,
}
GNUNET_free (mc->commit_coins[k]);
}
- GNUNET_free_non_null (mc->commit_links[k]);
}
GNUNET_free (mc);
}
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 6f5599d6f..cda2df0d0 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -160,8 +160,6 @@ postgres_drop_tables (void *cls,
SQLEXEC_ (session->conn,
"DROP TABLE IF EXISTS refresh_order;");
SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_melts;");
- SQLEXEC_ (session->conn,
"DROP TABLE IF EXISTS refresh_sessions;");
SQLEXEC_ (session->conn,
"DROP TABLE IF EXISTS known_coins;");
@@ -338,36 +336,24 @@ postgres_create_tables (void *cls)
/**
* The DB will show negative values for some values of the following fields as
* we use them as 16 bit unsigned integers
- * @a num_oldcoins
* @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?
*/
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_sessions "
"(session_hash BYTEA PRIMARY KEY CHECK (LENGTH(session_hash)=64)"
- ",num_oldcoins INT2 NOT NULL"
- ",num_newcoins INT2 NOT NULL"
- ",noreveal_index INT2 NOT NULL"
- ")");
- /* Table with coins that have been melted. Gives the coin's public
- key (coin_pub), the melting session, the index of this coin in that
- session, the signature affirming the melting and the amount that
- this coin contributed to the melting session.
- */
- SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_melts "
- "(coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub)"
- ",session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash)"
- ",oldcoin_index INT2 NOT NULL"
- ",coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)"
+ ",old_coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub)"
+ ",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"
",melt_fee_val INT8 NOT NULL"
",melt_fee_frac INT4 NOT NULL"
",melt_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
- ",PRIMARY KEY (session_hash, oldcoin_index)" /* a coin can be used only
- once in a refresh session */
- ") ");
+ ",num_newcoins INT2 NOT NULL"
+ ",noreveal_index INT2 NOT NULL"
+ ")");
/* Table with information about coins that have been refunded. (Technically
one of the deposit operations that a coin was involved with is refunded.)*/
SQLEXEC("CREATE TABLE IF NOT EXISTS refunds "
@@ -401,15 +387,11 @@ postgres_create_tables (void *cls)
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).
- NOTE: We might want to simplify this and not have the oldcoin_index
- and instead store all link secrets, one after the other, in one big BYTEA.
- (#3814) */
+ link secret) */
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_link "
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash)"
",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
",link_secret_enc BYTEA NOT NULL"
- ",oldcoin_index INT2 NOT NULL"
",cnc_index INT2 NOT NULL"
")");
/* Table with the commitments for the new coins that are to be created
@@ -726,7 +708,14 @@ postgres_prepare (PGconn *db_conn)
high-level information about a refresh session */
PREPARE ("get_refresh_session",
"SELECT"
- " num_oldcoins"
+ " old_coin_pub"
+ ",old_coin_sig"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",amount_with_fee_curr"
+ ",melt_fee_val "
+ ",melt_fee_frac "
+ ",melt_fee_curr "
",num_newcoins"
",noreveal_index"
" FROM refresh_sessions "
@@ -738,12 +727,19 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("insert_refresh_session",
"INSERT INTO refresh_sessions "
"(session_hash "
- ",num_oldcoins "
+ ",old_coin_pub "
+ ",old_coin_sig "
+ ",amount_with_fee_val "
+ ",amount_with_fee_frac "
+ ",amount_with_fee_curr "
+ ",melt_fee_val "
+ ",melt_fee_frac "
+ ",melt_fee_curr "
",num_newcoins "
",noreveal_index "
") VALUES "
- "($1, $2, $3, $4);",
- 4, NULL);
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);",
+ 11, NULL);
/* Used in #postgres_get_known_coin() to fetch
the denomination public key and signature for
@@ -787,54 +783,19 @@ postgres_prepare (PGconn *db_conn)
" WHERE session_hash=$1 AND newcoin_index=$2",
2, NULL);
- /* Used in #postgres_insert_refresh_melt to store information
- about melted coins */
- PREPARE ("insert_refresh_melt",
- "INSERT INTO refresh_melts "
- "(coin_pub "
- ",session_hash"
- ",oldcoin_index "
- ",coin_sig "
- ",amount_with_fee_val "
- ",amount_with_fee_frac "
- ",amount_with_fee_curr "
- ",melt_fee_val "
- ",melt_fee_frac "
- ",melt_fee_curr "
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);",
- 10, NULL);
-
- /* Used in #postgres_get_refresh_melt to obtain information
- about melted coins */
- PREPARE ("get_refresh_melt",
- "SELECT"
- " coin_pub"
- ",coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",amount_with_fee_curr"
- ",melt_fee_val "
- ",melt_fee_frac "
- ",melt_fee_curr "
- " FROM refresh_melts"
- " WHERE session_hash=$1 AND oldcoin_index=$2",
- 2, NULL);
-
- /* Query the 'refresh_melts' by coin public key */
- PREPARE ("get_refresh_melt_by_coin",
+ /* Query the 'refresh_sessions' by coin public key */
+ PREPARE ("get_refresh_session_by_coin",
"SELECT"
" session_hash"
- /* ",oldcoin_index" // not needed */
- ",coin_sig"
+ ",old_coin_sig"
",amount_with_fee_val"
",amount_with_fee_frac"
",amount_with_fee_curr"
",melt_fee_val "
",melt_fee_frac "
",melt_fee_curr "
- " FROM refresh_melts"
- " WHERE coin_pub=$1",
+ " FROM refresh_sessions"
+ " WHERE old_coin_pub=$1",
1, NULL);
/* Query the 'refunds' by coin public key */
@@ -856,28 +817,27 @@ postgres_prepare (PGconn *db_conn)
1, NULL);
- /* Used in #postgres_insert_refresh_commit_links() to
+ /* Used in #postgres_insert_refresh_commit_link() to
store commitments */
PREPARE ("insert_refresh_commit_link",
"INSERT INTO refresh_commit_link "
"(session_hash"
",transfer_pub"
",cnc_index"
- ",oldcoin_index"
",link_secret_enc"
") VALUES "
- "($1, $2, $3, $4, $5);",
- 5, NULL);
+ "($1, $2, $3, $4);",
+ 4, NULL);
- /* Used in #postgres_get_refresh_commit_links() to
+ /* Used in #postgres_get_refresh_commit_link() to
retrieve original commitments during /refresh/reveal */
PREPARE ("get_refresh_commit_link",
"SELECT"
" transfer_pub"
",link_secret_enc"
" FROM refresh_commit_link"
- " WHERE session_hash=$1 AND cnc_index=$2 AND oldcoin_index=$3",
- 3, NULL);
+ " WHERE session_hash=$1 AND cnc_index=$2",
+ 2, NULL);
/* Used in #postgres_insert_refresh_commit_coins() to
store coin commitments. */
@@ -1110,10 +1070,9 @@ postgres_prepare (PGconn *db_conn)
efficient ways to express the same query. */
PREPARE ("get_link",
"SELECT link_vector_enc,ev_sig,ro.denom_pub"
- " FROM refresh_melts rm "
+ " FROM refresh_sessions rs "
" JOIN refresh_order ro USING (session_hash)"
" JOIN refresh_commit_coin rcc USING (session_hash)"
- " JOIN refresh_sessions rs USING (session_hash)"
" JOIN refresh_out rc USING (session_hash)"
" WHERE ro.session_hash=$1"
" AND ro.newcoin_index=rcc.newcoin_index"
@@ -1125,18 +1084,14 @@ postgres_prepare (PGconn *db_conn)
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"
- and the transfer public key to the corresponding index of the
- old coin.
+ 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. */
PREPARE ("get_transfer",
"SELECT transfer_pub,link_secret_enc,session_hash"
- " FROM refresh_melts rm"
+ " FROM refresh_sessions rs"
" JOIN refresh_commit_link rcl USING (session_hash)"
- " JOIN refresh_sessions rs USING (session_hash)"
- " WHERE rm.coin_pub=$1"
- " AND rm.oldcoin_index = rcl.oldcoin_index"
+ " WHERE rs.old_coin_pub=$1"
" AND rcl.cnc_index=rs.noreveal_index",
1, NULL);
@@ -2288,7 +2243,7 @@ postgres_test_deposit_done (void *cls,
{
/* NOTE: maybe wrong type for a 'boolean' */
- uint32_t done;
+ uint32_t done = 0;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint32 ("done",
&done),
@@ -2812,12 +2767,14 @@ postgres_get_refresh_session (void *cls,
sizeof (struct TALER_EXCHANGEDB_RefreshSession));
{
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint16 ("num_oldcoins",
- &refresh_session->num_oldcoins),
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_auto_from_type ("old_coin_pub", &refresh_session->melt.coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig", &refresh_session->melt.coin_sig),
+ TALER_PQ_result_spec_amount ("amount_with_fee", &refresh_session->melt.amount_with_fee),
+ TALER_PQ_result_spec_amount ("melt_fee", &refresh_session->melt.melt_fee),
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
@@ -2829,6 +2786,16 @@ postgres_get_refresh_session (void *cls,
}
}
PQclear (result);
+ if (GNUNET_OK !=
+ get_known_coin (cls,
+ session,
+ &refresh_session->melt.coin.coin_pub,
+ &refresh_session->melt.coin))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ refresh_session->melt.session_hash = *session_hash;
return GNUNET_YES;
}
@@ -2852,59 +2819,20 @@ postgres_create_refresh_session (void *cls,
PGresult *result;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&refresh_session->num_oldcoins),
+ 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),
+ TALER_PQ_query_param_amount (&refresh_session->melt.melt_fee),
GNUNET_PQ_query_param_uint16 (&refresh_session->num_newcoins),
GNUNET_PQ_query_param_uint16 (&refresh_session->noreveal_index),
GNUNET_PQ_query_param_end
};
-
- result = GNUNET_PQ_exec_prepared (session->conn,
- "insert_refresh_session",
- params);
- if (PGRES_COMMAND_OK != PQresultStatus (result))
- {
- BREAK_DB_ERR (result);
- PQclear (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
- return GNUNET_OK;
-}
-
-
-/**
- * Store the given /refresh/melt request in the database.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param oldcoin_index index of the coin to store
- * @param melt melt operation details to store; includes
- * the session hash of the melt
- * @return #GNUNET_OK on success
- * #GNUNET_SYSERR on internal error
- */
-static int
-postgres_insert_refresh_melt (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- uint16_t oldcoin_index,
- const struct TALER_EXCHANGEDB_RefreshMelt *melt)
-{
- PGresult *result;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&melt->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&melt->session_hash),
- GNUNET_PQ_query_param_uint16 (&oldcoin_index),
- GNUNET_PQ_query_param_auto_from_type (&melt->coin_sig),
- TALER_PQ_query_param_amount (&melt->amount_with_fee),
- TALER_PQ_query_param_amount (&melt->melt_fee),
- GNUNET_PQ_query_param_end
- };
int ret;
/* check if the coin is already known */
ret = get_known_coin (cls,
session,
- &melt->coin.coin_pub,
+ &refresh_session->melt.coin.coin_pub,
NULL);
if (GNUNET_SYSERR == ret)
{
@@ -2916,15 +2844,15 @@ postgres_insert_refresh_melt (void *cls,
if (GNUNET_SYSERR ==
insert_known_coin (cls,
session,
- &melt->coin))
+ &refresh_session->melt.coin))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
}
- /* insert the melt */
+ /* insert session */
result = GNUNET_PQ_exec_prepared (session->conn,
- "insert_refresh_melt",
+ "insert_refresh_session",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
@@ -2938,93 +2866,6 @@ postgres_insert_refresh_melt (void *cls,
/**
- * Get information about melted coin details from the database.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database connection
- * @param session_hash session hash of the melt operation
- * @param oldcoin_index index of the coin to retrieve
- * @param melt melt data to fill in, can be NULL
- * @return #GNUNET_OK on success
- * #GNUNET_SYSERR on internal error
- */
-static int
-postgres_get_refresh_melt (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t oldcoin_index,
- struct TALER_EXCHANGEDB_RefreshMelt *melt)
-{
- PGresult *result;
- struct TALER_CoinPublicInfo coin;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount melt_fee;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&oldcoin_index),
- GNUNET_PQ_query_param_end
- };
- int nrows;
-
- /* check if the melt record exists and get it */
- result = GNUNET_PQ_exec_prepared (session->conn,
- "get_refresh_melt",
- params);
- if (PGRES_TUPLES_OK != PQresultStatus (result))
- {
- BREAK_DB_ERR (result);
- PQclear (result);
- return GNUNET_SYSERR;
- }
- nrows = PQntuples (result);
- if (0 == nrows)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "get_refresh_melt() returned 0 matching rows\n");
- PQclear (result);
- return GNUNET_NO;
- }
- GNUNET_assert (1 == nrows); /* due to primary key constraint */
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig", &coin_sig),
- TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee),
- TALER_PQ_result_spec_amount ("melt_fee", &melt_fee),
- GNUNET_PQ_result_spec_end
- };
- if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0))
- {
- GNUNET_break (0);
- PQclear (result);
- return GNUNET_SYSERR;
- }
- PQclear (result);
- }
- /* fetch the coin info and denomination info */
- if (GNUNET_OK !=
- get_known_coin (cls,
- session,
- &coin.coin_pub,
- &coin))
- return GNUNET_SYSERR;
- if (NULL == melt)
- {
- GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
- GNUNET_CRYPTO_rsa_public_key_free (coin.denom_pub.rsa_public_key);
- return GNUNET_OK;
- }
- melt->coin = coin;
- melt->coin_sig = coin_sig;
- melt->session_hash = *session_hash;
- melt->amount_with_fee = amount_with_fee;
- melt->melt_fee = melt_fee;
- return GNUNET_OK;
-}
-
-
-/**
* Store in the database which coin(s) we want to create
* in a given refresh operation.
*
@@ -3369,48 +3210,42 @@ postgres_get_refresh_commit_coins (void *cls,
* @param session database connection to use
* @param session_hash hash to identify refresh session
* @param cnc_index cut and choose index (1st dimension)
- * @param num_links size of the @a links array to return
- * @param[out] links array of link information to store return
+ * @param[out] link link information to store return
* @return #GNUNET_SYSERR on internal error, #GNUNET_OK on success
*/
static int
-postgres_insert_refresh_commit_links (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t cnc_index,
- uint16_t num_links,
- const struct TALER_RefreshCommitLinkP *links)
+postgres_insert_refresh_commit_link (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct GNUNET_HashCode *session_hash,
+ uint16_t cnc_index,
+ const struct TALER_RefreshCommitLinkP *link)
{
- uint16_t i;
-
- for (i=0;i<num_links;i++)
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_auto_from_type (&links[i].transfer_pub),
- GNUNET_PQ_query_param_uint16 (&cnc_index),
- GNUNET_PQ_query_param_uint16 (&i),
- GNUNET_PQ_query_param_auto_from_type (&links[i].shared_secret_enc),
- GNUNET_PQ_query_param_end
- };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_auto_from_type (&link->transfer_pub),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_auto_from_type (&link->shared_secret_enc),
+ GNUNET_PQ_query_param_end
+ };
- PGresult *result = GNUNET_PQ_exec_prepared (session->conn,
- "insert_refresh_commit_link",
- params);
- if (PGRES_COMMAND_OK != PQresultStatus (result))
- {
- BREAK_DB_ERR (result);
- PQclear (result);
- return GNUNET_SYSERR;
- }
+ PGresult *result;
- if (0 != strcmp ("1", PQcmdTuples (result)))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ result = GNUNET_PQ_exec_prepared (session->conn,
+ "insert_refresh_commit_link",
+ params);
+ if (PGRES_COMMAND_OK != PQresultStatus (result))
+ {
+ BREAK_DB_ERR (result);
PQclear (result);
+ return GNUNET_SYSERR;
+ }
+
+ if (0 != strcmp ("1", PQcmdTuples (result)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
+ PQclear (result);
return GNUNET_OK;
}
@@ -3423,64 +3258,56 @@ postgres_insert_refresh_commit_links (void *cls,
* @param session database connection to use
* @param session_hash hash to identify refresh session
* @param cnc_index cut and choose index (1st dimension)
- * @param num_links size of the @a commit_link array
- * @param[out] links array of link information to return
+ * @param[out] link information to return
* @return #GNUNET_SYSERR on internal error,
* #GNUNET_NO if commitment was not found
* #GNUNET_OK on success
*/
static int
-postgres_get_refresh_commit_links (void *cls,
- struct TALER_EXCHANGEDB_Session *session,
- const struct GNUNET_HashCode *session_hash,
- uint16_t cnc_index,
- uint16_t num_links,
- struct TALER_RefreshCommitLinkP *links)
+postgres_get_refresh_commit_link (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct GNUNET_HashCode *session_hash,
+ uint16_t cnc_index,
+ struct TALER_RefreshCommitLinkP *link)
{
- uint16_t i;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_end
+ };
+ PGresult *result;
- for (i=0;i<num_links;i++)
+ result = GNUNET_PQ_exec_prepared (session->conn,
+ "get_refresh_commit_link",
+ params);
+ if (PGRES_TUPLES_OK != PQresultStatus (result))
{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (session_hash),
- GNUNET_PQ_query_param_uint16 (&cnc_index),
- GNUNET_PQ_query_param_uint16 (&i),
- GNUNET_PQ_query_param_end
+ BREAK_DB_ERR (result);
+ PQclear (result);
+ return GNUNET_SYSERR;
+ }
+ if (0 == PQntuples (result))
+ {
+ PQclear (result);
+ return GNUNET_NO;
+ }
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
+ &link->transfer_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("link_secret_enc",
+ &link->shared_secret_enc),
+ GNUNET_PQ_result_spec_end
};
- PGresult *result;
- result = GNUNET_PQ_exec_prepared (session->conn,
- "get_refresh_commit_link",
- params);
- if (PGRES_TUPLES_OK != PQresultStatus (result))
+ if (GNUNET_YES !=
+ GNUNET_PQ_extract_result (result, rs, 0))
{
- BREAK_DB_ERR (result);
PQclear (result);
return GNUNET_SYSERR;
}
- if (0 == PQntuples (result))
- {
- PQclear (result);
- return GNUNET_NO;
- }
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
- &links[i].transfer_pub),
- GNUNET_PQ_result_spec_auto_from_type ("link_secret_enc",
- &links[i].shared_secret_enc),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_YES !=
- GNUNET_PQ_extract_result (result, rs, 0))
- {
- PQclear (result);
- return GNUNET_SYSERR;
- }
- }
- PQclear (result);
}
+ PQclear (result);
return GNUNET_OK;
}
@@ -3502,7 +3329,6 @@ postgres_get_melt_commitment (void *cls,
struct TALER_EXCHANGEDB_RefreshSession rs;
struct TALER_EXCHANGEDB_MeltCommitment *mc;
uint16_t cnc_index;
- unsigned int i;
if (GNUNET_OK !=
postgres_get_refresh_session (cls,
@@ -3512,17 +3338,6 @@ postgres_get_melt_commitment (void *cls,
return NULL;
mc = GNUNET_new (struct TALER_EXCHANGEDB_MeltCommitment);
mc->num_newcoins = rs.num_newcoins;
- mc->num_oldcoins = rs.num_oldcoins;
- mc->melts = GNUNET_malloc (mc->num_oldcoins *
- sizeof (struct TALER_EXCHANGEDB_RefreshMelt));
- for (i=0;i<mc->num_oldcoins;i++)
- if (GNUNET_OK !=
- postgres_get_refresh_melt (cls,
- session,
- session_hash,
- (uint16_t) i,
- &mc->melts[i]))
- goto cleanup;
mc->denom_pubs = GNUNET_malloc (mc->num_newcoins *
sizeof (struct TALER_DenominationPublicKey));
if (GNUNET_OK !=
@@ -3545,16 +3360,12 @@ postgres_get_melt_commitment (void *cls,
mc->num_newcoins,
mc->commit_coins[cnc_index]))
goto cleanup;
- mc->commit_links[cnc_index]
- = GNUNET_malloc (mc->num_oldcoins *
- sizeof (struct TALER_RefreshCommitLinkP));
if (GNUNET_OK !=
- postgres_get_refresh_commit_links (cls,
- session,
- session_hash,
- cnc_index,
- mc->num_oldcoins,
- mc->commit_links[cnc_index]))
+ postgres_get_refresh_commit_link (cls,
+ session,
+ session_hash,
+ cnc_index,
+ &mc->commit_links[cnc_index]))
goto cleanup;
}
return mc;
@@ -3803,8 +3614,8 @@ postgres_get_coin_transactions (void *cls,
struct TALER_EXCHANGEDB_TransactionList *tl;
result = GNUNET_PQ_exec_prepared (session->conn,
- "get_deposit_with_coin_pub",
- params);
+ "get_deposit_with_coin_pub",
+ params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
QUERY_ERR (result);
@@ -3820,21 +3631,21 @@ postgres_get_coin_transactions (void *cls,
{
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("transaction_id",
- &deposit->transaction_id),
+ &deposit->transaction_id),
TALER_PQ_result_spec_amount ("amount_with_fee",
&deposit->amount_with_fee),
TALER_PQ_result_spec_amount ("deposit_fee",
&deposit->deposit_fee),
GNUNET_PQ_result_spec_absolute_time ("timestamp",
- &deposit->timestamp),
+ &deposit->timestamp),
GNUNET_PQ_result_spec_absolute_time ("refund_deadline",
- &deposit->refund_deadline),
+ &deposit->refund_deadline),
GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &deposit->merchant_pub),
+ &deposit->merchant_pub),
GNUNET_PQ_result_spec_auto_from_type ("h_contract",
- &deposit->h_contract),
+ &deposit->h_contract),
GNUNET_PQ_result_spec_auto_from_type ("h_wire",
- &deposit->h_wire),
+ &deposit->h_wire),
TALER_PQ_result_spec_json ("wire",
&deposit->wire),
GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
@@ -3874,8 +3685,8 @@ postgres_get_coin_transactions (void *cls,
/* check if the melt records exist and get them */
result = GNUNET_PQ_exec_prepared (session->conn,
- "get_refresh_melt_by_coin",
- params);
+ "get_refresh_session_by_coin",
+ params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result);
@@ -3891,10 +3702,10 @@ postgres_get_coin_transactions (void *cls,
{
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("session_hash",
- &melt->session_hash),
+ &melt->session_hash),
/* oldcoin_index not needed */
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &melt->coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
+ &melt->coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
&melt->amount_with_fee),
TALER_PQ_result_spec_amount ("melt_fee",
@@ -4506,14 +4317,12 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
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_melt = &postgres_insert_refresh_melt;
- plugin->get_refresh_melt = &postgres_get_refresh_melt;
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->insert_refresh_commit_links = &postgres_insert_refresh_commit_links;
- plugin->get_refresh_commit_links = &postgres_get_refresh_commit_links;
+ plugin->insert_refresh_commit_link = &postgres_insert_refresh_commit_link;
+ plugin->get_refresh_commit_link = &postgres_get_refresh_commit_link;
plugin->get_melt_commitment = &postgres_get_melt_commitment;
plugin->free_melt_commitment = &common_free_melt_commitment;
plugin->insert_refresh_out = &postgres_insert_refresh_out;
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 2feeb5247..3169f06db 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -458,14 +458,13 @@ test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session,
static int
test_melting (struct TALER_EXCHANGEDB_Session *session)
{
-#define MELT_OLD_COINS 10
struct TALER_EXCHANGEDB_RefreshSession refresh_session;
struct TALER_EXCHANGEDB_RefreshSession ret_refresh_session;
struct GNUNET_HashCode session_hash;
struct DenomKeyPair *dkp;
struct DenomKeyPair **new_dkp;
/* struct TALER_CoinPublicInfo *coins; */
- struct TALER_EXCHANGEDB_RefreshMelt *melts;
+ struct TALER_EXCHANGEDB_RefreshMelt *meltp;
struct TALER_DenominationPublicKey *new_denom_pubs;
struct TALER_DenominationPublicKey *ret_denom_pubs;
struct TALER_EXCHANGEDB_MeltCommitment *mc;
@@ -475,89 +474,77 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
ret = GNUNET_SYSERR;
RND_BLK (&refresh_session);
RND_BLK (&session_hash);
- melts = NULL;
dkp = NULL;
new_dkp = NULL;
new_denom_pubs = NULL;
ret_denom_pubs = NULL;
/* create and test a refresh session */
- refresh_session.num_oldcoins = MELT_OLD_COINS;
refresh_session.num_newcoins = 1;
refresh_session.noreveal_index = 1;
- FAILIF (GNUNET_OK != plugin->create_refresh_session (plugin->cls,
- session,
- &session_hash,
- &refresh_session));
- FAILIF (GNUNET_OK != plugin->get_refresh_session (plugin->cls,
- session,
- &session_hash,
- &ret_refresh_session));
- FAILIF (0 != memcmp (&ret_refresh_session,
- &refresh_session,
- sizeof (refresh_session)));
-
/* create a denomination (value: 1; fraction: 100) */
- dkp = create_denom_key_pair (512, session,
+ dkp = create_denom_key_pair (512,
+ session,
&value,
&fee_withdraw,
&fee_deposit,
&fee_refresh,
&fee_refund);
- /* create MELT_OLD_COINS number of refresh melts */
- melts = GNUNET_new_array (MELT_OLD_COINS,
- struct TALER_EXCHANGEDB_RefreshMelt);
- for (cnt=0; cnt < MELT_OLD_COINS; cnt++)
+ /* initialize refresh session melt data */
{
struct GNUNET_HashCode hc;
- RND_BLK (&melts[cnt].coin.coin_pub);
- GNUNET_CRYPTO_hash (&melts[cnt].coin.coin_pub,
- sizeof (melts[cnt].coin.coin_pub),
+ meltp = &refresh_session.melt;
+ RND_BLK (&meltp->coin.coin_pub);
+ GNUNET_CRYPTO_hash (&meltp->coin.coin_pub,
+ sizeof (meltp->coin.coin_pub),
&hc);
- melts[cnt].coin.denom_sig.rsa_signature =
+ meltp->coin.denom_sig.rsa_signature =
GNUNET_CRYPTO_rsa_sign_fdh (dkp->priv.rsa_private_key,
&hc);
- melts[cnt].coin.denom_pub = dkp->pub;
- RND_BLK (&melts[cnt].coin_sig);
- melts[cnt].session_hash = session_hash;
- melts[cnt].amount_with_fee = amount_with_fee;
- melts[cnt].melt_fee = fee_refresh;
- FAILIF (GNUNET_OK !=
- plugin->insert_refresh_melt (plugin->cls,
- session,
- cnt,
- &melts[cnt]));
+ 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;
}
- for (cnt = 0; cnt < MELT_OLD_COINS; cnt++)
+
+ FAILIF (GNUNET_OK != plugin->create_refresh_session (plugin->cls,
+ session,
+ &session_hash,
+ &refresh_session));
+ FAILIF (GNUNET_OK != plugin->get_refresh_session (plugin->cls,
+ session,
+ &session_hash,
+ &ret_refresh_session));
+ FAILIF (ret_refresh_session.num_newcoins != refresh_session.num_newcoins);
+ FAILIF (ret_refresh_session.noreveal_index != refresh_session.noreveal_index);
+
+ /* check refresh sesison melt data */
{
- struct TALER_EXCHANGEDB_RefreshMelt ret_melt;
- FAILIF (GNUNET_OK !=
- plugin->get_refresh_melt (plugin->cls,
- session,
- &session_hash,
- cnt,
- &ret_melt));
+ 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,
- melts[cnt].coin.denom_sig.rsa_signature));
- FAILIF (0 != memcmp (&ret_melt.coin.coin_pub,
- &melts[cnt].coin.coin_pub,
- sizeof (ret_melt.coin.coin_pub)));
+ (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,
- melts[cnt].coin.denom_pub.rsa_public_key));
- FAILIF (0 != memcmp (&ret_melt.coin_sig,
- &melts[cnt].coin_sig,
- sizeof (ret_melt.coin_sig)));
- FAILIF (0 != memcmp (&ret_melt.session_hash,
- &melts[cnt].session_hash,
- sizeof (ret_melt.session_hash)));
- FAILIF (0 != TALER_amount_cmp (&ret_melt.amount_with_fee,
- &melts[cnt].amount_with_fee));
- FAILIF (0 != TALER_amount_cmp (&ret_melt.melt_fee,
- &melts[cnt].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);
+ (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_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
@@ -619,15 +606,10 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
drop:
if (NULL != dkp)
destroy_denom_key_pair (dkp);
- if (NULL != melts)
- {
- for (cnt = 0; cnt < MELT_OLD_COINS; cnt++)
- GNUNET_CRYPTO_rsa_signature_free (melts[cnt].coin.denom_sig.rsa_signature);
- GNUNET_free (melts);
- }
+ GNUNET_CRYPTO_rsa_signature_free (meltp->coin.denom_sig.rsa_signature);
for (cnt = 0;
(NULL != ret_denom_pubs) && (cnt < MELT_NEW_COINS)
- && (NULL != ret_denom_pubs[cnt].rsa_public_key);
+ && (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);