gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: add API for /management/wire-fee


From: gnunet
Subject: [taler-exchange] branch master updated: add API for /management/wire-fees
Date: Mon, 30 Nov 2020 14:05:38 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new a1af10a8 add API for /management/wire-fees
a1af10a8 is described below

commit a1af10a832de7070420c61cc6d9daf0311726c90
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Nov 30 14:05:34 2020 +0100

    add API for /management/wire-fees
---
 src/include/taler_exchange_service.h               |  58 ++++++++
 src/lib/Makefile.am                                |   1 +
 ...le.c => exchange_api_management_set_wire_fee.c} | 154 ++++++++++-----------
 src/lib/exchange_api_management_wire_enable.c      |  20 ---
 4 files changed, 131 insertions(+), 102 deletions(-)

diff --git a/src/include/taler_exchange_service.h 
b/src/include/taler_exchange_service.h
index d1ce5a23..a8b78a2b 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -2535,6 +2535,64 @@ TALER_EXCHANGE_management_disable_wire_cancel (
   struct TALER_EXCHANGE_ManagementWireDisableHandle *wh);
 
 
+/**
+ * Function called with information about the wire enable operation result.
+ *
+ * @param cls closure
+ * @param hr HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ManagementSetWireFeeCallback) (
+  void *cls,
+  const struct TALER_EXCHANGE_HttpResponse *hr);
+
+
+/**
+ * @brief Handle for a POST /management/wire-fees request.
+ */
+struct TALER_EXCHANGE_ManagementSetWireFeeHandle;
+
+
+/**
+ * Inform the exchange about future wire fees.
+ *
+ * @param ctx the context
+ * @param exchange_base_url HTTP base URL for the exchange
+ * @param wire_method for which wire method are fees provided
+ * @param validity_start start date for the provided wire fees
+ * @param validity_end end date for the provided wire fees
+ * @param wire_fee the wire fee for this time period
+ * @param closing_fee the closing fee for this time period
+ * @param master_sig signature affirming the wire fees;
+ *        of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_ManagementSetWireFeeHandle *
+TALER_EXCHANGE_management_set_wire_fees (
+  struct GNUNET_CURL_Context *ctx,
+  const char *exchange_base_url,
+  const char *wire_method,
+  struct GNUNET_TIME_Absolute validity_start,
+  struct GNUNET_TIME_Absolute validity_end,
+  const struct TALER_Amount *wire_fee,
+  const struct TALER_Amount *closing_fee,
+  const struct TALER_MasterSignatureP *master_sig,
+  TALER_EXCHANGE_ManagementWireEnableCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_management_enable_wire() operation.
+ *
+ * @param wh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_management_set_wire_fees_cancel (
+  struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh);
+
+
 /**
  * Function called with information about the POST
  * /auditor/$AUDITOR_PUB/$H_DENOM_PUB operation result.
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 44d15ac6..22209de4 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -34,6 +34,7 @@ libtalerexchange_la_SOURCES = \
   exchange_api_management_post_keys.c \
   exchange_api_management_revoke_denomination_key.c \
   exchange_api_management_revoke_signing_key.c \
+  exchange_api_management_set_wire_fee.c \
   exchange_api_management_wire_disable.c \
   exchange_api_management_wire_enable.c \
   exchange_api_melt.c \
diff --git a/src/lib/exchange_api_management_wire_enable.c 
b/src/lib/exchange_api_management_set_wire_fee.c
similarity index 51%
copy from src/lib/exchange_api_management_wire_enable.c
copy to src/lib/exchange_api_management_set_wire_fee.c
index 9de52fe0..8d296648 100644
--- a/src/lib/exchange_api_management_wire_enable.c
+++ b/src/lib/exchange_api_management_set_wire_fee.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2015-2020 Taler Systems SA
+  Copyright (C) 2020 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
@@ -15,8 +15,8 @@
   <http://www.gnu.org/licenses/>
 */
 /**
- * @file lib/exchange_api_management_wire_enable.c
- * @brief functions to enable an exchange wire method / bank account
+ * @file lib/exchange_api_management_set_wire_fee.c
+ * @brief functions to set wire fees at an exchange
  * @author Christian Grothoff
  */
 #include "platform.h"
@@ -28,7 +28,7 @@
 #include "taler_json_lib.h"
 
 
-struct TALER_EXCHANGE_ManagementWireEnableHandle
+struct TALER_EXCHANGE_ManagementSetWireFeeHandle
 {
 
   /**
@@ -49,7 +49,7 @@ struct TALER_EXCHANGE_ManagementWireEnableHandle
   /**
    * Function to call with the result.
    */
-  TALER_EXCHANGE_ManagementWireEnableCallback cb;
+  TALER_EXCHANGE_ManagementSetWireFeeCallback cb;
 
   /**
    * Closure for @a cb.
@@ -72,18 +72,18 @@ struct TALER_EXCHANGE_ManagementWireEnableHandle
  * @param response response body, NULL if not in JSON
  */
 static void
-handle_auditor_enable_finished (void *cls,
-                                long response_code,
-                                const void *response)
+handle_set_wire_fee_finished (void *cls,
+                              long response_code,
+                              const void *response)
 {
-  struct TALER_EXCHANGE_ManagementWireEnableHandle *wh = cls;
+  struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh = cls;
   const json_t *json = response;
   struct TALER_EXCHANGE_HttpResponse hr = {
     .http_status = (unsigned int) response_code,
     .reply = json
   };
 
-  wh->job = NULL;
+  swfh->job = NULL;
   switch (response_code)
   {
   case MHD_HTTP_NO_CONTENT:
@@ -96,6 +96,10 @@ handle_auditor_enable_finished (void *cls,
     hr.ec = TALER_JSON_get_error_code (json);
     hr.hint = TALER_JSON_get_error_hint (json);
     break;
+  case MHD_HTTP_PRECONDITION_FAILED:
+    hr.ec = TALER_JSON_get_error_code (json);
+    hr.hint = TALER_JSON_get_error_hint (json);
+    break;
   default:
     /* unexpected response code */
     GNUNET_break_op (0);
@@ -107,124 +111,110 @@ handle_auditor_enable_finished (void *cls,
                 (int) hr.ec);
     break;
   }
-  if (NULL != wh->cb)
+  if (NULL != swfh->cb)
   {
-    wh->cb (wh->cb_cls,
-            &hr);
-    wh->cb = NULL;
+    swfh->cb (swfh->cb_cls,
+              &hr);
+    swfh->cb = NULL;
   }
-  TALER_EXCHANGE_management_enable_wire_cancel (wh);
+  TALER_EXCHANGE_management_set_wire_fees_cancel (swfh);
 }
 
 
-/**
- * Inform the exchange that a wire account should be enabled.
- *
- * @param ctx the context
- * @param url HTTP base URL for the exchange
- * @param payto_uri RFC 8905 URI of the exchange's bank account
- * @param validity_start when was this decided?
- * @param master_sig1 signature affirming the wire addition
- *        of purpose #TALER_SIGNATURE_MASTER_ADD_WIRE
- * @param master_sig2 signature affirming the validity of the account for 
clients;
- *        of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS.
- * @param cb function to call with the exchange's result
- * @param cb_cls closure for @a cb
- * @return the request handle; NULL upon error
- */
-struct TALER_EXCHANGE_ManagementWireEnableHandle *
-TALER_EXCHANGE_management_enable_wire (
+struct TALER_EXCHANGE_ManagementSetWireFeeHandle *
+TALER_EXCHANGE_management_set_wire_fees (
   struct GNUNET_CURL_Context *ctx,
-  const char *url,
-  const char *payto_uri,
+  const char *exchange_base_url,
+  const char *wire_method,
   struct GNUNET_TIME_Absolute validity_start,
-  const struct TALER_MasterSignatureP *master_sig1,
-  const struct TALER_MasterSignatureP *master_sig2,
+  struct GNUNET_TIME_Absolute validity_end,
+  const struct TALER_Amount *wire_fee,
+  const struct TALER_Amount *closing_fee,
+  const struct TALER_MasterSignatureP *master_sig,
   TALER_EXCHANGE_ManagementWireEnableCallback cb,
   void *cb_cls)
 {
-  struct TALER_EXCHANGE_ManagementWireEnableHandle *wh;
+  struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh;
   CURL *eh;
   json_t *body;
 
-  wh = GNUNET_new (struct TALER_EXCHANGE_ManagementWireEnableHandle);
-  wh->cb = cb;
-  wh->cb_cls = cb_cls;
-  wh->ctx = ctx;
-  wh->url = TALER_url_join (url,
-                            "management/wire/enable",
-                            NULL);
-  if (NULL == wh->url)
+  swfh = GNUNET_new (struct TALER_EXCHANGE_ManagementSetWireFeeHandle);
+  swfh->cb = cb;
+  swfh->cb_cls = cb_cls;
+  swfh->ctx = ctx;
+  swfh->url = TALER_url_join (exchange_base_url,
+                              "management/wire-fee",
+                              NULL);
+  if (NULL == swfh->url)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not construct request URL.\n");
-    GNUNET_free (wh);
+    GNUNET_free (swfh);
     return NULL;
   }
-  body = json_pack ("{s:s, s:s, s:o, s:o, s:o}",
-                    "payto_uri",
-                    payto_uri,
-                    "master_sig_add",
-                    GNUNET_JSON_from_data_auto (master_sig1),
-                    "master_sig_wire",
-                    GNUNET_JSON_from_data_auto (master_sig2),
-                    "validity_start",
-                    GNUNET_JSON_from_time_abs (validity_start));
+  body = json_pack ("{s:s, s:o, s:o, s:o, s:o}",
+                    "wire_method",
+                    wire_method,
+                    "master_sig",
+                    GNUNET_JSON_from_data_auto (master_sig),
+                    "fee_start",
+                    GNUNET_JSON_from_time_abs (validity_start),
+                    "fee_end",
+                    GNUNET_JSON_from_time_abs (validity_end),
+                    "closing_fee",
+                    TALER_JSON_from_amount (closing_fee),
+                    "wire_fee",
+                    TALER_JSON_from_amount (wire_fee));
   if (NULL == body)
   {
     GNUNET_break (0);
-    GNUNET_free (wh->url);
-    GNUNET_free (wh);
+    GNUNET_free (swfh->url);
+    GNUNET_free (swfh);
     return NULL;
   }
   eh = curl_easy_init ();
   if (GNUNET_OK !=
-      TALER_curl_easy_post (&wh->post_ctx,
+      TALER_curl_easy_post (&swfh->post_ctx,
                             eh,
                             body))
   {
     GNUNET_break (0);
     json_decref (body);
-    GNUNET_free (wh->url);
+    GNUNET_free (swfh->url);
     GNUNET_free (eh);
     return NULL;
   }
   json_decref (body);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Requesting URL '%s'\n",
-              wh->url);
+              swfh->url);
   GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
                                                CURLOPT_URL,
-                                               wh->url));
-  wh->job = GNUNET_CURL_job_add2 (ctx,
-                                  eh,
-                                  wh->post_ctx.headers,
-                                  &handle_auditor_enable_finished,
-                                  wh);
-  if (NULL == wh->job)
+                                               swfh->url));
+  swfh->job = GNUNET_CURL_job_add2 (ctx,
+                                    eh,
+                                    swfh->post_ctx.headers,
+                                    &handle_set_wire_fee_finished,
+                                    swfh);
+  if (NULL == swfh->job)
   {
-    TALER_EXCHANGE_management_enable_wire_cancel (wh);
+    TALER_EXCHANGE_management_set_wire_fees_cancel (swfh);
     return NULL;
   }
-  return wh;
+  return swfh;
 }
 
 
-/**
- * Cancel #TALER_EXCHANGE_management_enable_wire() operation.
- *
- * @param wh handle of the operation to cancel
- */
 void
-TALER_EXCHANGE_management_enable_wire_cancel (
-  struct TALER_EXCHANGE_ManagementWireEnableHandle *wh)
+TALER_EXCHANGE_management_set_wire_fees_cancel (
+  struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh)
 {
-  if (NULL != wh->job)
+  if (NULL != swfh->job)
   {
-    GNUNET_CURL_job_cancel (wh->job);
-    wh->job = NULL;
+    GNUNET_CURL_job_cancel (swfh->job);
+    swfh->job = NULL;
   }
-  TALER_curl_easy_post_finished (&wh->post_ctx);
-  GNUNET_free (wh->url);
-  GNUNET_free (wh);
+  TALER_curl_easy_post_finished (&swfh->post_ctx);
+  GNUNET_free (swfh->url);
+  GNUNET_free (swfh);
 }
diff --git a/src/lib/exchange_api_management_wire_enable.c 
b/src/lib/exchange_api_management_wire_enable.c
index 9de52fe0..f841098e 100644
--- a/src/lib/exchange_api_management_wire_enable.c
+++ b/src/lib/exchange_api_management_wire_enable.c
@@ -117,21 +117,6 @@ handle_auditor_enable_finished (void *cls,
 }
 
 
-/**
- * Inform the exchange that a wire account should be enabled.
- *
- * @param ctx the context
- * @param url HTTP base URL for the exchange
- * @param payto_uri RFC 8905 URI of the exchange's bank account
- * @param validity_start when was this decided?
- * @param master_sig1 signature affirming the wire addition
- *        of purpose #TALER_SIGNATURE_MASTER_ADD_WIRE
- * @param master_sig2 signature affirming the validity of the account for 
clients;
- *        of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS.
- * @param cb function to call with the exchange's result
- * @param cb_cls closure for @a cb
- * @return the request handle; NULL upon error
- */
 struct TALER_EXCHANGE_ManagementWireEnableHandle *
 TALER_EXCHANGE_management_enable_wire (
   struct GNUNET_CURL_Context *ctx,
@@ -210,11 +195,6 @@ TALER_EXCHANGE_management_enable_wire (
 }
 
 
-/**
- * Cancel #TALER_EXCHANGE_management_enable_wire() operation.
- *
- * @param wh handle of the operation to cancel
- */
 void
 TALER_EXCHANGE_management_enable_wire_cancel (
   struct TALER_EXCHANGE_ManagementWireEnableHandle *wh)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]