diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-03-18 18:55:46 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-03-18 18:55:46 +0100 |
commit | 1f3f4ed8dd292f1aad0b2ca59dc9c669cafb19e4 (patch) | |
tree | 750a704ecb35d02da78999f7a8afb3a7c34b3cd0 /src/mint/mint_db.c | |
parent | 23bf1eee74bed73cf98264c247ab44df8dadfcd9 (diff) | |
parent | e6b13123d78c7da4fdcb2cf0e7eb5fafe1f62975 (diff) | |
download | exchange-1f3f4ed8dd292f1aad0b2ca59dc9c669cafb19e4.tar.xz |
Merge branch 'master' of git+ssh://taler.net/var/git/mint
Diffstat (limited to 'src/mint/mint_db.c')
-rw-r--r-- | src/mint/mint_db.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index 545a5252b..556d32af2 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c @@ -1040,6 +1040,8 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, * * @param db_conn database connection to use * @param h_blind hash of the blinded message + * @param withdraw amount by which the reserve will be withdrawn with this + * transaction * @param collectable corresponding collectable coin (blind signature) * if a coin is found * @return #GNUNET_SYSERR on internal error @@ -1049,9 +1051,11 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, int TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn, const struct GNUNET_HashCode *h_blind, + struct TALER_Amount withdraw, const struct CollectableBlindcoin *collectable) { PGresult *result; + struct Reserve reserve; char *denom_pub_enc = NULL; char *denom_sig_enc = NULL; size_t denom_pub_enc_size; @@ -1073,16 +1077,32 @@ TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn, TALER_DB_QUERY_PARAM_PTR (&collectable->reserve_sig), TALER_DB_QUERY_PARAM_END }; + if (GNUNET_OK != TALER_MINT_DB_transaction (db_conn)) + goto cleanup; result = TALER_DB_exec_prepared (db_conn, "insert_collectable_blindcoin", params); if (PGRES_COMMAND_OK != PQresultStatus (result)) { QUERY_ERR (result); + goto rollback; + } + reserve.pub = (struct GNUNET_CRYPTO_EddsaPublicKey *) + &collectable->reserve_pub; + if (GNUNET_OK != TALER_MINT_DB_reserve_get (db_conn, + &reserve)) + goto rollback; + reserve.balance = TALER_amount_subtract (reserve.balance, withdraw); + if (GNUNET_OK != reserves_update (db_conn, &reserve)) + goto rollback; + if (GNUNET_OK == TALER_MINT_DB_commit (db_conn)) + { + ret = GNUNET_OK; goto cleanup; } - ret = GNUNET_OK; + rollback: + TALER_MINT_DB_rollback(db_conn); cleanup: PQclear (result); GNUNET_free_non_null (denom_pub_enc); |