aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-12-14 00:34:35 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-12-14 19:25:42 +0100
commit15c1a877c617fd29ff61e2ebd1f6fac72e54afce (patch)
tree2781d327ca51bce8c172f0907bb93c86cc13d579
parentc2b6a1065474df88df8d501d7a83b67032bd121d (diff)
/history API semantics extended.
That API has now a new 'ordering' flag that lets the client choose what ordering the results should have: ascending or descending. In particular, this change adapted the fakebank and tests logic to such introduction.
-rw-r--r--src/bank-lib/bank_api_history.c13
-rw-r--r--src/bank-lib/fakebank.c78
-rw-r--r--src/bank-lib/test_bank_api_new.c5
-rw-r--r--src/bank-lib/test_bank_api_twisted.c1
-rw-r--r--src/bank-lib/test_bank_api_with_fakebank.c9
-rw-r--r--src/bank-lib/test_bank_api_with_fakebank_new.c13
-rw-r--r--src/bank-lib/test_bank_api_with_fakebank_twisted.c1
-rw-r--r--src/bank-lib/test_bank_interpreter.c1
-rw-r--r--src/bank-lib/test_bank_interpreter.h6
-rw-r--r--src/bank-lib/testing_api_cmd_history.c14
-rw-r--r--src/include/taler_bank_service.h2
-rw-r--r--src/include/taler_testing_bank_lib.h4
-rw-r--r--src/wire-plugins/plugin_wire_taler-bank.c2
13 files changed, 125 insertions, 24 deletions
diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c
index 844f9b0cd..ab757a2d2 100644
--- a/src/bank-lib/bank_api_history.c
+++ b/src/bank-lib/bank_api_history.c
@@ -256,6 +256,7 @@ handle_history_finished (void *cls,
* @param auth authentication data to use
* @param account_number which account number should we query
* @param direction what kinds of wire transfers should be returned
+ * @param ascending if GNUNET_YES, history elements will be returned in chronological order.
* @param start_row from which row on do we want to get results, use UINT64_MAX for the latest; exclusive
* @param num_results how many results do we want; negative numbers to go into the past,
* positive numbers to go into the future starting at @a start_row;
@@ -272,6 +273,7 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
const struct TALER_BANK_AuthenticationData *auth,
uint64_t account_number,
enum TALER_BANK_Direction direction,
+ unsigned int ascending,
uint64_t start_row,
int64_t num_results,
TALER_BANK_HistoryResultCallback hres_cb,
@@ -310,25 +312,28 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
can = "show";
else
can = "omit";
+
if (UINT64_MAX == start_row)
{
GNUNET_asprintf (&url,
- "/history?auth=basic&account_number=%llu&delta=%lld&direction=%s&cancelled=%s",
+ "/history?auth=basic&account_number=%llu&delta=%lld&direction=%s&cancelled=%s&ordering=%s",
(unsigned long long) account_number,
(long long) num_results,
dir,
- can);
+ can,
+ (GNUNET_YES == ascending) ? "ascending" : "descending");
}
else
{
GNUNET_asprintf (&url,
- "/history?auth=basic&account_number=%llu&delta=%lld&start=%llu&direction=%s&cancelled=%s",
+ "/history?auth=basic&account_number=%llu&delta=%lld&start=%llu&direction=%s&cancelled=%s&ordering=%s",
(unsigned long long) account_number,
(long long) num_results,
(unsigned long long) start_row,
dir,
- can);
+ can,
+ (GNUNET_YES == ascending) ? "ascending" : "descending");
}
hh = GNUNET_new (struct TALER_BANK_HistoryHandle);
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 82c5a6cab..52f0d73a9 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -96,6 +96,30 @@ struct Transaction
/**
+ * Needed to implement ascending/descending ordering
+ * of /history results.
+ */
+struct HistoryElement
+{
+
+ /**
+ * History JSON element.
+ */
+ json_t *element;
+
+ /**
+ * Previous element.
+ */
+ struct HistoryElement *prev;
+
+ /**
+ * Next element.
+ */
+ struct HistoryElement *next;
+};
+
+
+/**
* Handle for the fake bank.
*/
struct TALER_FAKEBANK_Handle
@@ -660,6 +684,7 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
const char *dir;
const char *acc;
const char *cancelled;
+ const char *ordering;
unsigned long long account_number;
unsigned long long start_number;
long long count;
@@ -668,6 +693,10 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
json_t *history;
json_t *jresponse;
int ret;
+ int ascending;
+ struct HistoryElement *history_results_head = NULL;
+ struct HistoryElement *history_results_tail = NULL;
+ struct HistoryElement *history_element = NULL;
auth = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
@@ -684,6 +713,9 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
start = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"start");
+ ordering = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "ordering");
acc = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"account_number");
@@ -727,11 +759,11 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
return MHD_NO;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Client asked for up to %lld results of type %s for account %llu starting at %s\n",
+ "Client asked for up to %lld results of type %s for account %llu starting at %llu\n",
count,
dir,
(unsigned long long) account_number,
- start);
+ start_number);
if (0 == strcasecmp (dir,
"CREDIT"))
{
@@ -767,12 +799,7 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
return MHD_NO;
}
if (NULL == start)
- {
- if (count > 0)
- pos = h->transactions_head;
- else
- pos = h->transactions_tail;
- }
+ pos = h->transactions_tail;
else if (NULL != h->transactions_head)
{
for (pos = h->transactions_head;
@@ -800,6 +827,13 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
}
history = json_array ();
+ if ((NULL != ordering)
+ && 0 == strcmp ("ascending",
+ ordering))
+ ascending = GNUNET_YES;
+ else
+ ascending = GNUNET_NO;
+
while ( (NULL != pos) &&
(0 != count) )
{
@@ -846,8 +880,19 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
"wt_subject", subject);
GNUNET_assert (NULL != trans);
GNUNET_free (subject);
- GNUNET_assert (0 == json_array_append_new (history,
- trans));
+
+ history_element = GNUNET_new (struct HistoryElement);
+ history_element->element = trans;
+
+ if (((0 < count) && (GNUNET_YES == ascending))
+ || ((0 > count) && (GNUNET_NO == ascending)))
+ GNUNET_CONTAINER_DLL_insert_tail (history_results_head,
+ history_results_tail,
+ history_element);
+ else
+ GNUNET_CONTAINER_DLL_insert (history_results_head,
+ history_results_tail,
+ history_element);
if (count > 0)
{
pos = pos->next;
@@ -859,6 +904,19 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
count++;
}
}
+
+ if (NULL != history_results_head)
+ history_element = history_results_head;
+ while (NULL != history_element)
+ {
+ json_array_append_new (history,
+ history_element->element);
+ history_element = history_element->next;
+ if (NULL != history_element)
+ GNUNET_free_non_null (history_element->prev);
+ }
+ GNUNET_free_non_null (history_results_tail);
+
if (0 == json_array_size (history))
{
struct MHD_Response *resp;
diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c
index 3645b3010..8513f5a53 100644
--- a/src/bank-lib/test_bank_api_new.c
+++ b/src/bank-lib/test_bank_api_new.c
@@ -78,6 +78,7 @@ run (void *cls,
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
5),
@@ -110,6 +111,7 @@ run (void *cls,
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_CREDIT,
+ GNUNET_NO,
NULL,
-5),
@@ -117,6 +119,7 @@ run (void *cls,
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_DEBIT,
+ GNUNET_NO,
NULL,
5),
@@ -124,6 +127,7 @@ run (void *cls,
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_DEBIT,
+ GNUNET_NO,
NULL,
-5),
@@ -131,6 +135,7 @@ run (void *cls,
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_DEBIT,
+ GNUNET_NO,
"deposit-1",
5),
diff --git a/src/bank-lib/test_bank_api_twisted.c b/src/bank-lib/test_bank_api_twisted.c
index f90b05725..99c33c9a9 100644
--- a/src/bank-lib/test_bank_api_twisted.c
+++ b/src/bank-lib/test_bank_api_twisted.c
@@ -88,6 +88,7 @@ run (void *cls,
twister_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
5),
/**
diff --git a/src/bank-lib/test_bank_api_with_fakebank.c b/src/bank-lib/test_bank_api_with_fakebank.c
index b860669ce..429784696 100644
--- a/src/bank-lib/test_bank_api_with_fakebank.c
+++ b/src/bank-lib/test_bank_api_with_fakebank.c
@@ -88,13 +88,14 @@ run (void *cls)
.details.history.account_number = 2,
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
.details.history.start_row_ref = NULL,
- .details.history.num_results = 5 },
+ .details.history.num_results = -5 },
{ .oc = TBI_OC_HISTORY,
.label = "history-2bi",
.details.history.account_number = 2,
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
.details.history.start_row_ref = "debit-1",
- .details.history.num_results = 5 },
+ .details.history.num_results = 5,
+ .details.history.ascending = GNUNET_YES},
/* check transfers arrived at fakebank */
{ .oc = TBI_OC_EXPECT_TRANSFER,
.label = "expect-2d",
@@ -129,13 +130,13 @@ run (void *cls)
in the history. So to see the rejected transfer, we need to start
looking after "credit-2" */
.details.history.start_row_ref = NULL,
- .details.history.num_results = 5 },
+ .details.history.num_results = -5 },
{ .oc = TBI_OC_HISTORY,
.label = "history-r1c",
.details.history.account_number = 1,
.details.history.direction = TALER_BANK_DIRECTION_BOTH | TALER_BANK_DIRECTION_CANCEL,
.details.history.start_row_ref = NULL,
- .details.history.num_results = 5 },
+ .details.history.num_results = -5 },
{ .oc = TBI_OC_EXPECT_TRANSFER,
.label = "expect-credit-reject-1",
.details.expect_transfer.cmd_ref = "credit-for-reject-1" },
diff --git a/src/bank-lib/test_bank_api_with_fakebank_new.c b/src/bank-lib/test_bank_api_with_fakebank_new.c
index 22ed30a52..cf7c0918e 100644
--- a/src/bank-lib/test_bank_api_with_fakebank_new.c
+++ b/src/bank-lib/test_bank_api_with_fakebank_new.c
@@ -73,6 +73,7 @@ run (void *cls,
fakebank_url,
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
1),
@@ -94,6 +95,7 @@ run (void *cls,
fakebank_url,
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_CREDIT,
+ GNUNET_NO,
NULL,
5),
@@ -101,6 +103,7 @@ run (void *cls,
fakebank_url,
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_DEBIT,
+ GNUNET_NO,
NULL,
5),
@@ -130,13 +133,15 @@ run (void *cls,
fakebank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
- 5),
+ -5),
TALER_TESTING_cmd_bank_history ("history-2bi",
fakebank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_YES,
"debit-1",
5),
@@ -170,16 +175,18 @@ run (void *cls,
fakebank_url,
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
- 5),
+ -5),
TALER_TESTING_cmd_bank_history ("history-r1c",
fakebank_url,
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH |
TALER_BANK_DIRECTION_CANCEL,
+ GNUNET_NO,
NULL,
- 5),
+ -5),
TALER_TESTING_cmd_check_bank_transfer_with_ref
("expect-credit-reject-1",
diff --git a/src/bank-lib/test_bank_api_with_fakebank_twisted.c b/src/bank-lib/test_bank_api_with_fakebank_twisted.c
index 88e9bc3b2..fdd18eb2d 100644
--- a/src/bank-lib/test_bank_api_with_fakebank_twisted.c
+++ b/src/bank-lib/test_bank_api_with_fakebank_twisted.c
@@ -80,6 +80,7 @@ run (void *cls,
fakebank_url,
EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH,
+ GNUNET_NO,
NULL,
5),
/**
diff --git a/src/bank-lib/test_bank_interpreter.c b/src/bank-lib/test_bank_interpreter.c
index fe6b4e1a2..562b6dae6 100644
--- a/src/bank-lib/test_bank_interpreter.c
+++ b/src/bank-lib/test_bank_interpreter.c
@@ -794,6 +794,7 @@ interpreter_run (void *cls)
&auth,
cmd->details.history.account_number,
cmd->details.history.direction,
+ cmd->details.history.ascending,
rowid,
cmd->details.history.num_results,
&history_cb,
diff --git a/src/bank-lib/test_bank_interpreter.h b/src/bank-lib/test_bank_interpreter.h
index 010538ac9..ae323055d 100644
--- a/src/bank-lib/test_bank_interpreter.h
+++ b/src/bank-lib/test_bank_interpreter.h
@@ -174,6 +174,12 @@ struct TBI_Command
*/
int failed;
+ /**
+ * if true, the history elements will be asked in
+ * chronological order.
+ */
+ unsigned int ascending;
+
} history;
/**
diff --git a/src/bank-lib/testing_api_cmd_history.c b/src/bank-lib/testing_api_cmd_history.c
index 7b831d4ed..c60f6a13d 100644
--- a/src/bank-lib/testing_api_cmd_history.c
+++ b/src/bank-lib/testing_api_cmd_history.c
@@ -84,6 +84,12 @@ struct HistoryState
* unexpected.
*/
int failed;
+
+ /**
+ * If GNUNET_YES, this parameter will ask for results in
+ * chronological order.
+ */
+ unsigned int ascending;
};
/**
@@ -726,6 +732,7 @@ history_run (void *cls,
auth,
hs->account_no,
hs->direction,
+ hs->ascending,
row_id,
hs->num_results,
&history_cb,
@@ -765,8 +772,9 @@ history_cleanup
* @param bank_url base URL of the bank offering the "history"
* operation.
* @param account_no bank account number to ask the history for.
- * @param direction which direction this operation is interested
- * in.
+ * @param direction which direction this operation is interested.
+ * @param ascending if GNUNET_YES, the bank will return the rows
+ * in ascending (= chronological) order.
* @param start_row_reference reference to a command that can
* offer a row identifier, to be used as the starting row
* to accept in the result.
@@ -780,6 +788,7 @@ TALER_TESTING_cmd_bank_history
const char *bank_url,
uint64_t account_no,
enum TALER_BANK_Direction direction,
+ unsigned int ascending,
const char *start_row_reference,
long long num_results)
{
@@ -792,6 +801,7 @@ TALER_TESTING_cmd_bank_history
hs->direction = direction;
hs->start_row_reference = start_row_reference;
hs->num_results = num_results;
+ hs->ascending = ascending;
cmd.label = label;
cmd.cls = hs;
diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h
index 1cad5710a..2f4a06023 100644
--- a/src/include/taler_bank_service.h
+++ b/src/include/taler_bank_service.h
@@ -257,6 +257,7 @@ typedef void
* @param auth authentication data to use
* @param account_number which account number should we query
* @param direction what kinds of wire transfers should be returned
+ * @param ascending if GNUNET_YES, history elements will be returned in chronological order.
* @param start_row from which row on do we want to get results, use UINT64_MAX for the latest; exclusive
* @param num_results how many results do we want; negative numbers to go into the past,
* positive numbers to go into the future starting at @a start_row;
@@ -273,6 +274,7 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
const struct TALER_BANK_AuthenticationData *auth,
uint64_t account_number,
enum TALER_BANK_Direction direction,
+ unsigned int ascending,
uint64_t start_row,
int64_t num_results,
TALER_BANK_HistoryResultCallback hres_cb,
diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h
index fd027c5b8..a3cc741e6 100644
--- a/src/include/taler_testing_bank_lib.h
+++ b/src/include/taler_testing_bank_lib.h
@@ -90,7 +90,8 @@ TALER_TESTING_prepare_bank (const char *config_filename);
* operation.
* @param account_no bank account number to ask the history for.
* @param direction which direction this operation is interested
- * in.
+ * @param ascending if GNUNET_YES, it ask the bank to return results
+ * in chronological order.
* @param start_row_reference reference to a command that can
* offer a row identifier, to be used as the starting row
* to accept in the result.
@@ -104,6 +105,7 @@ TALER_TESTING_cmd_bank_history
const char *bank_url,
uint64_t account_no,
enum TALER_BANK_Direction direction,
+ unsigned int ascending,
const char *start_row_reference,
long long num_results);
diff --git a/src/wire-plugins/plugin_wire_taler-bank.c b/src/wire-plugins/plugin_wire_taler-bank.c
index 8299e8e39..289c9b6a0 100644
--- a/src/wire-plugins/plugin_wire_taler-bank.c
+++ b/src/wire-plugins/plugin_wire_taler-bank.c
@@ -1093,6 +1093,8 @@ taler_bank_get_history (void *cls,
&whh->auth,
(uint64_t) account.no,
direction,
+ /* Defaults to descending ordering always. */
+ GNUNET_NO,
start_row,
num_results,
&bhist_cb,