diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_purses_merge.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_purses_merge.c | 165 |
1 files changed, 85 insertions, 80 deletions
diff --git a/src/exchange/taler-exchange-httpd_purses_merge.c b/src/exchange/taler-exchange-httpd_purses_merge.c index 9ce3033d5..fb5ce4d90 100644 --- a/src/exchange/taler-exchange-httpd_purses_merge.c +++ b/src/exchange/taler-exchange-httpd_purses_merge.c @@ -34,7 +34,6 @@ #include "taler-exchange-httpd_responses.h" #include "taler_exchangedb_lib.h" #include "taler-exchange-httpd_keys.h" -#include "taler-exchange-httpd_wire.h" /** @@ -168,15 +167,20 @@ reply_merge_success (struct MHD_Connection *connection, } else { +#if WAD_NOT_IMPLEMENTED + /* FIXME: figure out partner, lookup wad fee by partner! #7271 */ if (0 > TALER_amount_subtract (&merge_amount, &pcc->target_amount, - &pcc->wf->wad)) + &wad_fee)) { GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TEH_currency, &merge_amount)); } +#else + merge_amount = pcc->target_amount; +#endif } if (TALER_EC_NONE != (ec = TALER_exchange_online_purse_merged_sign ( @@ -275,23 +279,48 @@ merge_transaction (void *cls, bool in_conflict = true; bool no_balance = true; bool no_partner = true; - const char *required; + char *required; - required = TALER_KYCLOGIC_kyc_test_required ( + qs = TALER_KYCLOGIC_kyc_test_required ( TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE, &pcc->h_payto, TEH_plugin->select_satisfied_kyc_processes, TEH_plugin->cls, &amount_iterator, - pcc); + pcc, + &required); + if (qs < 0) + { + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + return qs; + GNUNET_break (0); + *mhd_ret = + TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "kyc_test_required"); + return qs; + } if (NULL != required) { pcc->kyc.ok = false; - return TEH_plugin->insert_kyc_requirement_for_account ( + qs = TEH_plugin->insert_kyc_requirement_for_account ( TEH_plugin->cls, required, &pcc->h_payto, - &pcc->kyc.legitimization_uuid); + &pcc->reserve_pub, + &pcc->kyc.requirement_row); + GNUNET_free (required); + if (GNUNET_DB_STATUS_HARD_ERROR == qs) + { + GNUNET_break (0); + *mhd_ret + = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert_kyc_requirement_for_account"); + } + return qs; } pcc->kyc.ok = true; qs = TEH_plugin->do_purse_merge ( @@ -309,8 +338,7 @@ merge_transaction (void *cls, { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) return qs; - TALER_LOG_WARNING ( - "Failed to store merge purse information in database\n"); + GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, @@ -342,13 +370,15 @@ merge_transaction (void *cls, struct GNUNET_TIME_Timestamp merge_timestamp; char *partner_url = NULL; struct TALER_ReservePublicKeyP reserve_pub; + bool refunded; qs = TEH_plugin->select_purse_merge (TEH_plugin->cls, pcc->purse_pub, &merge_sig, &merge_timestamp, &partner_url, - &reserve_pub); + &reserve_pub, + &refunded); if (qs <= 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) @@ -362,18 +392,39 @@ merge_transaction (void *cls, "select purse merge"); return qs; } - *mhd_ret = TALER_MHD_REPLY_JSON_PACK ( - connection, - MHD_HTTP_CONFLICT, - GNUNET_JSON_pack_timestamp ("merge_timestamp", - merge_timestamp), - GNUNET_JSON_pack_data_auto ("merge_sig", - &merge_sig), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("partner_url", - partner_url)), - GNUNET_JSON_pack_data_auto ("reserve_pub", - &reserve_pub)); + if (refunded) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Purse was already refunded\n"); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_GONE, + TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED, + NULL); + GNUNET_free (partner_url); + return GNUNET_DB_STATUS_HARD_ERROR; + } + if (0 != + GNUNET_memcmp (&merge_sig, + &pcc->merge_sig)) + { + *mhd_ret = TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_CONFLICT, + GNUNET_JSON_pack_timestamp ("merge_timestamp", + merge_timestamp), + GNUNET_JSON_pack_data_auto ("merge_sig", + &merge_sig), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("partner_url", + partner_url)), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &reserve_pub)); + GNUNET_free (partner_url); + return GNUNET_DB_STATUS_HARD_ERROR; + } + /* idempotent! */ + *mhd_ret = reply_merge_success (connection, + pcc); GNUNET_free (partner_url); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -393,8 +444,8 @@ TEH_handler_purses_merge ( .exchange_timestamp = GNUNET_TIME_timestamp_get () }; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("payto_uri", - &pcc.payto_uri), + TALER_JSON_spec_payto_uri ("payto_uri", + &pcc.payto_uri), GNUNET_JSON_spec_fixed_auto ("reserve_sig", &pcc.reserve_sig), GNUNET_JSON_spec_fixed_auto ("merge_sig", @@ -426,15 +477,15 @@ TEH_handler_purses_merge ( } /* Fetch purse details */ - qs = TEH_plugin->select_purse_request (TEH_plugin->cls, - pcc.purse_pub, - &pcc.merge_pub, - &pcc.purse_expiration, - &pcc.h_contract_terms, - &pcc.min_age, - &pcc.target_amount, - &pcc.balance, - &purse_sig); + qs = TEH_plugin->get_purse_request (TEH_plugin->cls, + pcc.purse_pub, + &pcc.merge_pub, + &pcc.purse_expiration, + &pcc.h_contract_terms, + &pcc.min_age, + &pcc.target_amount, + &pcc.balance, + &purse_sig); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -597,53 +648,6 @@ TEH_handler_purses_merge ( } } - if (GNUNET_TIME_absolute_is_past (pcc.purse_expiration.abs_time)) - { - struct TALER_PurseMergeSignatureP merge_sig; - struct GNUNET_TIME_Timestamp merge_timestamp; - char *partner_url = NULL; - struct TALER_ReservePublicKeyP reserve_pub; - - qs = TEH_plugin->select_purse_merge (TEH_plugin->cls, - pcc.purse_pub, - &merge_sig, - &merge_timestamp, - &partner_url, - &reserve_pub); - if (qs <= 0) - { - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_GONE, - TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED, - NULL); - } - if (0 != - GNUNET_memcmp (&merge_sig, - &pcc.merge_sig)) - { - MHD_RESULT mhd_res; - - mhd_res = TALER_MHD_REPLY_JSON_PACK ( - connection, - MHD_HTTP_CONFLICT, - GNUNET_JSON_pack_timestamp ("merge_timestamp", - merge_timestamp), - GNUNET_JSON_pack_data_auto ("merge_sig", - &merge_sig), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("partner_url", - partner_url)), - GNUNET_JSON_pack_data_auto ("reserve_pub", - &reserve_pub)); - GNUNET_free (partner_url); - return mhd_res; - } - GNUNET_free (partner_url); - /* request was idempotent, return success! */ - return reply_merge_success (connection, - &pcc); - } - /* execute transaction */ { MHD_RESULT mhd_ret; @@ -665,6 +669,7 @@ TEH_handler_purses_merge ( GNUNET_free (pcc.provider_url); if (! pcc.kyc.ok) return TEH_RESPONSE_reply_kyc_required (connection, + &pcc.h_payto, &pcc.kyc); { |