From 0328ab313b9194f10c154f74518089df9509fe09 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 17 Jan 2020 15:43:04 +0100 Subject: use more specific SELECT in exchange aggregator on refunds instead of filtering in application logic later --- src/exchangedb/plugin_exchangedb_postgres.c | 47 ++++++++++++++--------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/exchangedb/plugin_exchangedb_postgres.c') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 925f2853..8a013c40 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -736,6 +736,17 @@ postgres_get_session (void *cls) " JOIN denominations denom USING (denom_pub_hash)" " WHERE coin_pub=$1;", 1), + /* Query the 'refunds' by coin public key, merchant_pub and contract hash */ + GNUNET_PQ_make_prepare ("get_refunds_by_coin_and_contract", + "SELECT" + " amount_with_fee_val" + ",amount_with_fee_frac" + " FROM refunds" + " WHERE" + " coin_pub=$1" + " AND merchant_pub=$2" + " AND h_contract_terms=$3;", + 3), /* Fetch refunds with rowid '\geq' the given parameter */ GNUNET_PQ_make_prepare ("audit_get_refunds_incr", "SELECT" @@ -3296,25 +3307,10 @@ get_refunds_cb (void *cls, for (unsigned int i = 0; icb (srctx->cb_cls, - &merchant_pub, - &merchant_sig, - &h_contract, - rtransaction_id, - &amount_with_fee, - &refund_fee)) + &amount_with_fee)) return; } } /** - * Select refunds by @a coin_pub. + * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract. * * @param cls closure of plugin * @param session database handle to use * @param coin_pub coin to get refunds for + * @param merchant_pub merchant to get refunds for + * @param h_contract_pub contract (hash) to get refunds for * @param cb function to call for each refund found * @param cb_cls closure for @a cb * @return query result status @@ -3355,13 +3348,19 @@ postgres_select_refunds_by_coin (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_CoinSpendPublicKeyP *coin_pub, - TALER_EXCHANGEDB_RefundCoinCallback cb, + const struct + TALER_MerchantPublicKeyP *merchant_pub, + const struct GNUNET_HashCode *h_contract, + 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), + GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_auto_from_type (h_contract), GNUNET_PQ_query_param_end }; struct SelectRefundContext srctx = { @@ -3372,7 +3371,7 @@ postgres_select_refunds_by_coin (void *cls, }; qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "get_refunds_by_coin", + "get_refunds_by_coin_and_contract", params, &get_refunds_cb, &srctx); -- cgit v1.2.3