summaryrefslogtreecommitdiff
path: root/src/exchangedb/pg_ensure_coin_known.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/pg_ensure_coin_known.c')
-rw-r--r--src/exchangedb/pg_ensure_coin_known.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/exchangedb/pg_ensure_coin_known.c b/src/exchangedb/pg_ensure_coin_known.c
index 7ad37bf1d..307b8df52 100644
--- a/src/exchangedb/pg_ensure_coin_known.c
+++ b/src/exchangedb/pg_ensure_coin_known.c
@@ -21,6 +21,7 @@
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
#include "taler_pq_lib.h"
#include "pg_ensure_coin_known.h"
#include "pg_helper.h"
@@ -28,10 +29,10 @@
enum TALER_EXCHANGEDB_CoinKnownStatus
TEH_PG_ensure_coin_known (void *cls,
- const struct TALER_CoinPublicInfo *coin,
- uint64_t *known_coin_id,
- struct TALER_DenominationHashP *denom_hash,
- struct TALER_AgeCommitmentHash *h_age_commitment)
+ const struct TALER_CoinPublicInfo *coin,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash,
+ struct TALER_AgeCommitmentHash *h_age_commitment)
{
struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs;
@@ -41,7 +42,9 @@ TEH_PG_ensure_coin_known (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
GNUNET_PQ_query_param_auto_from_type (&coin->denom_pub_hash),
- GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
+ coin->no_age_commitment
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
TALER_PQ_query_param_denom_sig (&coin->denom_sig),
GNUNET_PQ_query_param_end
};
@@ -60,9 +63,8 @@ TEH_PG_ensure_coin_known (void *cls,
&is_age_hash_null),
GNUNET_PQ_result_spec_end
};
- /* Used in #postgres_insert_known_coin() to store the denomination public
- key and signature for a coin known to the exchange.
+ /*
See also:
https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
*/
@@ -70,13 +72,11 @@ TEH_PG_ensure_coin_known (void *cls,
"insert_known_coin",
"WITH dd"
" (denominations_serial"
- " ,coin_val"
- " ,coin_frac"
+ " ,coin"
" ) AS ("
" SELECT "
" denominations_serial"
- " ,coin_val"
- " ,coin_frac"
+ " ,coin"
" FROM denominations"
" WHERE denom_pub_hash=$2"
" ), input_rows"
@@ -88,15 +88,13 @@ TEH_PG_ensure_coin_known (void *cls,
" ,denominations_serial"
" ,age_commitment_hash"
" ,denom_sig"
- " ,remaining_val"
- " ,remaining_frac"
+ " ,remaining"
" ) SELECT "
" $1"
" ,denominations_serial"
" ,$3"
" ,$4"
- " ,coin_val"
- " ,coin_frac"
+ " ,coin"
" FROM dd"
" ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
" RETURNING "
@@ -146,13 +144,25 @@ TEH_PG_ensure_coin_known (void *cls,
return TALER_EXCHANGEDB_CKS_DENOM_CONFLICT;
}
- if ( (! is_age_hash_null) &&
- (0 != GNUNET_memcmp (h_age_commitment,
- &coin->h_age_commitment)) )
+ if (is_age_hash_null != coin->no_age_commitment)
+ {
+ if (is_age_hash_null)
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL;
+ }
+ }
+ else if ( (! is_age_hash_null) &&
+ (0 != GNUNET_memcmp (h_age_commitment,
+ &coin->h_age_commitment)) )
{
- GNUNET_break (GNUNET_is_zero (h_age_commitment));
GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_AGE_CONFLICT;
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS;
}
return TALER_EXCHANGEDB_CKS_PRESENT;