summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-10-04 14:39:03 +0200
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-10-04 14:39:03 +0200
commitdb6732f68cd97b1617959f4fa8bdf8a0966cf7f8 (patch)
treeb95fc14c152167269e8deb9ab23c0d36a942881e /src/backend
parent2ea70ac99ad4e3f7a396346297d483f5c17d6837 (diff)
downloadmerchant-db6732f68cd97b1617959f4fa8bdf8a0966cf7f8.tar.gz
merchant-db6732f68cd97b1617959f4fa8bdf8a0966cf7f8.tar.bz2
merchant-db6732f68cd97b1617959f4fa8bdf8a0966cf7f8.zip
populating array as response to /history
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd.c2
-rw-r--r--src/backend/taler-merchant-httpd_history.c64
2 files changed, 65 insertions, 1 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index f15da504..577a4ea3 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -204,7 +204,7 @@ url_handler (void *cls,
unsigned int i;
int ret;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Handling request for URL `%s'\n",
url);
for (i=0;NULL != handlers[i].url;i++)
diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c
index 4ad799d2..2e0f084a 100644
--- a/src/backend/taler-merchant-httpd_history.c
+++ b/src/backend/taler-merchant-httpd_history.c
@@ -25,6 +25,43 @@
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_responses.h"
+/**
+ * Function called with information about a transaction. Checks whether the
+ * returned tuple
+ *
+ * @param cls closure
+ * @param transaction_id of the contract
+ * @param exchange_uri URI of the exchange
+ * @param h_contract hash of the contract
+ * @param h_wire hash of our wire details
+ * @param timestamp time of the confirmation
+ * @param refund refund deadline
+ * @param total_amount total amount we receive for the contract after fees
+ */
+
+static void
+history_cb (void *cls,
+ uint64_t transaction_id,
+ const char *exchange_uri,
+ const struct GNUNET_HashCode *h_contract,
+ const struct GNUNET_HashCode *h_wire,
+ struct GNUNET_TIME_Absolute timestamp,
+ struct GNUNET_TIME_Absolute refund,
+ const struct TALER_Amount *total_amount)
+{
+ json_t *response = cls;
+ json_t *entry;
+
+ GNUNET_break (NULL !=
+ (entry = json_pack ("{s:I, s:s, s:o, s:o, s:o}",
+ "transaction_id", transaction_id,
+ "exchange", exchange_uri,
+ "h_contract", GNUNET_JSON_from_data_auto (h_contract),
+ "timestamp", GNUNET_JSON_from_time_abs (timestamp),
+ "total_amount",
+ TALER_JSON_from_amount (total_amount))));
+ GNUNET_break (0 == json_array_append (response, entry));
+}
/**
* Manage a /history request. Query the db and returns transactions
@@ -44,7 +81,34 @@ MH_handler_history (struct TMH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size)
{
+ #define LOG_INFO(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__)
+ const char *str;
+ struct GNUNET_TIME_Absolute date;
+ json_t *response;
+ unsigned int ret;
+
+ response = json_array (); /*FIXME who decrefs this?*/
+ str = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "date");
+
+ if (NULL == str)
+ return TMH_RESPONSE_reply_bad_request (connection,
+ "date argument missing");
+ if (1 != sscanf (str, "%llu", &date.abs_value_us))
+ return TMH_RESPONSE_reply_bad_request (connection,
+ "date argument must be a timestamp");
+ ret = db->find_transactions_by_date (db->cls,
+ date,
+ history_cb,
+ response);
+ if (GNUNET_SYSERR == ret)
+ return TMH_RESPONSE_reply_internal_error (connection,
+ "db error to get history");
+ return TMH_RESPONSE_reply_json (connection,
+ response,
+ MHD_HTTP_OK);
}
/* end of taler-merchant-httpd_history.c */