diff --git a/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c index 5cee7277a..931463cbd 100644 --- a/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c +++ b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c @@ -22,6 +22,8 @@ #include #include #include +#include "taler-exchange-httpd_metrics.h" +#include "taler_exchangedb_plugin.h" #include "taler_mhd_lib.h" #include "taler-exchange-httpd_mhd.h" #include "taler-exchange-httpd_age-withdraw_reveal.h" @@ -387,12 +389,10 @@ denomination_is_valid ( struct TEH_DenominationKey *dks, MHD_RESULT *result) { - dks = TEH_keys_denomination_by_hash2 ( - ksh, - denom_h, - connection, - result); - + dks = TEH_keys_denomination_by_hash2 (ksh, + denom_h, + connection, + result); if (NULL == dks) { /* The denomination doesn't exist */ @@ -784,6 +784,43 @@ verify_commitment_and_max_age ( } +/** + * @brief Send a response for "/age-withdraw/$RCH/reveal" + * + * @param connection The http connection to the client to send the reponse to + * @param num_coins Number of new coins with age restriction for which we reveal data + * @param awrcs array of @a num_coins signatures revealed + * @return a MHD result code + */ +static MHD_RESULT +reply_age_withdraw_reveal_success ( + struct MHD_Connection *connection, + unsigned int num_coins, + const struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin *awrcs) +{ + json_t *list = json_array (); + GNUNET_assert (NULL != list); + + for (unsigned int index = 0; + index < num_coins; + index++) + { + json_t *obj = GNUNET_JSON_PACK ( + TALER_JSON_pack_blinded_denom_sig ("ev_sig", + &awrcs[index].coin_sig)); + GNUNET_assert (0 == + json_array_append_new (list, + obj)); + } + + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("ev_sigs", + list)); +} + + /** * @brief Signs and persists the undisclosed coins * @@ -796,7 +833,7 @@ verify_commitment_and_max_age ( * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ static enum GNUNET_GenericReturnValue -finalize_age_withdraw_and_sign ( +sign_and_finalize_age_withdraw ( struct MHD_Connection *connection, const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, const uint32_t num_coins, @@ -806,7 +843,9 @@ finalize_age_withdraw_and_sign ( { enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR; struct TEH_CoinSignData csds[num_coins]; - struct TALER_BlindedDenominationSignature bss[num_coins]; + struct TALER_BlindedDenominationSignature bds[num_coins]; + struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin awrcs[num_coins]; + enum GNUNET_DB_QueryStatus qs; for (uint32_t i = 0; istart (TEH_plugin->cls, + "insert_age_withdraw_reveal batch")) + { + GNUNET_break (0); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_START_FAILED, + NULL); + goto cleanup; + } + + qs = TEH_plugin->insert_age_withdraw_reveal (TEH_plugin->cls, + h_commitment, + num_coins, + awrcs); + + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + { + TEH_plugin->rollback (TEH_plugin->cls); + continue; + } + else if (GNUNET_DB_STATUS_HARD_ERROR == qs) + { + GNUNET_break (0); + TEH_plugin->rollback (TEH_plugin->cls); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert_age_withdraw_reveal"); + goto cleanup; + } + + changed = (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs); + + /* Commit the transaction */ + qs = TEH_plugin->commit (TEH_plugin->cls); + if (qs >= 0) + { + if (changed) + TEH_METRICS_num_success[TEH_MT_SUCCESS_AGE_WITHDRAW_REVEAL]++; + + break; /* success */ + + } + else if (GNUNET_DB_STATUS_HARD_ERROR == qs) + { + GNUNET_break (0); + TEH_plugin->rollback (TEH_plugin->cls); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_COMMIT_FAILED, + NULL); + goto cleanup; + } + else + { + TEH_plugin->rollback (TEH_plugin->cls); + } + } /* end of retry */ + + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + { + GNUNET_break (0); + TEH_plugin->rollback (TEH_plugin->cls); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SOFT_FAILURE, + NULL); + goto cleanup; + } + + /* Generate final (positive) response */ + ret = reply_age_withdraw_reveal_success (connection, + num_coins, + awrcs); +cleanup: + // TODO[oec]: handle error cases + // TODO[oec]: cleanup! return ret; } @@ -922,7 +1053,7 @@ TEH_handler_age_withdraw_reveal ( break; /* Finally, sign and persist the coins */ - if (GNUNET_OK != finalize_age_withdraw_and_sign ( + if (GNUNET_OK != sign_and_finalize_age_withdraw ( rc->connection, &actx.commitment.h_commitment, actx.num_coins, diff --git a/src/exchange/taler-exchange-httpd_metrics.h b/src/exchange/taler-exchange-httpd_metrics.h index 8f6804355..318113c1f 100644 --- a/src/exchange/taler-exchange-httpd_metrics.h +++ b/src/exchange/taler-exchange-httpd_metrics.h @@ -61,7 +61,8 @@ enum TEH_MetricTypeSuccess TEH_MT_SUCCESS_BATCH_WITHDRAW = 3, TEH_MT_SUCCESS_MELT = 4, TEH_MT_SUCCESS_REFRESH_REVEAL = 5, - TEH_MT_SUCCESS_COUNT = 6 /* MUST BE LAST! */ + TEH_MT_SUCCESS_AGE_WITHDRAW_REVEAL = 6, + TEH_MT_SUCCESS_COUNT = 7 /* MUST BE LAST! */ }; /** diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c index 08a85265c..89bdf2724 100644 --- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c +++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c @@ -773,12 +773,17 @@ clean_age: NULL); goto cleanup; } + for (unsigned int i = 0; inum_fresh_coins; i++) + { rrcs[i].coin_sig = bss[i]; + rrcs[i].blinded_planchet = rcds[i].blinded_planchet; + } } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Signatures ready, starting DB interaction\n"); + for (unsigned int r = 0; rnum_fresh_coins; i++) - { - struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i]; - rrc->blinded_planchet = rcds[i].blinded_planchet; - } qs = TEH_plugin->insert_refresh_reveal ( TEH_plugin->cls, melt_serial_id, diff --git a/src/exchangedb/0003-withdraw_age_commitments.sql b/src/exchangedb/0003-age_withdraw_commitments.sql similarity index 68% rename from src/exchangedb/0003-withdraw_age_commitments.sql rename to src/exchangedb/0003-age_withdraw_commitments.sql index b8451129a..d74a697c3 100644 --- a/src/exchangedb/0003-withdraw_age_commitments.sql +++ b/src/exchangedb/0003-age_withdraw_commitments.sql @@ -14,24 +14,24 @@ -- TALER; see the file COPYING. If not, see -- -CREATE FUNCTION create_table_withdraw_age_commitments( +CREATE FUNCTION create_table_age_withdraw_commitments( IN partition_suffix VARCHAR DEFAULT NULL ) RETURNS VOID LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_commitments'; + table_name VARCHAR DEFAULT 'age_withdraw_commitments'; BEGIN PERFORM create_partitioned_table( 'CREATE TABLE %I' - '(withdraw_age_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY' - ',h_commitment BYTEA PRIMARY KEY CHECK (LENGTH(h_commitment)=64)' + '(age_withdraw_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY' + ',h_commitment BYTEA CHECK (LENGTH(h_commitment)=64)' ',amount_with_fee_val INT8 NOT NULL' ',amount_with_fee_frac INT4 NOT NULL' ',max_age INT2 NOT NULL' - ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' - ',reserve_sig BYTEA CHECK (LENGTH(reserve_sig)=64)' + ',reserve_pub BYTEA CHECK (LENGTH(reserve_pub)=32)' + ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)' ',noreveal_index INT4 NOT NULL' ') %s ;' ,table_name @@ -77,66 +77,58 @@ END $$; -CREATE FUNCTION constrain_table_withdraw_age_commitments( +CREATE FUNCTION constrain_table_age_withdraw_commitments( IN partition_suffix VARCHAR ) RETURNS void LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_commitments'; + table_name VARCHAR DEFAULT 'age_withdraw_commitments'; BEGIN table_name = concat_ws('_', table_name, partition_suffix); - EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD PRIMARY KEY (h_commitment, reserve_pub);' + ' ADD PRIMARY KEY (h_commitment);' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD CONSTRAINT ' || table_name || '_withdraw_age_commitment_id_key' - ' UNIQUE (withdraw_age_commitment_id);' + ' ADD CONSTRAINT ' || table_name || '_h_commitment_reserve_pub_key' + ' UNIQUE (h_commitment, reserve_pub);' + ); + EXECUTE FORMAT ( + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_age_withdraw_commitment_id_key' + ' UNIQUE (age_withdraw_commitment_id);' ); END $$; -CREATE FUNCTION foreign_table_withdraw_age_commitments() +CREATE FUNCTION foreign_table_age_withdraw_commitments() RETURNS void LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_commitments'; + table_name VARCHAR DEFAULT 'age_withdraw_commitments'; BEGIN EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub' ' FOREIGN KEY (reserve_pub)' - ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE;' + ' REFERENCES reserves(reserve_pub) ON DELETE CASCADE;' ); END $$; -INSERT INTO exchange_tables - (name - ,version - ,action - ,partitioned - ,by_range) - VALUES - ('withdraw_age_commitments' - ,'exchange-0003' - ,'create' - ,TRUE - ,FALSE), - ('withdraw_age_commitments' - ,'exchange-0003' - ,'constrain' - ,TRUE - ,FALSE), - ('withdraw_age_commitments' - ,'exchange-0003' - ,'foreign' - ,TRUE - ,FALSE); +INSERT INTO exchange_tables + (name + ,version + ,action + ,partitioned + ,by_range) +VALUES + ('age_withdraw_commitments', 'exchange-0003', 'create', TRUE ,FALSE), + ('age_withdraw_commitments', 'exchange-0003', 'constrain',TRUE ,FALSE), + ('age_withdraw_commitments', 'exchange-0003', 'foreign', TRUE ,FALSE); diff --git a/src/exchangedb/0003-withdraw_age_reveals.sql b/src/exchangedb/0003-age_withdraw_reveals.sql similarity index 79% rename from src/exchangedb/0003-withdraw_age_reveals.sql rename to src/exchangedb/0003-age_withdraw_reveals.sql index af66eab75..1c55fb190 100644 --- a/src/exchangedb/0003-withdraw_age_reveals.sql +++ b/src/exchangedb/0003-age_withdraw_reveals.sql @@ -14,25 +14,24 @@ -- TALER; see the file COPYING. If not, see -- -CREATE FUNCTION create_table_withdraw_age_revealed_coins( +CREATE FUNCTION create_table_age_withdraw_revealed_coins( IN partition_suffix VARCHAR DEFAULT NULL ) RETURNS VOID LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_revealed_coins'; + table_name VARCHAR DEFAULT 'age_withdraw_revealed_coins'; BEGIN PERFORM create_partitioned_table( 'CREATE TABLE %I' - '(withdraw_age_revealed_coins_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE + '(age_withdraw_revealed_coins_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE ',h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=64)' ',freshcoin_index INT4 NOT NULL' ',denominations_serial INT8 NOT NULL' ',coin_ev BYTEA NOT NULL' ',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=64)' ',ev_sig BYTEA NOT NULL' - ',ewv BYTEA NOT NULL' ') %s ;' ,table_name ,'PARTITION BY HASH (h_commitment)' @@ -79,30 +78,24 @@ BEGIN ,table_name ,partition_suffix ); - PERFORM comment_partitioned_column( - 'Exchange contributed values in the creation of the fresh coin (see /csr)' - ,'ewv' - ,table_name - ,partition_suffix - ); END $$; -CREATE FUNCTION constrain_table_withdraw_age_revealed_coins( +CREATE FUNCTION constrain_table_age_withdraw_revealed_coins( IN partition_suffix VARCHAR ) RETURNS void LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_revealed_coins'; + table_name VARCHAR DEFAULT 'age_withdraw_revealed_coins'; BEGIN table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD CONSTRAINT ' || table_name || '_withdraw_age_revealed_coins_id_key' - ' UNIQUE (withdraw_age_revealed_coins_id);' + ' ADD CONSTRAINT ' || table_name || '_age_withdraw_revealed_coins_id_key' + ' UNIQUE (age_withdraw_revealed_coins_id);' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || @@ -112,18 +105,18 @@ BEGIN END $$; -CREATE FUNCTION foreign_table_withdraw_age_revealed_coins() +CREATE FUNCTION foreign_table_age_withdraw_revealed_coins() RETURNS void LANGUAGE plpgsql AS $$ DECLARE - table_name VARCHAR DEFAULT 'withdraw_age_revealed_coins'; + table_name VARCHAR DEFAULT 'age_withdraw_revealed_coins'; BEGIN EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || ' ADD CONSTRAINT ' || table_name || '_foreign_h_commitment' ' FOREIGN KEY (h_commitment)' - ' REFERENCES withdraw_age_commitments (h_commitment) ON DELETE CASCADE;' + ' REFERENCES age_withdraw_commitments (h_commitment) ON DELETE CASCADE;' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || @@ -142,17 +135,17 @@ INSERT INTO exchange_tables ,partitioned ,by_range) VALUES - ('withdraw_age_revealed_coins' + ('age_withdraw_revealed_coins' ,'exchange-0003' ,'create' ,TRUE ,FALSE), - ('withdraw_age_revealed_coins' + ('age_withdraw_revealed_coins' ,'exchange-0003' ,'constrain' ,TRUE ,FALSE), - ('withdraw_age_revealed_coins' + ('age_withdraw_revealed_coins' ,'exchange-0003' ,'foreign' ,TRUE diff --git a/src/exchangedb/exchange-0003.sql.in b/src/exchangedb/exchange-0003.sql.in index 5461c0dd3..01733ea24 100644 --- a/src/exchangedb/exchange-0003.sql.in +++ b/src/exchangedb/exchange-0003.sql.in @@ -25,6 +25,8 @@ SET search_path TO exchange; #include "0003-aml_status.sql" #include "0003-aml_staff.sql" #include "0003-aml_history.sql" +#include "0003-age_withdraw_commitments.sql" +#include "0003-age_withdraw_reveals.sql" COMMIT; diff --git a/src/exchangedb/pg_get_age_withdraw_info.c b/src/exchangedb/pg_get_age_withdraw_info.c index 754b572c9..f4a68b377 100644 --- a/src/exchangedb/pg_get_age_withdraw_info.c +++ b/src/exchangedb/pg_get_age_withdraw_info.c @@ -69,7 +69,7 @@ TEH_PG_get_age_withdraw_info ( ",amount_with_fee_val" ",amount_with_fee_frac" ",noreveal_index" - " FROM withdraw_age_commitments" + " FROM age_withdraw_commitments" " WHERE reserve_pub=$1 and h_commitment=$2;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "get_age_withdraw_info", diff --git a/src/exchangedb/pg_insert_age_withdraw_reveal.c b/src/exchangedb/pg_insert_age_withdraw_reveal.c index 336ed384f..ebba7ebbc 100644 --- a/src/exchangedb/pg_insert_age_withdraw_reveal.c +++ b/src/exchangedb/pg_insert_age_withdraw_reveal.c @@ -42,8 +42,8 @@ TEH_PG_insert_age_withdraw_reveal ( /* TODO */ #if 0 PREPARE (pg, - "insert_withdraw_age_revealed_coin", - "INSERT INTO withdraw_age_reveals " + "insert_age_withdraw_revealed_coin", + "INSERT INTO age_withdraw_reveals " "(h_commitment " ",freshcoin_index " ",denominations_serial " diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c index 3ec9c77cc..e597f2bf5 100644 --- a/src/exchangedb/pg_insert_records_by_table.c +++ b/src/exchangedb/pg_insert_records_by_table.c @@ -2062,39 +2062,39 @@ irbt_cb_table_purse_deletion (struct PostgresClosure *pg, /** - * Function called with withdraw_age_commitments records to insert into table. + * Function called with age_withdraw_commitments records to insert into table. * * @param pg plugin context * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_withdraw_age_commitments (struct PostgresClosure *pg, +irbt_cb_table_age_withdraw_commitments (struct PostgresClosure *pg, const struct TALER_EXCHANGEDB_TableData *td) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw_age_commitments.h_commitment), + &td->details.age_withdraw_commitments.h_commitment), TALER_PQ_query_param_amount ( - &td->details.withdraw_age_commitments.amount_with_fee), + &td->details.age_withdraw_commitments.amount_with_fee), GNUNET_PQ_query_param_uint16 ( - &td->details.withdraw_age_commitments.max_age), + &td->details.age_withdraw_commitments.max_age), GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw_age_commitments.reserve_pub), + &td->details.age_withdraw_commitments.reserve_pub), GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw_age_commitments.reserve_sig), + &td->details.age_withdraw_commitments.reserve_sig), GNUNET_PQ_query_param_uint32 ( - &td->details.withdraw_age_commitments.noreveal_index), + &td->details.age_withdraw_commitments.noreveal_index), GNUNET_PQ_query_param_absolute_time ( - &td->details.withdraw_age_commitments.timestamp), + &td->details.age_withdraw_commitments.timestamp), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_withdraw_age_commitments", - "INSERT INTO withdraw_age_commitments" - "(withdraw_age_commitment_id" + "insert_into_table_age_withdraw_commitments", + "INSERT INTO age_withdraw_commitments" + "(age_withdraw_commitment_id" ",h_commitment" ",amount_with_fee_val" ",amount_with_fee_frac" @@ -2106,19 +2106,19 @@ irbt_cb_table_withdraw_age_commitments (struct PostgresClosure *pg, ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_withdraw_age_commitments", + "insert_into_table_age_withdraw_commitments", params); } /** - * Function called with withdraw_age_revealed_coins records to insert into table. + * Function called with age_withdraw_revealed_coins records to insert into table. * * @param pg plugin context * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_withdraw_age_revealed_coins (struct PostgresClosure *pg, +irbt_cb_table_age_withdraw_revealed_coins (struct PostgresClosure *pg, const struct TALER_EXCHANGEDB_TableData *td) { @@ -2126,26 +2126,26 @@ irbt_cb_table_withdraw_age_revealed_coins (struct PostgresClosure *pg, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw_age_revealed_coins.h_commitment), + &td->details.age_withdraw_revealed_coins.h_commitment), GNUNET_PQ_query_param_uint32 ( - &td->details.withdraw_age_revealed_coins.freshcoin_index), + &td->details.age_withdraw_revealed_coins.freshcoin_index), GNUNET_PQ_query_param_uint64 ( - &td->details.withdraw_age_revealed_coins.denominations_serial), + &td->details.age_withdraw_revealed_coins.denominations_serial), GNUNET_PQ_query_param_fixed_size ( - td->details.withdraw_age_revealed_coins.coin_ev, - td->details.withdraw_age_revealed_coins.coin_ev_size), + td->details.age_withdraw_revealed_coins.coin_ev, + td->details.age_withdraw_revealed_coins.coin_ev_size), GNUNET_PQ_query_param_auto_from_type (&h_coin_ev), TALER_PQ_query_param_blinded_denom_sig ( - &td->details.withdraw_age_revealed_coins.ev_sig), + &td->details.age_withdraw_revealed_coins.ev_sig), TALER_PQ_query_param_exchange_withdraw_values ( - &td->details.withdraw_age_revealed_coins.ewv), + &td->details.age_withdraw_revealed_coins.ewv), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_withdraw_age_revealed_coins", - "INSERT INTO withdraw_age_revealed_coins" - "(withdraw_age_revealed_coins_id" + "insert_into_table_age_withdraw_revealed_coins", + "INSERT INTO age_withdraw_revealed_coins" + "(age_withdraw_revealed_coins_id" ",h_commitment" ",freshcoin_index" ",denominations_serial" @@ -2156,12 +2156,12 @@ irbt_cb_table_withdraw_age_revealed_coins (struct PostgresClosure *pg, ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8);"); - GNUNET_CRYPTO_hash (td->details.withdraw_age_revealed_coins.coin_ev, - td->details.withdraw_age_revealed_coins.coin_ev_size, + GNUNET_CRYPTO_hash (td->details.age_withdraw_revealed_coins.coin_ev, + td->details.age_withdraw_revealed_coins.coin_ev_size, &h_coin_ev); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_withdraw_age_revealed_coins", + "insert_into_table_age_withdraw_revealed_coins", params); } @@ -2314,10 +2314,10 @@ TEH_PG_insert_records_by_table (void *cls, rh = &irbt_cb_table_purse_deletion; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS: - rh = &irbt_cb_table_withdraw_age_commitments; + rh = &irbt_cb_table_age_withdraw_commitments; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALED_COINS: - rh = &irbt_cb_table_withdraw_age_revealed_coins; + rh = &irbt_cb_table_age_withdraw_revealed_coins; break; } if (NULL == rh) diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c index 2e157360f..efa0fec54 100644 --- a/src/exchangedb/pg_lookup_records_by_table.c +++ b/src/exchangedb/pg_lookup_records_by_table.c @@ -2767,14 +2767,14 @@ lrbt_cb_table_purse_deletion (void *cls, /** - * Function called with withdraw_age_commitments table entries. + * Function called with age_withdraw_commitments table entries. * * @param cls closure * @param result the postgres result * @param num_results the number of results in @a result */ static void -lrbt_cb_table_withdraw_age_commitments (void *cls, +lrbt_cb_table_age_withdraw_commitments (void *cls, PGresult *result, unsigned int num_results) { @@ -2788,26 +2788,26 @@ lrbt_cb_table_withdraw_age_commitments (void *cls, { struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( - "withdraw_age_commitment_id", + "age_withdraw_commitment_id", &td.serial), GNUNET_PQ_result_spec_auto_from_type ( "h_commitment", - &td.details.withdraw_age_commitments.h_commitment), + &td.details.age_withdraw_commitments.h_commitment), GNUNET_PQ_result_spec_uint16 ( "max_age", - &td.details.withdraw_age_commitments.max_age), + &td.details.age_withdraw_commitments.max_age), TALER_PQ_RESULT_SPEC_AMOUNT ( "amount_with_fee", - &td.details.withdraw_age_commitments.amount_with_fee), + &td.details.age_withdraw_commitments.amount_with_fee), GNUNET_PQ_result_spec_auto_from_type ( "reserve_pub", - &td.details.withdraw_age_commitments.reserve_pub), + &td.details.age_withdraw_commitments.reserve_pub), GNUNET_PQ_result_spec_auto_from_type ( "reserve_sig", - &td.details.withdraw_age_commitments.reserve_sig), + &td.details.age_withdraw_commitments.reserve_sig), GNUNET_PQ_result_spec_uint32 ( "noreveal_index", - &td.details.withdraw_age_commitments.noreveal_index), + &td.details.age_withdraw_commitments.noreveal_index), GNUNET_PQ_result_spec_end }; @@ -2828,14 +2828,14 @@ lrbt_cb_table_withdraw_age_commitments (void *cls, /** - * Function called with withdraw_age_revealed_coins table entries. + * Function called with age_withdraw_revealed_coins table entries. * * @param cls closure * @param result the postgres result * @param num_results the number of results in @a result */ static void -lrbt_cb_table_withdraw_age_revealed_coins (void *cls, +lrbt_cb_table_age_withdraw_revealed_coins (void *cls, PGresult *result, unsigned int num_results) { @@ -2848,22 +2848,22 @@ lrbt_cb_table_withdraw_age_revealed_coins (void *cls, { struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( - "withdraw_age_revealed_coins_id", + "age_withdraw_revealed_coins_id", &td.serial), GNUNET_PQ_result_spec_auto_from_type ( "h_commitment", - &td.details.withdraw_age_revealed_coins.h_commitment), + &td.details.age_withdraw_revealed_coins.h_commitment), GNUNET_PQ_result_spec_uint32 ( "freshcoin_index", - &td.details.withdraw_age_revealed_coins.freshcoin_index), + &td.details.age_withdraw_revealed_coins.freshcoin_index), GNUNET_PQ_result_spec_uint64 ( "denominations_serial", - &td.details.withdraw_age_revealed_coins.denominations_serial), + &td.details.age_withdraw_revealed_coins.denominations_serial), /* Note: h_coin_ev is recalculated */ GNUNET_PQ_result_spec_variable_size ( "coin_ev", - (void **) &td.details.withdraw_age_revealed_coins.coin_ev, - &td.details.withdraw_age_revealed_coins.coin_ev_size), + (void **) &td.details.age_withdraw_revealed_coins.coin_ev, + &td.details.age_withdraw_revealed_coins.coin_ev_size), TALER_PQ_result_spec_blinded_denom_sig ( "ev_sig", &td.details.refresh_revealed_coins.ev_sig), @@ -3598,9 +3598,9 @@ TEH_PG_lookup_records_by_table (void *cls, rh = &lrbt_cb_table_purse_deletion; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS: - XPREPARE ("select_above_serial_by_table_withdraw_age_commitments", + XPREPARE ("select_above_serial_by_table_age_withdraw_commitments", "SELECT" - " withdraw_age_commitment_id" + " age_withdraw_commitment_id" ",h_commitment" ",amount_with_fee_val" ",amount_with_fee_frac" @@ -3608,15 +3608,15 @@ TEH_PG_lookup_records_by_table (void *cls, ",reserve_pub" ",reserve_sig" ",noreveal_index" - " FROM withdraw_age_commitments" - " WHERE withdraw_age_commitment_id > $1" - " ORDER BY withdraw_age_commitment_id ASC;"); - rh = &lrbt_cb_table_withdraw_age_commitments; + " FROM age_withdraw_commitments" + " WHERE age_withdraw_commitment_id > $1" + " ORDER BY age_withdraw_commitment_id ASC;"); + rh = &lrbt_cb_table_age_withdraw_commitments; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALED_COINS: - XPREPARE ("select_above_serial_by_table_withdraw_age_revealed_coins", + XPREPARE ("select_above_serial_by_table_age_withdraw_revealed_coins", "SELECT" - " withdraw_age_revealed_coins_serial_id" + " age_withdraw_revealed_coins_serial_id" ",h_commitment" ",freshcoin_index" ",denominations_serial" @@ -3624,10 +3624,10 @@ TEH_PG_lookup_records_by_table (void *cls, ",h_coin_ev" ",ev_sig" ",ewv" - " FROM withdraw_age_revealed_coins" - " WHERE withdraw_age_revealed_coins_serial_id > $1" - " ORDER BY withdraw_age_revealed_coins_serial_id ASC;"); - rh = &lrbt_cb_table_withdraw_age_revealed_coins; + " FROM age_withdraw_revealed_coins" + " WHERE age_withdraw_revealed_coins_serial_id > $1" + " ORDER BY age_withdraw_revealed_coins_serial_id ASC;"); + rh = &lrbt_cb_table_age_withdraw_revealed_coins; break; } if (NULL == rh) diff --git a/src/exchangedb/pg_lookup_serial_by_table.c b/src/exchangedb/pg_lookup_serial_by_table.c index c98b4539e..2e3b41304 100644 --- a/src/exchangedb/pg_lookup_serial_by_table.c +++ b/src/exchangedb/pg_lookup_serial_by_table.c @@ -427,22 +427,22 @@ TEH_PG_lookup_serial_by_table (void *cls, statement = "select_serial_by_table_purse_deletion"; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS: - XPREPARE ("select_serial_by_table_withdraw_age_commitments", + XPREPARE ("select_serial_by_table_age_withdraw_commitments", "SELECT" - " withdraw_age_commitment_id AS serial" - " FROM withdraw_age_commitments" - " ORDER BY withdraw_age_commitment_id DESC" + " age_withdraw_commitment_id AS serial" + " FROM age_withdraw_commitments" + " ORDER BY age_withdraw_commitment_id DESC" " LIMIT 1;"); - statement = "select_serial_by_table_withdraw_age_commitments"; + statement = "select_serial_by_table_age_withdraw_commitments"; break; case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALED_COINS: - XPREPARE ("select_serial_by_table_withdraw_age_revealed_coins", + XPREPARE ("select_serial_by_table_age_withdraw_revealed_coins", "SELECT" - " withdraw_age_revealed_coins_id AS serial" - " FROM withdraw_age_revealed_coins" - " ORDER BY withdraw_age_revealed_coins_id DESC" + " age_withdraw_revealed_coins_id AS serial" + " FROM age_withdraw_revealed_coins" + " ORDER BY age_withdraw_revealed_coins_id DESC" " LIMIT 1;"); - statement = "select_serial_by_table_withdraw_age_revealed_coins"; + statement = "select_serial_by_table_age_withdraw_revealed_coins"; break; } if (NULL == statement) diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 43f6b73e8..e4c9a28be 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -760,7 +760,7 @@ struct TALER_EXCHANGEDB_TableData struct TALER_ReserveSignatureP reserve_sig; uint32_t noreveal_index; struct GNUNET_TIME_Absolute timestamp; - } withdraw_age_commitments; + } age_withdraw_commitments; struct { @@ -772,7 +772,7 @@ struct TALER_EXCHANGEDB_TableData struct TALER_ExchangeWithdrawValues ewv; // h_coin_ev omitted, to be recomputed! struct TALER_BlindedDenominationSignature ev_sig; - } withdraw_age_revealed_coins; + } age_withdraw_revealed_coins; } details; @@ -1200,8 +1200,9 @@ struct TALER_EXCHANGEDB_AgeWithdrawCommitment struct TALER_ReservePublicKeyP reserve_pub; /** - * Signature confirming the age withdrawal, matching @e reserve_pub, @e - * maximum_age_group and @e h_commitment and @e total_amount_with_fee. + * Signature confirming the age withdrawal commitment, matching @e + * reserve_pub, @e maximum_age_group and @e h_commitment and @e + * total_amount_with_fee. */ struct TALER_ReserveSignatureP reserve_sig; @@ -2737,6 +2738,28 @@ struct TALER_EXCHANGEDB_CsRevealFreshCoinData uint32_t coin_off; }; +/** + * Information about a coin that was revealed to the exchange + * during reveal. + */ +struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin +{ + /** + * Hash of the public denomination key of the coin. + */ + struct TALER_DenominationHashP h_denom_pub; + + /** + * Signature generated by the exchange over the coin (in blinded format). + */ + struct TALER_BlindedDenominationSignature coin_sig; + + /** + * Blinded hash of the new coin + */ + struct TALER_BlindedCoinHashP h_coin_ev; +}; + /** * Generic KYC status for some operation. @@ -3810,19 +3833,18 @@ struct TALER_EXCHANGEDB_Plugin * age restriction enabled in a given age-withdraw operation and the relevant * information we learned or created in the reveal steop * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param h_commitment The hash of the original age-withdraw commitment, which is a key into the withdraw_age_commitments table - * @param num_coins number of coins to generate, size of the @a coin_evs array - * TODO: oec + * @param cls The `struct PostgresClosure` with the plugin-specific state + * @param h_commitment The hash of the original age-withdraw commitment, which is a key into the age_withdraw_commitments table + * @param num_awrcs Number of coins to generate, size of the @a coin_evs array + * @param awrcs Array of @a num_awrcs information about coins to be created * @return query execution status */ enum GNUNET_DB_QueryStatus (*insert_age_withdraw_reveal)( void *cls, - uint64_t h_commitment, - uint32_t num_coins - /* TODO: oec */ - ); + const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, + uint32_t num_awrcs, + const struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin *awrcs); /** * Lookup in the database for the fresh coins with age-restriction that