diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-10-04 14:39:03 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-10-04 14:39:03 +0200 |
commit | db6732f68cd97b1617959f4fa8bdf8a0966cf7f8 (patch) | |
tree | b95fc14c152167269e8deb9ab23c0d36a942881e | |
parent | 2ea70ac99ad4e3f7a396346297d483f5c17d6837 (diff) |
populating array as response to /history
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 2 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_history.c | 64 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 2 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 3 |
4 files changed, 67 insertions, 4 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 */ diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 2cbc81e3..fc57929f 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -628,7 +628,7 @@ postgres_find_transactions_by_date (void *cls, GNUNET_PQ_cleanup_result (rs); } PQclear (result); - return GNUNET_OK; + return n; } /** diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 49dd5195..04cdf313 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -253,8 +253,7 @@ struct TALER_MERCHANTDB_Plugin * @param transaction_id the transaction id to search * @param cb function to call with transaction data * @param cb_cls closure for @a cb - * @return #GNUNET_OK if found, #GNUNET_NO if not, #GNUNET_SYSERR - * upon error + * @return number of found tuples, #GNUNET_SYSERR upon error */ int (*find_transaction_by_id) (void *cls, |