diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-10 21:20:46 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-10 21:20:46 +0200 |
commit | 257ee8379ecc4af7ac325aaf868b4e23a9293c14 (patch) | |
tree | a22bf720200913b145a2d4abd0e6f446b3a1eee8 /src | |
parent | 4f237e8aae9b67a0bdb9363934dcbbb3a7742daa (diff) | |
download | merchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.tar.gz merchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.tar.bz2 merchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.zip |
implement caching/persisting of exchange /refund responses
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd_refund_lookup.c | 60 |
1 files changed, 49 insertions, 11 deletions
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 @@ -64,6 +64,11 @@ struct CoinRefund struct ProcessRefundData *prd; /** + * URL of the exchange for this @e coin_pub. + */ + char *exchange_url; + + /** * Coin to refund. */ struct TALER_CoinSpendPublicKeyP coin_pub; @@ -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 */ |