summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_reserves_close.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-httpd_reserves_close.c')
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_close.c73
1 files changed, 51 insertions, 22 deletions
diff --git a/src/exchange/taler-exchange-httpd_reserves_close.c b/src/exchange/taler-exchange-httpd_reserves_close.c
index be36f1e73..bbf234428 100644
--- a/src/exchange/taler-exchange-httpd_reserves_close.c
+++ b/src/exchange/taler-exchange-httpd_reserves_close.c
@@ -27,7 +27,7 @@
#include "taler_mhd_lib.h"
#include "taler_json_lib.h"
#include "taler_dbevents.h"
-#include "taler-exchange-httpd_wire.h"
+#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_reserves_close.h"
#include "taler-exchange-httpd_responses.h"
@@ -178,14 +178,13 @@ reserve_close_transaction (void *cls,
{
struct ReserveCloseContext *rcc = cls;
enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount balance;
char *payto_uri = NULL;
const struct TALER_WireFeeSet *wf;
qs = TEH_plugin->select_reserve_close_info (
TEH_plugin->cls,
rcc->reserve_pub,
- &balance,
+ &rcc->balance,
&payto_uri);
switch (qs)
{
@@ -226,19 +225,34 @@ reserve_close_transaction (void *cls,
(0 != strcmp (payto_uri,
rcc->payto_uri)) ) )
{
- const char *kyc_needed;
+ /* KYC check may be needed: we're not returning
+ the money to the account that funded the reserve
+ in the first place. */
+ char *kyc_needed;
TALER_payto_hash (rcc->payto_uri,
&rcc->kyc_payto);
rcc->qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- kyc_needed
- = TALER_KYCLOGIC_kyc_test_required (
- TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE,
- &rcc->kyc_payto,
- TEH_plugin->select_satisfied_kyc_processes,
- TEH_plugin->cls,
- &amount_it,
- rcc);
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE,
+ &rcc->kyc_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &amount_it,
+ rcc,
+ &kyc_needed);
+ 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,
+ "iterate_reserve_close_info");
+ return qs;
+ }
if (rcc->qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == rcc->qs)
@@ -251,12 +265,27 @@ reserve_close_transaction (void *cls,
"iterate_reserve_close_info");
return qs;
}
- rcc->kyc.ok = false;
- return TEH_plugin->insert_kyc_requirement_for_account (
- TEH_plugin->cls,
- kyc_needed,
- &rcc->kyc_payto,
- &rcc->kyc.requirement_row);
+ if (NULL != kyc_needed)
+ {
+ rcc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ kyc_needed,
+ &rcc->kyc_payto,
+ rcc->reserve_pub,
+ &rcc->kyc.requirement_row);
+ GNUNET_free (kyc_needed);
+ 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;
+ }
}
rcc->kyc.ok = true;
@@ -284,7 +313,7 @@ reserve_close_transaction (void *cls,
if (0 >
TALER_amount_subtract (&rcc->wire_amount,
- &balance,
+ &rcc->balance,
&wf->closing))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -302,7 +331,7 @@ reserve_close_transaction (void *cls,
payto_uri,
&rcc->reserve_sig,
rcc->timestamp,
- &balance,
+ &rcc->balance,
&wf->closing);
GNUNET_free (payto_uri);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
@@ -338,8 +367,8 @@ TEH_handler_reserves_close (struct TEH_RequestContext *rc,
GNUNET_JSON_spec_timestamp ("request_timestamp",
&rcc.timestamp),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("payto_uri",
- &rcc.payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &rcc.payto_uri),
NULL),
GNUNET_JSON_spec_fixed_auto ("reserve_sig",
&rcc.reserve_sig),