modify fakebank API to allow arbitrary subjects, not just well-fromed WTIDs
This commit is contained in:
parent
1eb739c670
commit
16b7c26605
@ -65,7 +65,7 @@ struct Transaction
|
||||
/**
|
||||
* Subject of the transfer.
|
||||
*/
|
||||
struct TALER_WireTransferIdentifierRawP wtid;
|
||||
char *subject;
|
||||
|
||||
/**
|
||||
* Base URL of the exchange.
|
||||
@ -119,7 +119,7 @@ struct TALER_FAKEBANK_Handle
|
||||
/**
|
||||
* Check that the @a want_amount was transferred from
|
||||
* the @a want_debit to the @a want_credit account. If
|
||||
* so, set the @a wtid to the transfer identifier.
|
||||
* so, set the @a subject to the transfer identifier.
|
||||
* If not, return #GNUNET_SYSERR.
|
||||
*
|
||||
* @param h bank instance
|
||||
@ -137,11 +137,9 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h,
|
||||
uint64_t want_debit,
|
||||
uint64_t want_credit,
|
||||
const char *exchange_base_url,
|
||||
struct TALER_WireTransferIdentifierRawP *wtid)
|
||||
char **subject)
|
||||
{
|
||||
struct Transaction *t;
|
||||
|
||||
for (t = h->transactions_head; NULL != t; t = t->next)
|
||||
for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next)
|
||||
{
|
||||
if ( (want_debit == t->debit_account) &&
|
||||
(want_credit == t->credit_account) &&
|
||||
@ -153,7 +151,7 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h,
|
||||
GNUNET_CONTAINER_DLL_remove (h->transactions_head,
|
||||
h->transactions_tail,
|
||||
t);
|
||||
*wtid = t->wtid;
|
||||
*subject = t->subject;
|
||||
GNUNET_free (t->exchange_base_url);
|
||||
GNUNET_free (t);
|
||||
return GNUNET_OK;
|
||||
@ -161,7 +159,7 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h,
|
||||
}
|
||||
fprintf (stderr,
|
||||
"Did not find matching transaction!\nI have:\n");
|
||||
for (t = h->transactions_head; NULL != t; t = t->next)
|
||||
for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next)
|
||||
{
|
||||
char *s;
|
||||
|
||||
@ -178,6 +176,49 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell the fakebank to create another wire transfer.
|
||||
*
|
||||
* @param h fake bank handle
|
||||
* @param debit_account account to debit
|
||||
* @param credit_account account to credit
|
||||
* @param amount amount to transfer
|
||||
* @param subject wire transfer subject to use
|
||||
* @param exchange_base_url exchange URL
|
||||
* @return serial_id of the transfer
|
||||
*/
|
||||
uint64_t
|
||||
TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
|
||||
uint64_t debit_account,
|
||||
uint64_t credit_account,
|
||||
const struct TALER_Amount *amount,
|
||||
const char *subject,
|
||||
const char *exchange_base_url)
|
||||
{
|
||||
struct Transaction *t;
|
||||
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"Making transfer from %llu to %llu over %s and subject %s\n",
|
||||
(unsigned long long) debit_account,
|
||||
(unsigned long long) credit_account,
|
||||
TALER_amount2s (amount),
|
||||
subject);
|
||||
t = GNUNET_new (struct Transaction);
|
||||
t->debit_account = debit_account;
|
||||
t->credit_account = credit_account;
|
||||
t->amount = *amount;
|
||||
t->exchange_base_url = GNUNET_strdup (exchange_base_url);
|
||||
t->serial_id = ++h->serial_counter;
|
||||
t->date = GNUNET_TIME_absolute_get ();
|
||||
t->subject = GNUNET_strdup (subject);
|
||||
GNUNET_TIME_round_abs (&t->date);
|
||||
GNUNET_CONTAINER_DLL_insert_tail (h->transactions_head,
|
||||
h->transactions_tail,
|
||||
t);
|
||||
return t->serial_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that no wire transfers were ordered (or at least none
|
||||
* that have not been taken care of via #TALER_FAKEBANK_check()).
|
||||
@ -228,6 +269,7 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
|
||||
GNUNET_CONTAINER_DLL_remove (h->transactions_head,
|
||||
h->transactions_tail,
|
||||
t);
|
||||
GNUNET_free (t->subject);
|
||||
GNUNET_free (t->exchange_base_url);
|
||||
GNUNET_free (t);
|
||||
}
|
||||
@ -291,9 +333,9 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
||||
{
|
||||
enum GNUNET_JSON_PostResult pr;
|
||||
json_t *json;
|
||||
struct Transaction *t;
|
||||
struct MHD_Response *resp;
|
||||
int ret;
|
||||
uint64_t serial_id;
|
||||
|
||||
pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
|
||||
con_cls,
|
||||
@ -316,14 +358,17 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
||||
case GNUNET_JSON_PR_SUCCESS:
|
||||
break;
|
||||
}
|
||||
t = GNUNET_new (struct Transaction);
|
||||
{
|
||||
const char *wtid;
|
||||
uint64_t debit_account;
|
||||
uint64_t credit_account;
|
||||
const char *base_url;
|
||||
struct TALER_Amount amount;
|
||||
struct GNUNET_JSON_Specification spec[] = {
|
||||
GNUNET_JSON_spec_fixed_auto ("wtid", &t->wtid),
|
||||
GNUNET_JSON_spec_uint64 ("debit_account", &t->debit_account),
|
||||
GNUNET_JSON_spec_uint64 ("credit_account", &t->credit_account),
|
||||
TALER_JSON_spec_amount ("amount", &t->amount),
|
||||
GNUNET_JSON_spec_string ("wtid", &wtid),
|
||||
GNUNET_JSON_spec_uint64 ("debit_account", &debit_account),
|
||||
GNUNET_JSON_spec_uint64 ("credit_account", &credit_account),
|
||||
TALER_JSON_spec_amount ("amount", &amount),
|
||||
GNUNET_JSON_spec_string ("exchange_url", &base_url),
|
||||
GNUNET_JSON_spec_end ()
|
||||
};
|
||||
@ -336,19 +381,18 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
||||
json_decref (json);
|
||||
return MHD_NO;
|
||||
}
|
||||
t->exchange_base_url = GNUNET_strdup (base_url);
|
||||
t->serial_id = ++h->serial_counter;
|
||||
t->date = GNUNET_TIME_absolute_get ();
|
||||
GNUNET_TIME_round_abs (&t->date);
|
||||
GNUNET_CONTAINER_DLL_insert_tail (h->transactions_head,
|
||||
h->transactions_tail,
|
||||
t);
|
||||
}
|
||||
serial_id = TALER_FAKEBANK_make_transfer (h,
|
||||
debit_account,
|
||||
credit_account,
|
||||
&amount,
|
||||
wtid,
|
||||
base_url);
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Receiving incoming wire transfer: %llu->%llu from %s\n",
|
||||
(unsigned long long) t->debit_account,
|
||||
(unsigned long long) t->credit_account,
|
||||
t->exchange_base_url);
|
||||
(unsigned long long) debit_account,
|
||||
(unsigned long long) credit_account,
|
||||
base_url);
|
||||
}
|
||||
json_decref (json);
|
||||
|
||||
/* Finally build response object */
|
||||
@ -358,7 +402,7 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
||||
|
||||
json = json_pack ("{s:I}",
|
||||
"serial_id",
|
||||
(json_int_t) t->serial_id);
|
||||
(json_int_t) serial_id);
|
||||
json_str = json_dumps (json,
|
||||
JSON_INDENT(2));
|
||||
json_decref (json);
|
||||
@ -514,17 +558,10 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
char *ws;
|
||||
|
||||
ws = GNUNET_STRINGS_data_to_string_alloc (&pos->wtid,
|
||||
sizeof (pos->wtid));
|
||||
GNUNET_asprintf (&subject,
|
||||
"%s %s",
|
||||
ws,
|
||||
pos->subject,
|
||||
pos->exchange_base_url);
|
||||
GNUNET_free (ws);
|
||||
}
|
||||
trans = json_pack ("{s:I, s:o, s:o, s:s, s:I, s:s}",
|
||||
"row_id", (json_int_t) pos->serial_id,
|
||||
"date", GNUNET_JSON_from_time_abs (pos->date),
|
||||
|
@ -572,7 +572,9 @@ history_cb (void *cls,
|
||||
"Expected history of length %llu, got %llu\n",
|
||||
(unsigned long long) total,
|
||||
(unsigned long long) cmd->details.history.results_obtained);
|
||||
print_expected (h, total, UINT_MAX);
|
||||
print_expected (h,
|
||||
total,
|
||||
UINT_MAX);
|
||||
free_history (h,
|
||||
total);
|
||||
fail (is);
|
||||
@ -621,7 +623,6 @@ interpreter_run (void *cls)
|
||||
struct InterpreterState *is = cls;
|
||||
struct TBI_Command *cmd = &is->commands[is->ip];
|
||||
const struct TBI_Command *ref;
|
||||
struct TALER_WireTransferIdentifierRawP wtid;
|
||||
struct TALER_Amount amount;
|
||||
const struct GNUNET_SCHEDULER_TaskContext *tc;
|
||||
struct TALER_BANK_AuthenticationData auth;
|
||||
@ -719,26 +720,35 @@ interpreter_run (void *cls)
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
TALER_string_to_amount (ref->details.admin_add_incoming.amount,
|
||||
&amount));
|
||||
{
|
||||
char *subject;
|
||||
char *expect;
|
||||
|
||||
if (GNUNET_OK !=
|
||||
TALER_FAKEBANK_check (is->fakebank,
|
||||
&amount,
|
||||
ref->details.admin_add_incoming.debit_account_no,
|
||||
ref->details.admin_add_incoming.credit_account_no,
|
||||
ref->details.admin_add_incoming.exchange_base_url,
|
||||
&wtid))
|
||||
&subject))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
fail (is);
|
||||
return;
|
||||
}
|
||||
if (0 != memcmp (&wtid,
|
||||
&ref->details.admin_add_incoming.wtid,
|
||||
sizeof (wtid)))
|
||||
expect = GNUNET_STRINGS_data_to_string_alloc (&ref->details.admin_add_incoming.wtid,
|
||||
sizeof (ref->details.admin_add_incoming.wtid));
|
||||
if (0 != strcmp (subject, expect))
|
||||
{
|
||||
GNUNET_free (expect);
|
||||
GNUNET_free (subject);
|
||||
GNUNET_break (0);
|
||||
fail (is);
|
||||
return;
|
||||
}
|
||||
GNUNET_free (subject);
|
||||
GNUNET_free (expect);
|
||||
}
|
||||
is->ip++;
|
||||
is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
|
||||
is);
|
||||
|
@ -636,9 +636,9 @@ struct Command
|
||||
const char *exchange_base_url;
|
||||
|
||||
/**
|
||||
* Set (!) to the wire transfer identifier observed.
|
||||
* Set (!) to the wire transfer subject observed.
|
||||
*/
|
||||
struct TALER_WireTransferIdentifierRawP wtid;
|
||||
char *subject;
|
||||
|
||||
} check_bank_transfer;
|
||||
|
||||
@ -1805,18 +1805,24 @@ deposit_wtid_cb (void *cls,
|
||||
if (NULL != cmd->details.deposit_wtid.bank_transfer_ref)
|
||||
{
|
||||
const struct Command *ref;
|
||||
char *ws;
|
||||
|
||||
ws = GNUNET_STRINGS_data_to_string_alloc (wtid,
|
||||
sizeof (*wtid));
|
||||
|
||||
|
||||
ref = find_command (is,
|
||||
cmd->details.deposit_wtid.bank_transfer_ref);
|
||||
GNUNET_assert (NULL != ref);
|
||||
if (0 != memcmp (wtid,
|
||||
&ref->details.check_bank_transfer.wtid,
|
||||
sizeof (struct TALER_WireTransferIdentifierRawP)))
|
||||
if (0 != strcmp (ws,
|
||||
ref->details.check_bank_transfer.subject))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_free (ws);
|
||||
fail (is);
|
||||
return;
|
||||
}
|
||||
GNUNET_free (ws);
|
||||
}
|
||||
break;
|
||||
case MHD_HTTP_ACCEPTED:
|
||||
@ -2496,7 +2502,11 @@ interpreter_run (void *cls)
|
||||
cmd->details.wire_deposits.wtid = ref->details.deposit_wtid.wtid;
|
||||
break;
|
||||
case OC_CHECK_BANK_TRANSFER:
|
||||
cmd->details.wire_deposits.wtid = ref->details.check_bank_transfer.wtid;
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_STRINGS_string_to_data (ref->details.check_bank_transfer.subject,
|
||||
strlen (ref->details.check_bank_transfer.subject),
|
||||
&cmd->details.wire_deposits.wtid,
|
||||
sizeof (cmd->details.wire_deposits.wtid)));
|
||||
break;
|
||||
default:
|
||||
GNUNET_break (0);
|
||||
@ -2597,7 +2607,7 @@ interpreter_run (void *cls)
|
||||
cmd->details.check_bank_transfer.account_debit,
|
||||
cmd->details.check_bank_transfer.account_credit,
|
||||
cmd->details.check_bank_transfer.exchange_base_url,
|
||||
&cmd->details.check_bank_transfer.wtid))
|
||||
&cmd->details.check_bank_transfer.subject))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
fail (is);
|
||||
@ -2951,6 +2961,8 @@ do_shutdown (void *cls)
|
||||
}
|
||||
break;
|
||||
case OC_CHECK_BANK_TRANSFER:
|
||||
GNUNET_free_non_null (cmd->details.check_bank_transfer.subject);
|
||||
cmd->details.check_bank_transfer.subject = NULL;
|
||||
break;
|
||||
case OC_CHECK_BANK_TRANSFERS_EMPTY:
|
||||
break;
|
||||
|
@ -118,7 +118,7 @@ struct Command
|
||||
/**
|
||||
* Subject of the transfer, set by the command.
|
||||
*/
|
||||
struct TALER_WireTransferIdentifierRawP wtid;
|
||||
char *subject;
|
||||
|
||||
} expect_transaction;
|
||||
|
||||
@ -565,7 +565,7 @@ interpreter (void *cls)
|
||||
cmd->details.expect_transaction.debit_account,
|
||||
cmd->details.expect_transaction.credit_account,
|
||||
cmd->details.expect_transaction.exchange_base_url,
|
||||
&cmd->details.expect_transaction.wtid))
|
||||
&cmd->details.expect_transaction.subject))
|
||||
{
|
||||
fail (cmd);
|
||||
return;
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "taler_fakebank_lib.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Commands for the interpreter.
|
||||
*/
|
||||
@ -127,7 +126,7 @@ struct Command
|
||||
/**
|
||||
* Subject of the transfer, set by the command.
|
||||
*/
|
||||
struct TALER_WireTransferIdentifierRawP wtid;
|
||||
char *subject;
|
||||
|
||||
} expect_transfer;
|
||||
|
||||
@ -371,6 +370,8 @@ shutdown_action (void *cls)
|
||||
state);
|
||||
break;
|
||||
case OPCODE_EXPECT_TRANSFER:
|
||||
GNUNET_free_non_null (cmd->details.expect_transfer.subject);
|
||||
cmd->details.expect_transfer.subject = NULL;
|
||||
break;
|
||||
case OPCODE_EXPECT_TRANSFERS_EMPTY:
|
||||
break;
|
||||
@ -521,7 +522,7 @@ interpreter (void *cls)
|
||||
cmd->details.expect_transfer.debit_account,
|
||||
cmd->details.expect_transfer.credit_account,
|
||||
cmd->details.expect_transfer.exchange_base_url,
|
||||
&cmd->details.expect_transfer.wtid))
|
||||
&cmd->details.expect_transfer.subject))
|
||||
{
|
||||
fail (cmd);
|
||||
return;
|
||||
|
@ -61,9 +61,30 @@ int
|
||||
TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
|
||||
|
||||
|
||||
/**
|
||||
* Tell the fakebank to create another wire transfer.
|
||||
*
|
||||
* @param h fake bank handle
|
||||
* @param debit_account account to debit
|
||||
* @param credit_account account to credit
|
||||
* @param amount amount to transfer
|
||||
* @param subject wire transfer subject to use
|
||||
* @param exchange_base_url exchange URL
|
||||
* @return serial_id of the transfer
|
||||
*/
|
||||
uint64_t
|
||||
TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
|
||||
uint64_t debit_account,
|
||||
uint64_t credit_account,
|
||||
const struct TALER_Amount *amount,
|
||||
const char *subject,
|
||||
const char *exchange_base_url);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the @a want_amount was transferred from the @a
|
||||
* want_debit to the @a want_credit account. If so, set the @a wtid
|
||||
* want_debit to the @a want_credit account. If so, set the @a subject
|
||||
* to the transfer identifier and remove the transaction from the
|
||||
* list. If the transaction was not recorded, return #GNUNET_SYSERR.
|
||||
*
|
||||
@ -73,7 +94,7 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
|
||||
* @param want_debit account that should have been credited
|
||||
* @param exchange_base_url expected base URL of the exchange,
|
||||
* i.e. "https://example.com/"; may include a port
|
||||
* @param[out] wtid set to the wire transfer identifier
|
||||
* @param[out] subject set to the wire transfer identifier
|
||||
* @return #GNUNET_OK on success
|
||||
*/
|
||||
int
|
||||
@ -82,7 +103,7 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h,
|
||||
uint64_t want_debit,
|
||||
uint64_t want_credit,
|
||||
const char *exchange_base_url,
|
||||
struct TALER_WireTransferIdentifierRawP *wtid);
|
||||
char **subject);
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user