From 08b2623684a09bf5bb1e30282b1fd314df02b3e7 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 24 Sep 2023 19:03:37 +0200 Subject: combine deposit confirmation signatures into one big signature --- src/backenddb/plugin_merchantdb_postgres.c | 167 +++++++++++++++++------------ 1 file changed, 99 insertions(+), 68 deletions(-) (limited to 'src/backenddb/plugin_merchantdb_postgres.c') diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 3682e5c1..30def849 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -89,6 +89,7 @@ #include "pg_lookup_deposits.h" #include "pg_insert_exchange_signkey.h" #include "pg_insert_deposit.h" +#include "pg_insert_deposit_confirmation.h" #include "pg_lookup_refunds.h" #include "pg_mark_contract_paid.h" #include "pg_select_account_by_uri.h" @@ -3060,52 +3061,65 @@ postgres_connect (void *cls) /* for postgres_lookup_deposits_by_order() */ GNUNET_PQ_make_prepare ("lookup_deposits_by_order", "SELECT" - " deposit_serial" - ",exchange_url" - ",h_wire" - ",amount_with_fee" - ",deposit_fee" - ",coin_pub" - " FROM merchant_deposits" - " JOIN merchant_accounts USING (account_serial)" - " WHERE order_serial=$1"), + " dep.deposit_serial" + ",mcon.exchange_url" + ",acc.h_wire" + ",dep.amount_with_fee" + ",dep.deposit_fee" + ",dep.coin_pub" + " FROM merchant_deposits dep" + " JOIN merchant_deposit_confirmations mcon" + " USING(deposit_confirmation_serial)" + " JOIN merchant_accounts acc" + " USING (account_serial)" + " WHERE mcon.order_serial=$1"), /* for postgres_lookup_transfer_details_by_order() */ GNUNET_PQ_make_prepare ("lookup_transfer_details_by_order", "SELECT" " md.deposit_serial" - ",md.exchange_url" + ",mcon.exchange_url" ",mt.wtid" - ",exchange_deposit_value" - ",exchange_deposit_fee" - ",deposit_timestamp" + ",mtc.exchange_deposit_value" + ",mtc.exchange_deposit_fee" + ",mcon.deposit_timestamp" ",mt.confirmed AS transfer_confirmed" - " FROM merchant_transfer_to_coin" - " JOIN merchant_deposits AS md USING (deposit_serial)" - " JOIN merchant_transfers AS mt USING (credit_serial)" - " WHERE deposit_serial IN" - " (SELECT deposit_serial" - " FROM merchant_deposits" - " WHERE order_serial=$1)"), + " FROM merchant_transfer_to_coin mtc" + " JOIN merchant_deposits md" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_transfers mt" + " USING (credit_serial)" + " JOIN merchant_accounts acc" + " ON (acc.account_serial = mt.account_serial)" + /* Check that all this is for the same instance */ + " JOIN merchant_contract_terms contracts" + " USING (merchant_serial, order_serial)" + " WHERE mcon.order_serial=$1"), /* for postgres_mark_order_wired() */ GNUNET_PQ_make_prepare ("mark_order_wired", "UPDATE merchant_contract_terms SET" - " wired=true" + " wired=TRUE" " WHERE order_serial=$1"), /* for postgres_lookup_refunds_detailed() */ GNUNET_PQ_make_prepare ("lookup_refunds_detailed", "SELECT" - " refund_serial" - ",refund_timestamp" - ",coin_pub" - ",merchant_deposits.exchange_url" - ",rtransaction_id" - ",reason" - ",refund_amount" + " ref.refund_serial" + ",ref.refund_timestamp" + ",dep.coin_pub" + ",mcon.exchange_url" + ",ref.rtransaction_id" + ",ref.reason" + ",ref.refund_amount" ",merchant_refund_proofs.exchange_sig IS NULL AS pending" - " FROM merchant_refunds" - " JOIN merchant_deposits USING (order_serial, coin_pub)" - " LEFT JOIN merchant_refund_proofs USING (refund_serial)" - " WHERE order_serial=" + " FROM merchant_deposit_confirmations mcon" + " JOIN merchant_deposits dep" + " USING (deposit_confirmation_serial)" + " JOIN merchant_refunds ref" + " USING (order_serial, coin_pub)" + " LEFT JOIN merchant_refund_proofs" + " USING (refund_serial)" + " WHERE mcon.order_serial=" " (SELECT order_serial" " FROM merchant_contract_terms" " WHERE h_contract_terms=$2" @@ -3197,23 +3211,28 @@ postgres_connect (void *cls) /* for postgres_lookup_deposits_by_contract_and_coin() */ GNUNET_PQ_make_prepare ("lookup_deposits_by_contract_and_coin", "SELECT" - " exchange_url" - ",amount_with_fee" - ",deposit_fee" - ",refund_fee" - ",wire_fee" - ",h_wire" - ",deposit_timestamp" - ",refund_deadline" - ",exchange_sig" - ",exchange_pub" - " FROM merchant_contract_terms" - " JOIN merchant_deposits USING (order_serial)" - " JOIN merchant_exchange_signing_keys USING (signkey_serial)" - " JOIN merchant_accounts USING (account_serial)" + " mcon.exchange_url" + ",dep.amount_with_fee" + ",dep.deposit_fee" + ",dep.refund_fee" + ",mcon.wire_fee" + ",acc.h_wire" + ",mcon.deposit_timestamp" + ",mct.refund_deadline" + ",mcon.exchange_sig" + ",msig.exchange_pub" + " FROM merchant_contract_terms mct" + " JOIN merchant_deposit_confirmations mcon" + " USING (order_serial)" + " JOIN merchant_deposits dep" + " USING (deposit_confirmation_serial)" + " JOIN merchant_exchange_signing_keys msig" + " USING (signkey_serial)" + " JOIN merchant_accounts acc" + " USING (account_serial)" " WHERE h_contract_terms=$2" - " AND coin_pub=$3" - " AND merchant_contract_terms.merchant_serial=" + " AND dep.coin_pub=$3" + " AND mct.merchant_serial=" " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)"), @@ -3235,29 +3254,39 @@ postgres_connect (void *cls) /* for postgres_lookup_transfer_summary() */ GNUNET_PQ_make_prepare ("lookup_transfer_summary", "SELECT" - " order_id" - ",exchange_deposit_value" - ",exchange_deposit_fee" - " FROM merchant_transfers" - " JOIN merchant_transfer_to_coin USING (credit_serial)" - " JOIN merchant_deposits USING (deposit_serial)" - " JOIN merchant_contract_terms USING (order_serial)" - " WHERE wtid=$2" - " AND merchant_transfers.exchange_url=$1"), + " mct.order_id" + ",mtc.exchange_deposit_value" + ",mtc.exchange_deposit_fee" + " FROM merchant_transfers mtr" + " JOIN merchant_transfer_to_coin mtc" + " USING (credit_serial)" + " JOIN merchant_deposits dep" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_contract_terms mct" + " USING (order_serial)" + " WHERE mtr.wtid=$2" + " AND mtr.exchange_url=$1"), /* for postgres_lookup_transfer_details() */ GNUNET_PQ_make_prepare ("lookup_transfer_details", "SELECT" - " merchant_contract_terms.h_contract_terms" - ",merchant_transfer_to_coin.offset_in_exchange_list" - ",merchant_deposits.coin_pub" - ",exchange_deposit_value" - ",exchange_deposit_fee" - " FROM merchant_transfer_to_coin" - " JOIN merchant_deposits USING (deposit_serial)" - " JOIN merchant_contract_terms USING (order_serial)" - " JOIN merchant_transfers USING (credit_serial)" - " WHERE merchant_transfers.wtid=$2" - " AND merchant_transfers.exchange_url=$1"), + " mterm.h_contract_terms" + ",mtcoin.offset_in_exchange_list" + ",dep.coin_pub" + ",mtcoin.exchange_deposit_value" + ",mtcoin.exchange_deposit_fee" + " FROM merchant_transfer_to_coin mtcoin" + " JOIN merchant_deposits dep" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_contract_terms mterm" + " USING (order_serial)" + " JOIN merchant_transfers mtr" + " USING (credit_serial)" + " WHERE mtr.wtid=$2" + " AND mtr.exchange_url=$1"), /* For postgres_insert_reserve() */ GNUNET_PQ_make_prepare ("insert_reserve_key", "INSERT INTO merchant_reward_reserve_keys" @@ -3786,6 +3815,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_lookup_deposits; plugin->insert_exchange_signkey = &TMH_PG_insert_exchange_signkey; + plugin->insert_deposit_confirmation + = &TMH_PG_insert_deposit_confirmation; plugin->insert_deposit = &TMH_PG_insert_deposit; plugin->lookup_refunds -- cgit v1.2.3