From 4bf425c902c2047e766e0333e54188ee67a673f5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 17 Aug 2019 21:35:21 +0200 Subject: [PATCH] remove currency field from databases --- src/auditordb/plugin_auditordb_postgres.c | 1468 ++++++++-------- src/auditordb/test-auditor-db-postgres.conf | 3 + src/auditordb/test_auditordb.c | 2 +- src/exchange-tools/taler-exchange-wire.c | 6 +- src/exchange/taler-exchange-httpd.c | 3 + .../taler-exchange-httpd_validation.c | 5 +- src/exchangedb/plugin_exchangedb_postgres.c | 1564 ++++++++--------- src/exchangedb/test-exchange-db-postgres.conf | 2 + src/exchangedb/test_exchangedb.c | 77 +- src/include/taler_exchangedb_plugin.h | 156 -- src/include/taler_pq_lib.h | 8 +- src/include/taler_util.h | 3 +- src/json/json_wire.c | 1 - src/pq/pq_query_helper.c | 76 +- src/pq/pq_result_helper.c | 229 ++- src/pq/test_pq.c | 44 +- src/util/util.c | 4 +- 17 files changed, 1608 insertions(+), 2043 deletions(-) diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 67a8d7a88..face423dc 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -30,6 +30,25 @@ #define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", __VA_ARGS__) +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. + * + * @param field name of the database field to fetch amount from + * @param amountp[out] pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount(field,pg->currency,amountp) + +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. NBO variant. + * + * @param field name of the database field to fetch amount from + * @param amountp[out] pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field,amountp) TALER_PQ_result_spec_amount_nbo(field,pg->currency,amountp) + + /** * Handle for a database session (per-thread, for transactions). */ @@ -60,6 +79,11 @@ struct PostgresClosure * the configuration. */ char *connection_cfg_str; + + /** + * Which currency should we assume all amounts to be in? + */ + char *currency; }; @@ -196,43 +220,38 @@ postgres_create_tables (void *cls) struct GNUNET_PQ_ExecuteStatement es[] = { /* Table with list of exchanges we are auditing */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_exchanges" - "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)" - ",exchange_url VARCHAR NOT NULL" - ")"), + "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)" + ",exchange_url VARCHAR NOT NULL" + ")"), /* Table with list of signing keys of exchanges we are auditing */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_exchange_signkeys" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",ep_start INT8 NOT NULL" - ",ep_expire INT8 NOT NULL" - ",ep_end INT8 NOT NULL" - ",exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)" - ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)" + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",ep_start INT8 NOT NULL" + ",ep_expire INT8 NOT NULL" + ",ep_end INT8 NOT NULL" + ",exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)" + ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)" ")"), /* Table with all of the denomination keys that the auditor is aware of. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denominations" - "(denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)" - ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",valid_from INT8 NOT NULL" - ",expire_withdraw INT8 NOT NULL" - ",expire_deposit INT8 NOT NULL" - ",expire_legal INT8 NOT NULL" - ",coin_val INT8 NOT NULL" /* value of this denom */ - ",coin_frac INT4 NOT NULL" /* fractional value of this denom */ - ",coin_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" /* assuming same currency for fees */ - ",fee_withdraw_val INT8 NOT NULL" - ",fee_withdraw_frac INT4 NOT NULL" - ",fee_withdraw_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",fee_deposit_val INT8 NOT NULL" - ",fee_deposit_frac INT4 NOT NULL" - ",fee_deposit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",fee_refresh_val INT8 NOT NULL" - ",fee_refresh_frac INT4 NOT NULL" - ",fee_refresh_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",fee_refund_val INT8 NOT NULL" - ",fee_refund_frac INT4 NOT NULL" - ",fee_refund_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)" + ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",valid_from INT8 NOT NULL" + ",expire_withdraw INT8 NOT NULL" + ",expire_deposit INT8 NOT NULL" + ",expire_legal INT8 NOT NULL" + ",coin_val INT8 NOT NULL" /* value of this denom */ + ",coin_frac INT4 NOT NULL" /* fractional value of this denom */ + ",fee_withdraw_val INT8 NOT NULL" + ",fee_withdraw_frac INT4 NOT NULL" + ",fee_deposit_val INT8 NOT NULL" + ",fee_deposit_frac INT4 NOT NULL" + ",fee_refresh_val INT8 NOT NULL" + ",fee_refresh_frac INT4 NOT NULL" + ",fee_refund_val INT8 NOT NULL" + ",fee_refund_frac INT4 NOT NULL" + ")"), /* Table indicating up to which transactions the auditor has processed the exchange database. Used for SELECTing the statements to process. The indices below include the last @@ -241,38 +260,38 @@ postgres_create_tables (void *cls) strictly larger (and process in monotonically increasing order). */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress_reserve" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0" - ",last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0" - ",last_reserve_payback_serial_id INT8 NOT NULL DEFAULT 0" - ",last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0" + ",last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0" + ",last_reserve_payback_serial_id INT8 NOT NULL DEFAULT 0" + ",last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0" + ")"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress_aggregation" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",last_wire_out_serial_id INT8 NOT NULL DEFAULT 0" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",last_wire_out_serial_id INT8 NOT NULL DEFAULT 0" + ")"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress_deposit_confirmation" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",last_deposit_confirmation_serial_id INT8 NOT NULL DEFAULT 0" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",last_deposit_confirmation_serial_id INT8 NOT NULL DEFAULT 0" + ")"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress_coin" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",last_withdraw_serial_id INT8 NOT NULL DEFAULT 0" - ",last_deposit_serial_id INT8 NOT NULL DEFAULT 0" - ",last_melt_serial_id INT8 NOT NULL DEFAULT 0" - ",last_refund_serial_id INT8 NOT NULL DEFAULT 0" - ",last_payback_serial_id INT8 NOT NULL DEFAULT 0" - ",last_payback_refresh_serial_id INT8 NOT NULL DEFAULT 0" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",last_withdraw_serial_id INT8 NOT NULL DEFAULT 0" + ",last_deposit_serial_id INT8 NOT NULL DEFAULT 0" + ",last_melt_serial_id INT8 NOT NULL DEFAULT 0" + ",last_refund_serial_id INT8 NOT NULL DEFAULT 0" + ",last_payback_serial_id INT8 NOT NULL DEFAULT 0" + ",last_payback_refresh_serial_id INT8 NOT NULL DEFAULT 0" + ")"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_auditor_progress" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",account_name TEXT NOT NULL" - ",last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0" - ",last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0" - ",last_timestamp INT8 NOT NULL" - ",wire_in_off BYTEA" - ",wire_out_off BYTEA" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",account_name TEXT NOT NULL" + ",last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0" + ",last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0" + ",last_timestamp INT8 NOT NULL" + ",wire_in_off BYTEA" + ",wire_out_off BYTEA" + ")"), /* Table with all of the customer reserves and their respective balances that the auditor is aware of. "last_reserve_out_serial_id" marks the last withdrawal from @@ -280,38 +299,33 @@ postgres_create_tables (void *cls) and "last_reserve_in_serial_id" is the last "reserve_in" operation about this reserve that the auditor is aware of. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_reserves" - "(reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)" - ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",reserve_balance_val INT8 NOT NULL" - ",reserve_balance_frac INT4 NOT NULL" - ",reserve_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",withdraw_fee_balance_val INT8 NOT NULL" - ",withdraw_fee_balance_frac INT4 NOT NULL" - ",withdraw_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",expiration_date INT8 NOT NULL" - ",auditor_reserves_rowid BIGSERIAL UNIQUE" - ")"), + "(reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)" + ",master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",reserve_balance_val INT8 NOT NULL" + ",reserve_balance_frac INT4 NOT NULL" + ",withdraw_fee_balance_val INT8 NOT NULL" + ",withdraw_fee_balance_frac INT4 NOT NULL" + ",expiration_date INT8 NOT NULL" + ",auditor_reserves_rowid BIGSERIAL UNIQUE" + ")"), GNUNET_PQ_make_try_execute ("CREATE INDEX auditor_reserves_by_reserve_pub " - "ON auditor_reserves(reserve_pub)"), + "ON auditor_reserves(reserve_pub)"), /* Table with the sum of the balances of all customer reserves (by exchange's master public key) */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_reserve_balance" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",reserve_balance_val INT8 NOT NULL" - ",reserve_balance_frac INT4 NOT NULL" - ",reserve_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",withdraw_fee_balance_val INT8 NOT NULL" - ",withdraw_fee_balance_frac INT4 NOT NULL" - ",withdraw_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",reserve_balance_val INT8 NOT NULL" + ",reserve_balance_frac INT4 NOT NULL" + ",withdraw_fee_balance_val INT8 NOT NULL" + ",withdraw_fee_balance_frac INT4 NOT NULL" + ")"), /* Table with the sum of the balances of all wire fees (by exchange's master public key) */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",wire_fee_balance_val INT8 NOT NULL" - ",wire_fee_balance_frac INT4 NOT NULL" - ",wire_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",wire_fee_balance_val INT8 NOT NULL" + ",wire_fee_balance_frac INT4 NOT NULL" + ")"), /* Table with all of the outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the @@ -319,19 +333,16 @@ postgres_create_tables (void *cls) issued (withdraw, refresh-reveal) and the number of coins seen at the exchange (refresh-commit, deposit), not just the amounts. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denomination_pending" - "(denom_pub_hash BYTEA PRIMARY KEY" - " REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE" - ",denom_balance_val INT8 NOT NULL" - ",denom_balance_frac INT4 NOT NULL" - ",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",num_issued INT8 NOT NULL" - ",denom_risk_val INT8 NOT NULL" - ",denom_risk_frac INT4 NOT NULL" - ",denom_risk_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",payback_loss_val INT8 NOT NULL" - ",payback_loss_frac INT4 NOT NULL" - ",payback_loss_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(denom_pub_hash BYTEA PRIMARY KEY" + " REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE" + ",denom_balance_val INT8 NOT NULL" + ",denom_balance_frac INT4 NOT NULL" + ",num_issued INT8 NOT NULL" + ",denom_risk_val INT8 NOT NULL" + ",denom_risk_frac INT4 NOT NULL" + ",payback_loss_val INT8 NOT NULL" + ",payback_loss_frac INT4 NOT NULL" + ")"), /* Table with the sum of the outstanding coins from "auditor_denomination_pending" (denom_pubs must belong to the respective's exchange's master public key); it represents the @@ -339,26 +350,20 @@ postgres_create_tables (void *cls) unexpected historic_loss-style events where denomination keys are compromised) */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_balance_summary" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",denom_balance_val INT8 NOT NULL" - ",denom_balance_frac INT4 NOT NULL" - ",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",deposit_fee_balance_val INT8 NOT NULL" - ",deposit_fee_balance_frac INT4 NOT NULL" - ",deposit_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",melt_fee_balance_val INT8 NOT NULL" - ",melt_fee_balance_frac INT4 NOT NULL" - ",melt_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",refund_fee_balance_val INT8 NOT NULL" - ",refund_fee_balance_frac INT4 NOT NULL" - ",refund_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",risk_val INT8 NOT NULL" - ",risk_frac INT4 NOT NULL" - ",risk_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",loss_val INT8 NOT NULL" - ",loss_frac INT4 NOT NULL" - ",loss_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",denom_balance_val INT8 NOT NULL" + ",denom_balance_frac INT4 NOT NULL" + ",deposit_fee_balance_val INT8 NOT NULL" + ",deposit_fee_balance_frac INT4 NOT NULL" + ",melt_fee_balance_val INT8 NOT NULL" + ",melt_fee_balance_frac INT4 NOT NULL" + ",refund_fee_balance_val INT8 NOT NULL" + ",refund_fee_balance_frac INT4 NOT NULL" + ",risk_val INT8 NOT NULL" + ",risk_frac INT4 NOT NULL" + ",loss_val INT8 NOT NULL" + ",loss_frac INT4 NOT NULL" + ")"), /* Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the "denom_pub" here @@ -369,50 +374,46 @@ postgres_create_tables (void *cls) individually; the delta to the revenue_balance is from coins that were withdrawn but never deposited prior to expiration. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_historic_denomination_revenue" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)" - ",revenue_timestamp INT8 NOT NULL" - ",revenue_balance_val INT8 NOT NULL" - ",revenue_balance_frac INT4 NOT NULL" - ",revenue_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",loss_balance_val INT8 NOT NULL" - ",loss_balance_frac INT4 NOT NULL" - ",loss_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)" + ",revenue_timestamp INT8 NOT NULL" + ",revenue_balance_val INT8 NOT NULL" + ",revenue_balance_frac INT4 NOT NULL" + ",loss_balance_val INT8 NOT NULL" + ",loss_balance_frac INT4 NOT NULL" + ")"), /* Table with historic profits from reserves; we eventually GC "auditor_historic_reserve_revenue", and then store the totals in here (by time intervals). */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",start_date INT8 NOT NULL" - ",end_date INT8 NOT NULL" - ",reserve_profits_val INT8 NOT NULL" - ",reserve_profits_frac INT4 NOT NULL" - ",reserve_profits_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",start_date INT8 NOT NULL" + ",end_date INT8 NOT NULL" + ",reserve_profits_val INT8 NOT NULL" + ",reserve_profits_frac INT4 NOT NULL" + ")"), GNUNET_PQ_make_try_execute ("CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date " - "ON auditor_historic_reserve_summary(master_pub,start_date)"), + "ON auditor_historic_reserve_summary(master_pub,start_date)"), /* Table with deposit confirmation sent to us by merchants; we must check that the exchange reported these properly. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS deposit_confirmations " - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",serial_id BIGSERIAL UNIQUE" - ",h_contract_terms BYTEA CHECK (LENGTH(h_contract_terms)=64)" - ",h_wire BYTEA CHECK (LENGTH(h_wire)=64)" - ",timestamp INT8 NOT NULL" - ",refund_deadline INT8 NOT NULL" - ",amount_without_fee_val INT8 NOT NULL" - ",amount_without_fee_frac INT4 NOT NULL" - ",amount_without_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)" - ",merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)" - ",exchange_sig BYTEA CHECK (LENGTH(exchange_sig)=64)" - ",exchange_pub BYTEA CHECK (LENGTH(exchange_pub)=32)" - ",master_sig BYTEA CHECK (LENGTH(master_sig)=64)" - ",PRIMARY KEY (h_contract_terms, h_wire, coin_pub, " - " merchant_pub, exchange_sig, exchange_pub, master_sig)" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",serial_id BIGSERIAL UNIQUE" + ",h_contract_terms BYTEA CHECK (LENGTH(h_contract_terms)=64)" + ",h_wire BYTEA CHECK (LENGTH(h_wire)=64)" + ",timestamp INT8 NOT NULL" + ",refund_deadline INT8 NOT NULL" + ",amount_without_fee_val INT8 NOT NULL" + ",amount_without_fee_frac INT4 NOT NULL" + ",coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)" + ",merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)" + ",exchange_sig BYTEA CHECK (LENGTH(exchange_sig)=64)" + ",exchange_pub BYTEA CHECK (LENGTH(exchange_pub)=32)" + ",master_sig BYTEA CHECK (LENGTH(master_sig)=64)" + ",PRIMARY KEY (h_contract_terms, h_wire, coin_pub, " + " merchant_pub, exchange_sig, exchange_pub, master_sig)" + ")"), /* Table with historic business ledger; basically, when the exchange operator decides to use operating costs for anything but wire transfers to merchants, it goes in here. This happens when the @@ -426,25 +427,23 @@ postgres_create_tables (void *cls) (So this table for now just exists as a reminder of what we'll need in the long term.) */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_historic_ledger" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",purpose VARCHAR NOT NULL" - ",timestamp INT8 NOT NULL" - ",balance_val INT8 NOT NULL" - ",balance_frac INT4 NOT NULL" - ",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",purpose VARCHAR NOT NULL" + ",timestamp INT8 NOT NULL" + ",balance_val INT8 NOT NULL" + ",balance_frac INT4 NOT NULL" + ")"), GNUNET_PQ_make_try_execute ("CREATE INDEX history_ledger_by_master_pub_and_time " - "ON auditor_historic_ledger(master_pub,timestamp)"), + "ON auditor_historic_ledger(master_pub,timestamp)"), /* Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance. This is the final amount that the exchange should have in its bank account right now. */ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_predicted_result" - "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" - ",balance_val INT8 NOT NULL" - ",balance_frac INT4 NOT NULL" - ",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"), + "(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE" + ",balance_val INT8 NOT NULL" + ",balance_frac INT4 NOT NULL" + ")"), GNUNET_PQ_EXECUTE_STATEMENT_END }; PGconn *conn; @@ -507,533 +506,470 @@ postgres_prepare (PGconn *db_conn) 6), /* Used in #postgres_insert_denomination_info() */ GNUNET_PQ_make_prepare ("auditor_denominations_insert", - "INSERT INTO auditor_denominations " - "(denom_pub_hash" - ",master_pub" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin_val" - ",coin_frac" - ",coin_curr" - ",fee_withdraw_val" - ",fee_withdraw_frac" - ",fee_withdraw_curr" - ",fee_deposit_val" - ",fee_deposit_frac" - ",fee_deposit_curr" - ",fee_refresh_val" - ",fee_refresh_frac" - ",fee_refresh_curr" - ",fee_refund_val" - ",fee_refund_frac" - ",fee_refund_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21);", - 21), + "INSERT INTO auditor_denominations " + "(denom_pub_hash" + ",master_pub" + ",valid_from" + ",expire_withdraw" + ",expire_deposit" + ",expire_legal" + ",coin_val" + ",coin_frac" + ",fee_withdraw_val" + ",fee_withdraw_frac" + ",fee_deposit_val" + ",fee_deposit_frac" + ",fee_refresh_val" + ",fee_refresh_frac" + ",fee_refund_val" + ",fee_refund_frac" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);", + 16), /* Used in #postgres_insert_denomination_info() */ GNUNET_PQ_make_prepare ("auditor_denominations_select", - "SELECT" - " denom_pub_hash" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin_val" - ",coin_frac" - ",coin_curr" - ",fee_withdraw_val" - ",fee_withdraw_frac" - ",fee_withdraw_curr" - ",fee_deposit_val" - ",fee_deposit_frac" - ",fee_deposit_curr" - ",fee_refresh_val" - ",fee_refresh_frac" - ",fee_refresh_curr" - ",fee_refund_val" - ",fee_refund_frac" - ",fee_refund_curr" - " FROM auditor_denominations" - " WHERE master_pub=$1;", - 1), + "SELECT" + " denom_pub_hash" + ",valid_from" + ",expire_withdraw" + ",expire_deposit" + ",expire_legal" + ",coin_val" + ",coin_frac" + ",fee_withdraw_val" + ",fee_withdraw_frac" + ",fee_deposit_val" + ",fee_deposit_frac" + ",fee_refresh_val" + ",fee_refresh_frac" + ",fee_refund_val" + ",fee_refund_frac" + " FROM auditor_denominations" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_deposit_confirmation() */ GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_insert", - "INSERT INTO deposit_confirmations " - "(master_pub" - ",h_contract_terms" - ",h_wire" - ",timestamp" - ",refund_deadline" - ",amount_without_fee_val" - ",amount_without_fee_frac" - ",amount_without_fee_curr" - ",coin_pub" - ",merchant_pub" - ",exchange_sig" - ",exchange_pub" - ",master_sig" /* master_sig could be normalized... */ - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);", - 13), + "INSERT INTO deposit_confirmations " + "(master_pub" + ",h_contract_terms" + ",h_wire" + ",timestamp" + ",refund_deadline" + ",amount_without_fee_val" + ",amount_without_fee_frac" + ",coin_pub" + ",merchant_pub" + ",exchange_sig" + ",exchange_pub" + ",master_sig" /* master_sig could be normalized... */ + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);", + 12), /* Used in #postgres_get_deposit_confirmations() */ GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_select", - "SELECT" - " serial_id" - ",h_contract_terms" - ",h_wire" - ",timestamp" - ",refund_deadline" - ",amount_without_fee_val" - ",amount_without_fee_frac" - ",amount_without_fee_curr" - ",coin_pub" - ",merchant_pub" - ",exchange_sig" - ",exchange_pub" - ",master_sig" /* master_sig could be normalized... */ - " FROM deposit_confirmations" - " WHERE master_pub=$1" - " AND serial_id>$2", - 2), + "SELECT" + " serial_id" + ",h_contract_terms" + ",h_wire" + ",timestamp" + ",refund_deadline" + ",amount_without_fee_val" + ",amount_without_fee_frac" + ",coin_pub" + ",merchant_pub" + ",exchange_sig" + ",exchange_pub" + ",master_sig" /* master_sig could be normalized... */ + " FROM deposit_confirmations" + " WHERE master_pub=$1" + " AND serial_id>$2", + 2), /* Used in #postgres_update_auditor_progress_reserve() */ GNUNET_PQ_make_prepare ("auditor_progress_update_reserve", - "UPDATE auditor_progress_reserve SET " - " last_reserve_in_serial_id=$1" - ",last_reserve_out_serial_id=$2" - ",last_reserve_payback_serial_id=$3" - ",last_reserve_close_serial_id=$4" - " WHERE master_pub=$5", - 5), + "UPDATE auditor_progress_reserve SET " + " last_reserve_in_serial_id=$1" + ",last_reserve_out_serial_id=$2" + ",last_reserve_payback_serial_id=$3" + ",last_reserve_close_serial_id=$4" + " WHERE master_pub=$5", + 5), /* Used in #postgres_get_auditor_progress_reserve() */ GNUNET_PQ_make_prepare ("auditor_progress_select_reserve", - "SELECT" - " last_reserve_in_serial_id" - ",last_reserve_out_serial_id" - ",last_reserve_payback_serial_id" - ",last_reserve_close_serial_id" - " FROM auditor_progress_reserve" - " WHERE master_pub=$1;", - 1), + "SELECT" + " last_reserve_in_serial_id" + ",last_reserve_out_serial_id" + ",last_reserve_payback_serial_id" + ",last_reserve_close_serial_id" + " FROM auditor_progress_reserve" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_auditor_progress_reserve() */ GNUNET_PQ_make_prepare ("auditor_progress_insert_reserve", - "INSERT INTO auditor_progress_reserve " - "(master_pub" - ",last_reserve_in_serial_id" - ",last_reserve_out_serial_id" - ",last_reserve_payback_serial_id" - ",last_reserve_close_serial_id" - ") VALUES ($1,$2,$3,$4,$5);", - 5), + "INSERT INTO auditor_progress_reserve " + "(master_pub" + ",last_reserve_in_serial_id" + ",last_reserve_out_serial_id" + ",last_reserve_payback_serial_id" + ",last_reserve_close_serial_id" + ") VALUES ($1,$2,$3,$4,$5);", + 5), /* Used in #postgres_update_auditor_progress_aggregation() */ GNUNET_PQ_make_prepare ("auditor_progress_update_aggregation", - "UPDATE auditor_progress_aggregation SET " - " last_wire_out_serial_id=$1" - " WHERE master_pub=$2", - 2), + "UPDATE auditor_progress_aggregation SET " + " last_wire_out_serial_id=$1" + " WHERE master_pub=$2", + 2), /* Used in #postgres_get_auditor_progress_aggregation() */ GNUNET_PQ_make_prepare ("auditor_progress_select_aggregation", - "SELECT" - " last_wire_out_serial_id" - " FROM auditor_progress_aggregation" - " WHERE master_pub=$1;", - 1), + "SELECT" + " last_wire_out_serial_id" + " FROM auditor_progress_aggregation" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_auditor_progress_aggregation() */ GNUNET_PQ_make_prepare ("auditor_progress_insert_aggregation", - "INSERT INTO auditor_progress_aggregation " - "(master_pub" - ",last_wire_out_serial_id" - ") VALUES ($1,$2);", - 2), + "INSERT INTO auditor_progress_aggregation " + "(master_pub" + ",last_wire_out_serial_id" + ") VALUES ($1,$2);", + 2), /* Used in #postgres_update_auditor_progress_deposit_confirmation() */ GNUNET_PQ_make_prepare ("auditor_progress_update_deposit_confirmation", - "UPDATE auditor_progress_deposit_confirmation SET " - " last_deposit_confirmation_serial_id=$1" - " WHERE master_pub=$2", - 2), + "UPDATE auditor_progress_deposit_confirmation SET " + " last_deposit_confirmation_serial_id=$1" + " WHERE master_pub=$2", + 2), /* Used in #postgres_get_auditor_progress_deposit_confirmation() */ GNUNET_PQ_make_prepare ("auditor_progress_select_deposit_confirmation", - "SELECT" - " last_deposit_confirmation_serial_id" - " FROM auditor_progress_deposit_confirmation" - " WHERE master_pub=$1;", - 1), + "SELECT" + " last_deposit_confirmation_serial_id" + " FROM auditor_progress_deposit_confirmation" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_auditor_progress_deposit_confirmation() */ GNUNET_PQ_make_prepare ("auditor_progress_insert_deposit_confirmation", - "INSERT INTO auditor_progress_deposit_confirmation " - "(master_pub" - ",last_deposit_confirmation_serial_id" - ") VALUES ($1,$2);", - 2), + "INSERT INTO auditor_progress_deposit_confirmation " + "(master_pub" + ",last_deposit_confirmation_serial_id" + ") VALUES ($1,$2);", + 2), /* Used in #postgres_update_auditor_progress_coin() */ GNUNET_PQ_make_prepare ("auditor_progress_update_coin", - "UPDATE auditor_progress_coin SET " - " last_withdraw_serial_id=$1" - ",last_deposit_serial_id=$2" - ",last_melt_serial_id=$3" - ",last_refund_serial_id=$4" - ",last_payback_serial_id=$5" - ",last_payback_refresh_serial_id=$6" - " WHERE master_pub=$7", - 7), + "UPDATE auditor_progress_coin SET " + " last_withdraw_serial_id=$1" + ",last_deposit_serial_id=$2" + ",last_melt_serial_id=$3" + ",last_refund_serial_id=$4" + ",last_payback_serial_id=$5" + ",last_payback_refresh_serial_id=$6" + " WHERE master_pub=$7", + 7), /* Used in #postgres_get_auditor_progress_coin() */ GNUNET_PQ_make_prepare ("auditor_progress_select_coin", - "SELECT" - " last_withdraw_serial_id" - ",last_deposit_serial_id" - ",last_melt_serial_id" - ",last_refund_serial_id" - ",last_payback_serial_id" - ",last_payback_refresh_serial_id" - " FROM auditor_progress_coin" - " WHERE master_pub=$1;", - 1), + "SELECT" + " last_withdraw_serial_id" + ",last_deposit_serial_id" + ",last_melt_serial_id" + ",last_refund_serial_id" + ",last_payback_serial_id" + ",last_payback_refresh_serial_id" + " FROM auditor_progress_coin" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_auditor_progress() */ GNUNET_PQ_make_prepare ("auditor_progress_insert_coin", - "INSERT INTO auditor_progress_coin " - "(master_pub" - ",last_withdraw_serial_id" - ",last_deposit_serial_id" - ",last_melt_serial_id" - ",last_refund_serial_id" - ",last_payback_serial_id" - ",last_payback_refresh_serial_id" - ") VALUES ($1,$2,$3,$4,$5,$6,$7);", - 7), + "INSERT INTO auditor_progress_coin " + "(master_pub" + ",last_withdraw_serial_id" + ",last_deposit_serial_id" + ",last_melt_serial_id" + ",last_refund_serial_id" + ",last_payback_serial_id" + ",last_payback_refresh_serial_id" + ") VALUES ($1,$2,$3,$4,$5,$6,$7);", + 7), /* Used in #postgres_insert_wire_auditor_progress() */ GNUNET_PQ_make_prepare ("wire_auditor_progress_insert", - "INSERT INTO wire_auditor_progress " - "(master_pub" - ",account_name" - ",last_wire_reserve_in_serial_id" - ",last_wire_wire_out_serial_id" - ",last_timestamp" - ",wire_in_off" - ",wire_out_off" - ") VALUES ($1,$2,$3,$4,$5,$6,$7);", - 7), + "INSERT INTO wire_auditor_progress " + "(master_pub" + ",account_name" + ",last_wire_reserve_in_serial_id" + ",last_wire_wire_out_serial_id" + ",last_timestamp" + ",wire_in_off" + ",wire_out_off" + ") VALUES ($1,$2,$3,$4,$5,$6,$7);", + 7), /* Used in #postgres_update_wire_auditor_progress() */ GNUNET_PQ_make_prepare ("wire_auditor_progress_update", - "UPDATE wire_auditor_progress SET " - " last_wire_reserve_in_serial_id=$1" - ",last_wire_wire_out_serial_id=$2" - ",last_timestamp=$3" - ",wire_in_off=$4" - ",wire_out_off=$5" - " WHERE master_pub=$6 AND account_name=$7", - 7), + "UPDATE wire_auditor_progress SET " + " last_wire_reserve_in_serial_id=$1" + ",last_wire_wire_out_serial_id=$2" + ",last_timestamp=$3" + ",wire_in_off=$4" + ",wire_out_off=$5" + " WHERE master_pub=$6 AND account_name=$7", + 7), /* Used in #postgres_get_wire_auditor_progress() */ GNUNET_PQ_make_prepare ("wire_auditor_progress_select", - "SELECT" - " last_wire_reserve_in_serial_id" - ",last_wire_wire_out_serial_id" - ",last_timestamp" - ",wire_in_off" - ",wire_out_off" - " FROM wire_auditor_progress" - " WHERE master_pub=$1 AND account_name=$2;", - 2), + "SELECT" + " last_wire_reserve_in_serial_id" + ",last_wire_wire_out_serial_id" + ",last_timestamp" + ",wire_in_off" + ",wire_out_off" + " FROM wire_auditor_progress" + " WHERE master_pub=$1 AND account_name=$2;", + 2), /* Used in #postgres_insert_reserve_info() */ GNUNET_PQ_make_prepare ("auditor_reserves_insert", - "INSERT INTO auditor_reserves " - "(reserve_pub" - ",master_pub" - ",reserve_balance_val" - ",reserve_balance_frac" - ",reserve_balance_curr" - ",withdraw_fee_balance_val" - ",withdraw_fee_balance_frac" - ",withdraw_fee_balance_curr" - ",expiration_date" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);", - 9), + "INSERT INTO auditor_reserves " + "(reserve_pub" + ",master_pub" + ",reserve_balance_val" + ",reserve_balance_frac" + ",withdraw_fee_balance_val" + ",withdraw_fee_balance_frac" + ",expiration_date" + ") VALUES ($1,$2,$3,$4,$5,$6,$7);", + 7), /* Used in #postgres_update_reserve_info() */ GNUNET_PQ_make_prepare ("auditor_reserves_update", - "UPDATE auditor_reserves SET" - " reserve_balance_val=$1" - ",reserve_balance_frac=$2" - ",reserve_balance_curr=$3" - ",withdraw_fee_balance_val=$4" - ",withdraw_fee_balance_frac=$5" - ",withdraw_fee_balance_curr=$6" - ",expiration_date=$7" - " WHERE reserve_pub=$8 AND master_pub=$9;", - 9), + "UPDATE auditor_reserves SET" + " reserve_balance_val=$1" + ",reserve_balance_frac=$2" + ",withdraw_fee_balance_val=$3" + ",withdraw_fee_balance_frac=$4" + ",expiration_date=$5" + " WHERE reserve_pub=$6 AND master_pub=$7;", + 7), /* Used in #postgres_get_reserve_info() */ GNUNET_PQ_make_prepare ("auditor_reserves_select", - "SELECT" - " reserve_balance_val" - ",reserve_balance_frac" - ",reserve_balance_curr" - ",withdraw_fee_balance_val" - ",withdraw_fee_balance_frac" - ",withdraw_fee_balance_curr" - ",expiration_date" - ",auditor_reserves_rowid" - " FROM auditor_reserves" - " WHERE reserve_pub=$1 AND master_pub=$2;", - 2), + "SELECT" + " reserve_balance_val" + ",reserve_balance_frac" + ",withdraw_fee_balance_val" + ",withdraw_fee_balance_frac" + ",expiration_date" + ",auditor_reserves_rowid" + " FROM auditor_reserves" + " WHERE reserve_pub=$1 AND master_pub=$2;", + 2), /* Used in #postgres_del_reserve_info() */ GNUNET_PQ_make_prepare ("auditor_reserves_delete", - "DELETE" - " FROM auditor_reserves" - " WHERE reserve_pub=$1 AND master_pub=$2;", - 2), + "DELETE" + " FROM auditor_reserves" + " WHERE reserve_pub=$1 AND master_pub=$2;", + 2), /* Used in #postgres_insert_reserve_summary() */ GNUNET_PQ_make_prepare ("auditor_reserve_balance_insert", - "INSERT INTO auditor_reserve_balance" - "(master_pub" - ",reserve_balance_val" - ",reserve_balance_frac" - ",reserve_balance_curr" - ",withdraw_fee_balance_val" - ",withdraw_fee_balance_frac" - ",withdraw_fee_balance_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7)", - 7), + "INSERT INTO auditor_reserve_balance" + "(master_pub" + ",reserve_balance_val" + ",reserve_balance_frac" + ",withdraw_fee_balance_val" + ",withdraw_fee_balance_frac" + ") VALUES ($1,$2,$3,$4,$5)", + 5), /* Used in #postgres_update_reserve_summary() */ GNUNET_PQ_make_prepare ("auditor_reserve_balance_update", - "UPDATE auditor_reserve_balance SET" - " reserve_balance_val=$1" - ",reserve_balance_frac=$2" - ",reserve_balance_curr=$3" - ",withdraw_fee_balance_val=$4" - ",withdraw_fee_balance_frac=$5" - ",withdraw_fee_balance_curr=$6" - " WHERE master_pub=$7;", - 7), + "UPDATE auditor_reserve_balance SET" + " reserve_balance_val=$1" + ",reserve_balance_frac=$2" + ",withdraw_fee_balance_val=$3" + ",withdraw_fee_balance_frac=$4" + " WHERE master_pub=$5;", + 5), /* Used in #postgres_get_reserve_summary() */ GNUNET_PQ_make_prepare ("auditor_reserve_balance_select", - "SELECT" - " reserve_balance_val" - ",reserve_balance_frac" - ",reserve_balance_curr" - ",withdraw_fee_balance_val" - ",withdraw_fee_balance_frac" - ",withdraw_fee_balance_curr" - " FROM auditor_reserve_balance" - " WHERE master_pub=$1;", - 1), + "SELECT" + " reserve_balance_val" + ",reserve_balance_frac" + ",withdraw_fee_balance_val" + ",withdraw_fee_balance_frac" + " FROM auditor_reserve_balance" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_wire_fee_summary() */ GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_insert", - "INSERT INTO auditor_wire_fee_balance" - "(master_pub" - ",wire_fee_balance_val" - ",wire_fee_balance_frac" - ",wire_fee_balance_curr" - ") VALUES ($1,$2,$3,$4)", - 4), + "INSERT INTO auditor_wire_fee_balance" + "(master_pub" + ",wire_fee_balance_val" + ",wire_fee_balance_frac" + ") VALUES ($1,$2,$3)", + 3), /* Used in #postgres_update_wire_fee_summary() */ GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_update", - "UPDATE auditor_wire_fee_balance SET" - " wire_fee_balance_val=$1" - ",wire_fee_balance_frac=$2" - ",wire_fee_balance_curr=$3" - " WHERE master_pub=$4;", - 4), + "UPDATE auditor_wire_fee_balance SET" + " wire_fee_balance_val=$1" + ",wire_fee_balance_frac=$2" + " WHERE master_pub=$3;", + 3), /* Used in #postgres_get_wire_fee_summary() */ GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_select", - "SELECT" - " wire_fee_balance_val" - ",wire_fee_balance_frac" - ",wire_fee_balance_curr" - " FROM auditor_wire_fee_balance" - " WHERE master_pub=$1;", - 1), + "SELECT" + " wire_fee_balance_val" + ",wire_fee_balance_frac" + " FROM auditor_wire_fee_balance" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_denomination_balance() */ GNUNET_PQ_make_prepare ("auditor_denomination_pending_insert", - "INSERT INTO auditor_denomination_pending " - "(denom_pub_hash" - ",denom_balance_val" - ",denom_balance_frac" - ",denom_balance_curr" - ",num_issued" - ",denom_risk_val" - ",denom_risk_frac" - ",denom_risk_curr" - ",payback_loss_val" - ",payback_loss_frac" - ",payback_loss_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);", - 11), + "INSERT INTO auditor_denomination_pending " + "(denom_pub_hash" + ",denom_balance_val" + ",denom_balance_frac" + ",num_issued" + ",denom_risk_val" + ",denom_risk_frac" + ",payback_loss_val" + ",payback_loss_frac" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8);", + 8), /* Used in #postgres_update_denomination_balance() */ GNUNET_PQ_make_prepare ("auditor_denomination_pending_update", - "UPDATE auditor_denomination_pending SET" - " denom_balance_val=$1" - ",denom_balance_frac=$2" - ",denom_balance_curr=$3" - ",num_issued=$4" - ",denom_risk_val=$5" - ",denom_risk_frac=$6" - ",denom_risk_curr=$7" - ",payback_loss_val=$8" - ",payback_loss_frac=$9" - ",payback_loss_curr=$10" - " WHERE denom_pub_hash=$11", - 11), + "UPDATE auditor_denomination_pending SET" + " denom_balance_val=$1" + ",denom_balance_frac=$2" + ",num_issued=$3" + ",denom_risk_val=$4" + ",denom_risk_frac=$5" + ",payback_loss_val=$6" + ",payback_loss_frac=$7" + " WHERE denom_pub_hash=$8", + 8), /* Used in #postgres_get_denomination_balance() */ GNUNET_PQ_make_prepare ("auditor_denomination_pending_select", - "SELECT" - " denom_balance_val" - ",denom_balance_frac" - ",denom_balance_curr" - ",num_issued" - ",denom_risk_val" - ",denom_risk_frac" - ",denom_risk_curr" - ",payback_loss_val" - ",payback_loss_frac" - ",payback_loss_curr" - " FROM auditor_denomination_pending" - " WHERE denom_pub_hash=$1", - 1), + "SELECT" + " denom_balance_val" + ",denom_balance_frac" + ",num_issued" + ",denom_risk_val" + ",denom_risk_frac" + ",payback_loss_val" + ",payback_loss_frac" + " FROM auditor_denomination_pending" + " WHERE denom_pub_hash=$1", + 1), /* Used in #postgres_insert_balance_summary() */ GNUNET_PQ_make_prepare ("auditor_balance_summary_insert", - "INSERT INTO auditor_balance_summary " - "(master_pub" - ",denom_balance_val" - ",denom_balance_frac" - ",denom_balance_curr" - ",deposit_fee_balance_val" - ",deposit_fee_balance_frac" - ",deposit_fee_balance_curr" - ",melt_fee_balance_val" - ",melt_fee_balance_frac" - ",melt_fee_balance_curr" - ",refund_fee_balance_val" - ",refund_fee_balance_frac" - ",refund_fee_balance_curr" - ",risk_val" - ",risk_frac" - ",risk_curr" - ",loss_val" - ",loss_frac" - ",loss_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10," - " $11,$12,$13,$14,$15,$16,$17,$18,$19);", - 19), + "INSERT INTO auditor_balance_summary " + "(master_pub" + ",denom_balance_val" + ",denom_balance_frac" + ",deposit_fee_balance_val" + ",deposit_fee_balance_frac" + ",melt_fee_balance_val" + ",melt_fee_balance_frac" + ",refund_fee_balance_val" + ",refund_fee_balance_frac" + ",risk_val" + ",risk_frac" + ",loss_val" + ",loss_frac" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10," + " $11,$12,$13);", + 13), /* Used in #postgres_update_balance_summary() */ GNUNET_PQ_make_prepare ("auditor_balance_summary_update", - "UPDATE auditor_balance_summary SET" - " denom_balance_val=$1" - ",denom_balance_frac=$2" - ",denom_balance_curr=$3" - ",deposit_fee_balance_val=$4" - ",deposit_fee_balance_frac=$5" - ",deposit_fee_balance_curr=$6" - ",melt_fee_balance_val=$7" - ",melt_fee_balance_frac=$8" - ",melt_fee_balance_curr=$9" - ",refund_fee_balance_val=$10" - ",refund_fee_balance_frac=$11" - ",refund_fee_balance_curr=$12" - ",risk_val=$13" - ",risk_frac=$14" - ",risk_curr=$15" - ",loss_val=$16" - ",loss_frac=$17" - ",loss_curr=$18" - " WHERE master_pub=$19;", - 19), + "UPDATE auditor_balance_summary SET" + " denom_balance_val=$1" + ",denom_balance_frac=$2" + ",deposit_fee_balance_val=$3" + ",deposit_fee_balance_frac=$4" + ",melt_fee_balance_val=$5" + ",melt_fee_balance_frac=$6" + ",refund_fee_balance_val=$7" + ",refund_fee_balance_frac=$8" + ",risk_val=$9" + ",risk_frac=$10" + ",loss_val=$11" + ",loss_frac=$12" + " WHERE master_pub=$13;", + 13), /* Used in #postgres_get_balance_summary() */ GNUNET_PQ_make_prepare ("auditor_balance_summary_select", - "SELECT" - " denom_balance_val" - ",denom_balance_frac" - ",denom_balance_curr" - ",deposit_fee_balance_val" - ",deposit_fee_balance_frac" - ",deposit_fee_balance_curr" - ",melt_fee_balance_val" - ",melt_fee_balance_frac" - ",melt_fee_balance_curr" - ",refund_fee_balance_val" - ",refund_fee_balance_frac" - ",refund_fee_balance_curr" - ",risk_val" - ",risk_frac" - ",risk_curr" - ",loss_val" - ",loss_frac" - ",loss_curr" - " FROM auditor_balance_summary" - " WHERE master_pub=$1;", - 1), + "SELECT" + " denom_balance_val" + ",denom_balance_frac" + ",deposit_fee_balance_val" + ",deposit_fee_balance_frac" + ",melt_fee_balance_val" + ",melt_fee_balance_frac" + ",refund_fee_balance_val" + ",refund_fee_balance_frac" + ",risk_val" + ",risk_frac" + ",loss_val" + ",loss_frac" + " FROM auditor_balance_summary" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_historic_denom_revenue() */ GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_insert", - "INSERT INTO auditor_historic_denomination_revenue" - "(master_pub" - ",denom_pub_hash" - ",revenue_timestamp" - ",revenue_balance_val" - ",revenue_balance_frac" - ",revenue_balance_curr" - ",loss_balance_val" - ",loss_balance_frac" - ",loss_balance_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);", - 9), + "INSERT INTO auditor_historic_denomination_revenue" + "(master_pub" + ",denom_pub_hash" + ",revenue_timestamp" + ",revenue_balance_val" + ",revenue_balance_frac" + ",loss_balance_val" + ",loss_balance_frac" + ") VALUES ($1,$2,$3,$4,$5,$6,$7);", + 7), /* Used in #postgres_select_historic_denom_revenue() */ GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_select", - "SELECT" - " denom_pub_hash" - ",revenue_timestamp" - ",revenue_balance_val" - ",revenue_balance_frac" - ",revenue_balance_curr" - ",loss_balance_val" - ",loss_balance_frac" - ",loss_balance_curr" - " FROM auditor_historic_denomination_revenue" - " WHERE master_pub=$1;", - 1), + "SELECT" + " denom_pub_hash" + ",revenue_timestamp" + ",revenue_balance_val" + ",revenue_balance_frac" + ",loss_balance_val" + ",loss_balance_frac" + " FROM auditor_historic_denomination_revenue" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_historic_reserve_revenue() */ GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_insert", - "INSERT INTO auditor_historic_reserve_summary" - "(master_pub" - ",start_date" - ",end_date" - ",reserve_profits_val" - ",reserve_profits_frac" - ",reserve_profits_curr" - ") VALUES ($1,$2,$3,$4,$5,$6);", - 6), + "INSERT INTO auditor_historic_reserve_summary" + "(master_pub" + ",start_date" + ",end_date" + ",reserve_profits_val" + ",reserve_profits_frac" + ") VALUES ($1,$2,$3,$4,$5);", + 5), /* Used in #postgres_select_historic_reserve_revenue() */ GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_select", - "SELECT" - " start_date" - ",end_date" - ",reserve_profits_val" - ",reserve_profits_frac" - ",reserve_profits_curr" - " FROM auditor_historic_reserve_summary" - " WHERE master_pub=$1;", - 1), + "SELECT" + " start_date" + ",end_date" + ",reserve_profits_val" + ",reserve_profits_frac" + " FROM auditor_historic_reserve_summary" + " WHERE master_pub=$1;", + 1), /* Used in #postgres_insert_predicted_result() */ GNUNET_PQ_make_prepare ("auditor_predicted_result_insert", - "INSERT INTO auditor_predicted_result" - "(master_pub" - ",balance_val" - ",balance_frac" - ",balance_curr" - ") VALUES ($1,$2,$3,$4);", - 4), + "INSERT INTO auditor_predicted_result" + "(master_pub" + ",balance_val" + ",balance_frac" + ") VALUES ($1,$2,$3);", + 3), /* Used in #postgres_update_predicted_result() */ GNUNET_PQ_make_prepare ("auditor_predicted_result_update", - "UPDATE auditor_predicted_result SET" - " balance_val=$1" - ",balance_frac=$2" - ",balance_curr=$3" - " WHERE master_pub=$4;", - 4), + "UPDATE auditor_predicted_result SET" + " balance_val=$1" + ",balance_frac=$2" + " WHERE master_pub=$3;", + 3), /* Used in #postgres_get_predicted_balance() */ GNUNET_PQ_make_prepare ("auditor_predicted_result_select", - "SELECT" - " balance_val" - ",balance_frac" - ",balance_curr" - " FROM auditor_predicted_result" - " WHERE master_pub=$1;", - 1), + "SELECT" + " balance_val" + ",balance_frac" + " FROM auditor_predicted_result" + " WHERE master_pub=$1;", + 1), GNUNET_PQ_PREPARED_STATEMENT_END }; @@ -1282,8 +1218,8 @@ postgres_delete_exchange (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_delete_exchange", - params); + "auditor_delete_exchange", + params); } @@ -1338,8 +1274,8 @@ exchange_info_cb (void *cls, if (GNUNET_OK != GNUNET_PQ_extract_result (result, - rs, - i)) + rs, + i)) { GNUNET_break (0); eic->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -1379,10 +1315,10 @@ postgres_list_exchanges (void *cls, enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "auditor_list_exchanges", - params, - &exchange_info_cb, - &eic); + "auditor_list_exchanges", + params, + &exchange_info_cb, + &eic); if (qs > 0) return eic.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); @@ -1414,8 +1350,8 @@ postgres_insert_exchange_signkey (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_insert_exchange_signkey", - params); + "auditor_insert_exchange_signkey", + params); } @@ -1448,8 +1384,8 @@ postgres_insert_deposit_confirmation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_deposit_confirmation_insert", - params); + "auditor_deposit_confirmation_insert", + params); } @@ -1474,6 +1410,11 @@ struct DepositConfirmationContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Query status to return. */ @@ -1496,7 +1437,8 @@ deposit_confirmation_cb (void *cls, unsigned int num_results) { struct DepositConfirmationContext *dcc = cls; - + struct PostgresClosure *pg = dcc->pg; + for (unsigned int i = 0; i < num_results; i++) { uint64_t serial_id; @@ -1514,7 +1456,7 @@ deposit_confirmation_cb (void *cls, &dc.timestamp), GNUNET_PQ_result_spec_absolute_time ("refund_deadline", &dc.refund_deadline), - TALER_PQ_result_spec_amount ("amount_without_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_without_fee", &dc.amount_without_fee), GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &dc.coin_pub), @@ -1566,6 +1508,7 @@ postgres_get_deposit_confirmations (void *cls, TALER_AUDITORDB_DepositConfirmationCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_public_key), GNUNET_PQ_query_param_uint64 (&start_id), @@ -1574,7 +1517,8 @@ postgres_get_deposit_confirmations (void *cls, struct DepositConfirmationContext dcc = { .master_pub = master_public_key, .cb = cb, - .cb_cls = cb_cls + .cb_cls = cb_cls, + .pg = pg }; enum GNUNET_DB_QueryStatus qs; @@ -1661,6 +1605,11 @@ struct DenominationInfoContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Query status to return. */ @@ -1679,10 +1628,11 @@ struct DenominationInfoContext */ static void denomination_info_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct DenominationInfoContext *dic = cls; + struct PostgresClosure *pg = dic->pg; for (unsigned int i = 0; i < num_results; i++) { @@ -1695,11 +1645,11 @@ denomination_info_cb (void *cls, TALER_PQ_result_spec_absolute_time_nbo ("expire_withdraw", &issue.expire_withdraw), TALER_PQ_result_spec_absolute_time_nbo ("expire_deposit", &issue.expire_deposit), TALER_PQ_result_spec_absolute_time_nbo ("expire_legal", &issue.expire_legal), - TALER_PQ_result_spec_amount_nbo ("coin", &issue.value), - TALER_PQ_result_spec_amount_nbo ("fee_withdraw", &issue.fee_withdraw), - TALER_PQ_result_spec_amount_nbo ("fee_deposit", &issue.fee_deposit), - TALER_PQ_result_spec_amount_nbo ("fee_refresh", &issue.fee_refresh), - TALER_PQ_result_spec_amount_nbo ("fee_refund", &issue.fee_refund), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("coin", &issue.value), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_withdraw", &issue.fee_withdraw), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_deposit", &issue.fee_deposit), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refresh", &issue.fee_refresh), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refund", &issue.fee_refund), GNUNET_PQ_result_spec_end }; @@ -1738,6 +1688,7 @@ postgres_select_denomination_info (void *cls, TALER_AUDITORDB_DenominationInfoDataCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end @@ -1745,7 +1696,8 @@ postgres_select_denomination_info (void *cls, struct DenominationInfoContext dic = { .master_pub = master_pub, .cb = cb, - .cb_cls = cb_cls + .cb_cls = cb_cls, + .pg = pg }; enum GNUNET_DB_QueryStatus qs; @@ -1787,8 +1739,8 @@ postgres_insert_auditor_progress_reserve (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_insert_reserve", - params); + "auditor_progress_insert_reserve", + params); } @@ -1818,8 +1770,8 @@ postgres_update_auditor_progress_reserve (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_update_reserve", - params); + "auditor_progress_update_reserve", + params); } @@ -1855,9 +1807,9 @@ postgres_get_auditor_progress_reserve (void *cls, }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_progress_select_reserve", - params, - rs); + "auditor_progress_select_reserve", + params, + rs); } @@ -1884,8 +1836,8 @@ postgres_insert_auditor_progress_aggregation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_insert_aggregation", - params); + "auditor_progress_insert_aggregation", + params); } @@ -1912,8 +1864,8 @@ postgres_update_auditor_progress_aggregation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_update_aggregation", - params); + "auditor_progress_update_aggregation", + params); } @@ -1943,9 +1895,9 @@ postgres_get_auditor_progress_aggregation (void *cls, }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_progress_select_aggregation", - params, - rs); + "auditor_progress_select_aggregation", + params, + rs); } @@ -1972,8 +1924,8 @@ postgres_insert_auditor_progress_deposit_confirmation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_insert_deposit_confirmation", - params); + "auditor_progress_insert_deposit_confirmation", + params); } @@ -2000,8 +1952,8 @@ postgres_update_auditor_progress_deposit_confirmation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_progress_update_deposit_confirmation", - params); + "auditor_progress_update_deposit_confirmation", + params); } @@ -2031,9 +1983,9 @@ postgres_get_auditor_progress_deposit_confirmation (void *cls, }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_progress_select_deposit_confirmation", - params, - rs); + "auditor_progress_select_deposit_confirmation", + params, + rs); } @@ -2180,8 +2132,8 @@ postgres_insert_wire_auditor_progress (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "wire_auditor_progress_insert", - params); + "wire_auditor_progress_insert", + params); } @@ -2220,8 +2172,8 @@ postgres_update_wire_auditor_progress (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "wire_auditor_progress_update", - params); + "wire_auditor_progress_update", + params); } @@ -2319,8 +2271,8 @@ postgres_insert_reserve_info (void *cls, withdraw_fee_balance)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_reserves_insert", - params); + "auditor_reserves_insert", + params); } @@ -2361,8 +2313,8 @@ postgres_update_reserve_info (void *cls, withdraw_fee_balance)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_reserves_update", - params); + "auditor_reserves_update", + params); } @@ -2388,8 +2340,8 @@ postgres_del_reserve_info (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_reserves_delete", - params); + "auditor_reserves_delete", + params); } @@ -2417,23 +2369,24 @@ postgres_get_reserve_info (void *cls, struct TALER_Amount *withdraw_fee_balance, struct GNUNET_TIME_Absolute *expiration_date) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (reserve_pub), GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("reserve_balance", reserve_balance), - TALER_PQ_result_spec_amount ("withdraw_fee_balance", withdraw_fee_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance", reserve_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance", withdraw_fee_balance), TALER_PQ_result_spec_absolute_time ("expiration_date", expiration_date), GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid", rowid), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_reserves_select", - params, - rs); + "auditor_reserves_select", + params, + rs); } @@ -2468,8 +2421,8 @@ postgres_insert_reserve_summary (void *cls, withdraw_fee_balance)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_reserve_balance_insert", - params); + "auditor_reserve_balance_insert", + params); } @@ -2500,8 +2453,8 @@ postgres_update_reserve_summary (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_reserve_balance_update", - params); + "auditor_reserve_balance_update", + params); } @@ -2523,21 +2476,22 @@ postgres_get_reserve_summary (void *cls, struct TALER_Amount *reserve_balance, struct TALER_Amount *withdraw_fee_balance) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("reserve_balance", reserve_balance), - TALER_PQ_result_spec_amount ("withdraw_fee_balance", withdraw_fee_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance", reserve_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance", withdraw_fee_balance), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_reserve_balance_select", - params, - rs); + "auditor_reserve_balance_select", + params, + rs); } @@ -2564,8 +2518,8 @@ postgres_insert_wire_fee_summary (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_wire_fee_balance_insert", - params); + "auditor_wire_fee_balance_insert", + params); } @@ -2592,8 +2546,8 @@ postgres_update_wire_fee_summary (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_wire_fee_balance_update", - params); + "auditor_wire_fee_balance_update", + params); } @@ -2612,20 +2566,21 @@ postgres_get_wire_fee_summary (void *cls, const struct TALER_MasterPublicKeyP *master_pub, struct TALER_Amount *wire_fee_balance) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("wire_fee_balance", wire_fee_balance), - + TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee_balance", + wire_fee_balance), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_wire_fee_balance_select", - params, - rs); + "auditor_wire_fee_balance_select", + params, + rs); } @@ -2661,8 +2616,8 @@ postgres_insert_denomination_balance (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_denomination_pending_insert", - params); + "auditor_denomination_pending_insert", + params); } @@ -2698,8 +2653,8 @@ postgres_update_denomination_balance (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_denomination_pending_update", - params); + "auditor_denomination_pending_update", + params); } @@ -2724,22 +2679,23 @@ postgres_get_denomination_balance (void *cls, struct TALER_Amount *payback_loss, uint64_t *num_issued) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("denom_balance", denom_balance), - TALER_PQ_result_spec_amount ("denom_risk", denom_risk), - TALER_PQ_result_spec_amount ("payback_loss", payback_loss), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", denom_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", denom_risk), + TALER_PQ_RESULT_SPEC_AMOUNT ("payback_loss", payback_loss), GNUNET_PQ_result_spec_uint64 ("num_issued", num_issued), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_denomination_pending_select", - params, - rs); + "auditor_denomination_pending_select", + params, + rs); } @@ -2793,8 +2749,8 @@ postgres_insert_balance_summary (void *cls, refund_fee_balance)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_balance_summary_insert", - params); + "auditor_balance_summary_insert", + params); } @@ -2836,8 +2792,8 @@ postgres_update_balance_summary (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_balance_summary_update", - params); + "auditor_balance_summary_update", + params); } @@ -2866,17 +2822,18 @@ postgres_get_balance_summary (void *cls, struct TALER_Amount *risk, struct TALER_Amount *loss) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("denom_balance", denom_balance), - TALER_PQ_result_spec_amount ("deposit_fee_balance", deposit_fee_balance), - TALER_PQ_result_spec_amount ("melt_fee_balance", melt_fee_balance), - TALER_PQ_result_spec_amount ("refund_fee_balance", refund_fee_balance), - TALER_PQ_result_spec_amount ("risk", risk), - TALER_PQ_result_spec_amount ("loss", loss), + TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", denom_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee_balance", deposit_fee_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("melt_fee_balance", melt_fee_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("refund_fee_balance", refund_fee_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("risk", risk), + TALER_PQ_RESULT_SPEC_AMOUNT ("loss", loss), GNUNET_PQ_result_spec_end }; @@ -2940,6 +2897,11 @@ struct HistoricDenomRevenueContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Number of results processed. */ @@ -2958,11 +2920,12 @@ struct HistoricDenomRevenueContext */ static void historic_denom_revenue_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct HistoricDenomRevenueContext *hrc = cls; - + struct PostgresClosure *pg = hrc->pg; + for (unsigned int i = 0; i < num_results; i++) { struct GNUNET_HashCode denom_pub_hash; @@ -2972,15 +2935,15 @@ historic_denom_revenue_cb (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &denom_pub_hash), TALER_PQ_result_spec_absolute_time ("revenue_timestamp", &revenue_timestamp), - TALER_PQ_result_spec_amount ("revenue_balance", &revenue_balance), - TALER_PQ_result_spec_amount ("loss_balance", &loss), + TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance", &revenue_balance), + TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance", &loss), GNUNET_PQ_result_spec_end }; if (GNUNET_OK != GNUNET_PQ_extract_result (result, - rs, - i)) + rs, + i)) { GNUNET_break (0); hrc->qs = GNUNET_DB_STATUS_HARD_ERROR; @@ -2989,11 +2952,11 @@ historic_denom_revenue_cb (void *cls, hrc->qs = i + 1; if (GNUNET_OK != - hrc->cb (hrc->cb_cls, - &denom_pub_hash, - revenue_timestamp, - &revenue_balance, - &loss)) + hrc->cb (hrc->cb_cls, + &denom_pub_hash, + revenue_timestamp, + &revenue_balance, + &loss)) break; } } @@ -3017,21 +2980,23 @@ postgres_select_historic_denom_revenue (void *cls, TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct HistoricDenomRevenueContext hrc = { .cb = cb, - .cb_cls = cb_cls + .cb_cls = cb_cls, + .pg = pg }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "auditor_historic_denomination_revenue_select", - params, - &historic_denom_revenue_cb, - &hrc); + "auditor_historic_denomination_revenue_select", + params, + &historic_denom_revenue_cb, + &hrc); if (qs <= 0) return qs; return hrc.qs; @@ -3086,6 +3051,11 @@ struct HistoricReserveRevenueContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Number of results processed. */ @@ -3108,7 +3078,8 @@ historic_reserve_revenue_cb (void *cls, unsigned int num_results) { struct HistoricReserveRevenueContext *hrc = cls; - + struct PostgresClosure *pg = hrc->pg; + for (unsigned int i = 0; i < num_results; i++) { struct GNUNET_TIME_Absolute start_date; @@ -3117,7 +3088,7 @@ historic_reserve_revenue_cb (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_absolute_time ("start_date", &start_date), TALER_PQ_result_spec_absolute_time ("end_date", &end_date), - TALER_PQ_result_spec_amount ("reserve_profits", &reserve_profits), + TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits", &reserve_profits), GNUNET_PQ_result_spec_end }; @@ -3132,10 +3103,10 @@ historic_reserve_revenue_cb (void *cls, } hrc->qs = i + 1; if (GNUNET_OK != - hrc->cb (hrc->cb_cls, - start_date, - end_date, - &reserve_profits)) + hrc->cb (hrc->cb_cls, + start_date, + end_date, + &reserve_profits)) break; } } @@ -3158,6 +3129,7 @@ postgres_select_historic_reserve_revenue (void *cls, TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end @@ -3165,7 +3137,8 @@ postgres_select_historic_reserve_revenue (void *cls, enum GNUNET_DB_QueryStatus qs; struct HistoricReserveRevenueContext hrc = { .cb = cb, - .cb_cls = cb_cls + .cb_cls = cb_cls, + .pg = pg }; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, @@ -3202,8 +3175,8 @@ postgres_insert_predicted_result (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_predicted_result_insert", - params); + "auditor_predicted_result_insert", + params); } @@ -3230,8 +3203,8 @@ postgres_update_predicted_result (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_predicted_result_update", - params); + "auditor_predicted_result_update", + params); } @@ -3250,20 +3223,21 @@ postgres_get_predicted_balance (void *cls, const struct TALER_MasterPublicKeyP *master_pub, struct TALER_Amount *balance) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("balance", balance), - + TALER_PQ_RESULT_SPEC_AMOUNT ("balance", + balance), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "auditor_predicted_result_select", - params, - rs); + "auditor_predicted_result_select", + params, + rs); } @@ -3309,6 +3283,19 @@ libtaler_plugin_auditordb_postgres_init (void *cls) return NULL; } } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "taler", + "CURRENCY", + &pg->currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "taler", + "CURRENCY"); + GNUNET_free (pg->connection_cfg_str); + GNUNET_free (pg); + return NULL; + } plugin = GNUNET_new (struct TALER_AUDITORDB_Plugin); plugin->cls = pg; plugin->get_session = &postgres_get_session; @@ -3394,6 +3381,7 @@ libtaler_plugin_auditordb_postgres_done (void *cls) struct PostgresClosure *pg = plugin->cls; GNUNET_free (pg->connection_cfg_str); + GNUNET_free (pg->currency); GNUNET_free (pg); GNUNET_free (plugin); return NULL; diff --git a/src/auditordb/test-auditor-db-postgres.conf b/src/auditordb/test-auditor-db-postgres.conf index fd8ffbfdd..e06d511c1 100644 --- a/src/auditordb/test-auditor-db-postgres.conf +++ b/src/auditordb/test-auditor-db-postgres.conf @@ -5,3 +5,6 @@ DB = postgres [auditordb-postgres] # Argument for Postgres for how to connect to the database. CONFIG = "postgres:///talercheck" + +[taler] +CURRENCY = "EUR" \ No newline at end of file diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c index 80c442a9a..68aa4564e 100644 --- a/src/auditordb/test_auditordb.c +++ b/src/auditordb/test_auditordb.c @@ -54,7 +54,7 @@ static int result = -1; /** - * Currency we use. + * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf". */ #define CURRENCY "EUR" diff --git a/src/exchange-tools/taler-exchange-wire.c b/src/exchange-tools/taler-exchange-wire.c index 1ea3c5c06..366b69ecd 100644 --- a/src/exchange-tools/taler-exchange-wire.c +++ b/src/exchange-tools/taler-exchange-wire.c @@ -60,7 +60,7 @@ sign_account_data (void *cls, char *json_out; FILE *out; int ret; - + if (GNUNET_NO == ai->credit_enabled) return; if (NULL == ai->wire_response_filename) @@ -71,6 +71,7 @@ sign_account_data (void *cls, global_ret = 1; return; } + wire = TALER_JSON_exchange_wire_signature_make (ai->payto_url, &master_priv); GNUNET_assert (NULL != wire); @@ -199,6 +200,9 @@ run (void *cls, global_ret = 1; return; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Signing /wire response with private key matching public key `%s'\n", + masters); GNUNET_free (masters); TALER_EXCHANGEDB_find_accounts (cfg, &sign_account_data, diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index f0059736f..b30b19c3f 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -684,6 +684,9 @@ exchange_serve_process_config () return GNUNET_SYSERR; } GNUNET_free (TEH_master_public_key_str); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Launching exchange with public key `%s'...\n", + GNUNET_p2s (&TEH_master_public_key.eddsa_pub)); if ( (GNUNET_OK != TEH_VALIDATION_init (cfg)) || diff --git a/src/exchange/taler-exchange-httpd_validation.c b/src/exchange/taler-exchange-httpd_validation.c index ba34de80c..acb121178 100644 --- a/src/exchange/taler-exchange-httpd_validation.c +++ b/src/exchange/taler-exchange-httpd_validation.c @@ -173,8 +173,9 @@ load_account (void *cls, &TEH_master_public_key)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid signature in `%s'\n", - ai->wire_response_filename); + "Invalid signature in `%s' for public key `%s'\n", + ai->wire_response_filename, + GNUNET_p2s (&TEH_master_public_key.eddsa_pub)); json_decref (wire_s); *ret = GNUNET_SYSERR; return; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index c89e44721..b1f1aba8e 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -38,6 +38,24 @@ */ #define AUTO_EXPLAIN 1 +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. + * + * @param field name of the database field to fetch amount from + * @param amountp[out] pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount(field,pg->currency,amountp) + +/** + * Wrapper macro to add the currency from the plugin's state + * when fetching amounts from the database. NBO variant. + * + * @param field name of the database field to fetch amount from + * @param amountp[out] pointer to amount to set + */ +#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field,amountp) TALER_PQ_result_spec_amount_nbo(field,pg->currency,amountp) + /** * Log a really unexpected PQ error with all the details we can get hold of. * @@ -70,7 +88,7 @@ struct TALER_EXCHANGEDB_Session * Name of the current transaction, for debugging. */ const char *transaction_name; - + }; @@ -103,6 +121,11 @@ struct PostgresClosure * be garbage collected? */ struct GNUNET_TIME_Relative legal_reserve_expiration_time; + + /** + * Which currency should we assume all amounts to be in? + */ + char *currency; }; @@ -180,19 +203,14 @@ postgres_create_tables (void *cls) ",expire_legal INT8 NOT NULL" ",coin_val INT8 NOT NULL" /* value of this denom */ ",coin_frac INT4 NOT NULL" /* fractional value of this denom */ - ",coin_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" /* assuming same currency for fees */ ",fee_withdraw_val INT8 NOT NULL" ",fee_withdraw_frac INT4 NOT NULL" - ",fee_withdraw_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",fee_deposit_val INT8 NOT NULL" ",fee_deposit_frac INT4 NOT NULL" - ",fee_deposit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",fee_refresh_val INT8 NOT NULL" ",fee_refresh_frac INT4 NOT NULL" - ",fee_refresh_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",fee_refund_val INT8 NOT NULL" ",fee_refund_frac INT4 NOT NULL" - ",fee_refund_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ")"), /* index for gc_denominations */ GNUNET_PQ_make_try_execute ("CREATE INDEX denominations_expire_legal_index ON " @@ -214,7 +232,6 @@ postgres_create_tables (void *cls) ",account_details TEXT NOT NULL " ",current_balance_val INT8 NOT NULL" ",current_balance_frac INT4 NOT NULL" - ",current_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",expiration_date INT8 NOT NULL" ",gc_date INT8 NOT NULL" ");"), @@ -236,7 +253,6 @@ postgres_create_tables (void *cls) ",wire_reference BYTEA NOT NULL" ",credit_val INT8 NOT NULL" ",credit_frac INT4 NOT NULL" - ",credit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",sender_account_details TEXT NOT NULL" ",exchange_account_section TEXT NOT NULL" ",execution_date INT8 NOT NULL" @@ -262,10 +278,8 @@ postgres_create_tables (void *cls) ",receiver_account TEXT NOT NULL" ",amount_val INT8 NOT NULL" ",amount_frac INT4 NOT NULL" - ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",closing_fee_val INT8 NOT NULL" ",closing_fee_frac INT4 NOT NULL" - ",closing_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ");"), GNUNET_PQ_make_try_execute("CREATE INDEX reserves_close_by_reserve " "ON reserves_close(reserve_pub)"), @@ -284,7 +298,6 @@ postgres_create_tables (void *cls) ",execution_date INT8 NOT NULL" ",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_frac INT4 NOT NULL" - ",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ");"), /* Index blindcoins(reserve_pub) for get_reserves_out statement */ GNUNET_PQ_make_try_execute ("CREATE INDEX reserves_out_reserve_pub_index ON" @@ -311,7 +324,6 @@ postgres_create_tables (void *cls) ",old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)" ",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_frac INT4 NOT NULL" - ",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",noreveal_index INT4 NOT NULL" ");"), GNUNET_PQ_make_try_execute ("CREATE INDEX refresh_commitments_old_coin_pub_index ON " @@ -360,7 +372,6 @@ postgres_create_tables (void *cls) ",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE" ",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_frac INT4 NOT NULL" - ",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",timestamp INT8 NOT NULL" ",refund_deadline INT8 NOT NULL" ",wire_deadline INT8 NOT NULL" @@ -394,7 +405,6 @@ postgres_create_tables (void *cls) ",rtransaction_id INT8 NOT NULL" ",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_frac INT4 NOT NULL" - ",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",PRIMARY KEY (coin_pub, merchant_pub, h_contract_terms, rtransaction_id)" /* this combo must be unique, and we usually select by coin_pub */ ");"), GNUNET_PQ_make_try_execute("CREATE INDEX refunds_coin_pub_index " @@ -409,7 +419,6 @@ postgres_create_tables (void *cls) ",exchange_account_section TEXT NOT NULL" ",amount_val INT8 NOT NULL" ",amount_frac INT4 NOT NULL" - ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ");"), /* Table for the tracking API, mapping from wire transfer identifiers to transactions and back */ @@ -428,10 +437,8 @@ postgres_create_tables (void *cls) ",end_date INT8 NOT NULL" ",wire_fee_val INT8 NOT NULL" ",wire_fee_frac INT4 NOT NULL" - ",wire_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",closing_fee_val INT8 NOT NULL" ",closing_fee_frac INT4 NOT NULL" - ",closing_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)" ",PRIMARY KEY (wire_method, start_date)" /* this combo must be unique */ ");"), @@ -449,7 +456,6 @@ postgres_create_tables (void *cls) ",coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)" ",amount_val INT8 NOT NULL" ",amount_frac INT4 NOT NULL" - ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",timestamp INT8 NOT NULL" ",h_blind_ev BYTEA NOT NULL REFERENCES reserves_out (h_blind_ev) ON DELETE CASCADE" ");"), @@ -470,7 +476,6 @@ postgres_create_tables (void *cls) ",coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)" ",amount_val INT8 NOT NULL" ",amount_frac INT4 NOT NULL" - ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",timestamp INT8 NOT NULL" ",h_blind_ev BYTEA NOT NULL REFERENCES refresh_revealed_coins (h_coin_ev) ON DELETE CASCADE" ");"), @@ -515,7 +520,6 @@ postgres_create_tables (void *cls) "(merchant_serial_id BIGSERIAL NOT NULL REFERENCES kyc_merchants (merchant_serial_id) ON DELETE CASCADE" ",amount_val INT8 NOT NULL" ",amount_frac INT4 NOT NULL" - ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",timestamp INT8 NOT NULL" ");"), @@ -564,24 +568,18 @@ postgres_prepare (PGconn *db_conn) ",expire_legal" ",coin_val" /* value of this denom */ ",coin_frac" /* fractional value of this denom */ - ",coin_curr" /* assuming same currency for fees */ ",fee_withdraw_val" ",fee_withdraw_frac" - ",fee_withdraw_curr" /* must match coin_curr */ ",fee_deposit_val" ",fee_deposit_frac" - ",fee_deposit_curr" /* must match coin_curr */ ",fee_refresh_val" ",fee_refresh_frac" - ",fee_refresh_curr" /* must match coin_curr */ ",fee_refund_val" ",fee_refund_frac" - ",fee_refund_curr" /* must match coin_curr */ ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," - " $11, $12, $13, $14, $15, $16, $17, $18," - " $19, $20, $21, $22, $23);", - 23), + " $11, $12, $13, $14, $15, $16, $17, $18);", + 18), /* Used in #postgres_iterate_denomination_info() */ GNUNET_PQ_make_prepare ("denomination_iterate", "SELECT" @@ -593,19 +591,14 @@ postgres_prepare (PGconn *db_conn) ",expire_legal" ",coin_val" /* value of this denom */ ",coin_frac" /* fractional value of this denom */ - ",coin_curr" /* assuming same currency for fees */ ",fee_withdraw_val" ",fee_withdraw_frac" - ",fee_withdraw_curr" /* must match coin_curr */ ",fee_deposit_val" ",fee_deposit_frac" - ",fee_deposit_curr" /* must match coin_curr */ ",fee_refresh_val" ",fee_refresh_frac" - ",fee_refresh_curr" /* must match coin_curr */ ",fee_refund_val" ",fee_refund_frac" - ",fee_refund_curr" /* must match coin_curr */ ",denom_pub" " FROM denominations;", 0), @@ -620,19 +613,14 @@ postgres_prepare (PGconn *db_conn) ",expire_legal" ",coin_val" /* value of this denom */ ",coin_frac" /* fractional value of this denom */ - ",coin_curr" /* assuming same currency for fees */ ",fee_withdraw_val" ",fee_withdraw_frac" - ",fee_withdraw_curr" /* must match coin_curr */ ",fee_deposit_val" ",fee_deposit_frac" - ",fee_deposit_curr" /* must match coin_curr */ ",fee_refresh_val" ",fee_refresh_frac" - ",fee_refresh_curr" /* must match coin_curr */ ",fee_refund_val" ",fee_refund_frac" - ",fee_refund_curr" /* must match coin_curr */ " FROM denominations" " WHERE denom_pub_hash=$1;", 1), @@ -657,7 +645,6 @@ postgres_prepare (PGconn *db_conn) "SELECT" " current_balance_val" ",current_balance_frac" - ",current_balance_curr" ",expiration_date" ",gc_date" " FROM reserves" @@ -672,12 +659,11 @@ postgres_prepare (PGconn *db_conn) ",account_details" ",current_balance_val" ",current_balance_frac" - ",current_balance_curr" ",expiration_date" ",gc_date" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);", - 7), + "($1, $2, $3, $4, $5, $6);", + 6), /* Used in #postgres_insert_reserve_closed() */ GNUNET_PQ_make_prepare ("reserves_close_insert", "INSERT INTO reserves_close " @@ -687,13 +673,11 @@ postgres_prepare (PGconn *db_conn) ",receiver_account" ",amount_val" ",amount_frac" - ",amount_curr" ",closing_fee_val" ",closing_fee_frac" - ",closing_fee_curr" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);", - 10), + "($1, $2, $3, $4, $5, $6, $7, $8);", + 8), /* Used in #reserves_update() when the reserve is updated */ GNUNET_PQ_make_prepare ("reserve_update", "UPDATE reserves" @@ -702,10 +686,9 @@ postgres_prepare (PGconn *db_conn) ",gc_date=$2" ",current_balance_val=$3" ",current_balance_frac=$4" - ",current_balance_curr=$5" " WHERE" - " reserve_pub=$6;", - 6), + " reserve_pub=$5;", + 5), /* Used in #postgres_reserves_in_insert() to store transaction details */ GNUNET_PQ_make_prepare ("reserves_in_add_transaction", "INSERT INTO reserves_in " @@ -713,14 +696,13 @@ postgres_prepare (PGconn *db_conn) ",wire_reference" ",credit_val" ",credit_frac" - ",credit_curr" ",exchange_account_section" ",sender_account_details" ",execution_date" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8) " + "($1, $2, $3, $4, $5, $6, $7) " "ON CONFLICT DO NOTHING;", - 8), + 7), /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound transactions for reserves with serial id '\geq' the given parameter */ GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference", @@ -739,7 +721,6 @@ postgres_prepare (PGconn *db_conn) ",wire_reference" ",credit_val" ",credit_frac" - ",credit_curr" ",execution_date" ",sender_account_details" ",reserve_in_serial_id" @@ -755,7 +736,6 @@ postgres_prepare (PGconn *db_conn) ",wire_reference" ",credit_val" ",credit_frac" - ",credit_curr" ",execution_date" ",sender_account_details" ",reserve_in_serial_id" @@ -770,7 +750,6 @@ postgres_prepare (PGconn *db_conn) " wire_reference" ",credit_val" ",credit_frac" - ",credit_curr" ",execution_date" ",sender_account_details" " FROM reserves_in" @@ -800,10 +779,9 @@ postgres_prepare (PGconn *db_conn) ",execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);", - 9), + "($1, $2, $3, $4, $5, $6, $7, $8);", + 8), /* Used in #postgres_get_withdraw_info() to locate the response for a /reserve/withdraw request using the hash of the blinded message. Used to @@ -817,10 +795,8 @@ postgres_prepare (PGconn *db_conn) ",execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_withdraw_val" ",denom.fee_withdraw_frac" - ",denom.fee_withdraw_curr" " FROM reserves_out" " JOIN denominations denom" " USING (denom_pub_hash)" @@ -840,10 +816,8 @@ postgres_prepare (PGconn *db_conn) ",execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_withdraw_val" ",denom.fee_withdraw_frac" - ",denom.fee_withdraw_curr" " FROM reserves_out" " JOIN denominations denom" " USING (denom_pub_hash)" @@ -861,7 +835,6 @@ postgres_prepare (PGconn *db_conn) ",execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",reserve_out_serial_id" " FROM reserves_out" " JOIN denominations denom" @@ -909,11 +882,10 @@ postgres_prepare (PGconn *db_conn) ",old_coin_sig " ",amount_with_fee_val " ",amount_with_fee_frac " - ",amount_with_fee_curr " ",noreveal_index " ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);", - 7), + "($1, $2, $3, $4, $5, $6);", + 6), /* Used in #postgres_get_melt() to fetch high-level information about a melt operation */ GNUNET_PQ_make_prepare ("get_melt", @@ -921,13 +893,11 @@ postgres_prepare (PGconn *db_conn) " kc.denom_pub_hash" ",denom.fee_refresh_val" ",denom.fee_refresh_frac" - ",denom.fee_refresh_curr" ",kc.denom_sig" ",old_coin_pub" ",old_coin_sig" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",noreveal_index" " FROM refresh_commitments" " JOIN known_coins kc" @@ -953,7 +923,6 @@ postgres_prepare (PGconn *db_conn) ",old_coin_sig" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",noreveal_index" ",melt_serial_id" ",rc" @@ -972,10 +941,8 @@ postgres_prepare (PGconn *db_conn) ",old_coin_sig" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_refresh_val " ",denom.fee_refresh_frac " - ",denom.fee_refresh_curr " " FROM refresh_commitments" " JOIN known_coins " " ON (refresh_commitments.old_coin_pub = known_coins.coin_pub)" @@ -1045,10 +1012,9 @@ postgres_prepare (PGconn *db_conn) ",rtransaction_id " ",amount_with_fee_val " ",amount_with_fee_frac " - ",amount_with_fee_curr " ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);", - 8), + "($1, $2, $3, $4, $5, $6, $7);", + 7), /* Query the 'refunds' by coin public key */ GNUNET_PQ_make_prepare ("get_refunds_by_coin", "SELECT" @@ -1058,10 +1024,8 @@ postgres_prepare (PGconn *db_conn) ",rtransaction_id" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_refund_val " ",denom.fee_refund_frac " - ",denom.fee_refund_curr " " FROM refunds" " JOIN known_coins USING (coin_pub)" " JOIN denominations denom USING (denom_pub_hash)" @@ -1078,7 +1042,6 @@ postgres_prepare (PGconn *db_conn) ",coin_pub" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",refund_serial_id" " FROM refunds" " JOIN known_coins kc USING (coin_pub)" @@ -1099,7 +1062,6 @@ postgres_prepare (PGconn *db_conn) "(coin_pub" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",timestamp" ",refund_deadline" ",wire_deadline" @@ -1110,15 +1072,14 @@ postgres_prepare (PGconn *db_conn) ",wire" ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," - " $11, $12);", - 12), + " $11);", + 11), /* Fetch an existing deposit request, used to ensure idempotency during /deposit processing. Used in #postgres_have_deposit(). */ GNUNET_PQ_make_prepare ("get_deposit", "SELECT" " amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",timestamp" ",refund_deadline" ",wire_deadline" @@ -1135,7 +1096,6 @@ postgres_prepare (PGconn *db_conn) "SELECT" " amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",timestamp" ",merchant_pub" ",denom.denom_pub" @@ -1161,10 +1121,8 @@ postgres_prepare (PGconn *db_conn) "SELECT" " amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" ",wire_deadline" " FROM deposits" " JOIN known_coins USING (coin_pub)" @@ -1182,10 +1140,8 @@ postgres_prepare (PGconn *db_conn) " deposit_serial_id" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" ",wire_deadline" ",h_contract_terms" ",wire" @@ -1207,10 +1163,8 @@ postgres_prepare (PGconn *db_conn) " deposit_serial_id" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" ",wire_deadline" ",h_contract_terms" ",coin_pub" @@ -1253,10 +1207,8 @@ postgres_prepare (PGconn *db_conn) "SELECT" " amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" ",timestamp" ",refund_deadline" ",wire_deadline" @@ -1303,10 +1255,8 @@ postgres_prepare (PGconn *db_conn) ",wire_out.execution_date" ",deposits.amount_with_fee_val" ",deposits.amount_with_fee_frac" - ",deposits.amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" ",denom.denom_pub" " FROM aggregation_tracking" " JOIN deposits" @@ -1326,10 +1276,8 @@ postgres_prepare (PGconn *db_conn) ",wire_out.execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" - ",amount_with_fee_curr" ",denom.fee_deposit_val" ",denom.fee_deposit_frac" - ",denom.fee_deposit_curr" " FROM deposits" " JOIN aggregation_tracking" " USING (deposit_serial_id)" @@ -1359,10 +1307,8 @@ postgres_prepare (PGconn *db_conn) ",end_date" ",wire_fee_val" ",wire_fee_frac" - ",wire_fee_curr" ",closing_fee_val" ",closing_fee_frac" - ",closing_fee_curr" ",master_sig" " FROM wire_fee" " WHERE wire_method=$1" @@ -1377,14 +1323,12 @@ postgres_prepare (PGconn *db_conn) ",end_date" ",wire_fee_val" ",wire_fee_frac" - ",wire_fee_curr" ",closing_fee_val" ",closing_fee_frac" - ",closing_fee_curr" ",master_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);", - 19), + "($1, $2, $3, $4, $5, $6, $7, $8);", + 8), /* Used in #postgres_store_wire_transfer_out */ GNUNET_PQ_make_prepare ("insert_wire_out", "INSERT INTO wire_out " @@ -1394,10 +1338,9 @@ postgres_prepare (PGconn *db_conn) ",exchange_account_section" ",amount_val" ",amount_frac" - ",amount_curr" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);", - 7), + "($1, $2, $3, $4, $5, $6);", + 6), /* Used in #postgres_wire_prepare_data_insert() to store wire transfer information before actually committing it with the bank */ GNUNET_PQ_make_prepare ("wire_prepare_data_insert", @@ -1438,7 +1381,6 @@ postgres_prepare (PGconn *db_conn) " merchant_serial_id" ",amount_val" ",amount_frac" - ",amount_curr" " FROM kyc_events" " WHERE merchant_serial_id=$1", 1), @@ -1483,33 +1425,31 @@ postgres_prepare (PGconn *db_conn) "(merchant_serial_id" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp)" - " VALUES ($1, $2, $3, $4, $5)", - 5), + " VALUES ($1, $2, $3, $4)", + 4), /* Used in #postgres_select_deposits_missing_wire */ GNUNET_PQ_make_prepare ("deposits_get_overdue", - "SELECT" - " deposit_serial_id" - ",coin_pub" - ",amount_with_fee_val" - ",amount_with_fee_frac" - ",amount_with_fee_curr" - ",wire" - ",wire_deadline" - ",tiny" - ",done" - " FROM deposits" - " WHERE wire_deadline >= $1" - " AND wire_deadline < $2" - " AND NOT (EXISTS (SELECT 1" - " FROM refunds" - " WHERE (refunds.coin_pub = deposits.coin_pub))" - " OR EXISTS (SELECT 1" - " FROM aggregation_tracking" - " WHERE (aggregation_tracking.deposit_serial_id = deposits.deposit_serial_id)))" - " ORDER BY wire_deadline ASC", + "SELECT" + " deposit_serial_id" + ",coin_pub" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",wire" + ",wire_deadline" + ",tiny" + ",done" + " FROM deposits" + " WHERE wire_deadline >= $1" + " AND wire_deadline < $2" + " AND NOT (EXISTS (SELECT 1" + " FROM refunds" + " WHERE (refunds.coin_pub = deposits.coin_pub))" + " OR EXISTS (SELECT 1" + " FROM aggregation_tracking" + " WHERE (aggregation_tracking.deposit_serial_id = deposits.deposit_serial_id)))" + " ORDER BY wire_deadline ASC", 2), /* Used in #postgres_gc() */ GNUNET_PQ_make_prepare ("gc_prewire", @@ -1526,7 +1466,6 @@ postgres_prepare (PGconn *db_conn) ",wire_target" ",amount_val" ",amount_frac" - ",amount_curr" " FROM wire_out" " WHERE wireout_uuid>=$1" " ORDER BY wireout_uuid ASC;", @@ -1540,7 +1479,6 @@ postgres_prepare (PGconn *db_conn) ",wire_target" ",amount_val" ",amount_frac" - ",amount_curr" " FROM wire_out" " WHERE wireout_uuid>=$1 AND exchange_account_section=$2" " ORDER BY wireout_uuid ASC;", @@ -1554,12 +1492,11 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",h_blind_ev" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);", - 8), + "($1, $2, $3, $4, $5, $6, $7);", + 7), /* Used in #postgres_insert_payback_request() to store payback-refresh information */ GNUNET_PQ_make_prepare ("payback_refresh_insert", @@ -1569,12 +1506,11 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",h_blind_ev" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);", - 8), + "($1, $2, $3, $4, $5, $6, $7);", + 7), /* Used in #postgres_select_payback_above_serial_id() to obtain payback transactions */ GNUNET_PQ_make_prepare ("payback_get_incr", "SELECT" @@ -1590,7 +1526,6 @@ postgres_prepare (PGconn *db_conn) ",coins.denom_sig" ",amount_val" ",amount_frac" - ",amount_curr" " FROM payback" " JOIN known_coins coins" " USING (coin_pub)" @@ -1617,7 +1552,6 @@ postgres_prepare (PGconn *db_conn) ",coins.denom_sig" ",amount_val" ",amount_frac" - ",amount_curr" " FROM payback_refresh" " JOIN refresh_revealed_coins rrc" " ON (rrc.coin_ev = h_blind_ev)" @@ -1641,10 +1575,8 @@ postgres_prepare (PGconn *db_conn) ",receiver_account" ",amount_val" ",amount_frac" - ",amount_curr" ",closing_fee_val" ",closing_fee_frac" - ",closing_fee_curr" " FROM reserves_close" " WHERE close_uuid>=$1" " ORDER BY close_uuid ASC;", @@ -1658,7 +1590,6 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",coins.denom_pub_hash" ",coins.denom_sig" @@ -1679,7 +1610,6 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",coins.denom_pub_hash" ",coins.denom_sig" @@ -1699,10 +1629,8 @@ postgres_prepare (PGconn *db_conn) "SELECT" " amount_val" ",amount_frac" - ",amount_curr" ",closing_fee_val" ",closing_fee_frac" - ",closing_fee_curr" ",execution_date" ",receiver_account" ",wtid" @@ -1718,7 +1646,6 @@ postgres_prepare (PGconn *db_conn) ",reserve_pub" ",current_balance_val" ",current_balance_frac" - ",current_balance_curr" " FROM reserves" " WHERE expiration_date<=$1" " AND (current_balance_val != 0 " @@ -1735,7 +1662,6 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",coins.denom_pub_hash" ",coins.denom_sig" @@ -1756,7 +1682,6 @@ postgres_prepare (PGconn *db_conn) ",coin_blind" ",amount_val" ",amount_frac" - ",amount_curr" ",timestamp" ",coins.denom_pub_hash" ",coins.denom_sig" @@ -1862,8 +1787,8 @@ postgres_get_session (void *cls) * DB. Needed after the database server restarts as we need to * properly reconnect. */ GNUNET_assert (0 == - pthread_setspecific (pc->db_conn_threadlocal, - NULL)); + pthread_setspecific (pc->db_conn_threadlocal, + NULL)); PQfinish (session->conn); GNUNET_free (session); } @@ -2089,8 +2014,8 @@ postgres_insert_denomination_info (void *cls, &issue->properties.fee_refund)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "denomination_insert", - params); + "denomination_insert", + params); } @@ -2109,6 +2034,7 @@ postgres_get_denomination_info (void *cls, const struct GNUNET_HashCode *denom_pub_hash, struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) { + struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), @@ -2116,34 +2042,34 @@ postgres_get_denomination_info (void *cls, }; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("master_pub", - &issue->properties.master), + &issue->properties.master), GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &issue->signature), + &issue->signature), TALER_PQ_result_spec_absolute_time_nbo ("valid_from", - &issue->properties.start), + &issue->properties.start), TALER_PQ_result_spec_absolute_time_nbo ("expire_withdraw", - &issue->properties.expire_withdraw), + &issue->properties.expire_withdraw), TALER_PQ_result_spec_absolute_time_nbo ("expire_deposit", - &issue->properties.expire_deposit), + &issue->properties.expire_deposit), TALER_PQ_result_spec_absolute_time_nbo ("expire_legal", - &issue->properties.expire_legal), - TALER_PQ_result_spec_amount_nbo ("coin", - &issue->properties.value), - TALER_PQ_result_spec_amount_nbo ("fee_withdraw", - &issue->properties.fee_withdraw), - TALER_PQ_result_spec_amount_nbo ("fee_deposit", - &issue->properties.fee_deposit), - TALER_PQ_result_spec_amount_nbo ("fee_refresh", - &issue->properties.fee_refresh), - TALER_PQ_result_spec_amount_nbo ("fee_refund", - &issue->properties.fee_refund), + &issue->properties.expire_legal), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("coin", + &issue->properties.value), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_withdraw", + &issue->properties.fee_withdraw), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_deposit", + &issue->properties.fee_deposit), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refresh", + &issue->properties.fee_refresh), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refund", + &issue->properties.fee_refund), GNUNET_PQ_result_spec_end }; qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "denomination_get", - params, - rs); + "denomination_get", + params, + rs); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) return qs; issue->properties.purpose.size = htonl (sizeof (struct TALER_DenominationKeyValidityPS)); @@ -2167,6 +2093,11 @@ struct DenomIteratorContext * Closure to pass to @e cb */ void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; }; @@ -2184,7 +2115,8 @@ domination_cb_helper (void *cls, unsigned int num_results) { struct DenomIteratorContext *dic = cls; - + struct PostgresClosure *pg = dic->pg; + for (unsigned int i=0;iconn, - "denomination_iterate", - params, - &domination_cb_helper, - &dic); + "denomination_iterate", + params, + &domination_cb_helper, + &dic); } @@ -2284,12 +2217,13 @@ postgres_reserve_get (void *cls, struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Reserve *reserve) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type(&reserve->pub), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount("current_balance", &reserve->balance), + TALER_PQ_RESULT_SPEC_AMOUNT("current_balance", &reserve->balance), TALER_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry), TALER_PQ_result_spec_absolute_time("gc_date", &reserve->gc), GNUNET_PQ_result_spec_end @@ -2515,15 +2449,15 @@ postgres_get_latest_reserve_in_reference (void *cls, }; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_variable_size ("wire_reference", - wire_reference, - wire_reference_size), + wire_reference, + wire_reference_size), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "reserves_in_get_latest_wire_reference", - params, - rs); + "reserves_in_get_latest_wire_reference", + params, + rs); } @@ -2545,6 +2479,7 @@ postgres_get_withdraw_info (void *cls, const struct GNUNET_HashCode *h_blind, struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam no_params[] = { GNUNET_PQ_query_param_end }; @@ -2558,13 +2493,13 @@ postgres_get_withdraw_info (void *cls, GNUNET_PQ_result_spec_rsa_signature ("denom_sig", &collectable->sig.rsa_signature), GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &collectable->reserve_sig), + &collectable->reserve_sig), GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &collectable->reserve_pub), - TALER_PQ_result_spec_amount ("amount_with_fee", - &collectable->amount_with_fee), - TALER_PQ_result_spec_amount ("fee_withdraw", - &collectable->withdraw_fee), + &collectable->reserve_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &collectable->amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", + &collectable->withdraw_fee), GNUNET_PQ_result_spec_end }; enum GNUNET_DB_QueryStatus qs; @@ -2688,6 +2623,11 @@ struct ReserveHistoryContext */ struct TALER_EXCHANGEDB_ReserveHistory *rh_tail; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to #GNUNET_SYSERR on serious internal errors during * the callbacks. @@ -2732,10 +2672,11 @@ append_rh (struct ReserveHistoryContext *rhc) */ static void add_bank_to_exchange (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReserveHistoryContext *rhc = cls; + struct PostgresClosure *pg = rhc->pg; while (0 < num_results) { @@ -2745,27 +2686,27 @@ add_bank_to_exchange (void *cls, bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer); { struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_variable_size ("wire_reference", - &bt->wire_reference, - &bt->wire_reference_size), - TALER_PQ_result_spec_amount ("credit", - &bt->amount), - TALER_PQ_result_spec_absolute_time ("execution_date", - &bt->execution_date), - GNUNET_PQ_result_spec_string ("sender_account_details", + GNUNET_PQ_result_spec_variable_size ("wire_reference", + &bt->wire_reference, + &bt->wire_reference_size), + TALER_PQ_RESULT_SPEC_AMOUNT ("credit", + &bt->amount), + TALER_PQ_result_spec_absolute_time ("execution_date", + &bt->execution_date), + GNUNET_PQ_result_spec_string ("sender_account_details", &bt->sender_account_details), - GNUNET_PQ_result_spec_end + GNUNET_PQ_result_spec_end }; if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - --num_results)) + GNUNET_PQ_extract_result (result, + rs, + --num_results)) { - GNUNET_break (0); - GNUNET_free (bt); - rhc->status = GNUNET_SYSERR; - return; + GNUNET_break (0); + GNUNET_free (bt); + rhc->status = GNUNET_SYSERR; + return; } } bt->reserve_pub = *rhc->reserve_pub; @@ -2785,10 +2726,11 @@ add_bank_to_exchange (void *cls, */ static void add_withdraw_coin (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReserveHistoryContext *rhc = cls; + struct PostgresClosure *pg = rhc->pg; while (0 < num_results) { @@ -2798,30 +2740,30 @@ add_withdraw_coin (void *cls, cbc = GNUNET_new (struct TALER_EXCHANGEDB_CollectableBlindcoin); { struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev", - &cbc->h_coin_envelope), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &cbc->denom_pub_hash), - GNUNET_PQ_result_spec_rsa_signature ("denom_sig", - &cbc->sig.rsa_signature), - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &cbc->reserve_sig), - TALER_PQ_result_spec_amount ("amount_with_fee", - &cbc->amount_with_fee), - TALER_PQ_result_spec_amount ("fee_withdraw", - &cbc->withdraw_fee), - GNUNET_PQ_result_spec_end + GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev", + &cbc->h_coin_envelope), + GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", + &cbc->denom_pub_hash), + GNUNET_PQ_result_spec_rsa_signature ("denom_sig", + &cbc->sig.rsa_signature), + GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", + &cbc->reserve_sig), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &cbc->amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", + &cbc->withdraw_fee), + GNUNET_PQ_result_spec_end }; if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - --num_results)) + GNUNET_PQ_extract_result (result, + rs, + --num_results)) { - GNUNET_break (0); - GNUNET_free (cbc); - rhc->status = GNUNET_SYSERR; - return; + GNUNET_break (0); + GNUNET_free (cbc); + rhc->status = GNUNET_SYSERR; + return; } } cbc->reserve_pub = *rhc->reserve_pub; @@ -2841,10 +2783,11 @@ add_withdraw_coin (void *cls, */ static void add_payback (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReserveHistoryContext *rhc = cls; + struct PostgresClosure *pg = rhc->pg; while (0 < num_results) { @@ -2854,32 +2797,32 @@ add_payback (void *cls, payback = GNUNET_new (struct TALER_EXCHANGEDB_Payback); { struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount", - &payback->value), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &payback->coin.coin_pub), - GNUNET_PQ_result_spec_auto_from_type ("coin_blind", - &payback->coin_blind), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &payback->coin_sig), - TALER_PQ_result_spec_absolute_time ("timestamp", - &payback->timestamp), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &payback->coin.denom_pub_hash), - GNUNET_PQ_result_spec_rsa_signature ("denom_sig", - &payback->coin.denom_sig.rsa_signature), - GNUNET_PQ_result_spec_end + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &payback->value), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &payback->coin.coin_pub), + GNUNET_PQ_result_spec_auto_from_type ("coin_blind", + &payback->coin_blind), + GNUNET_PQ_result_spec_auto_from_type ("coin_sig", + &payback->coin_sig), + TALER_PQ_result_spec_absolute_time ("timestamp", + &payback->timestamp), + GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", + &payback->coin.denom_pub_hash), + GNUNET_PQ_result_spec_rsa_signature ("denom_sig", + &payback->coin.denom_sig.rsa_signature), + GNUNET_PQ_result_spec_end }; if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - --num_results)) + GNUNET_PQ_extract_result (result, + rs, + --num_results)) { - GNUNET_break (0); - GNUNET_free (payback); - rhc->status = GNUNET_SYSERR; - return; + GNUNET_break (0); + GNUNET_free (payback); + rhc->status = GNUNET_SYSERR; + return; } } payback->reserve_pub = *rhc->reserve_pub; @@ -2900,11 +2843,12 @@ add_payback (void *cls, */ static void add_exchange_to_bank (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReserveHistoryContext *rhc = cls; - + struct PostgresClosure *pg = rhc->pg; + while (0 < num_results) { struct TALER_EXCHANGEDB_ClosingTransfer *closing; @@ -2913,9 +2857,9 @@ add_exchange_to_bank (void *cls, closing = GNUNET_new (struct TALER_EXCHANGEDB_ClosingTransfer); { struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &closing->amount), - TALER_PQ_result_spec_amount ("closing_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee", &closing->closing_fee), TALER_PQ_result_spec_absolute_time ("execution_date", &closing->execution_date), @@ -2959,8 +2903,9 @@ static enum GNUNET_DB_QueryStatus postgres_get_reserve_history (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_EXCHANGEDB_ReserveHistory **rhp) + struct TALER_EXCHANGEDB_ReserveHistory **rhp) { + struct PostgresClosure *pg = cls; struct ReserveHistoryContext rhc; struct { /** @@ -2997,6 +2942,7 @@ postgres_get_reserve_history (void *cls, rhc.reserve_pub = reserve_pub; rhc.rh = NULL; rhc.rh_tail = NULL; + rhc.pg = pg; rhc.status = GNUNET_OK; qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */ for (unsigned int i=0;NULL != work[i].cb;i++) @@ -3044,6 +2990,7 @@ postgres_have_deposit (void *cls, const struct TALER_EXCHANGEDB_Deposit *deposit, int check_extras) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub), GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms), @@ -3055,7 +3002,7 @@ postgres_have_deposit (void *cls, }; struct TALER_EXCHANGEDB_Deposit deposit2; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &deposit2.amount_with_fee), TALER_PQ_result_spec_absolute_time ("timestamp", &deposit2.timestamp), @@ -3125,8 +3072,8 @@ postgres_mark_deposit_tiny (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "mark_deposit_tiny", - params); + "mark_deposit_tiny", + params); } @@ -3156,15 +3103,15 @@ postgres_test_deposit_done (void *cls, uint8_t done = 0; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("done", - &done), + &done), GNUNET_PQ_result_spec_end }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "test_deposit_done", - params, - rs); + "test_deposit_done", + params, + rs); if (qs < 0) return qs; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) @@ -3196,8 +3143,8 @@ postgres_mark_deposit_done (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "mark_deposit_done", - params); + "mark_deposit_done", + params); } @@ -3218,6 +3165,7 @@ postgres_get_ready_deposit (void *cls, TALER_EXCHANGEDB_DepositIterator deposit_cb, void *deposit_cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); struct GNUNET_PQ_QueryParam params[] = { TALER_PQ_query_param_absolute_time (&now), @@ -3233,19 +3181,19 @@ postgres_get_ready_deposit (void *cls, json_t *wire; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("deposit_serial_id", - &serial_id), - TALER_PQ_result_spec_amount ("amount_with_fee", - &amount_with_fee), - TALER_PQ_result_spec_amount ("fee_deposit", - &deposit_fee), + &serial_id), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", + &deposit_fee), TALER_PQ_result_spec_absolute_time ("wire_deadline", - &wire_deadline), + &wire_deadline), GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &h_contract_terms), + &h_contract_terms), GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", - &merchant_pub), + &merchant_pub), GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), + &coin_pub), TALER_PQ_result_spec_json ("wire", &wire), GNUNET_PQ_result_spec_end @@ -3254,26 +3202,26 @@ postgres_get_ready_deposit (void *cls, (void) GNUNET_TIME_round_abs (&now); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Finding ready deposits by deadline %s (%llu)\n", - GNUNET_STRINGS_absolute_time_to_string (now), - (unsigned long long) now.abs_value_us); + "Finding ready deposits by deadline %s (%llu)\n", + GNUNET_STRINGS_absolute_time_to_string (now), + (unsigned long long) now.abs_value_us); qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "deposits_get_ready", - params, - rs); + "deposits_get_ready", + params, + rs); if (qs <= 0) return qs; qs = deposit_cb (deposit_cb_cls, - serial_id, - &merchant_pub, - &coin_pub, - &amount_with_fee, - &deposit_fee, - &h_contract_terms, - wire_deadline, - wire); + serial_id, + &merchant_pub, + &coin_pub, + &amount_with_fee, + &deposit_fee, + &h_contract_terms, + wire_deadline, + wire); GNUNET_PQ_cleanup_result (rs); return qs; } @@ -3299,6 +3247,11 @@ struct MatchingDepositContext */ const struct TALER_MerchantPublicKeyP *merchant_pub; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Maximum number of results to return. */ @@ -3327,17 +3280,18 @@ struct MatchingDepositContext */ static void match_deposit_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct MatchingDepositContext *mdc = cls; + struct PostgresClosure *pg = mdc->pg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u/%u matching deposits\n", - num_results, - mdc->limit); + num_results, + mdc->limit); num_results = GNUNET_MIN (num_results, - mdc->limit); + mdc->limit); for (mdc->i=0;mdc->ii++) { struct TALER_Amount amount_with_fee; @@ -3350,9 +3304,9 @@ match_deposit_cb (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("deposit_serial_id", &serial_id), - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &amount_with_fee), - TALER_PQ_result_spec_amount ("fee_deposit", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", &deposit_fee), TALER_PQ_result_spec_absolute_time ("wire_deadline", &wire_deadline), @@ -3373,14 +3327,14 @@ match_deposit_cb (void *cls, return; } qs = mdc->deposit_cb (mdc->deposit_cb_cls, - serial_id, - mdc->merchant_pub, - &coin_pub, - &amount_with_fee, - &deposit_fee, - &h_contract_terms, - wire_deadline, - NULL); + serial_id, + mdc->merchant_pub, + &coin_pub, + &amount_with_fee, + &deposit_fee, + &h_contract_terms, + wire_deadline, + NULL); GNUNET_PQ_cleanup_result (rs); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) break; @@ -3411,6 +3365,7 @@ postgres_iterate_matching_deposits (void *cls, void *deposit_cb_cls, uint32_t limit) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_auto_from_type (h_wire), @@ -3422,13 +3377,14 @@ postgres_iterate_matching_deposits (void *cls, mdc.deposit_cb = deposit_cb; mdc.deposit_cb_cls = deposit_cb_cls; mdc.merchant_pub = merchant_pub; + mdc.pg = pg; mdc.limit = limit; mdc.status = GNUNET_OK; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "deposits_iterate_matching", - params, - &match_deposit_cb, - &mdc); + "deposits_iterate_matching", + params, + &match_deposit_cb, + &mdc); if (GNUNET_OK != mdc.status) { GNUNET_break (0); @@ -3464,7 +3420,7 @@ postgres_get_known_coin (void *cls, GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &coin_info->denom_pub_hash), GNUNET_PQ_result_spec_rsa_signature ("denom_sig", - &coin_info->denom_sig.rsa_signature), + &coin_info->denom_sig.rsa_signature), GNUNET_PQ_result_spec_end }; @@ -3475,9 +3431,9 @@ postgres_get_known_coin (void *cls, if (NULL == session) session = postgres_get_session (pc); return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "get_known_coin", - params, - rs); + "get_known_coin", + params, + rs); } @@ -3668,8 +3624,8 @@ postgres_insert_refund (void *cls, TALER_amount_cmp_currency (&refund->refund_amount, &refund->refund_fee)); return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_refund", - params); + "insert_refund", + params); } @@ -3688,6 +3644,11 @@ struct SelectRefundContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to #GNUNET_SYSERR on error. */ @@ -3709,6 +3670,7 @@ get_refunds_cb (void *cls, unsigned int num_results) { struct SelectRefundContext *srctx = cls; + struct PostgresClosure *pg = srctx->pg; for (unsigned int i=0;istatus = GNUNET_SYSERR; return; } if (GNUNET_OK != - srctx->cb (srctx->cb_cls, - &merchant_pub, - &merchant_sig, - &h_contract, - rtransaction_id, - &amount_with_fee, - &refund_fee)) + srctx->cb (srctx->cb_cls, + &merchant_pub, + &merchant_sig, + &h_contract, + rtransaction_id, + &amount_with_fee, + &refund_fee)) return; } } @@ -3768,11 +3730,12 @@ get_refunds_cb (void *cls, */ static enum GNUNET_DB_QueryStatus postgres_select_refunds_by_coin (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - TALER_EXCHANGEDB_RefundCoinCallback cb, - void *cb_cls) + struct TALER_EXCHANGEDB_Session *session, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + TALER_EXCHANGEDB_RefundCoinCallback cb, + void *cb_cls) { + struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (coin_pub), @@ -3781,6 +3744,7 @@ postgres_select_refunds_by_coin (void *cls, struct SelectRefundContext srctx = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; @@ -3810,7 +3774,7 @@ postgres_get_melt (void *cls, const struct TALER_RefreshCommitmentP *rc, struct TALER_EXCHANGEDB_RefreshMelt *refresh_melt) { - struct PostgresClosure *pc = cls; + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (rc), GNUNET_PQ_query_param_end @@ -3818,7 +3782,7 @@ postgres_get_melt (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &refresh_melt->session.coin.denom_pub_hash), - TALER_PQ_result_spec_amount ("fee_refresh", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", &refresh_melt->melt_fee), GNUNET_PQ_result_spec_rsa_signature ("denom_sig", &refresh_melt->session.coin.denom_sig.rsa_signature), @@ -3828,14 +3792,14 @@ postgres_get_melt (void *cls, &refresh_melt->session.coin.coin_pub), GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig", &refresh_melt->session.coin_sig), - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &refresh_melt->session.amount_with_fee), GNUNET_PQ_result_spec_end }; enum GNUNET_DB_QueryStatus qs; if (NULL == session) - session = postgres_get_session (pc); + session = postgres_get_session (pg); qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, "get_melt", params, @@ -3867,7 +3831,7 @@ postgres_get_melt_index (void *cls, }; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint32 ("noreveal_index", - noreveal_index), + noreveal_index), GNUNET_PQ_result_spec_end }; @@ -4041,12 +4005,12 @@ add_revealed_coins (void *cls, GNUNET_PQ_result_spec_uint32 ("newcoin_index", &off), GNUNET_PQ_result_spec_rsa_public_key ("denom_pub", - &rrc->denom_pub.rsa_public_key), + &rrc->denom_pub.rsa_public_key), GNUNET_PQ_result_spec_auto_from_type ("link_sig", &rrc->orig_coin_link_sig), GNUNET_PQ_result_spec_variable_size ("coin_ev", - (void **) &rrc->coin_ev, - &rrc->coin_ev_size), + (void **) &rrc->coin_ev, + &rrc->coin_ev_size), GNUNET_PQ_result_spec_rsa_signature ("ev_sig", &rrc->coin_sig.rsa_signature), GNUNET_PQ_result_spec_end @@ -4280,14 +4244,14 @@ add_ldl (void *cls, }; if (GNUNET_OK != - GNUNET_PQ_extract_result (result, + GNUNET_PQ_extract_result (result, rs, i)) { - GNUNET_break (0); - GNUNET_free (pos); - ldctx->status = GNUNET_SYSERR; - return; + GNUNET_break (0); + GNUNET_free (pos); + ldctx->status = GNUNET_SYSERR; + return; } } if ( (NULL != ldctx->last) && @@ -4391,6 +4355,11 @@ struct CoinHistoryContext */ struct TALER_EXCHANGEDB_Session *session; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to transaction status. */ @@ -4412,7 +4381,8 @@ add_coin_deposit (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; - + struct PostgresClosure *pg = chc->pg; + for (unsigned int i = 0; i < num_results; i++) { struct TALER_EXCHANGEDB_Deposit *deposit; @@ -4422,9 +4392,9 @@ add_coin_deposit (void *cls, deposit = GNUNET_new (struct TALER_EXCHANGEDB_Deposit); { struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &deposit->amount_with_fee), - TALER_PQ_result_spec_amount ("fee_deposit", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", &deposit->deposit_fee), TALER_PQ_result_spec_absolute_time ("timestamp", &deposit->timestamp), @@ -4491,6 +4461,7 @@ add_coin_melt (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; for (unsigned int i=0;isession.coin_sig), - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &melt->session.amount_with_fee), - TALER_PQ_result_spec_amount ("fee_refresh", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", &melt->melt_fee), GNUNET_PQ_result_spec_end }; @@ -4560,6 +4531,7 @@ add_coin_refund (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; for (unsigned int i=0;ih_contract_terms), GNUNET_PQ_result_spec_uint64 ("rtransaction_id", &refund->rtransaction_id), - TALER_PQ_result_spec_amount ("amount_with_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &refund->refund_amount), - TALER_PQ_result_spec_amount ("fee_refund", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", &refund->refund_fee), GNUNET_PQ_result_spec_end }; @@ -4631,6 +4603,7 @@ add_old_coin_payback (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; for (unsigned int i=0;icoin_sig), GNUNET_PQ_result_spec_auto_from_type ("coin_blind", &payback->coin_blind), - TALER_PQ_result_spec_amount ("amount", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &payback->value), TALER_PQ_result_spec_absolute_time ("timestamp", &payback->timestamp), @@ -4692,6 +4665,7 @@ add_coin_payback (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; for (unsigned int i=0;ivalue), GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", &payback->reserve_pub), @@ -4753,6 +4727,7 @@ add_coin_payback_refresh (void *cls, unsigned int num_results) { struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; for (unsigned int i=0;icoin_sig), GNUNET_PQ_result_spec_auto_from_type ("coin_blind", &payback->coin_blind), - TALER_PQ_result_spec_amount ("amount", + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &payback->value), TALER_PQ_result_spec_absolute_time ("timestamp", &payback->timestamp), @@ -4834,6 +4809,7 @@ postgres_get_coin_transactions (void *cls, int include_payback, struct TALER_EXCHANGEDB_TransactionList **tlp) { + struct PostgresClosure *pg = cls; static const struct Work work_op[] = { /** #TALER_EXCHANGEDB_TT_DEPOSIT */ { "get_deposit_with_coin_pub", @@ -4883,6 +4859,7 @@ postgres_get_coin_transactions (void *cls, chc.status = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; chc.coin_pub = coin_pub; chc.session = session; + chc.pg = pg; chc.db_cls = cls; for (unsigned int i=0;NULL != work[i].statement; i++) { @@ -4925,6 +4902,11 @@ struct WireTransferResultContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to #GNUNET_SYSERR on serious errors. */ @@ -4947,6 +4929,7 @@ handle_wt_result (void *cls, unsigned int num_results) { struct WireTransferResultContext *ctx = cls; + struct PostgresClosure *pg = ctx->pg; for (unsigned int i=0;iconn, @@ -5053,17 +5038,18 @@ postgres_lookup_wire_transfer (void *cls, * @param cb function to call with the result * @param cb_cls closure to pass to @a cb * @return transaction status code - */ +- */ static enum GNUNET_DB_QueryStatus postgres_wire_lookup_deposit_wtid (void *cls, struct TALER_EXCHANGEDB_Session *session, - const struct GNUNET_HashCode *h_contract_terms, - const struct GNUNET_HashCode *h_wire, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_MerchantPublicKeyP *merchant_pub, - TALER_EXCHANGEDB_TrackTransactionCallback cb, - void *cb_cls) + const struct GNUNET_HashCode *h_contract_terms, + const struct GNUNET_HashCode *h_wire, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_EXCHANGEDB_TrackTransactionCallback cb, + void *cb_cls) { + struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (coin_pub), @@ -5079,8 +5065,8 @@ postgres_wire_lookup_deposit_wtid (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", &wtid), TALER_PQ_result_spec_absolute_time ("execution_date", &exec_time), - TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee), - TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", &deposit_fee), GNUNET_PQ_result_spec_end }; @@ -5103,7 +5089,7 @@ postgres_wire_lookup_deposit_wtid (void *cls, GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "lookup_deposit_wtid returned 0 matching rows\n"); + "lookup_deposit_wtid returned 0 matching rows\n"); { /* Check if transaction exists in deposits, so that we just do not have a WTID yet, if so, do call the CB with a NULL wtid @@ -5119,16 +5105,16 @@ postgres_wire_lookup_deposit_wtid (void *cls, struct TALER_Amount amount_with_fee; struct TALER_Amount deposit_fee; struct GNUNET_PQ_ResultSpec rs2[] = { - TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee), - TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", &deposit_fee), TALER_PQ_result_spec_absolute_time ("wire_deadline", &exec_time), GNUNET_PQ_result_spec_end }; qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "get_deposit_for_wtid", - params2, - rs2); + "get_deposit_for_wtid", + params2, + rs2); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { /* Ok, we're aware of the transaction, but it has not yet been @@ -5168,8 +5154,8 @@ postgres_insert_aggregation_tracking (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_aggregation_tracking", - params); + "insert_aggregation_tracking", + params); } @@ -5195,9 +5181,10 @@ postgres_get_wire_fee (void *cls, struct GNUNET_TIME_Absolute *start_date, struct GNUNET_TIME_Absolute *end_date, struct TALER_Amount *wire_fee, - struct TALER_Amount *closing_fee, + struct TALER_Amount *closing_fee, struct TALER_MasterSignatureP *master_sig) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (type), TALER_PQ_query_param_absolute_time (&date), @@ -5206,16 +5193,16 @@ postgres_get_wire_fee (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_absolute_time ("start_date", start_date), TALER_PQ_result_spec_absolute_time ("end_date", end_date), - TALER_PQ_result_spec_amount ("wire_fee", wire_fee), - TALER_PQ_result_spec_amount ("closing_fee", closing_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee", wire_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee", closing_fee), GNUNET_PQ_result_spec_auto_from_type ("master_sig", master_sig), GNUNET_PQ_result_spec_end }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "get_wire_fee", - params, - rs); + "get_wire_fee", + params, + rs); } @@ -5242,6 +5229,7 @@ postgres_insert_wire_fee (void *cls, const struct TALER_Amount *closing_fee, const struct TALER_MasterSignatureP *master_sig) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (type), TALER_PQ_query_param_absolute_time (&start_date), @@ -5258,15 +5246,15 @@ postgres_insert_wire_fee (void *cls, struct GNUNET_TIME_Absolute ed; enum GNUNET_DB_QueryStatus qs; - qs = postgres_get_wire_fee (cls, - session, - type, - start_date, - &sd, - &ed, - &wf, - &cf, - &sig); + qs = postgres_get_wire_fee (pg, + session, + type, + start_date, + &sd, + &ed, + &wf, + &cf, + &sig); if (qs < 0) return qs; if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) @@ -5300,8 +5288,8 @@ postgres_insert_wire_fee (void *cls, } return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_wire_fee", - params); + "insert_wire_fee", + params); } @@ -5320,6 +5308,11 @@ struct ExpiredReserveContext */ void *rec_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to #GNUNET_SYSERR on error. */ @@ -5337,10 +5330,11 @@ struct ExpiredReserveContext */ static void reserve_expired_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ExpiredReserveContext *erc = cls; + struct PostgresClosure *pg = erc->pg; int ret; ret = GNUNET_OK; @@ -5352,30 +5346,30 @@ reserve_expired_cb (void *cls, struct TALER_Amount remaining_balance; struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_absolute_time ("expiration_date", - &exp_date), + &exp_date), GNUNET_PQ_result_spec_string ("account_details", &account_details), GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - TALER_PQ_result_spec_amount ("current_balance", - &remaining_balance), + &reserve_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance", + &remaining_balance), GNUNET_PQ_result_spec_end }; if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) + GNUNET_PQ_extract_result (result, + rs, + i)) { GNUNET_break (0); ret = GNUNET_SYSERR; break; } ret = erc->rec (erc->rec_cls, - &reserve_pub, - &remaining_balance, - account_details, - exp_date); + &reserve_pub, + &remaining_balance, + account_details, + exp_date); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -5397,11 +5391,12 @@ reserve_expired_cb (void *cls, */ static enum GNUNET_DB_QueryStatus postgres_get_expired_reserves (void *cls, - struct TALER_EXCHANGEDB_Session *session, - struct GNUNET_TIME_Absolute now, - TALER_EXCHANGEDB_ReserveExpiredCallback rec, - void *rec_cls) + struct TALER_EXCHANGEDB_Session *session, + struct GNUNET_TIME_Absolute now, + TALER_EXCHANGEDB_ReserveExpiredCallback rec, + void *rec_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { TALER_PQ_query_param_absolute_time (&now), GNUNET_PQ_query_param_end @@ -5411,12 +5406,13 @@ postgres_get_expired_reserves (void *cls, ectx.rec = rec; ectx.rec_cls = rec_cls; + ectx.pg = pg; ectx.status = GNUNET_OK; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "get_expired_reserves", - params, - &reserve_expired_cb, - &ectx); + "get_expired_reserves", + params, + &reserve_expired_cb, + &ectx); if (GNUNET_OK != ectx.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -5438,13 +5434,13 @@ postgres_get_expired_reserves (void *cls, */ static enum GNUNET_DB_QueryStatus postgres_insert_reserve_closed (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct GNUNET_TIME_Absolute execution_date, - const char *receiver_account, - const struct TALER_WireTransferIdentifierRawP *wtid, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *closing_fee) + struct TALER_EXCHANGEDB_Session *session, + const struct TALER_ReservePublicKeyP *reserve_pub, + struct GNUNET_TIME_Absolute execution_date, + const char *receiver_account, + const struct TALER_WireTransferIdentifierRawP *wtid, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *closing_fee) { struct TALER_EXCHANGEDB_Reserve reserve; struct GNUNET_PQ_QueryParam params[] = { @@ -5522,8 +5518,8 @@ postgres_wire_prepare_data_insert (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "wire_prepare_data_insert", - params); + "wire_prepare_data_insert", + params); } @@ -5546,8 +5542,8 @@ postgres_wire_prepare_data_mark_finished (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "wire_prepare_data_mark_done", - params); + "wire_prepare_data_mark_done", + params); } @@ -5577,19 +5573,19 @@ postgres_wire_prepare_data_get (void *cls, size_t buf_size; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("prewire_uuid", - &prewire_uuid), + &prewire_uuid), GNUNET_PQ_result_spec_string ("type", - &type), + &type), GNUNET_PQ_result_spec_variable_size ("buf", - &buf, - &buf_size), + &buf, + &buf_size), GNUNET_PQ_result_spec_end }; qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "wire_prepare_data_get", - params, - rs); + "wire_prepare_data_get", + params, + rs); if (0 >= qs) return qs; cb (cb_cls, @@ -5676,8 +5672,8 @@ postgres_store_wire_transfer_out (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_wire_out", - params); + "insert_wire_out", + params); } @@ -5692,7 +5688,7 @@ postgres_store_wire_transfer_out (void *cls, static int postgres_gc (void *cls) { - struct PostgresClosure *pc = cls; + struct PostgresClosure *pg = cls; struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute long_ago; struct GNUNET_PQ_QueryParam params_none[] = { @@ -5718,7 +5714,7 @@ postgres_gc (void *cls) GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 10)); /* FIXME: use GNUNET_PQ_connect_with_cfg instead? */ - conn = GNUNET_PQ_connect (pc->connection_cfg_str); + conn = GNUNET_PQ_connect (pg->connection_cfg_str); if (NULL == conn) return GNUNET_SYSERR; ret = postgres_prepare (conn); @@ -5766,6 +5762,11 @@ struct DepositSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -5783,11 +5784,12 @@ struct DepositSerialContext */ static void deposit_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct DepositSerialContext *dsc = cls; - + struct PostgresClosure *pg = dsc->pg; + for (unsigned int i=0;icb (dsc->cb_cls, - rowid, - deposit.timestamp, - &deposit.merchant_pub, - &denom_pub, - &deposit.coin.coin_pub, - &deposit.csig, - &deposit.amount_with_fee, - &deposit.h_contract_terms, - deposit.refund_deadline, - deposit.wire_deadline, - deposit.receiver_wire_account, - done); + rowid, + deposit.timestamp, + &deposit.merchant_pub, + &denom_pub, + &deposit.coin.coin_pub, + &deposit.csig, + &deposit.amount_with_fee, + &deposit.h_contract_terms, + deposit.refund_deadline, + deposit.wire_deadline, + deposit.receiver_wire_account, + done); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -5870,6 +5872,7 @@ postgres_select_deposits_above_serial_id (void *cls, TALER_EXCHANGEDB_DepositCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -5877,15 +5880,16 @@ postgres_select_deposits_above_serial_id (void *cls, struct DepositSerialContext dsc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_deposits_incr", - params, - &deposit_serial_helper_cb, - &dsc); + "audit_get_deposits_incr", + params, + &deposit_serial_helper_cb, + &dsc); if (GNUNET_OK != dsc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -5908,6 +5912,11 @@ struct RefreshsSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -5925,11 +5934,12 @@ struct RefreshsSerialContext */ static void refreshs_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct RefreshsSerialContext *rsc = cls; - + struct PostgresClosure *pg = rsc->pg; + for (unsigned int i=0;icb (rsc->cb_cls, - rowid, - &denom_pub, - &coin_pub, - &coin_sig, - &amount_with_fee, - noreveal_index, - &rc); + rowid, + &denom_pub, + &coin_pub, + &coin_sig, + &amount_with_fee, + noreveal_index, + &rc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -6000,6 +6010,7 @@ postgres_select_refreshs_above_serial_id (void *cls, TALER_EXCHANGEDB_RefreshSessionCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -6007,15 +6018,16 @@ postgres_select_refreshs_above_serial_id (void *cls, struct RefreshsSerialContext rsc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_refresh_commitments_incr", - params, - &refreshs_serial_helper_cb, - &rsc); + "audit_get_refresh_commitments_incr", + params, + &refreshs_serial_helper_cb, + &rsc); if (GNUNET_OK != rsc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6038,6 +6050,11 @@ struct RefundsSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -6055,11 +6072,12 @@ struct RefundsSerialContext */ static void refunds_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct RefundsSerialContext *rsc = cls; - + struct PostgresClosure *pg = rsc->pg; + for (unsigned int i=0;icb (rsc->cb_cls, - rowid, - &denom_pub, - &refund.coin.coin_pub, - &refund.merchant_pub, - &refund.merchant_sig, - &refund.h_contract_terms, - refund.rtransaction_id, - &refund.refund_amount); + rowid, + &denom_pub, + &refund.coin.coin_pub, + &refund.merchant_pub, + &refund.merchant_sig, + &refund.h_contract_terms, + refund.rtransaction_id, + &refund.refund_amount); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -6129,6 +6147,7 @@ postgres_select_refunds_above_serial_id (void *cls, TALER_EXCHANGEDB_RefundCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -6136,15 +6155,16 @@ postgres_select_refunds_above_serial_id (void *cls, struct RefundsSerialContext rsc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_refunds_incr", - params, - &refunds_serial_helper_cb, - &rsc); + "audit_get_refunds_incr", + params, + &refunds_serial_helper_cb, + &rsc); if (GNUNET_OK != rsc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6167,6 +6187,11 @@ struct ReservesInSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -6184,11 +6209,12 @@ struct ReservesInSerialContext */ static void reserves_in_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReservesInSerialContext *risc = cls; - + struct PostgresClosure *pg = risc->pg; + for (unsigned int i=0;icb (risc->cb_cls, - rowid, - &reserve_pub, - &credit, - sender_account_details, - wire_reference, - wire_reference_size, - execution_date); + rowid, + &reserve_pub, + &credit, + sender_account_details, + wire_reference, + wire_reference_size, + execution_date); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -6258,6 +6284,7 @@ postgres_select_reserves_in_above_serial_id (void *cls, TALER_EXCHANGEDB_ReserveInCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -6265,15 +6292,16 @@ postgres_select_reserves_in_above_serial_id (void *cls, struct ReservesInSerialContext risc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_reserves_in_get_transactions_incr", - params, - &reserves_in_serial_helper_cb, - &risc); + "audit_reserves_in_get_transactions_incr", + params, + &reserves_in_serial_helper_cb, + &risc); if (GNUNET_OK != risc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6300,6 +6328,7 @@ postgres_select_reserves_in_above_serial_id_by_account (void *cls, TALER_EXCHANGEDB_ReserveInCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_string (account_name), @@ -6308,15 +6337,16 @@ postgres_select_reserves_in_above_serial_id_by_account (void *cls, struct ReservesInSerialContext risc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_reserves_in_get_transactions_incr_by_account", - params, - &reserves_in_serial_helper_cb, - &risc); + "audit_reserves_in_get_transactions_incr_by_account", + params, + &reserves_in_serial_helper_cb, + &risc); if (GNUNET_OK != risc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6339,6 +6369,11 @@ struct ReservesOutSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -6356,11 +6391,12 @@ struct ReservesOutSerialContext */ static void reserves_out_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct ReservesOutSerialContext *rosc = cls; - + struct PostgresClosure *pg = rosc->pg; + for (unsigned int i=0;icb (rosc->cb_cls, - rowid, - &h_blind_ev, - &denom_pub, - &denom_sig, - &reserve_pub, - &reserve_sig, - execution_date, - &amount_with_fee); + rowid, + &h_blind_ev, + &denom_pub, + &denom_sig, + &reserve_pub, + &reserve_sig, + execution_date, + &amount_with_fee); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -6435,6 +6471,7 @@ postgres_select_reserves_out_above_serial_id (void *cls, TALER_EXCHANGEDB_WithdrawCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -6442,15 +6479,16 @@ postgres_select_reserves_out_above_serial_id (void *cls, struct ReservesOutSerialContext rosc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_reserves_out_incr", - params, - &reserves_out_serial_helper_cb, - &rosc); + "audit_get_reserves_out_incr", + params, + &reserves_out_serial_helper_cb, + &rosc); if (GNUNET_OK != rosc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6473,6 +6511,11 @@ struct WireOutSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -6490,11 +6533,12 @@ struct WireOutSerialContext */ static void wire_out_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct WireOutSerialContext *wosc = cls; - + struct PostgresClosure *pg = wosc->pg; + for (unsigned int i=0;icb (wosc->cb_cls, - rowid, - date, - &wtid, - wire, - &amount); + rowid, + date, + &wtid, + wire, + &amount); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -6557,6 +6601,7 @@ postgres_select_wire_out_above_serial_id (void *cls, TALER_EXCHANGEDB_WireTransferOutCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -6564,15 +6609,16 @@ postgres_select_wire_out_above_serial_id (void *cls, struct WireOutSerialContext wosc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_wire_incr", - params, - &wire_out_serial_helper_cb, - &wosc); + "audit_get_wire_incr", + params, + &wire_out_serial_helper_cb, + &wosc); if (GNUNET_OK != wosc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6599,6 +6645,7 @@ postgres_select_wire_out_above_serial_id_by_account (void *cls, TALER_EXCHANGEDB_WireTransferOutCallback cb, void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_string (account_name), @@ -6607,15 +6654,16 @@ postgres_select_wire_out_above_serial_id_by_account (void *cls, struct WireOutSerialContext wosc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "audit_get_wire_incr_by_account", - params, - &wire_out_serial_helper_cb, - &wosc); + "audit_get_wire_incr_by_account", + params, + &wire_out_serial_helper_cb, + &wosc); if (GNUNET_OK != wosc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -6638,6 +6686,11 @@ struct PaybackSerialContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Status code, set to #GNUNET_SYSERR on hard errors. */ @@ -6659,7 +6712,8 @@ payback_serial_helper_cb (void *cls, unsigned int num_results) { struct PaybackSerialContext *psc = cls; - + struct PostgresClosure *pg = psc->pg; + for (unsigned int i=0;ipg; + for (unsigned int i=0;ipg; + for (unsigned int i=0;icb (rcsc->cb_cls, - rowid, - execution_date, - &amount_with_fee, - &closing_fee, - &reserve_pub, - receiver_account, - &wtid); + rowid, + execution_date, + &amount_with_fee, + &closing_fee, + &reserve_pub, + receiver_account, + &wtid); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != ret) break; @@ -7011,7 +7081,8 @@ postgres_select_reserve_closed_above_serial_id (void *cls, uint64_t serial_id, TALER_EXCHANGEDB_ReserveClosedCallback cb, void *cb_cls) -{ +{ + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&serial_id), GNUNET_PQ_query_param_end @@ -7019,15 +7090,16 @@ postgres_select_reserve_closed_above_serial_id (void *cls, struct ReserveClosedSerialContext rcsc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "reserves_close_get_incr", - params, - &reserve_closed_serial_helper_cb, - &rcsc); + "reserves_close_get_incr", + params, + &reserve_closed_serial_helper_cb, + &rcsc); if (GNUNET_OK != rcsc.status) return GNUNET_DB_STATUS_HARD_ERROR; return qs; @@ -7199,7 +7271,7 @@ postgres_get_reserve_by_h_blind (void *cls, }; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - reserve_pub), + reserve_pub), GNUNET_PQ_result_spec_end }; @@ -7266,8 +7338,8 @@ postgres_insert_denomination_revocation (void *cls, }; return GNUNET_PQ_eval_prepared_non_select (session->conn, - "denomination_revocation_insert", - params); + "denomination_revocation_insert", + params); } @@ -7287,7 +7359,7 @@ postgres_get_denomination_revocation (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, struct TALER_MasterSignatureP *master_sig, - uint64_t *rowid) + uint64_t *rowid) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), @@ -7300,9 +7372,9 @@ postgres_get_denomination_revocation (void *cls, }; return GNUNET_PQ_eval_prepared_singleton_select (session->conn, - "denomination_revocation_get", - params, - rs); + "denomination_revocation_get", + params, + rs); } @@ -7321,6 +7393,11 @@ struct MissingWireContext */ void *cb_cls; + /** + * Plugin context. + */ + struct PostgresClosure *pg; + /** * Set to #GNUNET_SYSERR on error. */ @@ -7337,10 +7414,11 @@ struct MissingWireContext */ static void missing_wire_cb (void *cls, - PGresult *result, - unsigned int num_results) + PGresult *result, + unsigned int num_results) { struct MissingWireContext *mwc = cls; + struct PostgresClosure *pg = mwc->pg; while (0 < num_results) { @@ -7353,15 +7431,15 @@ missing_wire_cb (void *cls, uint8_t done; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("deposit_serial_id", - &rowid), + &rowid), GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), - TALER_PQ_result_spec_amount ("amount_with_fee", - &amount), + &coin_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &amount), TALER_PQ_result_spec_json ("wire", &wire), TALER_PQ_result_spec_absolute_time ("wire_deadline", - &deadline), + &deadline), GNUNET_PQ_result_spec_auto_from_type ("tiny", &tiny), GNUNET_PQ_result_spec_auto_from_type ("done", @@ -7379,13 +7457,13 @@ missing_wire_cb (void *cls, return; } mwc->cb (mwc->cb_cls, - rowid, - &coin_pub, - &amount, - wire, - deadline, - tiny, - done); + rowid, + &coin_pub, + &amount, + wire, + deadline, + tiny, + done); GNUNET_PQ_cleanup_result (rs); } } @@ -7406,20 +7484,22 @@ missing_wire_cb (void *cls, */ static enum GNUNET_DB_QueryStatus postgres_select_deposits_missing_wire (void *cls, - struct TALER_EXCHANGEDB_Session *session, - struct GNUNET_TIME_Absolute start_date, - struct GNUNET_TIME_Absolute end_date, - TALER_EXCHANGEDB_WireMissingCallback cb, - void *cb_cls) + struct TALER_EXCHANGEDB_Session *session, + struct GNUNET_TIME_Absolute start_date, + struct GNUNET_TIME_Absolute end_date, + TALER_EXCHANGEDB_WireMissingCallback cb, + void *cb_cls) { + struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { TALER_PQ_query_param_absolute_time (&start_date), TALER_PQ_query_param_absolute_time (&end_date), GNUNET_PQ_query_param_end }; - struct MissingWireContext mwc = { + struct MissingWireContext mwc = { .cb = cb, .cb_cls = cb_cls, + .pg = pg, .status = GNUNET_OK }; enum GNUNET_DB_QueryStatus qs; @@ -7434,280 +7514,6 @@ postgres_select_deposits_missing_wire (void *cls, return qs; } -/** - * Delete wire transfer records related to a particular merchant. - * This method would be called by the logic once that merchant - * gets successfully KYC checked. - * - * @param cls closure - * @param session DB session - * @param merchant_serial_id serial id of the merchant whose - * KYC records have to be deleted. - * @return DB transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_clean_kyc_events (void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&merchant_serial_id), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (session->conn, - "clean_kyc_events", - params); - -} - - -/** - * Mark a merchant as NOT KYC-checked. - * - * @param cls closure - * @param session DB session - * @param payto_url payto:// URL indentifying the merchant - * to unmark. Note, different banks may have different - * policies to check their customers. - * @return database transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_unmark_kyc_merchant - (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url) -{ - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_url), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select - (session->conn, - "unmark_kyc_merchant", - params); -} - -/** - * Record timestamp where a particular merchant performed - * a wire transfer. - * - * @param cls closure. - * @param session db session. - * @param merchant_serial_id serial id of the merchant who - * performed the wire transfer. - * @param amount amount of the wire transfer being monitored. - * @return database transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_kyc_event - (void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id, - struct TALER_Amount *amount) -{ - struct GNUNET_TIME_Absolute now; - - now = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&merchant_serial_id), - TALER_PQ_query_param_amount (amount), - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_kyc_event", - params); -} - -/** - * Mark a merchant as KYC-checked. - * - * @param payto_url payto:// URL indentifying the merchant - * to mark. Note, different banks may have different - * policies to check their customers. - * @return database transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_mark_kyc_merchant - (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url) -{ - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_url), - GNUNET_PQ_query_param_end - }; - - return GNUNET_PQ_eval_prepared_non_select (session->conn, - "mark_kyc_merchant", - params); -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure - * @param result the postgres result - * @param num_result the number of results in @a result - */ -static void -sum_kyc_events (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct TALER_Amount *tot = cls; - struct TALER_Amount tmp; - - int ntuples = PQntuples (result); - - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount", &tmp), - GNUNET_PQ_result_spec_end - }; - - for (unsigned int i = 0; i < ntuples; i++) - { - GNUNET_assert - (GNUNET_OK == GNUNET_PQ_extract_result (result, - rs, - i)); - - if ((0 == tot->value) && (0 == tot->fraction)) - *tot = tmp; - else - GNUNET_assert - (GNUNET_SYSERR != TALER_amount_add (tot, - tot, - &tmp)); - - } - -} - - -/** - * Calculate sum of money flow related to a particular merchant, - * used for KYC monitoring. - * - * @param cls closure - * @param session DB session - * @param merchant_serial_id serial id identifying the merchant - * into the KYC monitoring system. - * @param amount[out] will store the amount of money received - * by this merchant. - */ -static enum GNUNET_DB_QueryStatus -postgres_get_kyc_events (void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id, - struct TALER_Amount *amount) -{ - enum GNUNET_DB_QueryStatus qs; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&merchant_serial_id), - GNUNET_PQ_query_param_end - }; - - /* make sure sum object starts virgin. */ - memset (amount, - 0, - sizeof (struct TALER_Amount)); - - qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "get_kyc_events", - params, - sum_kyc_events, - amount); - return qs; -} - -/** - * Retrieve KYC-check status related to a particular merchant. - * - * @param payto_url URL identifying a merchant bank account, - * whose KYC is going to be retrieved. - * @param[out] status store the result. - * @return transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_get_kyc_status (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url, - TALER_EXCHANGEDB_KycStatusCallback ksc, - void *ksc_cls) -{ - uint8_t status; - uint64_t merchant_serial_id; - enum GNUNET_DB_QueryStatus qs; - char *general_id; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_url), - GNUNET_PQ_query_param_end - }; - - - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("general_id", - &general_id), - GNUNET_PQ_result_spec_auto_from_type ("kyc_checked", - &status), - GNUNET_PQ_result_spec_uint64 ("merchant_serial_id", - &merchant_serial_id), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select - (session->conn, - "get_kyc_status", - params, - rs); - - if (0 >= qs) - return qs; - - ksc (ksc_cls, - payto_url, - general_id, - status, - merchant_serial_id); - - return qs; -} - - - -/** - * Insert a merchant into the KYC monitor table. - * - * @param payto_url payto:// URL indentifying the merchant - * bank account. - * @return database transaction status. - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_kyc_merchant (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *general_id, - const char *payto_url) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_url), - GNUNET_PQ_query_param_string (general_id), - GNUNET_PQ_query_param_end - }; - return GNUNET_PQ_eval_prepared_non_select (session->conn, - "insert_kyc_merchant", - params); -} - /** * Initialize Postgres database subsystem. @@ -7771,6 +7577,18 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "taler", + "CURRENCY", + &pg->currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "taler", + "CURRENCY"); + GNUNET_free (pg); + return NULL; + } plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin); plugin->cls = pg; plugin->get_session = &postgres_get_session; @@ -7860,14 +7678,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->select_deposits_missing_wire = &postgres_select_deposits_missing_wire; - plugin->insert_kyc_merchant = postgres_insert_kyc_merchant; - plugin->mark_kyc_merchant = postgres_mark_kyc_merchant; - plugin->unmark_kyc_merchant = postgres_unmark_kyc_merchant; - plugin->get_kyc_status = postgres_get_kyc_status; - plugin->insert_kyc_event = postgres_insert_kyc_event; - plugin->get_kyc_events = postgres_get_kyc_events; - plugin->clean_kyc_events = postgres_clean_kyc_events; - return plugin; } diff --git a/src/exchangedb/test-exchange-db-postgres.conf b/src/exchangedb/test-exchange-db-postgres.conf index be821d758..e61c4505a 100644 --- a/src/exchangedb/test-exchange-db-postgres.conf +++ b/src/exchangedb/test-exchange-db-postgres.conf @@ -7,6 +7,8 @@ DB = postgres #The connection string the plugin has to use for connecting to the database CONFIG = postgres:///talercheck +[taler] +CURRENCY = EUR [exchangedb] diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index ef4775482..5018ec63d 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -55,7 +55,7 @@ static int result; /** - * Currency we use. + * Currency we use. Must match test-exchange-db-*.conf. */ #define CURRENCY "EUR" @@ -343,61 +343,6 @@ never_called_cb (void *cls, } -/** - * Callback used to process data of a merchant under KYC monitoring. - * - * @param cls closure - * @param payto_url payto URL of this particular merchant (bank account) - * @param general_id general identificator valid at the KYC-caring institution - * @param kyc_checked status of KYC check: if GNUNET_OK, the merchant was - * checked at least once, never otherwise. - * @param merchant_serial_id serial ID identifying this merchant (bank - * account) into the database system; it helps making more efficient - * queries instead of the payto URL. - */ -static void -kcs (void *cls, - const char *payto_url, - const char *general_id, - uint8_t kyc_checked, - uint64_t merchant_serial_id) -{ - struct TALER_EXCHANGEDB_Session *session = cls; - struct TALER_Amount amount; - struct TALER_Amount sum; - - GNUNET_assert (GNUNET_OK == - TALER_amount_get_zero (CURRENCY, - &amount)); - amount.value = 30; - FAILIF - (GNUNET_OK != plugin->insert_kyc_event (NULL, - session, - merchant_serial_id, - &amount)); - amount.value = 20; - amount.fraction = 70; - FAILIF - (GNUNET_OK != plugin->insert_kyc_event (NULL, - session, - merchant_serial_id, - &amount)); - FAILIF - (0 >= plugin->get_kyc_events (NULL, - session, - merchant_serial_id, - &sum)); - - FAILIF ((50 != sum.value) || (70 != sum.fraction)); - - FAILIF (2 != plugin->clean_kyc_events (NULL, - session, - merchant_serial_id)); - - drop: - return; -} - /** * Function called with information about a refresh order. * Checks that the response matches what we expect to see. @@ -2225,26 +2170,6 @@ run (void *cls) FAILIF (GNUNET_OK != test_wire_fees (session)); - FAILIF (GNUNET_OK != - plugin->insert_kyc_merchant (NULL, - session, - "dummy", // NULL segfaults. - "payto://mock")); - FAILIF (GNUNET_OK != - plugin->mark_kyc_merchant (NULL, - session, - "payto://mock")); - FAILIF (GNUNET_OK != - plugin->get_kyc_status (NULL, - session, - "payto://mock", - &kcs, - session)); - - FAILIF (GNUNET_OK != - plugin->unmark_kyc_merchant (NULL, - session, - "payto://mock")); plugin->preflight (plugin->cls, session); diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index a065534b8..61ec53054 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -793,29 +793,6 @@ typedef int int done); -/** - * Callback used to process data of a merchant under KYC monitoring. - * - * @param cls closure - * @param payto_url payto URL of this particular - * merchant (bank account) - * @param general_id general identificator valid - * at the KYC-caring institution - * @param kyc_checked status of KYC check: - * if GNUNET_OK, the merchant was checked at least once, - * never otherwise. - * @param merchant_serial_id serial ID identifying - * this merchant (bank account) into the database system; - * it helps making more efficient queries than the payto - * URL. - */ -typedef void -(*TALER_EXCHANGEDB_KycStatusCallback)(void *cls, - const char *payto_url, - const char *general_id, - uint8_t kyc_checked, - uint64_t merchant_serial_id); - /** * Function called with details about coins that were melted, * with the goal of auditing the refresh's execution. @@ -918,19 +895,6 @@ typedef void const struct TALER_TransferPublicKeyP *tp); -/** - * Callback for handling a KYC timestamped event associated with - * a certain customer (= merchant). - * - * @param cls closure - * @param url "payto" URL associated with the customer - * @param timeout last time when the KYC was issued to the customer. - */ -typedef void -(*TALER_EXCHANGEDB_KycCallback)(void *cls, - const char *url, - struct GNUNET_TIME_Absolute timeout); - /** * Function called with details about coins that were refunding, * with the goal of auditing the refund's execution. @@ -2509,126 +2473,6 @@ struct TALER_EXCHANGEDB_Plugin TALER_EXCHANGEDB_WireMissingCallback cb, void *cb_cls); - /** - * Insert a merchant into the KYC monitor table, namely it - * associates a flag to the merchant that indicates whether - * a KYC check has been done or not on this merchant. - * - * @param cls closure - * @param session db session - * @param general_id identificator at the KYC-aware institution, - * can be NULL if this is in-line wiht the rules. - * @param payto_url payto:// URL indentifying the merchant - * bank account. - * @return database transaction status. - */ - enum GNUNET_DB_QueryStatus - (*insert_kyc_merchant)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *general_id, - const char *payto_url); - - /** - * Mark a merchant as KYC-checked. - * - * @param cls closure - * @param session db session - * @param payto_url payto:// URL indentifying the merchant - * to check. Note, different banks may have different - * policies to check their customers. - * @return database transaction status. - */ - enum GNUNET_DB_QueryStatus - (*mark_kyc_merchant)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url); - - - /** - * Mark a merchant as NOT KYC-checked. - * - * @param cls closure - * @param session db session - * @param payto_url payto:// URL indentifying the merchant - * to unmark. Note, different banks may have different - * policies to check their customers. - * @return database transaction status. - */ - enum GNUNET_DB_QueryStatus - (*unmark_kyc_merchant)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url); - - - /** - * Retrieve KYC-check status related to a particular merchant. - * - * @param cls closure - * @param session db session - * @param payto_url URL identifying a merchant bank account, - * whose KYC is going to be retrieved. - * @param ksc callback to process all the row's columns. As - * expectable, it will only be called _if_ a row is found. - * @param ksc_cls closure for above callback. - * @return transaction status. - */ - enum GNUNET_DB_QueryStatus - (*get_kyc_status)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - const char *payto_url, - TALER_EXCHANGEDB_KycStatusCallback ksc, - void *ksc_cls); - - /** - * Record timestamp where a particular merchant performed - * a wire transfer. - * - * @param cls closure. - * @param session db session. - * @param merchant_serial_id serial id of the merchant who - * performed the wire transfer. - * @param amount amount of the wire transfer being monitored. - * @return database transaction status. - */ - enum GNUNET_DB_QueryStatus - (*insert_kyc_event)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id, - struct TALER_Amount *amount); - - - /** - * Calculate sum of money flow related to a particular merchant, - * used for KYC monitoring. - * - * @param cls closure - * @param session DB session - * @param merchant_serial_id serial id identifying the merchant - * into the KYC monitoring system. - * @param amount[out] will store the amount of money received - * by this merchant. - */ - enum GNUNET_DB_QueryStatus - (*get_kyc_events)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id, - struct TALER_Amount *amount); - - /** - * Delete wire transfer records related to a particular merchant. - * This method would be called by the logic once that merchant - * gets successfully KYC checked. - * - * @param cls closure - * @param session DB session - * @param merchant_serial_id serial id of the merchant whose - * KYC records have to be deleted. - * @return DB transaction status. - */ - enum GNUNET_DB_QueryStatus - (*clean_kyc_events)(void *cls, - struct TALER_EXCHANGEDB_Session *session, - uint64_t merchant_serial_id); }; #endif /* _TALER_EXCHANGE_DB_H */ diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h index 4ac0a6df2..47040ea02 100644 --- a/src/include/taler_pq_lib.h +++ b/src/include/taler_pq_lib.h @@ -94,24 +94,28 @@ TALER_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) * Currency amount expected. * * @param name name of the field in the table + * @param currency expected currency for the @a amount * @param[out] amount where to store the result * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_amount_nbo (const char *name, - struct TALER_AmountNBO *amount); + const char *currency, + struct TALER_AmountNBO *amount); /** * Currency amount expected. * * @param name name of the field in the table + * @param currency expected currency for the @a amount * @param[out] amount where to store the result * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_amount (const char *name, - struct TALER_Amount *amount); + const char *currency, + struct TALER_Amount *amount); /** diff --git a/src/include/taler_util.h b/src/include/taler_util.h index 2bdc888a6..479a45754 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h @@ -87,7 +87,8 @@ TALER_gcrypt_init (void); */ const char * TALER_b2s (const void *buf, - size_t buf_size); + size_t buf_size); + /** * Convert a fixed-sized object to a string using diff --git a/src/json/json_wire.c b/src/json/json_wire.c index 91e502c1d..57a0db108 100644 --- a/src/json/json_wire.c +++ b/src/json/json_wire.c @@ -150,7 +150,6 @@ TALER_JSON_exchange_wire_signature_make (const char *payto_url, GNUNET_CRYPTO_eddsa_key_get_public (&master_priv->eddsa_priv, &master_pub.eddsa_pub); - TALER_exchange_wire_signature_make (payto_url, master_priv, &master_sig); diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index 6386749c9..1a03c2d49 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c @@ -42,19 +42,19 @@ */ static int qconv_amount_nbo (void *cls, - const void *data, - size_t data_len, - void *param_values[], - int param_lengths[], - int param_formats[], - unsigned int param_length, - void *scratch[], - unsigned int scratch_length) + const void *data, + size_t data_len, + void *param_values[], + int param_lengths[], + int param_formats[], + unsigned int param_length, + void *scratch[], + unsigned int scratch_length) { const struct TALER_AmountNBO *amount = data; unsigned int off = 0; - GNUNET_assert (3 == param_length); + GNUNET_assert (2 == param_length); param_values[off] = (void *) &amount->value; param_lengths[off] = sizeof (amount->value); param_formats[off] = 1; @@ -62,10 +62,6 @@ qconv_amount_nbo (void *cls, param_values[off] = (void *) &amount->fraction; param_lengths[off] = sizeof (amount->fraction); param_formats[off] = 1; - off++; - param_values[off] = (void *) amount->currency; - param_lengths[off] = strlen (amount->currency); - param_formats[off] = 1; return 0; } @@ -83,7 +79,7 @@ struct GNUNET_PQ_QueryParam TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x) { struct GNUNET_PQ_QueryParam res = - { &qconv_amount_nbo, NULL, x, sizeof (*x), 3 }; + { &qconv_amount_nbo, NULL, x, sizeof (*x), 2 }; return res; } @@ -104,14 +100,14 @@ TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x) */ static int qconv_amount (void *cls, - const void *data, - size_t data_len, - void *param_values[], - int param_lengths[], - int param_formats[], - unsigned int param_length, - void *scratch[], - unsigned int scratch_length) + const void *data, + size_t data_len, + void *param_values[], + int param_lengths[], + int param_formats[], + unsigned int param_length, + void *scratch[], + unsigned int scratch_length) { const struct TALER_Amount *amount_hbo = data; struct TALER_AmountNBO *amount; @@ -119,16 +115,16 @@ qconv_amount (void *cls, amount = GNUNET_new (struct TALER_AmountNBO); scratch[0] = amount; TALER_amount_hton (amount, - amount_hbo); + amount_hbo); qconv_amount_nbo (cls, - amount, - sizeof (struct TALER_AmountNBO), - param_values, - param_lengths, - param_formats, - param_length, - &scratch[1], - scratch_length - 1); + amount, + sizeof (struct TALER_AmountNBO), + param_values, + param_lengths, + param_formats, + param_length, + &scratch[1], + scratch_length - 1); return 1; } @@ -146,7 +142,7 @@ struct GNUNET_PQ_QueryParam TALER_PQ_query_param_amount (const struct TALER_Amount *x) { struct GNUNET_PQ_QueryParam res = - { &qconv_amount, NULL, x, sizeof (*x), 3 }; + { &qconv_amount, NULL, x, sizeof (*x), 2 }; return res; } @@ -167,14 +163,14 @@ TALER_PQ_query_param_amount (const struct TALER_Amount *x) */ static int qconv_json (void *cls, - const void *data, - size_t data_len, - void *param_values[], - int param_lengths[], - int param_formats[], - unsigned int param_length, - void *scratch[], - unsigned int scratch_length) + const void *data, + size_t data_len, + void *param_values[], + int param_lengths[], + int param_formats[], + unsigned int param_length, + void *scratch[], + unsigned int scratch_length) { const json_t *json = data; char *str; diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index c1395b7c8..92b8e8f4f 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -40,15 +40,14 @@ */ static int extract_amount_nbo_helper (PGresult *result, - int row, - const char *val_name, - const char *frac_name, - const char *curr_name, - struct TALER_AmountNBO *r_amount_nbo) + int row, + const char *currency, + const char *val_name, + const char *frac_name, + struct TALER_AmountNBO *r_amount_nbo) { int val_num; int frac_num; - int curr_num; int len; /* These checks are simply to check that clients obey by our naming @@ -59,9 +58,6 @@ extract_amount_nbo_helper (PGresult *result, GNUNET_assert (NULL != strstr (frac_name, "_frac")); - GNUNET_assert (NULL != - strstr (curr_name, - "_curr")); /* Set return value to invalid in case we don't finish */ memset (r_amount_nbo, 0, @@ -70,27 +66,18 @@ extract_amount_nbo_helper (PGresult *result, val_name); frac_num = PQfnumber (result, frac_name); - curr_num = PQfnumber (result, - curr_name); if (val_num < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - val_name); + "Field `%s' does not exist in result\n", + val_name); return GNUNET_SYSERR; } if (frac_num < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - frac_name); - return GNUNET_SYSERR; - } - if (curr_num < 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - curr_name); + "Field `%s' does not exist in result\n", + frac_name); return GNUNET_SYSERR; } if ( (PQgetisnull (result, @@ -98,10 +85,7 @@ extract_amount_nbo_helper (PGresult *result, val_num)) || (PQgetisnull (result, row, - frac_num)) || - (PQgetisnull (result, - row, - curr_num)) ) + frac_num)) ) { GNUNET_break (0); return GNUNET_NO; @@ -115,13 +99,9 @@ extract_amount_nbo_helper (PGresult *result, row, frac_num); len = GNUNET_MIN (TALER_CURRENCY_LEN - 1, - PQgetlength (result, - row, - curr_num)); + strlen (currency)); memcpy (r_amount_nbo->currency, - PQgetvalue (result, - row, - curr_num), + currency, len); return GNUNET_OK; } @@ -130,7 +110,7 @@ extract_amount_nbo_helper (PGresult *result, /** * Extract data from a Postgres database @a result at row @a row. * - * @param cls closure + * @param cls closure, a `const char *` giving the currency * @param result where to extract data from * @param row row to extract data from * @param fname name (or prefix) of the fields to extract from @@ -143,35 +123,31 @@ extract_amount_nbo_helper (PGresult *result, */ static int extract_amount_nbo (void *cls, - PGresult *result, - int row, - const char *fname, - size_t *dst_size, - void *dst) + PGresult *result, + int row, + const char *fname, + size_t *dst_size, + void *dst) { + const char *currency = cls; char *val_name; char *frac_name; - char *curr_name; int ret; GNUNET_asprintf (&val_name, - "%s_val", - fname); + "%s_val", + fname); GNUNET_asprintf (&frac_name, - "%s_frac", - fname); - GNUNET_asprintf (&curr_name, - "%s_curr", - fname); + "%s_frac", + fname); ret = extract_amount_nbo_helper (result, - row, - val_name, - frac_name, - curr_name, - dst); + row, + currency, + val_name, + frac_name, + dst); GNUNET_free (val_name); GNUNET_free (frac_name); - GNUNET_free (curr_name); return ret; } @@ -185,12 +161,17 @@ extract_amount_nbo (void *cls, */ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_amount_nbo (const char *name, - struct TALER_AmountNBO *amount) + const char *currency, + struct TALER_AmountNBO *amount) { - struct GNUNET_PQ_ResultSpec res = - { &extract_amount_nbo, NULL, NULL, - (void *) amount, sizeof (*amount), - name, NULL }; + struct GNUNET_PQ_ResultSpec res = { + .conv = &extract_amount_nbo, + .cls = (void *) currency, + .dst = (void *) amount, + .dst_size = sizeof (*amount), + .fname = name + }; + return res; } @@ -198,7 +179,7 @@ TALER_PQ_result_spec_amount_nbo (const char *name, /** * Extract data from a Postgres database @a result at row @a row. * - * @param cls closure + * @param cls closure, a `const char *` giving the currency * @param result where to extract data from * @param row row to extract data from * @param fname name (or prefix) of the fields to extract from @@ -211,39 +192,35 @@ TALER_PQ_result_spec_amount_nbo (const char *name, */ static int extract_amount (void *cls, - PGresult *result, - int row, - const char *fname, - size_t *dst_size, - void *dst) + PGresult *result, + int row, + const char *fname, + size_t *dst_size, + void *dst) { + const char *currency = cls; struct TALER_Amount *r_amount = dst; char *val_name; char *frac_name; - char *curr_name; struct TALER_AmountNBO amount_nbo; int ret; GNUNET_asprintf (&val_name, - "%s_val", - fname); + "%s_val", + fname); GNUNET_asprintf (&frac_name, - "%s_frac", - fname); - GNUNET_asprintf (&curr_name, - "%s_curr", - fname); + "%s_frac", + fname); ret = extract_amount_nbo_helper (result, - row, - val_name, - frac_name, - curr_name, - &amount_nbo); + row, + currency, + val_name, + frac_name, + &amount_nbo); TALER_amount_ntoh (r_amount, &amount_nbo); GNUNET_free (val_name); GNUNET_free (frac_name); - GNUNET_free (curr_name); return ret; } @@ -252,17 +229,23 @@ extract_amount (void *cls, * Currency amount expected. * * @param name name of the field in the table + * @param currency the currency the amount is in * @param[out] amount where to store the result * @return array entry for the result specification to use */ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_amount (const char *name, - struct TALER_Amount *amount) + const char *currency, + struct TALER_Amount *amount) { - struct GNUNET_PQ_ResultSpec res = - { &extract_amount, NULL, NULL, - (void *) amount, sizeof (*amount), - name, NULL }; + struct GNUNET_PQ_ResultSpec res = { + .conv = &extract_amount, + .cls = (void *) currency, + .dst = (void *) amount, + .dst_size = sizeof (*amount), + .fname = name + }; + return res; } @@ -283,11 +266,11 @@ TALER_PQ_result_spec_amount (const char *name, */ static int extract_json (void *cls, - PGresult *result, - int row, - const char *fname, - size_t *dst_size, - void *dst) + PGresult *result, + int row, + const char *fname, + size_t *dst_size, + void *dst) { json_t **j_dst = dst; const char *res; @@ -296,33 +279,33 @@ extract_json (void *cls, size_t slen; fnum = PQfnumber (result, - fname); + fname); if (fnum < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + "Field `%s' does not exist in result\n", + fname); return GNUNET_SYSERR; } if (PQgetisnull (result, - row, - fnum)) + row, + fnum)) return GNUNET_NO; slen = PQgetlength (result, - row, - fnum); + row, + fnum); res = (const char *) PQgetvalue (result, - row, - fnum); + row, + fnum); *j_dst = json_loadb (res, - slen, - JSON_REJECT_DUPLICATES, - &json_error); + slen, + JSON_REJECT_DUPLICATES, + &json_error); if (NULL == *j_dst) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse JSON result for field `%s': %s (%s)\n", - fname, + "Failed to parse JSON result for field `%s': %s (%s)\n", + fname, json_error.text, json_error.source); return GNUNET_SYSERR; @@ -340,7 +323,7 @@ extract_json (void *cls, */ static void clean_json (void *cls, - void *rd) + void *rd) { json_t **dst = rd; @@ -363,15 +346,17 @@ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_json (const char *name, json_t **jp) { - struct GNUNET_PQ_ResultSpec res = - { &extract_json, &clean_json, NULL, - (void *) jp, 0, - name, NULL }; + struct GNUNET_PQ_ResultSpec res = { + .conv = &extract_json, + .cleaner = &clean_json, + .dst = (void *) jp, + .fname = name + }; + return res; } - /** * Extract data from a Postgres database @a result at row @a row. * @@ -399,7 +384,7 @@ extract_round_time (void *cls, int fnum; fnum = PQfnumber (result, - fname); + fname); if (fnum < 0) { GNUNET_break (0); @@ -443,10 +428,13 @@ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at) { - struct GNUNET_PQ_ResultSpec res = - { &extract_round_time, NULL, NULL, - (void *) at, sizeof (struct GNUNET_TIME_Absolute), - name, NULL }; + struct GNUNET_PQ_ResultSpec res = { + .conv = &extract_round_time, + .dst = (void *) at, + .dst_size = sizeof (struct GNUNET_TIME_Absolute), + .fname = name + }; + return res; } @@ -478,15 +466,15 @@ extract_round_time_nbo (void *cls, int fnum; fnum = PQfnumber (result, - fname); + fname); if (fnum < 0) { GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, - row, - fnum)) + row, + fnum)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -522,10 +510,13 @@ struct GNUNET_PQ_ResultSpec TALER_PQ_result_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at) { - struct GNUNET_PQ_ResultSpec res = - { &extract_round_time_nbo, NULL, NULL, - (void *) at, sizeof (struct GNUNET_TIME_AbsoluteNBO), - name, NULL }; + struct GNUNET_PQ_ResultSpec res = { + .conv = &extract_round_time_nbo, + .dst = (void *) at, + .dst_size = sizeof (struct GNUNET_TIME_AbsoluteNBO), + .fname = name + }; + return res; } diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index 6f7de0db2..471326f02 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c @@ -50,23 +50,18 @@ postgres_prepare (PGconn *db_conn) "INSERT INTO test_pq (" " hamount_val" ",hamount_frac" - ",hamount_curr" ",namount_val" ",namount_frac" - ",namount_curr" ",json" ") VALUES " - "($1, $2, $3, $4, $5, $6," - "$7);", - 7, NULL); + "($1, $2, $3, $4, $5);", + 5, NULL); PREPARE ("test_select", "SELECT" " hamount_val" ",hamount_frac" - ",hamount_curr" ",namount_val" ",namount_frac" - ",namount_curr" ",json" " FROM test_pq;", 0, NULL); @@ -113,8 +108,8 @@ run_queries (PGconn *conn) }; result = GNUNET_PQ_exec_prepared (conn, - "test_insert", - params_insert); + "test_insert", + params_insert); if (PGRES_COMMAND_OK != PQresultStatus (result)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -131,10 +126,10 @@ run_queries (PGconn *conn) }; result = GNUNET_PQ_exec_prepared (conn, - "test_select", - params_select); + "test_select", + params_select); if (1 != - PQntuples (result)) + PQntuples (result)) { GNUNET_break (0); PQclear (result); @@ -144,8 +139,8 @@ run_queries (PGconn *conn) { struct GNUNET_PQ_ResultSpec results_select[] = { - TALER_PQ_result_spec_amount ("hamount", &hamount2), - TALER_PQ_result_spec_amount_nbo ("namount", &namount2), + TALER_PQ_result_spec_amount ("hamount", "EUR", &hamount2), + TALER_PQ_result_spec_amount_nbo ("namount", "EUR", &namount2), TALER_PQ_result_spec_json ("json", &json2), GNUNET_PQ_result_spec_end }; @@ -163,8 +158,9 @@ run_queries (PGconn *conn) &namount2); GNUNET_break (0 == TALER_amount_cmp (&hamount, - &hamount2)); - GNUNET_break (42 == json_integer_value (json_object_get (json2, "foo"))); + &hamount2)); + GNUNET_break (42 == + json_integer_value (json_object_get (json2, "foo"))); GNUNET_PQ_cleanup_result (results_select); PQclear (result); } @@ -185,8 +181,8 @@ main(int argc, int ret; GNUNET_log_setup ("test-pq", - "WARNING", - NULL); + "WARNING", + NULL); conn = PQconnectdb ("postgres:///talercheck"); if (CONNECTION_OK != PQstatus (conn)) { @@ -202,17 +198,15 @@ main(int argc, "CREATE TEMPORARY TABLE IF NOT EXISTS test_pq (" " hamount_val INT8 NOT NULL" ",hamount_frac INT4 NOT NULL" - ",hamount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",namount_val INT8 NOT NULL" ",namount_frac INT4 NOT NULL" - ",namount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",json VARCHAR NOT NULL" ")"); if (PGRES_COMMAND_OK != PQresultStatus (result)) { fprintf (stderr, - "Failed to create table: %s\n", - PQerrorMessage (conn)); + "Failed to create table: %s\n", + PQerrorMessage (conn)); PQclear (result); PQfinish (conn); return 1; @@ -227,12 +221,12 @@ main(int argc, } ret = run_queries (conn); result = PQexec (conn, - "DROP TABLE test_pq"); + "DROP TABLE test_pq"); if (PGRES_COMMAND_OK != PQresultStatus (result)) { fprintf (stderr, - "Failed to create table: %s\n", - PQerrorMessage (conn)); + "Failed to create table: %s\n", + PQerrorMessage (conn)); PQclear (result); PQfinish (conn); return 1; diff --git a/src/util/util.c b/src/util/util.c index ceb3a3a8c..51726290f 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -39,7 +39,7 @@ */ const char * TALER_b2s (const void *buf, - size_t buf_size) + size_t buf_size) { static char ret[9]; struct GNUNET_HashCode hc; @@ -49,7 +49,7 @@ TALER_b2s (const void *buf, buf_size, &hc); tmp = GNUNET_STRINGS_data_to_string_alloc (&hc, - sizeof (hc)); + sizeof (hc)); memcpy (ret, tmp, 8);