diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange_do_age_withdraw.sql | 34 | ||||
-rw-r--r-- | src/exchangedb/pg_do_age_withdraw.c | 12 | ||||
-rw-r--r-- | src/exchangedb/pg_do_age_withdraw.h | 2 |
3 files changed, 25 insertions, 23 deletions
diff --git a/src/exchangedb/exchange_do_age_withdraw.sql b/src/exchangedb/exchange_do_age_withdraw.sql index d6ae118a..2230d4bf 100644 --- a/src/exchangedb/exchange_do_age_withdraw.sql +++ b/src/exchangedb/exchange_do_age_withdraw.sql @@ -32,6 +32,7 @@ CREATE OR REPLACE FUNCTION exchange_do_age_withdraw( OUT balance_ok BOOLEAN, OUT age_ok BOOLEAN, OUT required_age INT2, -- in years ϵ [0,1..) + OUT reserve_birthday INT4, OUT conflict BOOLEAN) LANGUAGE plpgsql AS $$ @@ -39,7 +40,6 @@ DECLARE reserve_gc INT8; reserve_val INT8; reserve_frac INT4; - reserve_birthday INT4; not_before date; earliest_date date; BEGIN @@ -64,23 +64,20 @@ SELECT IF NOT FOUND THEN - -- reserve unknown reserve_found=FALSE; - balance_ok=FALSE; - age_ok=FALSE; - required_age=0; + age_ok = FALSE; + required_age=-1; conflict=FALSE; + balance_ok=FALSE; RETURN; END IF; +reserve_found = TRUE; +conflict=FALSE; -- not really yet determined -- Check age requirements -IF ((maximum_age_committed = 0) OR (reserve_birthday = 0)) +IF (reserve_birthday <> 0) THEN - -- No commitment to a non-zero age was provided or the reserve is marked as - -- having no age restriction. We can simply pass. - age_ok = OK; -ELSE not_before=date '1970-01-01' + reserve_birthday; earliest_date = current_date - make_interval(maximum_age_committed); -- @@ -95,14 +92,18 @@ ELSE -- IF (earliest_date < not_before) THEN - reserve_found = TRUE; - balance_ok = FALSE; + required_age = extract(year from age(current_date, not_before)); age_ok = FALSE; - required_age = extract(year from age(not_before, current_date)) + 1; + balance_ok=TRUE; -- NOT REALLY RETURN; END IF; END IF; +age_ok = TRUE; +required_age=0; + + + -- Check reserve balance is sufficient. IF (reserve_val > amount_val) THEN @@ -125,6 +126,8 @@ ELSE END IF; END IF; +balance_ok=TRUE; + -- Calculate new expiration dates. min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc); @@ -136,9 +139,6 @@ UPDATE reserves SET WHERE reserves.reserve_pub=rpub; -reserve_found=TRUE; -balance_ok=TRUE; - -- Write the commitment into the age-withdraw table INSERT INTO exchange.age_withdraw (h_commitment @@ -146,7 +146,7 @@ INSERT INTO exchange.age_withdraw ,reserve_pub ,reserve_sig ,noreveal_index - ,denomination_serials + ,denom_serials ,h_blind_evs ,denom_sigs) VALUES diff --git a/src/exchangedb/pg_do_age_withdraw.c b/src/exchangedb/pg_do_age_withdraw.c index 8a93ef8d..c79b2b3d 100644 --- a/src/exchangedb/pg_do_age_withdraw.c +++ b/src/exchangedb/pg_do_age_withdraw.c @@ -38,8 +38,8 @@ TEH_PG_do_age_withdraw ( bool *balance_ok, bool *age_ok, uint16_t *required_age, - bool *conflict, - uint64_t *ruuid) + uint32_t *reserve_birthday, + bool *conflict) { struct PostgresClosure *pg = cls; struct GNUNET_TIME_Timestamp gc; @@ -72,10 +72,10 @@ TEH_PG_do_age_withdraw ( age_ok), GNUNET_PQ_result_spec_uint16 ("required_age", required_age), + GNUNET_PQ_result_spec_uint32 ("reserve_birthday", + reserve_birthday), GNUNET_PQ_result_spec_bool ("conflict", conflict), - GNUNET_PQ_result_spec_uint64 ("ruuid", - ruuid), GNUNET_PQ_result_spec_end }; @@ -93,9 +93,9 @@ TEH_PG_do_age_withdraw ( ",balance_ok" ",age_ok" ",required_age" + ",reserve_birthday" ",conflict" - ",ruuid" - " FROM exchange_do_batch_withdraw" + " FROM exchange_do_age_withdraw" " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "call_age_withdraw", diff --git a/src/exchangedb/pg_do_age_withdraw.h b/src/exchangedb/pg_do_age_withdraw.h index 8f42bfb5..71376022 100644 --- a/src/exchangedb/pg_do_age_withdraw.h +++ b/src/exchangedb/pg_do_age_withdraw.h @@ -36,6 +36,7 @@ * @param[out] balance_ok set to true if the balance was sufficient * @param[out] age_ok set to true if no age requirements are present on the reserve * @param[out] required_age if @e age_ok is false, set to the maximum allowed age when withdrawing from this reserve + * @param[out] reserve_birthday if @e age_ok is false, set to the birthday of the reserve * @param[out] conflict set to true if there already is an entry in the database for the given pair (h_commitment, reserve_pub) * @return query execution status */ @@ -48,6 +49,7 @@ TEH_PG_do_age_withdraw ( bool *balance_ok, bool *age_ok, uint16_t *required_age, + uint32_t *reserve_birthday, bool *conflict); #endif |