From 4a031a692b962483d9ebc04f6d2526e192f1c7cd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 4 May 2016 09:42:52 +0200 Subject: implementing /refund API (#3848) --- src/exchange-lib/exchange_api_refund.c | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/exchange-lib/exchange_api_refund.c') diff --git a/src/exchange-lib/exchange_api_refund.c b/src/exchange-lib/exchange_api_refund.c index ade07009..f29488fb 100644 --- a/src/exchange-lib/exchange_api_refund.c +++ b/src/exchange-lib/exchange_api_refund.c @@ -17,7 +17,6 @@ /** * @file exchange-lib/exchange_api_refund.c * @brief Implementation of the /refund request of the exchange's HTTP API - * @author Sree Harsha Totakura * @author Christian Grothoff */ #include "platform.h" @@ -138,8 +137,8 @@ verify_refund_signature_ok (const struct TALER_EXCHANGE_RefundHandle *rh, */ static void handle_refund_finished (void *cls, - long response_code, - const json_t *json) + long response_code, + const json_t *json) { struct TALER_EXCHANGE_RefundHandle *rh = cls; @@ -205,7 +204,7 @@ handle_refund_finished (void *cls, * * @param exchange the exchange handle; the exchange must be ready to operate * @param amount the amount to be refunded; must be larger than the refund fee - * (as that fee is still being subtracted), and smaller than the amount + * (as that fee is still being subtracted), and smaller than the amount * (with deposit fee) of the original deposit contribution of this coin * @param refund_fee fee applicable to this coin for the refund * @param h_contract hash of the contact of the merchant with the customer that is being refunded @@ -226,6 +225,7 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, const struct TALER_Amount *amount, const struct TALER_Amount *refund_fee, const struct GNUNET_HashCode *h_contract, + uint64_t transaction_id, const struct TALER_CoinSpendPublicKeyP *coin_pub, uint64_t rtransaction_id, const struct TALER_MerchantPrivateKeyP *merchant_priv, @@ -234,8 +234,8 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, { struct TALER_EXCHANGE_RefundHandle *rh; struct GNUNET_CURL_Context *ctx; + struct TALER_RefundRequestPS rr; struct TALER_MerchantSignatureP merchant_sig; - struct TALER_MerchantPublicKeyP merchant_pub; json_t *refund_obj; CURL *eh; @@ -245,8 +245,22 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, GNUNET_break (0); return NULL; } - /* FIXME: create signature! */ - + rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND); + rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS)); + rr.h_contract = *h_contract; + rr.transaction_id = GNUNET_htonll (transaction_id); + rr.coin_pub = *coin_pub; + GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv, + &rr.merchant.eddsa_pub); + rr.rtransaction_id = GNUNET_htonll (rtransaction_id); + TALER_amount_hton (&rr.refund_amount, + amount); + TALER_amount_hton (&rr.refund_fee, + refund_fee); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (&merchant_priv->eddsa_priv, + &rr.purpose, + &merchant_sig.eddsa_sig)); refund_obj = json_pack ("{s:o, s:o," /* amount/fee */ " s:o, s:o," /* H_contract, coin_pub */ " s:I, s:I," /* transaction id, rtransaction id */ @@ -259,8 +273,8 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, sizeof (*coin_pub)), "transaction_id", (json_int_t) transaction_id, "rtransaction_id", (json_int_t) rtransaction_id, - "merchant_pub", GNUNET_JSON_from_data (&merchant_pub, - sizeof (merchant_pub)), + "merchant_pub", GNUNET_JSON_from_data (&rr.merchant, + sizeof (struct TALER_MerchantPublicKeyP)), "merchant_sig", GNUNET_JSON_from_data (&merchant_sig, sizeof (merchant_sig)) ); @@ -274,13 +288,13 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, rh->depconf.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_REFUND); rh->depconf.h_contract = *h_contract; rh->depconf.transaction_id = GNUNET_htonll (transaction_id); + rh->depconf.coin_pub = *coin_pub; + rh->depconf.merchant = rr.merchant; rh->depconf.rtransaction_id = GNUNET_htonll (rtransaction_id); TALER_amount_hton (&rh->depconf.refund_amount, amount); TALER_amount_hton (&rh->depconf.refund_fee, refund_fee); - rh->depconf.coin_pub = *coin_pub; - rh->depconf.merchant = *merchant_pub; eh = curl_easy_init (); GNUNET_assert (NULL != (rh->json_enc = -- cgit v1.2.3 From ad6a40aaa580551b2861d51740a427af05d9f165 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 4 May 2016 13:21:22 +0200 Subject: fix fmt string issues --- src/bank-lib/bank_api_admin.c | 2 +- src/exchange-lib/exchange_api_admin.c | 2 +- src/exchange-lib/exchange_api_deposit.c | 2 +- src/exchange-lib/exchange_api_deposit_wtid.c | 2 +- src/exchange-lib/exchange_api_handle.c | 2 +- src/exchange-lib/exchange_api_refresh.c | 4 ++-- src/exchange-lib/exchange_api_refresh_link.c | 2 +- src/exchange-lib/exchange_api_refund.c | 2 +- src/exchange-lib/exchange_api_reserve.c | 4 ++-- src/exchange-lib/exchange_api_wire.c | 2 +- src/exchange-lib/exchange_api_wire_deposits.c | 2 +- src/exchange-lib/test_exchange_api.c | 8 +++----- src/exchangedb/exchangedb_keyio.c | 2 +- 13 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/exchange-lib/exchange_api_refund.c') diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index df352518..5cd82b09 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c @@ -143,7 +143,7 @@ handle_admin_add_incoming_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c index 06a39ffa..068a11e0 100644 --- a/src/exchange-lib/exchange_api_admin.c +++ b/src/exchange-lib/exchange_api_admin.c @@ -122,7 +122,7 @@ handle_admin_add_incoming_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c index 8a2837ac..0dc03637 100644 --- a/src/exchange-lib/exchange_api_deposit.c +++ b/src/exchange-lib/exchange_api_deposit.c @@ -246,7 +246,7 @@ handle_deposit_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_deposit_wtid.c b/src/exchange-lib/exchange_api_deposit_wtid.c index 8547979b..b3c5b328 100644 --- a/src/exchange-lib/exchange_api_deposit_wtid.c +++ b/src/exchange-lib/exchange_api_deposit_wtid.c @@ -224,7 +224,7 @@ handle_deposit_wtid_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index 04508aa3..e5586022 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -632,7 +632,7 @@ keys_completed_cb (void *cls, default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); break; } diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index f112152c..a63f03ac 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -1325,7 +1325,7 @@ handle_refresh_melt_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; @@ -1860,7 +1860,7 @@ handle_refresh_reveal_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c index e809c3f1..cd3f6d72 100644 --- a/src/exchange-lib/exchange_api_refresh_link.c +++ b/src/exchange-lib/exchange_api_refresh_link.c @@ -364,7 +364,7 @@ handle_refresh_link_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_refund.c b/src/exchange-lib/exchange_api_refund.c index f29488fb..a6069f0b 100644 --- a/src/exchange-lib/exchange_api_refund.c +++ b/src/exchange-lib/exchange_api_refund.c @@ -177,7 +177,7 @@ handle_refund_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c index d3e55ed9..056d2f08 100644 --- a/src/exchange-lib/exchange_api_reserve.c +++ b/src/exchange-lib/exchange_api_reserve.c @@ -363,7 +363,7 @@ handle_reserve_status_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; @@ -738,7 +738,7 @@ handle_reserve_withdraw_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c index 453da14d..7515806a 100644 --- a/src/exchange-lib/exchange_api_wire.c +++ b/src/exchange-lib/exchange_api_wire.c @@ -203,7 +203,7 @@ handle_wire_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/exchange_api_wire_deposits.c b/src/exchange-lib/exchange_api_wire_deposits.c index 446ac003..0601f9b4 100644 --- a/src/exchange-lib/exchange_api_wire_deposits.c +++ b/src/exchange-lib/exchange_api_wire_deposits.c @@ -217,7 +217,7 @@ handle_wire_deposits_finished (void *cls, /* unexpected response code */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", - response_code); + (unsigned int) response_code); GNUNET_break (0); response_code = 0; break; diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 05d18633..49c124c8 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -1270,9 +1270,9 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have denomination key for `%s', but with wrong expiration range %llu vs [%llu,%llu)\n", str, - now.abs_value_us, - pk->valid_from.abs_value_us, - pk->withdraw_valid_until.abs_value_us); + (unsigned long long) now.abs_value_us, + (unsigned long long) pk->valid_from.abs_value_us, + (unsigned long long) pk->withdraw_valid_until.abs_value_us); GNUNET_free (str); return NULL; } @@ -1397,7 +1397,6 @@ wire_deposits_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Total amount missmatch to command %s\n", - http_status, cmd->label); json_dumpf (json, stderr, 0); fail (is); @@ -1451,7 +1450,6 @@ wire_deposits_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Total amount missmatch to command %s\n", - http_status, cmd->label); json_dumpf (json, stderr, 0); fail (is); diff --git a/src/exchangedb/exchangedb_keyio.c b/src/exchangedb/exchangedb_keyio.c index 9f170f64..5f29cb0d 100644 --- a/src/exchangedb/exchangedb_keyio.c +++ b/src/exchangedb/exchangedb_keyio.c @@ -70,7 +70,7 @@ signkeys_iterate_dir_iter (void *cls, "Invalid signkey file `%s': wrong size (%d, expected %u)\n", filename, (int) nread, - sizeof (struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP)); + (unsigned int) sizeof (struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP)); return GNUNET_OK; } return skc->it (skc->it_cls, -- cgit v1.2.3