commit 9f1b0480d93a850c88353baab8710082ac51d70b
parent 1e4e3e06116d11546648869ddb49063df92f196a
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 13 Dec 2018 16:55:23 +0100
Changing /history semantics.
Return results younger than 'start' by default (= with positive/ungiven 'delta').
Diffstat:
8 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c
@@ -128,7 +128,7 @@ MH_handler_history (struct TMH_RequestHandler *rh,
unsigned long long seconds;
struct MerchantInstance *mi;
unsigned long long start = UINT64_MAX;
- unsigned int delta;
+ long long delta;
enum GNUNET_DB_QueryStatus qs;
struct ProcessContractClosure pcc;
@@ -234,14 +234,14 @@ MH_handler_history (struct TMH_RequestHandler *rh,
if (NULL != str)
{
if (1 != sscanf (str,
- "%u",
+ "%lld",
&delta))
return TMH_RESPONSE_reply_arg_invalid (connection,
TALER_EC_PARAMETER_MALFORMED,
"delta");
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Querying history back to %s, start: %lld, delta: %u\n",
+ "Querying history back to %s, start: %lld, delta: %lld\n",
GNUNET_STRINGS_absolute_time_to_string (date),
start,
delta);
@@ -252,8 +252,8 @@ MH_handler_history (struct TMH_RequestHandler *rh,
date,
&mi->pubkey,
start,
- delta,
- GNUNET_NO,
+ llabs (delta),
+ delta < 0 ? GNUNET_YES : GNUNET_NO,
&pd_cb,
&pcc);
if ( (0 > qs) ||
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
@@ -441,23 +441,23 @@ postgres_initialize (void *cls)
",row_id"
" FROM merchant_contract_terms"
" WHERE"
- " timestamp<$1"
+ " timestamp>$1"
" AND merchant_pub=$2"
- " AND row_id<$3"
+ " AND row_id>$3"
" AND paid=TRUE"
" ORDER BY row_id DESC, timestamp DESC"
" LIMIT $4",
4),
- GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_future",
+ GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_past",
"SELECT"
" contract_terms"
",order_id"
",row_id"
" FROM merchant_contract_terms"
" WHERE"
- " timestamp>$1"
+ " timestamp<$1"
" AND merchant_pub=$2"
- " AND row_id>$3"
+ " AND row_id<$3"
" AND paid=TRUE"
" ORDER BY row_id DESC, timestamp DESC"
" LIMIT $4",
@@ -1364,7 +1364,7 @@ find_contracts_cb (void *cls,
* furtherly older records, and so on. Alternatively, you can use always
* the same timestamp and just go behind in history by tuning `start`.
* @param nrows only nrows rows are returned.
- * @param future if set to #GNUNET_YES, retrieves rows younger than `date`.
+ * @param past if set to #GNUNET_YES, retrieves rows older than `date`.
* This is tipically used to show live updates on the merchant's backoffice
* Web interface.
* @param cb function to call with transaction data, can be NULL.
@@ -1377,7 +1377,7 @@ postgres_find_contract_terms_by_date_and_range (void *cls,
const struct TALER_MerchantPublicKeyP *merchant_pub,
uint64_t start,
uint64_t nrows,
- int future,
+ int past,
TALER_MERCHANTDB_ProposalDataCallback cb,
void *cb_cls)
{
@@ -1398,8 +1398,8 @@ postgres_find_contract_terms_by_date_and_range (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"DB serving /history with date %s\n",
GNUNET_STRINGS_absolute_time_to_string (date));
- if (GNUNET_YES == future)
- stmt = "find_contract_terms_by_date_and_range_future";
+ if (GNUNET_YES == past)
+ stmt = "find_contract_terms_by_date_and_range_past";
else
stmt = "find_contract_terms_by_date_and_range";
check_connection (pg);
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
@@ -904,7 +904,7 @@ run (void *cls)
&merchant_pub,
2,
1,
- GNUNET_NO,
+ GNUNET_YES,
&pd_cb,
NULL));
timestamp = GNUNET_TIME_absolute_get ();
@@ -934,7 +934,7 @@ run (void *cls)
&merchant_pub,
0,
5,
- GNUNET_YES,
+ GNUNET_NO,
&pd_cb,
NULL));
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
@@ -775,8 +775,8 @@ struct TALER_MERCHANT_HistoryOperation *
TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
const char *backend_url,
const char *instance,
- unsigned int start,
- unsigned int delta,
+ unsigned long long start,
+ long long delta,
struct GNUNET_TIME_Absolute date,
TALER_MERCHANT_HistoryOperationCallback history_cb,
void *history_cb_cls);
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
@@ -331,8 +331,8 @@ TALER_TESTING_cmd_history (const char *label,
unsigned int http_status,
struct GNUNET_TIME_Absolute time,
unsigned int nresult,
- unsigned int start,
- unsigned int nrows);
+ unsigned long long start,
+ long long nrows);
/**
* Define a "track transaction" CMD.
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
@@ -309,18 +309,18 @@ struct TALER_MERCHANTDB_Plugin
/**
- * Return proposals whose timestamp are older than `date`.
+ * Return proposals whose timestamps are younger than `date`.
* Among those proposals, only those ones being between the
* start-th and (start-nrows)-th record are returned. The rows
* are sorted having the youngest first.
*
* @param cls our plugin handle.
- * @param date only results older than this date are returned.
+ * @param date only results younger than this date are returned.
* @param merchant_pub instance's public key; only rows related to this
* instance are returned.
* @param start only rows with serial id less than start are returned.
* @param nrows only nrows rows are returned.
- * @param future if set to #GNUNET_YES, retrieves rows younger than `date`.
+ * @param past if set to #GNUNET_YES, retrieves rows older than `date`.
* This is typically used to show live updates on the merchant's backoffice
* @param cb function to call with transaction data, can be NULL.
* @param cb_cls closure for @a cb
@@ -332,7 +332,7 @@ struct TALER_MERCHANTDB_Plugin
const struct TALER_MerchantPublicKeyP *merchant_pub,
uint64_t start,
uint64_t nrows,
- int future,
+ int past,
TALER_MERCHANTDB_ProposalDataCallback cb,
void *cb_cls);
diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c
@@ -163,8 +163,8 @@ struct TALER_MERCHANT_HistoryOperation *
TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
const char *backend_url,
const char *instance,
- unsigned int start,
- unsigned int delta,
+ unsigned long long start,
+ long long delta,
struct GNUNET_TIME_Absolute date,
TALER_MERCHANT_HistoryOperationCallback history_cb,
void *history_cb_cls)
@@ -181,7 +181,7 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
seconds = date.abs_value_us / 1000LL / 1000LL;
base = TALER_url_join (backend_url, "/history", NULL);
GNUNET_asprintf (&ho->url,
- "%s?date=%llu&instance=%s&start=%d&delta=%d",
+ "%s?date=%llu&instance=%s&start=%llu&delta=%lld",
base,
seconds,
instance,
diff --git a/src/lib/testing_api_cmd_history.c b/src/lib/testing_api_cmd_history.c
@@ -76,12 +76,12 @@ struct HistoryState
/**
* First row index we want in the results.
*/
- unsigned int start;
+ unsigned long long start;
/**
* How many rows we want the response to contain, at most.
*/
- unsigned int nrows;
+ long long nrows;
/**
* Expected number of history entries returned by the
@@ -265,7 +265,7 @@ history_run (void *cls,
hs->merchant_url,
"default",
hs->start,
- hs->nrows,
+ (-1) * hs->nrows,
hs->time,
&history_cb,
hs)))
@@ -294,8 +294,8 @@ TALER_TESTING_cmd_history (const char *label,
unsigned int http_status,
struct GNUNET_TIME_Absolute time,
unsigned int nresult,
- unsigned int start,
- unsigned int nrows)
+ unsigned long long start,
+ long long nrows)
{
struct HistoryState *hs;
struct TALER_TESTING_Command cmd;