diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-11-01 22:02:34 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-11-01 22:02:34 +0100 |
commit | 8d5bb82d189de0263dbd7d572cab3e58bd676fcc (patch) | |
tree | a4e9b9a3526bd0bbd2a02c2f8f2f9d1c9d59b986 | |
parent | cdc85dd9f8f84f22daf882c7d5152ccfc04a2d2c (diff) | |
download | merchant-8d5bb82d189de0263dbd7d572cab3e58bd676fcc.tar.gz merchant-8d5bb82d189de0263dbd7d572cab3e58bd676fcc.zip |
handle wire transfer deadline like pay deadline
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 4 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 2 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 37 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_proposal.c | 16 |
4 files changed, 22 insertions, 37 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index da1c7b45..ef7b6502 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c | |||
@@ -77,7 +77,7 @@ static long long unsigned port; | |||
77 | * This value tells the exchange by which date this merchant would like | 77 | * This value tells the exchange by which date this merchant would like |
78 | * to receive the funds for a deposited payment | 78 | * to receive the funds for a deposited payment |
79 | */ | 79 | */ |
80 | struct GNUNET_TIME_Relative wire_transfer_delay; | 80 | struct GNUNET_TIME_Relative default_wire_transfer_delay; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Locations from the configuration. Mapping from | 83 | * Locations from the configuration. Mapping from |
@@ -1489,7 +1489,7 @@ run (void *cls, | |||
1489 | GNUNET_CONFIGURATION_get_value_time (config, | 1489 | GNUNET_CONFIGURATION_get_value_time (config, |
1490 | "merchant", | 1490 | "merchant", |
1491 | "WIRE_TRANSFER_DELAY", | 1491 | "WIRE_TRANSFER_DELAY", |
1492 | &wire_transfer_delay)) | 1492 | &default_wire_transfer_delay)) |
1493 | { | 1493 | { |
1494 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1494 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1495 | "merchant", | 1495 | "merchant", |
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index c166efb4..bc53bbc6 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h | |||
@@ -366,7 +366,7 @@ extern struct TALER_MERCHANTDB_Plugin *db; | |||
366 | * executing the wire transfer? This delay is added to the current | 366 | * executing the wire transfer? This delay is added to the current |
367 | * time when we generate the advisory execution time for the exchange. | 367 | * time when we generate the advisory execution time for the exchange. |
368 | */ | 368 | */ |
369 | extern struct GNUNET_TIME_Relative wire_transfer_delay; | 369 | extern struct GNUNET_TIME_Relative default_wire_transfer_delay; |
370 | 370 | ||
371 | /** | 371 | /** |
372 | * If the frontend does NOT specify a payment deadline, how long should | 372 | * If the frontend does NOT specify a payment deadline, how long should |
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index 4e19e6f0..1bd68d31 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c | |||
@@ -287,8 +287,7 @@ struct PayContext | |||
287 | 287 | ||
288 | /** | 288 | /** |
289 | * Wire transfer deadline. How soon would the merchant like the | 289 | * Wire transfer deadline. How soon would the merchant like the |
290 | * wire transfer to be executed? (Can be given by the frontend | 290 | * wire transfer to be executed? |
291 | * or be determined by our configuration via #wire_transfer_delay.) | ||
292 | */ | 291 | */ |
293 | struct GNUNET_TIME_Absolute wire_transfer_deadline; | 292 | struct GNUNET_TIME_Absolute wire_transfer_deadline; |
294 | 293 | ||
@@ -1445,7 +1444,6 @@ parse_pay (struct MHD_Connection *connection, | |||
1445 | }; | 1444 | }; |
1446 | enum GNUNET_DB_QueryStatus qs; | 1445 | enum GNUNET_DB_QueryStatus qs; |
1447 | const char *session_id; | 1446 | const char *session_id; |
1448 | struct GNUNET_TIME_Relative used_wire_transfer_delay; | ||
1449 | 1447 | ||
1450 | res = TMH_PARSE_json_data (connection, | 1448 | res = TMH_PARSE_json_data (connection, |
1451 | root, | 1449 | root, |
@@ -1551,6 +1549,8 @@ parse_pay (struct MHD_Connection *connection, | |||
1551 | &pc->refund_deadline), | 1549 | &pc->refund_deadline), |
1552 | GNUNET_JSON_spec_absolute_time ("pay_deadline", | 1550 | GNUNET_JSON_spec_absolute_time ("pay_deadline", |
1553 | &pc->pay_deadline), | 1551 | &pc->pay_deadline), |
1552 | GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline", | ||
1553 | &pc->wire_transfer_deadline), | ||
1554 | GNUNET_JSON_spec_absolute_time ("timestamp", | 1554 | GNUNET_JSON_spec_absolute_time ("timestamp", |
1555 | &pc->timestamp), | 1555 | &pc->timestamp), |
1556 | TALER_JSON_spec_amount ("max_fee", | 1556 | TALER_JSON_spec_amount ("max_fee", |
@@ -1576,39 +1576,10 @@ parse_pay (struct MHD_Connection *connection, | |||
1576 | 1576 | ||
1577 | pc->fulfillment_url = GNUNET_strdup (fulfillment_url); | 1577 | pc->fulfillment_url = GNUNET_strdup (fulfillment_url); |
1578 | 1578 | ||
1579 | /* Use the value from config as default. */ | ||
1580 | used_wire_transfer_delay = wire_transfer_delay; | ||
1581 | |||
1582 | if (NULL != json_object_get (pc->contract_terms, | ||
1583 | "wire_transfer_delay")) | ||
1584 | { | ||
1585 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1586 | "Frontend specified wire transfer delay\n"); | ||
1587 | |||
1588 | struct GNUNET_JSON_Specification wspec[] = { | ||
1589 | GNUNET_JSON_spec_relative_time ("wire_transfer_delay", | ||
1590 | &used_wire_transfer_delay), | ||
1591 | GNUNET_JSON_spec_end () | ||
1592 | }; | ||
1593 | |||
1594 | res = TMH_PARSE_json_data (connection, | ||
1595 | pc->contract_terms, | ||
1596 | wspec); | ||
1597 | if (GNUNET_YES != res) | ||
1598 | { | ||
1599 | GNUNET_JSON_parse_free (spec); | ||
1600 | GNUNET_break (0); | ||
1601 | return (GNUNET_NO == res) ? MHD_YES : MHD_NO; | ||
1602 | } | ||
1603 | } | ||
1604 | |||
1605 | pc->wire_transfer_deadline | ||
1606 | = GNUNET_TIME_absolute_add (pc->timestamp, | ||
1607 | used_wire_transfer_delay); | ||
1608 | |||
1609 | if (pc->wire_transfer_deadline.abs_value_us < | 1579 | if (pc->wire_transfer_deadline.abs_value_us < |
1610 | pc->refund_deadline.abs_value_us) | 1580 | pc->refund_deadline.abs_value_us) |
1611 | { | 1581 | { |
1582 | /* This should already have been checked when creating the order! */ | ||
1612 | GNUNET_break (0); | 1583 | GNUNET_break (0); |
1613 | GNUNET_JSON_parse_free (spec); | 1584 | GNUNET_JSON_parse_free (spec); |
1614 | return TMH_RESPONSE_reply_external_error (connection, | 1585 | return TMH_RESPONSE_reply_external_error (connection, |
diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c index bc7dd0e2..bb9ccbb0 100644 --- a/src/backend/taler-merchant-httpd_proposal.c +++ b/src/backend/taler-merchant-httpd_proposal.c | |||
@@ -202,11 +202,13 @@ make_merchant_base_url (struct MHD_Connection *connection, const | |||
202 | * of a MHD connection. | 202 | * of a MHD connection. |
203 | * | 203 | * |
204 | * @param connection connection to write the result or error to | 204 | * @param connection connection to write the result or error to |
205 | * @param root root of the request | ||
205 | * @param order[in] order to process (can be modified) | 206 | * @param order[in] order to process (can be modified) |
206 | * @return MHD result code | 207 | * @return MHD result code |
207 | */ | 208 | */ |
208 | static int | 209 | static int |
209 | proposal_put (struct MHD_Connection *connection, | 210 | proposal_put (struct MHD_Connection *connection, |
211 | json_t *root, | ||
210 | json_t *order, | 212 | json_t *order, |
211 | const struct MerchantInstance *mi) | 213 | const struct MerchantInstance *mi) |
212 | { | 214 | { |
@@ -316,6 +318,18 @@ proposal_put (struct MHD_Connection *connection, | |||
316 | } | 318 | } |
317 | 319 | ||
318 | if (NULL == json_object_get (order, | 320 | if (NULL == json_object_get (order, |
321 | "wire_transfer_deadline")) | ||
322 | { | ||
323 | struct GNUNET_TIME_Absolute t; | ||
324 | |||
325 | t = GNUNET_TIME_relative_to_absolute (default_wire_transfer_delay); | ||
326 | (void) GNUNET_TIME_round_abs (&t); | ||
327 | json_object_set_new (order, | ||
328 | "wire_transfer_deadline", | ||
329 | GNUNET_JSON_from_time_abs (t)); | ||
330 | } | ||
331 | |||
332 | if (NULL == json_object_get (order, | ||
319 | "max_wire_fee")) | 333 | "max_wire_fee")) |
320 | { | 334 | { |
321 | json_object_set_new (order, | 335 | json_object_set_new (order, |
@@ -656,7 +670,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, | |||
656 | "order"); | 670 | "order"); |
657 | } | 671 | } |
658 | else | 672 | else |
659 | res = proposal_put (connection, order, mi); | 673 | res = proposal_put (connection, root, order, mi); |
660 | json_decref (root); | 674 | json_decref (root); |
661 | return res; | 675 | return res; |
662 | } | 676 | } |