db: Implement get_collectable_blindcoin

This commit is contained in:
Sree Harsha Totakura 2015-03-07 14:03:01 +01:00
parent 19f05fd20b
commit 6714e6a9cc
3 changed files with 48 additions and 22 deletions

View File

@ -336,7 +336,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
4, NULL);
PREPARE ("get_collectable_blindcoins",
"SELECT "
"blind_ev_sig, denom_pub, reserve_sig, reserve_pub "
"denom_pub, reserve_sig, reserve_pub "
"FROM collectable_blindcoins "
"WHERE blind_ev = $1",
1, NULL);
@ -926,37 +926,35 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
const struct GNUNET_HashCode *h_blind,
struct CollectableBlindcoin *collectable)
{
// FIXME: check logic!
PGresult *result;
struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR (h_blind),
TALER_DB_QUERY_PARAM_END
};
char *sig_buf;
size_t sig_buf_size;
struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
char *denom_pub_enc;
size_t denom_pub_enc_size;
int ret;
ret = GNUNET_SYSERR;
denom_pub = NULL;
denom_pub_enc = NULL;
result = TALER_DB_exec_prepared (db_conn,
"get_collectable_blindcoins",
params);
if (PGRES_TUPLES_OK !=
PQresultStatus (result))
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Query failed: %s\n",
PQresultErrorMessage (result));
PQclear (result);
return GNUNET_SYSERR;
QUERY_ERR (result);
goto cleanup;
}
if (0 == PQntuples (result))
{
PQclear (result);
return GNUNET_NO;
ret = GNUNET_NO;
goto cleanup;
}
struct TALER_DB_ResultSpec rs[] = {
TALER_DB_RESULT_SPEC_VAR("blind_sig", &sig_buf, &sig_buf_size),
TALER_DB_RESULT_SPEC("denom_pub", &collectable->denom_pub),
TALER_DB_RESULT_SPEC_VAR("denom_pub", &denom_pub_enc, &denom_pub_enc_size),
TALER_DB_RESULT_SPEC("reserve_sig", &collectable->reserve_sig),
TALER_DB_RESULT_SPEC("reserve_pub", &collectable->reserve_pub),
TALER_DB_RESULT_SPEC_END
@ -965,11 +963,24 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
if (GNUNET_OK != TALER_DB_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
goto cleanup;
}
denom_pub = GNUNET_CRYPTO_rsa_public_key_decode (denom_pub_enc,
denom_pub_enc_size);
if (NULL == denom_pub)
{
GNUNET_break (0);
goto cleanup;
}
collectable->denom_pub = denom_pub;
ret = GNUNET_YES;
cleanup:
PQclear (result);
return GNUNET_OK;
GNUNET_free_non_null (denom_pub_enc);
if ((GNUNET_YES != ret) && (NULL != denom_pub))
GNUNET_CRYPTO_rsa_public_key_free (denom_pub);
return ret;
}

View File

@ -284,6 +284,7 @@ TALER_MINT_db_execute_withdraw_sign (struct MHD_Connection *connection,
res = TALER_MINT_reply_withdraw_sign_success (connection,
&collectable);
GNUNET_CRYPTO_rsa_signature_free (collectable.sig);
GNUNET_CRYPTO_rsa_public_key_free (collectable.denom_pub);
return res;
}
GNUNET_assert (GNUNET_NO == res);

View File

@ -36,6 +36,9 @@ static int result;
#define RND_BLK(ptr) \
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
#define ZR_BLK(ptr) \
memset (ptr, 0, sizeof (*ptr))
/**
* Checks if the given reserve has the given amount of balance and expiry
@ -115,9 +118,12 @@ run (void *cls, char *const *args, const char *cfgfile,
struct DenomKeyPair *dkp;
struct GNUNET_HashCode *h_blind;
struct CollectableBlindcoin cbc;
struct CollectableBlindcoin cbc2;
db = NULL;
dkp = NULL;
ZR_BLK (&cbc2);
if (GNUNET_OK != TALER_MINT_DB_init ("postgres:///taler"))
{
result = 1;
@ -167,9 +173,15 @@ run (void *cls, char *const *args, const char *cfgfile,
cbc.denom_pub = dkp->pub;
cbc.sig = NULL;
memcpy (&cbc.reserve_pub, &reserve_pub, sizeof (reserve_pub));
TALER_MINT_DB_insert_collectable_blindcoin (db,
&h_blind,
&cbc);
FAILIF (GNUNET_OK!= TALER_MINT_DB_insert_collectable_blindcoin (db,
&h_blind,
&cbc));
FAILIF (GNUNET_YES != TALER_MINT_DB_get_collectable_blindcoin (db,
&h_blind,
&cbc2));
FAILIF (NULL == cbc2.denom_pub);
FAILIF (0 != memcmp (&cbc2.reserve_sig, &cbc.reserve_sig, sizeof (cbc2.reserve_sig)));
FAILIF (0 != memcmp (&cbc2.reserve_pub, &cbc.reserve_pub, sizeof (cbc2.reserve_pub)));
result = 0;
drop:
@ -177,6 +189,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_break (GNUNET_OK == TALER_MINT_DB_drop_temporary (db));
if (NULL != dkp)
destroy_denon_key_pair (dkp);
if (NULL != cbc2.denom_pub)
GNUNET_CRYPTO_rsa_public_key_free (cbc2.denom_pub);
dkp = NULL;
}