summaryrefslogtreecommitdiff
path: root/src/lib/merchant_api_post_order_abort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/merchant_api_post_order_abort.c')
-rw-r--r--src/lib/merchant_api_post_order_abort.c186
1 files changed, 37 insertions, 149 deletions
diff --git a/src/lib/merchant_api_post_order_abort.c b/src/lib/merchant_api_post_order_abort.c
index 6ee20f93..3f1a7c0e 100644
--- a/src/lib/merchant_api_post_order_abort.c
+++ b/src/lib/merchant_api_post_order_abort.c
@@ -95,16 +95,16 @@ struct TALER_MERCHANT_OrderAbortHandle
/**
- * Check that the response for a /pay refund is well-formed,
+ * Check that the response for an abort is well-formed,
* and call the application callback with the result if it is
* OK. Otherwise returns #GNUNET_SYSERR.
*
- * @param ph handle to operation that created the reply
+ * @param oah handle to operation that created the reply
* @param json the reply to parse
* @return #GNUNET_OK on success
*/
static int
-check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
+check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah,
const json_t *json)
{
json_t *refunds;
@@ -161,9 +161,10 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
&res[i].exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&res[i].exchange_pub),
+ TALER_JSON_spec_amount ("refund_fee",
+ &res[i].refund_fee),
GNUNET_JSON_spec_end ()
};
- int found;
if (GNUNET_OK !=
GNUNET_JSON_parse (exchange_reply,
@@ -177,7 +178,7 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
}
{
- struct TALER_RefundRequestPS rr = {
+ struct TALER_RefundConfirmationPS rr = {
.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND),
.purpose.size = htonl (sizeof (rr)),
.h_contract_terms = oah->h_contract_terms,
@@ -189,12 +190,12 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
TALER_amount_hton (&rr.refund_amount,
&oah->coins[i].amount_with_fee);
TALER_amount_hton (&rr.refund_fee,
- &oah->coins[i].refund_fee);
+ &res[i].refund_fee);
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
+ GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND,
&rr,
- &sig->eddsa_sig,
- &merchant_pub.eddsa_pub))
+ &res[i].exchange_sig.eddsa_signature,
+ &res[i].exchange_pub.eddsa_pub))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -210,6 +211,7 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
oah->abort_cb (oah->abort_cb_cls,
&hr,
+ &oah->merchant_pub,
num_refunds,
res);
}
@@ -221,124 +223,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *ph,
/**
- * We got a 403 response back from the exchange (or the merchant).
- * Now we need to check the provided cryptographic proof that the
- * coin was actually already spent!
- *
- * @param pc handle of the original coin we paid with
- * @param json cryptographic proof of coin's transaction
- * history as was returned by the exchange/merchant
- * @return #GNUNET_OK if proof checks out
- */
-static int
-check_coin_history (const struct TALER_MERCHANT_PaidCoin *pc,
- json_t *json)
-{
- struct TALER_Amount spent;
- struct TALER_Amount spent_plus_contrib;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_verify_coin_history (NULL, /* do not verify fees */
- pc->amount_with_fee.currency,
- &pc->coin_pub,
- json,
- &spent))
- {
- /* Exchange's history fails to verify */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (&spent_plus_contrib,
- &spent,
- &pc->amount_with_fee))
- {
- /* We got an integer overflow? Bad application! */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if (-1 != TALER_amount_cmp (&pc->denom_value,
- &spent_plus_contrib))
- {
- /* according to our calculations, the transaction should
- have still worked, exchange error! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Accepting proof of double-spending\n");
- return GNUNET_OK;
-}
-
-
-/**
- * We got a 409 response back from the exchange (or the merchant).
- * Now we need to check the provided cryptographic proof that the
- * coin was actually already spent!
- *
- * @param ph handle of the original pay operation
- * @param json cryptographic proof returned by the
- * exchange/merchant
- * @return #GNUNET_OK if proof checks out
- */
-static int
-check_conflict (struct TALER_MERCHANT_Pay *ph,
- const json_t *json)
-{
- json_t *history;
- json_t *ereply;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("exchange_reply", &ereply),
- GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub),
- GNUNET_JSON_spec_end ()
- };
- struct GNUNET_JSON_Specification hspec[] = {
- GNUNET_JSON_spec_json ("history", &history),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_JSON_parse (ereply,
- hspec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- GNUNET_JSON_parse_free (spec);
-
- for (unsigned int i = 0; i<oah->num_coins; i++)
- {
- if (0 == memcmp (&oah->coins[i].coin_pub,
- &coin_pub,
- sizeof (struct TALER_CoinSpendPublicKeyP)))
- {
- int ret;
-
- ret = check_coin_history (&oah->coins[i],
- history);
- GNUNET_JSON_parse_free (hspec);
- return ret;
- }
- }
- GNUNET_break_op (0); /* complaint is not about any of the coins
- that we actually paid with... */
- GNUNET_JSON_parse_free (hspec);
- return GNUNET_SYSERR;
-}
-
-
-/**
* Function called when we're done processing the
* abort request.
*
@@ -436,9 +320,10 @@ handle_abort_finished (void *cls,
}
oah->abort_cb (oah->abort_cb_cls,
&hr,
+ NULL,
0,
NULL);
- TALER_MERCHANT_abort_cancel (oah);
+ TALER_MERCHANT_order_abort_cancel (oah);
}
@@ -470,6 +355,7 @@ TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx,
{
struct TALER_MERCHANT_OrderAbortHandle *oah;
json_t *abort_obj;
+ json_t *j_coins;
j_coins = json_array ();
if (NULL == j_coins)
@@ -542,30 +428,32 @@ TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx,
memcpy (oah->coins,
coins,
num_coins * sizeof (struct TALER_MERCHANT_AbortCoin));
-
- eh = curl_easy_init ();
- GNUNET_assert (NULL != eh);
- if (GNUNET_OK !=
- TALER_curl_easy_post (&oah->post_ctx,
- eh,
- abort_obj))
{
- GNUNET_break (0);
+ CURL *eh;
+
+ eh = curl_easy_init ();
+ GNUNET_assert (NULL != eh);
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&oah->post_ctx,
+ eh,
+ abort_obj))
+ {
+ GNUNET_break (0);
+ json_decref (abort_obj);
+ GNUNET_free (oah);
+ return NULL;
+ }
json_decref (abort_obj);
- GNUNET_free (oah);
- return NULL;
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ oah->url));
+ oah->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ oah->post_ctx.headers,
+ &handle_abort_finished,
+ oah);
}
- json_decref (abort_obj);
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_URL,
- oah->url));
- oah->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- oah->post_ctx.headers,
- &handle_abort_finished,
- oah);
-
return oah;
}