diff options
Diffstat (limited to 'src/exchangedb')
20 files changed, 304 insertions, 176 deletions
diff --git a/src/exchangedb/.gitignore b/src/exchangedb/.gitignore index fa833d81f..6e67fadb1 100644 --- a/src/exchangedb/.gitignore +++ b/src/exchangedb/.gitignore @@ -12,4 +12,5 @@ test-exchangedb-batch-reserves-in-insert-postgres test-exchangedb-by-j-postgres test-exchangedb-populate-link-data-postgres test-exchangedb-populate-ready-deposit-postgres -test-exchangedb-populate-select-refunds-by-coin-postgres
\ No newline at end of file +test-exchangedb-populate-select-refunds-by-coin-postgres +exchange-0004.sql diff --git a/src/exchangedb/0003-withdraw_age_commitments.sql b/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 <http://www.gnu.org/licenses/> -- -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 || '_h_commitment_reserve_pub_key' + ' UNIQUE (h_commitment, reserve_pub);' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD CONSTRAINT ' || table_name || '_withdraw_age_commitment_id_key' - ' UNIQUE (withdraw_age_commitment_id);' + ' 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 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 <http://www.gnu.org/licenses/> -- -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/0004-wire_accounts.sql b/src/exchangedb/0004-wire_accounts.sql new file mode 100644 index 000000000..6114c821a --- /dev/null +++ b/src/exchangedb/0004-wire_accounts.sql @@ -0,0 +1,26 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2023 Taler Systems SA +-- +-- TALER is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 3, or (at your option) any later version. +-- +-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- + +ALTER TABLE wire_accounts + ADD COLUMN conversion_url VARCHAR DEFAULT (NULL), + ADD COLUMN debit_restrictions VARCHAR DEFAULT (NULL), + ADD COLUMN credit_restrictions VARCHAR DEFAULT (NULL); +COMMENT ON COLUMN wire_accounts.conversion_url + IS 'URL of a currency conversion service if conversion is needed when this account is used; NULL if there is no conversion.'; +COMMENT ON COLUMN wire_accounts.debit_restrictions + IS 'JSON array describing restrictions imposed when debiting this account. Empty for no restrictions, NULL if account was migrated from previous database revision or account is disabled.'; +COMMENT ON COLUMN wire_accounts.credit_restrictions + IS 'JSON array describing restrictions imposed when crediting this account. Empty for no restrictions, NULL if account was migrated from previous database revision or account is disabled.'; diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index de76997cb..ee78b87f7 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -20,7 +20,9 @@ sqlinputs = \ 0002-*.sql \ exchange-0002.sql.in \ 0003-*.sql \ - exchange-0003.sql.in + exchange-0003.sql.in \ + 0004-*.sql \ + exchange-0004.sql.in sql_DATA = \ benchmark-0001.sql \ @@ -28,6 +30,7 @@ sql_DATA = \ exchange-0001.sql \ exchange-0002.sql \ exchange-0003.sql \ + exchange-0004.sql \ drop.sql \ procedures.sql @@ -39,7 +42,8 @@ BUILT_SOURCES = \ CLEANFILES = \ exchange-0002.sql \ - exchange-0003.sql + exchange-0003.sql \ + exchange-0004.sql procedures.sql: procedures.sql.in exchange_do_*.sql chmod +w $@ || true @@ -56,6 +60,11 @@ exchange-0003.sql: exchange-0003.sql.in 0003-*.sql gcc -E -P -undef - < exchange-0003.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@ chmod ugo-w $@ +exchange-0004.sql: exchange-0004.sql.in 0004-*.sql + chmod +w $@ || true + gcc -E -P -undef - < exchange-0004.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@ + chmod ugo-w $@ + EXTRA_DIST = \ exchangedb.conf \ exchangedb-postgres.conf \ diff --git a/src/exchangedb/bench_db.c b/src/exchangedb/bench_db.c index a85834d13..302d23062 100644 --- a/src/exchangedb/bench_db.c +++ b/src/exchangedb/bench_db.c @@ -169,9 +169,9 @@ bem_insert (struct GNUNET_PQ_Context *conn, GNUNET_CRYPTO_hash (&b, sizeof (b), &hc); - memcpy (&ihc, - &hc, - sizeof (ihc)); + GNUNET_memcpy (&ihc, + &hc, + sizeof (ihc)); { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (&hc), @@ -265,9 +265,9 @@ bem_select (struct GNUNET_PQ_Context *conn, GNUNET_CRYPTO_hash (&b, sizeof (b), &hc); - memcpy (&ihc, - &hc, - sizeof (ihc)); + GNUNET_memcpy (&ihc, + &hc, + sizeof (ihc)); { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint32 (&ihc), diff --git a/src/exchangedb/drop.sql b/src/exchangedb/drop.sql index ecebde6f5..843cda8ec 100644 --- a/src/exchangedb/drop.sql +++ b/src/exchangedb/drop.sql @@ -21,6 +21,7 @@ BEGIN; SELECT _v.unregister_patch('exchange-0001'); SELECT _v.unregister_patch('exchange-0002'); SELECT _v.unregister_patch('exchange-0003'); +SELECT _v.unregister_patch('exchange-0004'); DROP SCHEMA exchange CASCADE; 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/exchange-0004.sql.in b/src/exchangedb/exchange-0004.sql.in new file mode 100644 index 000000000..00979e193 --- /dev/null +++ b/src/exchangedb/exchange-0004.sql.in @@ -0,0 +1,24 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2014--2023 Taler Systems SA +-- +-- TALER is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 3, or (at your option) any later version. +-- +-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- + +BEGIN; + +SELECT _v.register_patch('exchange-0004', NULL, NULL); +SET search_path TO exchange; + +#include "0004-wire_accounts.sql" + +COMMIT; diff --git a/src/exchangedb/pg_aggregate.c b/src/exchangedb/pg_aggregate.c index 6e94cbebb..76d0adec3 100644 --- a/src/exchangedb/pg_aggregate.c +++ b/src/exchangedb/pg_aggregate.c @@ -22,6 +22,7 @@ #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" +#include "pg_event_notify.h" #include "pg_aggregate.h" #include "pg_helper.h" @@ -35,34 +36,12 @@ TEH_PG_aggregate ( { struct PostgresClosure *pg = cls; struct GNUNET_TIME_Absolute now = {0}; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_auto_from_type (h_payto), - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_end - }; uint64_t sum_deposit_value; uint64_t sum_deposit_frac; uint64_t sum_refund_value; uint64_t sum_refund_frac; uint64_t sum_fee_value; uint64_t sum_fee_frac; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("sum_deposit_value", - &sum_deposit_value), - GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction", - &sum_deposit_frac), - GNUNET_PQ_result_spec_uint64 ("sum_refund_value", - &sum_refund_value), - GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction", - &sum_refund_frac), - GNUNET_PQ_result_spec_uint64 ("sum_fee_value", - &sum_fee_value), - GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction", - &sum_fee_frac), - GNUNET_PQ_result_spec_end - }; enum GNUNET_DB_QueryStatus qs; struct TALER_Amount sum_deposit; struct TALER_Amount sum_refund; @@ -71,8 +50,6 @@ TEH_PG_aggregate ( now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (), pg->aggregator_shift); - - /* Used in #postgres_aggregate() */ PREPARE (pg, "aggregate", "WITH dep AS (" /* restrict to our merchant and account and mark as done */ @@ -148,11 +125,35 @@ TEH_PG_aggregate ( " FULL OUTER JOIN ref ON (FALSE)" /* We just want all sums */ " FULL OUTER JOIN fees ON (FALSE);"); + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_auto_from_type (h_payto), + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("sum_deposit_value", + &sum_deposit_value), + GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction", + &sum_deposit_frac), + GNUNET_PQ_result_spec_uint64 ("sum_refund_value", + &sum_refund_value), + GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction", + &sum_refund_frac), + GNUNET_PQ_result_spec_uint64 ("sum_fee_value", + &sum_fee_value), + GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction", + &sum_fee_frac), + GNUNET_PQ_result_spec_end + }; - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "aggregate", - params, - rs); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "aggregate", + params, + rs); + } if (qs < 0) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); @@ -165,6 +166,18 @@ TEH_PG_aggregate ( total)); return qs; } + { + struct TALER_CoinDepositEventP rep = { + .header.size = htons (sizeof (rep)), + .header.type = htons (TALER_DBEVENT_EXCHANGE_DEPOSIT_STATUS_CHANGED), + .merchant_pub = *merchant_pub + }; + + TEH_PG_event_notify (pg, + &rep.header, + NULL, + 0); + } GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (pg->currency, &sum_deposit)); 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_get_wire_accounts.c b/src/exchangedb/pg_get_wire_accounts.c index 43590acf8..23b939046 100644 --- a/src/exchangedb/pg_get_wire_accounts.c +++ b/src/exchangedb/pg_get_wire_accounts.c @@ -66,10 +66,25 @@ get_wire_accounts_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { char *payto_uri; + char *conversion_url = NULL; + json_t *debit_restrictions = NULL; + json_t *credit_restrictions = NULL; struct TALER_MasterSignatureP master_sig; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_string ("payto_uri", &payto_uri), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("conversion_url", + &conversion_url), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("debit_restrictions", + &debit_restrictions), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("credit_restrictions", + &credit_restrictions), + NULL), GNUNET_PQ_result_spec_auto_from_type ("master_sig", &master_sig), GNUNET_PQ_result_spec_end @@ -84,8 +99,21 @@ get_wire_accounts_cb (void *cls, ctx->status = GNUNET_SYSERR; return; } + if (NULL == debit_restrictions) + { + debit_restrictions = json_array (); + GNUNET_assert (NULL != debit_restrictions); + } + if (NULL == credit_restrictions) + { + credit_restrictions = json_array (); + GNUNET_assert (NULL != credit_restrictions); + } ctx->cb (ctx->cb_cls, payto_uri, + conversion_url, + debit_restrictions, + credit_restrictions, &master_sig); GNUNET_PQ_cleanup_result (rs); } @@ -112,6 +140,9 @@ TEH_PG_get_wire_accounts (void *cls, "get_wire_accounts", "SELECT" " payto_uri" + ",conversion_url" + ",debit_restrictions" + ",credit_restrictions" ",master_sig" " FROM wire_accounts" " WHERE is_active"); @@ -123,5 +154,4 @@ TEH_PG_get_wire_accounts (void *cls, if (GNUNET_OK != ctx.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; - } 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..e16a4b74f 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,24 @@ 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), - TALER_PQ_query_param_exchange_withdraw_values ( - &td->details.withdraw_age_revealed_coins.ewv), + &td->details.age_withdraw_revealed_coins.ev_sig), 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 +2154,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 +2312,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_insert_wire.c b/src/exchangedb/pg_insert_wire.c index 75323b6fc..8329a04af 100644 --- a/src/exchangedb/pg_insert_wire.c +++ b/src/exchangedb/pg_insert_wire.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -29,12 +29,20 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_wire (void *cls, const char *payto_uri, + const char *conversion_url, + json_t *debit_restrictions, + json_t *credit_restrictions, struct GNUNET_TIME_Timestamp start_date, const struct TALER_MasterSignatureP *master_sig) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (payto_uri), + NULL == conversion_url + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (conversion_url), + TALER_PQ_query_param_json (debit_restrictions), + TALER_PQ_query_param_json (credit_restrictions), GNUNET_PQ_query_param_auto_from_type (master_sig), GNUNET_PQ_query_param_timestamp (&start_date), GNUNET_PQ_query_param_end @@ -44,11 +52,14 @@ TEH_PG_insert_wire (void *cls, "insert_wire", "INSERT INTO wire_accounts " "(payto_uri" + ",conversion_url" + ",debit_restrictions" + ",credit_restrictions" ",master_sig" ",is_active" ",last_change" ") VALUES " - "($1, $2, true, $3);"); + "($1, $2, $3, $4, $5, true, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_wire", params); diff --git a/src/exchangedb/pg_insert_wire.h b/src/exchangedb/pg_insert_wire.h index 670928d7c..c949327d7 100644 --- a/src/exchangedb/pg_insert_wire.h +++ b/src/exchangedb/pg_insert_wire.h @@ -29,6 +29,9 @@ * * @param cls closure * @param payto_uri wire account of the exchange + * @param conversion_url URL of a conversion service, NULL if there is no conversion + * @param debit_restrictions JSON array with debit restrictions on the account + * @param credit_restrictions JSON array with credit restrictions on the account * @param start_date date when the account was added by the offline system * (only to be used for replay detection) * @param master_sig public signature affirming the existence of the account, @@ -38,6 +41,9 @@ enum GNUNET_DB_QueryStatus TEH_PG_insert_wire (void *cls, const char *payto_uri, + const char *conversion_url, + json_t *debit_restrictions, + json_t *credit_restrictions, struct GNUNET_TIME_Timestamp start_date, const struct TALER_MasterSignatureP *master_sig); diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c index 2e157360f..534e9a1d2 100644 --- a/src/exchangedb/pg_lookup_records_by_table.c +++ b/src/exchangedb/pg_lookup_records_by_table.c @@ -1118,9 +1118,9 @@ lrbt_cb_table_refresh_transfer_keys (void *cls, ctx->error = true; return; } - memcpy (&td.details.refresh_transfer_keys.tprivs[0], - tpriv, - tpriv_size); + GNUNET_memcpy (&td.details.refresh_transfer_keys.tprivs[0], + tpriv, + tpriv_size); ctx->cb (ctx->cb_cls, &td); GNUNET_PQ_cleanup_result (rs); @@ -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/exchangedb/pg_update_wire.c b/src/exchangedb/pg_update_wire.c index 4059348c9..0c4ec7b58 100644 --- a/src/exchangedb/pg_update_wire.c +++ b/src/exchangedb/pg_update_wire.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -29,6 +29,9 @@ enum GNUNET_DB_QueryStatus TEH_PG_update_wire (void *cls, const char *payto_uri, + const char *conversion_url, + json_t *debit_restrictions, + json_t *credit_restrictions, struct GNUNET_TIME_Timestamp change_date, bool enabled) { @@ -36,17 +39,28 @@ TEH_PG_update_wire (void *cls, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (payto_uri), GNUNET_PQ_query_param_bool (enabled), + NULL == conversion_url + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (conversion_url), + enabled + ? TALER_PQ_query_param_json (debit_restrictions) + : GNUNET_PQ_query_param_null (), + enabled + ? TALER_PQ_query_param_json (credit_restrictions) + : GNUNET_PQ_query_param_null (), GNUNET_PQ_query_param_timestamp (&change_date), GNUNET_PQ_query_param_end }; - /* used in #postgres_update_wire() */ PREPARE (pg, "update_wire", "UPDATE wire_accounts" " SET" " is_active=$2" - " ,last_change=$3" + " ,conversion_url=$3" + " ,debit_restrictions=$4" + " ,credit_restrictions=$5" + " ,last_change=$6" " WHERE payto_uri=$1"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "update_wire", diff --git a/src/exchangedb/pg_update_wire.h b/src/exchangedb/pg_update_wire.h index 67038b580..360b8845a 100644 --- a/src/exchangedb/pg_update_wire.h +++ b/src/exchangedb/pg_update_wire.h @@ -24,11 +24,16 @@ #include "taler_util.h" #include "taler_json_lib.h" #include "taler_exchangedb_plugin.h" + + /** * Update information about a wire account of the exchange. * * @param cls closure * @param payto_uri account the update is about + * @param conversion_url URL of a conversion service, NULL if there is no conversion + * @param debit_restrictions JSON array with debit restrictions on the account; NULL allowed if not @a enabled + * @param credit_restrictions JSON array with credit restrictions on the account; NULL allowed if not @a enabled * @param change_date date when the account status was last changed * (only to be used for replay detection) * @param enabled true to enable, false to disable (the actual change) @@ -37,6 +42,9 @@ enum GNUNET_DB_QueryStatus TEH_PG_update_wire (void *cls, const char *payto_uri, + const char *conversion_url, + json_t *debit_restrictions, + json_t *credit_restrictions, struct GNUNET_TIME_Timestamp change_date, bool enabled); |