diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001.sql | 52 | ||||
-rw-r--r-- | src/exchangedb/irbt_callbacks.c | 13 | ||||
-rw-r--r-- | src/exchangedb/lrbt_callbacks.c | 24 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 152 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 14 |
5 files changed, 134 insertions, 121 deletions
diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 1d86d5d9a..3331eada2 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -68,17 +68,17 @@ COMMENT ON TABLE denomination_revocations CREATE TABLE IF NOT EXISTS wire_targets (wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY -- UNIQUE - ,h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=64) + ,wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32) ,payto_uri VARCHAR NOT NULL ,kyc_ok BOOLEAN NOT NULL DEFAULT (FALSE) ,external_id VARCHAR ) - PARTITION BY HASH (h_payto); + PARTITION BY HASH (wire_target_h_payto); COMMENT ON TABLE wire_targets IS 'All senders and recipients of money via the exchange'; COMMENT ON COLUMN wire_targets.payto_uri IS 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)'; -COMMENT ON COLUMN wire_targets.h_payto +COMMENT ON COLUMN wire_targets.wire_target_h_payto IS 'Unsalted hash of payto_uri'; COMMENT ON COLUMN wire_targets.kyc_ok IS 'true if the KYC check was passed successfully'; @@ -106,7 +106,7 @@ $$; SELECT add_constraints_to_wire_targets_partition('default'); --- FIXME partition by serial_id rather than h_payto, +-- FIXME partition by serial_id rather than h_payto, -- it is used more in join conditions - crucial for sharding to select this. -- Author: (Boss Marco) CREATE INDEX IF NOT EXISTS wire_targets_serial_id_index @@ -160,14 +160,14 @@ CREATE TABLE IF NOT EXISTS reserves_in ,wire_reference INT8 NOT NULL ,credit_val INT8 NOT NULL ,credit_frac INT4 NOT NULL - ,wire_source_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) + ,wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32) ,exchange_account_section TEXT NOT NULL ,execution_date INT8 NOT NULL ) PARTITION BY HASH (reserve_pub); COMMENT ON TABLE reserves_in IS 'list of transfers of funds into the reserves, one per incoming wire transfer'; -COMMENT ON COLUMN reserves_in.wire_source_serial_id +COMMENT ON COLUMN reserves_in.wire_source_h_payto IS 'Identifies the debited bank account and KYC status'; COMMENT ON COLUMN reserves_in.reserve_pub IS 'Public key of the reserve. Private key signifies ownership of the remaining balance.'; @@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS reserves_close ,reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE ,execution_date INT8 NOT NULL ,wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32) - ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) + ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32) ,amount_val INT8 NOT NULL ,amount_frac INT4 NOT NULL ,closing_fee_val INT8 NOT NULL @@ -223,7 +223,7 @@ CREATE TABLE IF NOT EXISTS reserves_close PARTITION BY HASH (reserve_pub); COMMENT ON TABLE reserves_close IS 'wire transfers executed by the reserve to close reserves'; -COMMENT ON COLUMN reserves_close.wire_target_serial_id +COMMENT ON COLUMN reserves_close.wire_target_h_payto IS 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.'; CREATE TABLE IF NOT EXISTS reserves_close_default @@ -277,7 +277,7 @@ COMMENT ON COLUMN reserves_out.denominations_serial CREATE TABLE IF NOT EXISTS reserves_out_default PARTITION OF reserves_out FOR VALUES WITH (MODULUS 1, REMAINDER 0); - + CREATE OR REPLACE FUNCTION add_constraints_to_reserves_out_partition( IN partition_suffix VARCHAR ) @@ -618,7 +618,7 @@ CREATE TABLE IF NOT EXISTS deposits ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64) ,coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64) ,wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16) - ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) + ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32) ,tiny BOOLEAN NOT NULL DEFAULT FALSE ,done BOOLEAN NOT NULL DEFAULT FALSE ,extension_blocked BOOLEAN NOT NULL DEFAULT FALSE @@ -652,7 +652,7 @@ COMMENT ON TABLE deposits IS 'Deposits we have received and for which we need to make (aggregate) wire transfers (and manage refunds).'; COMMENT ON COLUMN deposits.shard IS 'Used for load sharding. Should be set based on h_payto and merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.'; -COMMENT ON COLUMN deposits.wire_target_serial_id +COMMENT ON COLUMN deposits.wire_target_h_payto IS 'Identifies the target bank account and KYC status'; COMMENT ON COLUMN deposits.wire_salt IS 'Salt used when hashing the payto://-URI to get the h_wire'; @@ -685,7 +685,7 @@ COMMENT ON INDEX deposits_for_get_ready_index CREATE INDEX IF NOT EXISTS deposits_for_iterate_matching_index ON deposits (merchant_pub - ,wire_target_serial_id + ,wire_target_h_payto ,done ,extension_blocked ,refund_deadline ASC @@ -742,7 +742,7 @@ CREATE TABLE IF NOT EXISTS wire_out (wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY -- PRIMARY KEY ,execution_date INT8 NOT NULL ,wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32) - ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) + ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32) ,exchange_account_section TEXT NOT NULL ,amount_val INT8 NOT NULL ,amount_frac INT4 NOT NULL @@ -752,7 +752,7 @@ COMMENT ON TABLE wire_out IS 'wire transfers the exchange has executed'; COMMENT ON COLUMN wire_out.exchange_account_section IS 'identifies the configuration section with the debit account of this payment'; -COMMENT ON COLUMN wire_out.wire_target_serial_id +COMMENT ON COLUMN wire_out.wire_target_h_payto IS 'Identifies the credited bank account and KYC status'; CREATE TABLE IF NOT EXISTS wire_out_default @@ -779,9 +779,9 @@ SELECT add_constraints_to_wire_out_partition('default'); CREATE INDEX IF NOT EXISTS wire_out_by_wireout_uuid_index ON wire_out (wireout_uuid); -CREATE INDEX IF NOT EXISTS wire_out_by_wire_target_serial_id_index +CREATE INDEX IF NOT EXISTS wire_out_by_wire_target_h_payto_index ON wire_out - (wire_target_serial_id); + (wire_target_h_payto); CREATE TABLE IF NOT EXISTS aggregation_tracking @@ -1143,7 +1143,7 @@ BEGIN -- reserves_out (INSERT, with CONFLICT detection) by wih -- reserves by reserve_pub (UPDATE) -- reserves_in by reserve_pub (SELECT) --- wire_targets by wire_target_serial_id +-- wire_targets by wire_target_h_payto SELECT denominations_serial INTO denom_serial @@ -1300,12 +1300,12 @@ END IF; -- this reserve. FIXME: likely not adequate for reserves that got P2P transfers! SELECT kyc_ok - ,wire_source_serial_id + ,wire_target_serial_id INTO kycok ,account_uuid FROM reserves_in - JOIN wire_targets ON (wire_source_serial_id = wire_target_serial_id) + JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto) WHERE reserve_pub=rpub LIMIT 1; -- limit 1 should not be required (without p2p transfers) @@ -1370,8 +1370,8 @@ IF EXISTS ( SELECT 1 FROM information_Schema.constraint_column_usage WHERE table_name='wire_out' - AND constraint_name='wire_out_ref') -THEN + AND constraint_name='wire_out_ref') +THEN SET CONSTRAINTS wire_out_ref DEFERRED; END IF; @@ -1424,12 +1424,12 @@ END IF; INSERT INTO wire_targets - (h_payto + (wire_target_h_payto ,payto_uri) VALUES (in_h_payto ,in_receiver_wire_account) -ON CONFLICT DO NOTHING -- for CONFLICT ON (h_payto) +ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto) RETURNING wire_target_serial_id INTO wtsi; IF NOT FOUND @@ -1437,7 +1437,7 @@ THEN SELECT wire_target_serial_id INTO wtsi FROM wire_targets - WHERE h_payto=in_h_payto; + WHERE wire_target_h_payto=in_h_payto; END IF; @@ -1454,7 +1454,7 @@ INSERT INTO deposits ,h_contract_terms ,coin_sig ,wire_salt - ,wire_target_serial_id + ,wire_target_h_payto ,extension_blocked ,extension_details_serial_id ) @@ -1471,7 +1471,7 @@ INSERT INTO deposits ,in_h_contract_terms ,in_coin_sig ,in_wire_salt - ,wtsi + ,in_h_payto ,in_extension_blocked ,xdi) ON CONFLICT DO NOTHING; diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c index 97ce2c094..012f8df26 100644 --- a/src/exchangedb/irbt_callbacks.c +++ b/src/exchangedb/irbt_callbacks.c @@ -176,7 +176,8 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg, GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference), TALER_PQ_query_param_amount (&td->details.reserves_in.credit), - GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.sender_account), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.reserves_in.sender_account_h_payto), GNUNET_PQ_query_param_string ( td->details.reserves_in.exchange_account_section), GNUNET_PQ_query_param_timestamp ( @@ -207,8 +208,8 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg, &td->details.reserves_close.execution_date), GNUNET_PQ_query_param_auto_from_type ( &td->details.reserves_close.wtid), - GNUNET_PQ_query_param_uint64 ( - &td->details.reserves_close.wire_target_serial_id), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.reserves_close.sender_account_h_payto), TALER_PQ_query_param_amount (&td->details.reserves_close.amount), TALER_PQ_query_param_amount (&td->details.reserves_close.closing_fee), GNUNET_PQ_query_param_auto_from_type ( @@ -523,7 +524,8 @@ irbt_cb_table_deposits (struct PostgresClosure *pg, &td->details.deposits.h_contract_terms), GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.coin_sig), GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.wire_salt), - GNUNET_PQ_query_param_uint64 (&td->details.deposits.wire_target_serial_id), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.deposits.wire_target_h_payto), GNUNET_PQ_query_param_bool (td->details.deposits.tiny), GNUNET_PQ_query_param_bool (td->details.deposits.done), GNUNET_PQ_query_param_bool (td->details.deposits.extension_blocked), @@ -579,7 +581,8 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg, GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_timestamp (&td->details.wire_out.execution_date), GNUNET_PQ_query_param_auto_from_type (&td->details.wire_out.wtid_raw), - GNUNET_PQ_query_param_uint64 (&td->details.wire_out.wire_target_serial_id), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.wire_out.wire_target_h_payto), GNUNET_PQ_query_param_string ( td->details.wire_out.exchange_account_section), TALER_PQ_query_param_amount (&td->details.wire_out.amount), diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/lrbt_callbacks.c index 01eddc5a6..f7b0e28d5 100644 --- a/src/exchangedb/lrbt_callbacks.c +++ b/src/exchangedb/lrbt_callbacks.c @@ -289,9 +289,9 @@ lrbt_cb_table_reserves_in (void *cls, TALER_PQ_RESULT_SPEC_AMOUNT ( "credit", &td.details.reserves_in.credit), - GNUNET_PQ_result_spec_uint64 ( - "wire_source_serial_id", - &td.details.reserves_in.sender_account), + GNUNET_PQ_result_spec_auto_from_type ( + "wire_source_h_payto", + &td.details.reserves_in.sender_account_h_payto), GNUNET_PQ_result_spec_string ( "exchange_account_section", &td.details.reserves_in.exchange_account_section), @@ -350,9 +350,9 @@ lrbt_cb_table_reserves_close (void *cls, GNUNET_PQ_result_spec_auto_from_type ( "wtid", &td.details.reserves_close.wtid), - GNUNET_PQ_result_spec_uint64 ( - "wire_target_serial_id", - &td.details.reserves_close.wire_target_serial_id), + GNUNET_PQ_result_spec_auto_from_type ( + "wire_target_h_payto", + &td.details.reserves_close.sender_account_h_payto), TALER_PQ_RESULT_SPEC_AMOUNT ( "amount", &td.details.reserves_close.amount), @@ -947,9 +947,9 @@ lrbt_cb_table_deposits (void *cls, GNUNET_PQ_result_spec_auto_from_type ( "wire_salt", &td.details.deposits.wire_salt), - GNUNET_PQ_result_spec_uint64 ( - "wire_target_serial_id", - &td.details.deposits.wire_target_serial_id), + GNUNET_PQ_result_spec_auto_from_type ( + "wire_target_h_payto", + &td.details.deposits.wire_target_h_payto), GNUNET_PQ_result_spec_bool ( "tiny", &td.details.deposits.tiny), @@ -1067,9 +1067,9 @@ lrbt_cb_table_wire_out (void *cls, GNUNET_PQ_result_spec_auto_from_type ( "wtid_raw", &td.details.wire_out.wtid_raw), - GNUNET_PQ_result_spec_uint64 ( - "wire_target_serial_id", - &td.details.wire_out.wire_target_serial_id), + GNUNET_PQ_result_spec_auto_from_type ( + "wire_target_h_payto", + &td.details.wire_out.wire_target_h_payto), GNUNET_PQ_result_spec_string ( "exchange_account_section", &td.details.wire_out.exchange_account_section), diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 86480f29b..53fd10e37 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -429,7 +429,7 @@ prepare_statements (struct PostgresClosure *pg) " FROM reserves" " JOIN reserves_in ri USING (reserve_pub)" " JOIN wire_targets wt " - " ON (ri.wire_source_serial_id = wt.wire_target_serial_id)" + " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)" " WHERE reserve_pub=$1" " LIMIT 1;", 1), @@ -439,31 +439,21 @@ prepare_statements (struct PostgresClosure *pg) "UPDATE wire_targets" " SET kyc_ok=TRUE" ",external_id=$2" - " WHERE wire_target_serial_id=$1", + " WHERE wire_target_h_payto=$1", 2), GNUNET_PQ_make_prepare ( "get_kyc_h_payto", "SELECT" - " h_payto" + " wire_target_h_payto" " FROM wire_targets" - " WHERE wire_target_serial_id=$1" + " WHERE wire_target_h_payto=$1" " LIMIT 1;", 1), - /* Used in #postgres_select_kyc_status() */ - GNUNET_PQ_make_prepare ( - "select_kyc_status", - "SELECT" - " kyc_ok" - ",h_payto" - " FROM wire_targets" - " WHERE" - " wire_target_serial_id=$1", - 1), /* Used in #postgres_inselect_wallet_kyc_status() */ GNUNET_PQ_make_prepare ( "insert_kyc_status", "INSERT INTO wire_targets" - " (h_payto" + " (wire_target_h_payto" " ,payto_uri" " ) VALUES " " ($1, $2)" @@ -475,7 +465,7 @@ prepare_statements (struct PostgresClosure *pg) " kyc_ok" ",wire_target_serial_id" " FROM wire_targets" - " WHERE h_payto=$1;", + " WHERE wire_target_h_payto=$1;", 1), /* Used in #reserves_get() */ GNUNET_PQ_make_prepare ( @@ -509,7 +499,7 @@ prepare_statements (struct PostgresClosure *pg) "(reserve_pub" ",execution_date" ",wtid" - ",wire_target_serial_id" + ",wire_target_h_payto" ",amount_val" ",amount_frac" ",closing_fee_val" @@ -536,11 +526,12 @@ prepare_statements (struct PostgresClosure *pg) ",credit_val" ",credit_frac" ",exchange_account_section" - ",wire_source_serial_id" + ",wire_source_h_payto" ",execution_date" ") VALUES ($1, $2, $3, $4, $5, $6, $7)" " ON CONFLICT DO NOTHING;", 7), +#if FIXME_DEAD /* Used in #postgres_reserves_in_insert() to store transaction details */ GNUNET_PQ_make_prepare ( "reserves_in_add_by_pub", @@ -550,11 +541,12 @@ prepare_statements (struct PostgresClosure *pg) ",credit_val" ",credit_frac" ",exchange_account_section" - ",wire_source_serial_id" + ",wire_source_h_payto" ",execution_date" ") VALUES ($1, $2, $3, $4, $5, $6, $7)" " ON CONFLICT DO NOTHING;", 7), +#endif /* 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 ( @@ -571,7 +563,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN reserves" " USING (reserve_pub)" " JOIN wire_targets" - " ON (wire_source_serial_id = wire_target_serial_id)" + " ON (wire_source_h_payto = wire_target_h_payto)" " WHERE reserve_in_serial_id>=$1" " ORDER BY reserve_in_serial_id;", 1), @@ -591,7 +583,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN reserves " " USING (reserve_pub)" " JOIN wire_targets" - " ON (wire_source_serial_id = wire_target_serial_id)" + " ON (wire_source_h_payto = wire_target_h_payto)" " WHERE reserve_in_serial_id>=$1 AND exchange_account_section=$2" " ORDER BY reserve_in_serial_id;", 2), @@ -607,7 +599,7 @@ prepare_statements (struct PostgresClosure *pg) ",payto_uri AS sender_account_details" " FROM reserves_in" " JOIN wire_targets" - " ON (wire_source_serial_id = wire_target_serial_id)" + " ON (wire_source_h_payto = wire_target_h_payto)" " WHERE reserve_pub=$1;", 1), /* Used in #postgres_do_withdraw() to store @@ -1067,7 +1059,7 @@ prepare_statements (struct PostgresClosure *pg) ",merchant_pub" ",h_contract_terms" ",wire_salt" - ",wire_target_serial_id" + ",wire_target_h_payto" ",coin_sig" ",exchange_timestamp" ",shard" @@ -1096,7 +1088,7 @@ prepare_statements (struct PostgresClosure *pg) " FROM deposits" " JOIN known_coins USING (known_coin_id)" " JOIN denominations USING (denominations_serial)" - " JOIN wire_targets USING (wire_target_serial_id)" + " JOIN wire_targets USING (wire_target_h_payto)" " WHERE ((coin_pub=$1)" " AND (merchant_pub=$3)" " AND (h_contract_terms=$2));", @@ -1122,7 +1114,7 @@ prepare_statements (struct PostgresClosure *pg) ",done" ",deposit_serial_id" " FROM deposits" - " JOIN wire_targets USING (wire_target_serial_id)" + " JOIN wire_targets USING (wire_target_h_payto)" " JOIN known_coins kc USING (known_coin_id)" " JOIN denominations denom USING (denominations_serial)" " WHERE (" @@ -1145,7 +1137,7 @@ prepare_statements (struct PostgresClosure *pg) ",denom.fee_deposit_frac" ",wire_deadline" " FROM deposits" - " JOIN wire_targets USING (wire_target_serial_id)" + " JOIN wire_targets USING (wire_target_h_payto)" " JOIN known_coins USING (known_coin_id)" " JOIN denominations denom USING (denominations_serial)" " WHERE ((coin_pub=$1)" @@ -1169,7 +1161,7 @@ prepare_statements (struct PostgresClosure *pg) ",kc.coin_pub" " FROM deposits" " JOIN wire_targets " - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " JOIN known_coins kc" " USING (known_coin_id)" " JOIN denominations denom" @@ -1203,7 +1195,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN denominations denom USING (denominations_serial)" " WHERE" " merchant_pub=$1" - " AND wire_target_serial_id=$2" + " AND wire_target_h_payto=$2" " AND done=FALSE" " AND extension_blocked=FALSE" " AND refund_deadline<$3" @@ -1251,7 +1243,7 @@ prepare_statements (struct PostgresClosure *pg) ",done" " FROM deposits" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " JOIN known_coins kc" " USING (known_coin_id)" " JOIN denominations denoms" @@ -1287,7 +1279,7 @@ prepare_statements (struct PostgresClosure *pg) " aggregation_serial_id" ",deposits.h_contract_terms" ",payto_uri" - ",h_payto" + ",wire_targets.wire_target_h_payto" ",kc.coin_pub" ",deposits.merchant_pub" ",wire_out.execution_date" @@ -1300,7 +1292,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN deposits" " USING (deposit_serial_id)" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " JOIN known_coins kc" " USING (known_coin_id)" " JOIN denominations denom" @@ -1323,7 +1315,7 @@ prepare_statements (struct PostgresClosure *pg) ",denom.fee_deposit_frac" " FROM deposits" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " JOIN aggregation_tracking" " USING (deposit_serial_id)" " JOIN known_coins" @@ -1382,7 +1374,7 @@ prepare_statements (struct PostgresClosure *pg) "INSERT INTO wire_out " "(execution_date" ",wtid_raw" - ",wire_target_serial_id" + ",wire_target_h_payto" ",exchange_account_section" ",amount_val" ",amount_frac" @@ -1395,7 +1387,7 @@ prepare_statements (struct PostgresClosure *pg) "(wireout_uuid" ",execution_date" ",wtid_raw" - ",wire_target_serial_id" + ",wire_target_h_payto" ",exchange_account_section" ",amount_val" ",amount_frac" @@ -1456,7 +1448,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN known_coins" " USING (known_coin_id)" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " WHERE wire_deadline >= $1" " AND wire_deadline < $2" " AND NOT (EXISTS (SELECT 1" @@ -1480,7 +1472,7 @@ prepare_statements (struct PostgresClosure *pg) ",amount_frac" " FROM wire_out" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " WHERE wireout_uuid>=$1" " ORDER BY wireout_uuid ASC;", 1), @@ -1496,7 +1488,7 @@ prepare_statements (struct PostgresClosure *pg) ",amount_frac" " FROM wire_out" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " WHERE " " wireout_uuid>=$1 " " AND exchange_account_section=$2" @@ -1580,7 +1572,7 @@ prepare_statements (struct PostgresClosure *pg) ",closing_fee_frac" " FROM reserves_close" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " JOIN reserves" " USING (reserve_pub)" " WHERE close_uuid>=$1" @@ -1649,7 +1641,7 @@ prepare_statements (struct PostgresClosure *pg) ",wtid" " FROM reserves_close" " JOIN wire_targets" - " USING (wire_target_serial_id)" + " USING (wire_target_h_payto)" " WHERE reserve_pub=$1;", 1), /* Used in #postgres_get_expired_reserves() */ @@ -1665,7 +1657,7 @@ prepare_statements (struct PostgresClosure *pg) " JOIN reserves_in ri" " USING (reserve_pub)" " JOIN wire_targets wt" - " ON (ri.wire_source_serial_id = wt.wire_target_serial_id)" + " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)" " WHERE expiration_date<=$1" " AND (current_balance_val != 0 " " OR current_balance_frac != 0)" @@ -2198,7 +2190,7 @@ prepare_statements (struct PostgresClosure *pg) ",wire_reference" ",credit_val" ",credit_frac" - ",wire_source_serial_id" + ",wire_source_h_payto" ",exchange_account_section" ",execution_date" " FROM reserves_in" @@ -2212,7 +2204,7 @@ prepare_statements (struct PostgresClosure *pg) ",reserve_pub" ",execution_date" ",wtid" - ",wire_target_serial_id" + ",wire_target_h_payto" ",amount_val" ",amount_frac" ",closing_fee_val" @@ -2354,7 +2346,7 @@ prepare_statements (struct PostgresClosure *pg) ",h_contract_terms" ",coin_sig" ",wire_salt" - ",wire_target_serial_id" + ",wire_target_h_payto" ",tiny" ",done" ",extension_blocked" @@ -2382,7 +2374,7 @@ prepare_statements (struct PostgresClosure *pg) " wireout_uuid AS serial" ",execution_date" ",wtid_raw" - ",wire_target_serial_id" + ",wire_target_h_payto" ",exchange_account_section" ",amount_val" ",amount_frac" @@ -2487,7 +2479,7 @@ prepare_statements (struct PostgresClosure *pg) "insert_into_table_wire_targets", "INSERT INTO wire_targets" "(wire_target_serial_id" - ",h_payto" + ",wire_target_h_payto" ",payto_uri" ",kyc_ok" ",external_id" @@ -2513,7 +2505,7 @@ prepare_statements (struct PostgresClosure *pg) ",wire_reference" ",credit_val" ",credit_frac" - ",wire_source_serial_id" + ",wire_source_h_payto" ",exchange_account_section" ",execution_date" ",reserve_pub" @@ -2526,7 +2518,7 @@ prepare_statements (struct PostgresClosure *pg) "(close_uuid" ",execution_date" ",wtid" - ",wire_target_serial_id" + ",wire_target_h_payto" ",amount_val" ",amount_frac" ",closing_fee_val" @@ -2660,7 +2652,7 @@ prepare_statements (struct PostgresClosure *pg) ",h_contract_terms" ",coin_sig" ",wire_salt" - ",wire_target_serial_id" + ",wire_target_h_payto" ",tiny" ",done" ",extension_blocked" @@ -3914,22 +3906,22 @@ postgres_reserves_get (void *cls, * Set the KYC status to "OK" for a bank account. * * @param cls the @e cls of this struct with the plugin-specific state - * @param payment_target_uuid which account has been checked + * @param h_payto which account has been checked * @param id external ID to persist * @return transaction status */ static enum GNUNET_DB_QueryStatus postgres_set_kyc_ok (void *cls, - uint64_t payment_target_uuid, + const struct TALER_PaytoHashP *h_payto, const char *id) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (h_payto), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_QueryParam params2[] = { - GNUNET_PQ_query_param_uint64 (&payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (h_payto), GNUNET_PQ_query_param_string (id), GNUNET_PQ_query_param_end }; @@ -3938,7 +3930,7 @@ postgres_set_kyc_ok (void *cls, .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED) }; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_payto", + GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto", &rep.h_payto), GNUNET_PQ_result_spec_end }; @@ -3967,34 +3959,31 @@ postgres_set_kyc_ok (void *cls, * Get the @a kyc status and @a h_payto by UUID. * * @param cls the @e cls of this struct with the plugin-specific state - * @param payment_target_uuid which account to get the KYC status for - * @param[out] h_payto set to the hash of the account's payto URI (unsalted) + * @param h_payto set to the hash of the account's payto URI (unsalted) * @param[out] kyc set to the KYC status of the account * @return transaction status */ static enum GNUNET_DB_QueryStatus postgres_select_kyc_status (void *cls, - uint64_t payment_target_uuid, - struct TALER_PaytoHashP *h_payto, + const struct TALER_PaytoHashP *h_payto, struct TALER_EXCHANGEDB_KycStatus *kyc) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (&h_payto), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_payto", - h_payto), - GNUNET_PQ_result_spec_auto_from_type ("kyc_ok", - &kyc->ok), + GNUNET_PQ_result_spec_uint64 ("wire_target_serial_id", + &kyc->payment_target_uuid), + GNUNET_PQ_result_spec_bool ("kyc_ok", + &kyc->ok), GNUNET_PQ_result_spec_end }; kyc->type = TALER_EXCHANGEDB_KYC_UNKNOWN; - kyc->payment_target_uuid = payment_target_uuid; return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "select_kyc_status", + "select_kyc_status_by_payto", params, rs); } @@ -4015,7 +4004,6 @@ inselect_account_kyc_status ( const char *payto_uri, struct TALER_EXCHANGEDB_KycStatus *kyc) { - struct TALER_PaytoHashP h_payto; enum GNUNET_DB_QueryStatus qs; @@ -4267,10 +4255,14 @@ postgres_reserves_in_insert (void *cls, enum GNUNET_DB_QueryStatus qs2; struct TALER_EXCHANGEDB_KycStatus kyc; enum GNUNET_DB_QueryStatus qs3; + struct TALER_PaytoHashP h_payto; + TALER_payto_hash (sender_account_details, + &h_payto); memset (&kyc, 0, sizeof (kyc)); + /* FIXME: inselect re-computes h_payto... */ qs3 = inselect_account_kyc_status (pg, sender_account_details, &kyc); @@ -4286,7 +4278,7 @@ postgres_reserves_in_insert (void *cls, GNUNET_PQ_query_param_uint64 (&wire_ref), TALER_PQ_query_param_amount (balance), GNUNET_PQ_query_param_string (exchange_account_section), - GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (&h_payto), GNUNET_PQ_query_param_timestamp (&execution_time), GNUNET_PQ_query_param_end }; @@ -5686,7 +5678,7 @@ match_deposit_cb (void *cls, * destination. Those deposits must not already be "done". * * @param cls the @e cls of this struct with the plugin-specific state - * @param wire_target destination of the wire transfer + * @param h_payto destination of the wire transfer * @param merchant_pub public key of the merchant * @param deposit_cb function to call for each deposit * @param deposit_cb_cls closure for @a deposit_cb @@ -5697,7 +5689,7 @@ match_deposit_cb (void *cls, static enum GNUNET_DB_QueryStatus postgres_iterate_matching_deposits ( void *cls, - uint64_t wire_target, + const struct TALER_PaytoHashP *h_payto, const struct TALER_MerchantPublicKeyP *merchant_pub, TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb, void *deposit_cb_cls, @@ -5707,7 +5699,7 @@ postgres_iterate_matching_deposits ( struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_uint64 (&wire_target), + GNUNET_PQ_query_param_auto_from_type (h_payto), GNUNET_PQ_query_param_absolute_time (&now), GNUNET_PQ_query_param_end }; @@ -5955,7 +5947,11 @@ postgres_insert_deposit (void *cls, struct PostgresClosure *pg = cls; struct TALER_EXCHANGEDB_KycStatus kyc; enum GNUNET_DB_QueryStatus qs; + struct TALER_PaytoHashP h_payto; + TALER_payto_hash (deposit->receiver_wire_account, + &h_payto); + /* FIXME: inselect re-computes h_payto... */ qs = inselect_account_kyc_status (pg, deposit->receiver_wire_account, &kyc); @@ -5975,7 +5971,7 @@ postgres_insert_deposit (void *cls, GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub), GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms), GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt), - GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (&h_payto), GNUNET_PQ_query_param_auto_from_type (&deposit->csig), GNUNET_PQ_query_param_timestamp (&exchange_timestamp), GNUNET_PQ_query_param_uint64 (&shard), @@ -7264,7 +7260,7 @@ handle_wt_result (void *cls, &h_contract_terms), GNUNET_PQ_result_spec_string ("payto_uri", &payto_uri), - GNUNET_PQ_result_spec_auto_from_type ("h_payto", + GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto", &h_payto), TALER_PQ_result_spec_denom_pub ("denom_pub", &denom_pub), @@ -7798,7 +7794,11 @@ postgres_insert_reserve_closed ( struct TALER_EXCHANGEDB_Reserve reserve; struct TALER_EXCHANGEDB_KycStatus kyc; enum GNUNET_DB_QueryStatus qs; + struct TALER_PaytoHashP h_payto; + TALER_payto_hash (receiver_account, + &h_payto); + /* FIXME: inselect re-computes h_payto... */ qs = inselect_account_kyc_status (pg, receiver_account, &kyc); @@ -7813,7 +7813,7 @@ postgres_insert_reserve_closed ( GNUNET_PQ_query_param_auto_from_type (reserve_pub), GNUNET_PQ_query_param_timestamp (&execution_date), GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), + GNUNET_PQ_query_param_auto_from_type (&h_payto), TALER_PQ_query_param_amount (amount_with_fee), TALER_PQ_query_param_amount (closing_fee), GNUNET_PQ_query_param_end @@ -8094,7 +8094,7 @@ postgres_start_deferred_wire_out (void *cls) * @param cls closure * @param date time of the wire transfer * @param wtid subject of the wire transfer - * @param wire_target identifies the receiver account of the wire transfer + * @param h_payto identifies the receiver account of the wire transfer * @param exchange_account_section configuration section of the exchange specifying the * exchange's bank account being used * @param amount amount that was transmitted @@ -8105,7 +8105,7 @@ postgres_store_wire_transfer_out ( void *cls, struct GNUNET_TIME_Timestamp date, const struct TALER_WireTransferIdentifierRawP *wtid, - uint64_t wire_target, + const struct TALER_PaytoHashP *h_payto, const char *exchange_account_section, const struct TALER_Amount *amount) { @@ -8113,7 +8113,7 @@ postgres_store_wire_transfer_out ( struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_timestamp (&date), GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_uint64 (&wire_target), + GNUNET_PQ_query_param_auto_from_type (h_payto), GNUNET_PQ_query_param_string (exchange_account_section), TALER_PQ_query_param_amount (amount), GNUNET_PQ_query_param_end @@ -11774,9 +11774,9 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->iterate_active_auditors = &postgres_iterate_active_auditors; plugin->iterate_auditor_denominations = &postgres_iterate_auditor_denominations; + plugin->select_kyc_status = &postgres_select_kyc_status; plugin->reserves_get = &postgres_reserves_get; plugin->set_kyc_ok = &postgres_set_kyc_ok; - plugin->select_kyc_status = &postgres_select_kyc_status; plugin->inselect_wallet_kyc_status = &postgres_inselect_wallet_kyc_status; plugin->reserves_in_insert = &postgres_reserves_in_insert; plugin->get_withdraw_info = &postgres_get_withdraw_info; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 7ca1839ff..10390b7fc 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -616,6 +616,10 @@ static uint64_t deposit_rowid; */ static uint64_t wire_target_row; +/** + * Here #deposit_cb() will store the hash of the payto URI. + */ +static struct TALER_PaytoHashP wire_target_h_payto; /** * Function called with details about deposits that @@ -662,6 +666,8 @@ deposit_cb (void *cls, { deposit_rowid = rowid; wire_target_row = wire_target; + TALER_payto_hash (payto_uri, + &wire_target_h_payto); result = 9; } return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; @@ -1048,6 +1054,10 @@ audit_wire_cb (void *cls, static enum GNUNET_GenericReturnValue test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit) { + struct TALER_PaytoHashP h_payto; + + TALER_payto_hash (deposit->receiver_wire_account, + &h_payto); auditor_row_cnt = 0; memset (&wire_out_wtid, 42, @@ -1127,7 +1137,7 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit) plugin->store_wire_transfer_out (plugin->cls, wire_out_date, &wire_out_wtid, - kyc.payment_target_uuid, + &h_payto, "my-config-section", &wire_out_amount)); } @@ -2267,7 +2277,7 @@ run (void *cls) FAILIF (8 == result); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->iterate_matching_deposits (plugin->cls, - wire_target_row, + &wire_target_h_payto, &deposit.merchant_pub, &matching_deposit_cb, &deposit, |