From 257ee8379ecc4af7ac325aaf868b4e23a9293c14 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 10 Apr 2020 21:20:46 +0200 Subject: implement caching/persisting of exchange /refund responses --- ChangeLog | 42 +++++++++-------- src/backend/taler-merchant-httpd_refund_lookup.c | 60 +++++++++++++++++++----- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index d34b96fb..4a61c55e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri 10 Apr 2020 09:01:22 PM CEST + Changing refund API to have the merchant backend make the /refund + request to the exchange instead of having the wallet do it (#5299). -CG + Tue 31 Mar 2020 04:17:58 PM CEST Releasing taler-merchant 0.7.0. -CG @@ -30,16 +34,16 @@ Wed Oct 18 15:33:23 CEST 2017 Releasing taler-merchant 0.4.0. -CG Thu Jun 22 15:12:37 CEST 2017 - Implementing /refund + Implementing /refund Tue Jun 6 14:30:43 CEST 2017 - Abstracting the response gotten from the exchange's tracking - API and relying it to the frontend. - A payment generator has been implemented so that the db can - easily be populated for testing purposes. - /history API now has the way to query from a starting base date - ahead into the future. - Memory leak fixes. -CG/MS + Abstracting the response gotten from the exchange's tracking + API and relying it to the frontend. + A payment generator has been implemented so that the db can + easily be populated for testing purposes. + /history API now has the way to query from a starting base date + ahead into the future. + Memory leak fixes. -CG/MS Releasing taler-merchant 0.3.0. -CG Mon Mar 6 17:57:51 CET 2017 @@ -52,24 +56,22 @@ Mon Mar 6 00:59:25 CET 2017 IP address (#4752). Enabling use of dual-stack by default. -CG Thu Dec 15 10:37:08 CET 2016 - Implementing: - - /map/in, /map/out API, to allow frontends to store - plain text contracts in database and retrieving them - by looking for their hashcodes. - + Implementing: + - /map/in, /map/out API, to allow frontends to store + plain text contracts in database and retrieving them + by looking for their hashcodes. Fri Nov 18 18:54:07 CET 2016 Misc. minor updates to match API changes from exchange 0.2. Releasing taler-merchant 0.2.0. -CG Mon Oct 10 16:27:57 CEST 2016 - Implementing: - - /track API, to map transactions to wire transfers and - viceversa. - - /history API, to get the list of transactions in DB. - - merchant "instances", to run make multiple shops on the - same backend. - -MS + Implementing: + - /track API, to map transactions to wire transfers and + viceversa. + - /history API, to get the list of transactions in DB. + - merchant "instances", to run make multiple shops on the + same backend. -MS Tue Jun 7 15:17:45 CEST 2016 Store signing key used by exchange in DB. Might be useful diff --git a/src/backend/taler-merchant-httpd_refund_lookup.c b/src/backend/taler-merchant-httpd_refund_lookup.c index e80241b7..0fd83ad3 100644 --- a/src/backend/taler-merchant-httpd_refund_lookup.c +++ b/src/backend/taler-merchant-httpd_refund_lookup.c @@ -63,6 +63,11 @@ struct CoinRefund */ struct ProcessRefundData *prd; + /** + * URL of the exchange for this @e coin_pub. + */ + char *exchange_url; + /** * Coin to refund. */ @@ -213,6 +218,7 @@ cleanup_prd (struct TM_HandlerContext *cls) json_decref (cr->exchange_reply); cr->exchange_reply = NULL; } + GNUNET_free (cr->exchange_url); GNUNET_free (cr); } GNUNET_free (prd); @@ -295,12 +301,25 @@ refund_cb (void *cls, } else { + enum GNUNET_DB_QueryStatus qs; + cr->exchange_pub = *exchange_pub; cr->exchange_sig = *exchange_sig; - /* FIXME: store in our database, - 1) as evidence for us that the refund happened, and - 2) to possibly avoid doing another exchange iteration - the next time around. */ + qs = db->put_refund_proof (db->cls, + &cr->prd->merchant->pubkey, + &cr->prd->h_contract_terms, + &cr->coin_pub, + cr->rtransaction_id, + exchange_pub, + exchange_sig); + if (0 >= qs) + { + /* generally, this is relatively harmless for the merchant, but let's at + least log this. */ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to persist exchange response to /refund in database: %d\n", + qs); + } } check_resume_prd (cr->prd); } @@ -381,6 +400,7 @@ process_refunds_cb (void *cls, TALER_amount2s (refund_amount), reason); cr = GNUNET_new (struct CoinRefund); + cr->exchange_url = GNUNET_strdup (exchange_url); cr->prd = prd; cr->coin_pub = *coin_pub; cr->rtransaction_id = rtransaction_id; @@ -389,13 +409,6 @@ process_refunds_cb (void *cls, GNUNET_CONTAINER_DLL_insert (prd->cr_head, prd->cr_tail, cr); - /* FIXME: check in database if we already got the - results from #refund_cb() from an earlier request, - if so, avoid this step: */ - cr->fo = TMH_EXCHANGES_find_exchange (exchange_url, - NULL, - &exchange_found_cb, - cr); } @@ -529,6 +542,31 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, TALER_EC_REFUND_LOOKUP_DB_ERROR, "Failed to lookup refunds for contract"); } + + /* Now launch exchange interactions, unless we already have the + response in the database! */ + for (struct CoinRefund *cr = prd->cr_head; + NULL != cr; + cr = cr->next) + { + enum GNUNET_DB_QueryStatus qs; + + qs = db->get_refund_proof (db->cls, + &cr->prd->merchant->pubkey, + &cr->prd->h_contract_terms, + &cr->coin_pub, + cr->rtransaction_id, + &cr->exchange_pub, + &cr->exchange_sig); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) + { + /* We need to talk to the exchange */ + cr->fo = TMH_EXCHANGES_find_exchange (cr->exchange_url, + NULL, + &exchange_found_cb, + cr); + } + } } /* Check if there are still exchange operations pending */ -- cgit v1.2.3