/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.
This commit is contained in:
parent
c2b6a10654
commit
15c1a877c6
@ -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);
|
||||
|
@ -95,6 +95,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.
|
||||
*/
|
||||
@ -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;
|
||||
|
@ -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),
|
||||
|
||||
|
@ -88,6 +88,7 @@ run (void *cls,
|
||||
twister_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_NO,
|
||||
NULL,
|
||||
5),
|
||||
/**
|
||||
|
@ -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" },
|
||||
|
@ -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",
|
||||
|
@ -80,6 +80,7 @@ run (void *cls,
|
||||
fakebank_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_NO,
|
||||
NULL,
|
||||
5),
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -174,6 +174,12 @@ struct TBI_Command
|
||||
*/
|
||||
int failed;
|
||||
|
||||
/**
|
||||
* if true, the history elements will be asked in
|
||||
* chronological order.
|
||||
*/
|
||||
unsigned int ascending;
|
||||
|
||||
} history;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user