fix fakebank API

This commit is contained in:
Christian Grothoff 2020-01-12 18:09:41 +01:00
parent c6ba84462d
commit c7610bf617
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 54 additions and 63 deletions

View File

@ -192,25 +192,16 @@ struct TALER_FAKEBANK_Handle
static void static void
check_log (struct TALER_FAKEBANK_Handle *h) check_log (struct TALER_FAKEBANK_Handle *h)
{ {
fprintf (stderr,
"Did not find matching transaction!\nI have:\n");
for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next) for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next)
{ {
if (GNUNET_YES == t->checked) if (GNUNET_YES == t->checked)
continue; continue;
fprintf (stderr, fprintf (stderr,
"%llu -> %llu (%s) from %s\n", "%llu -> %llu (%s)\n",
(unsigned long long) t->debit_account, (unsigned long long) t->debit_account,
(unsigned long long) t->credit_account, (unsigned long long) t->credit_account,
TALER_amount2s (&t->amount), TALER_amount2s (&t->amount));
t->exchange_base_url);
} }
fprintf (stderr,
"I wanted:\n%llu -> %llu (%s) from %s\n",
(unsigned long long) want_debit,
(unsigned long long) want_credit,
TALER_amount2s (want_amount),
exchange_base_url);
} }
@ -226,7 +217,7 @@ check_log (struct TALER_FAKEBANK_Handle *h)
* @param want_debit account that should have been credited * @param want_debit account that should have been credited
* @param exchange_base_url expected base URL of the exchange, * @param exchange_base_url expected base URL of the exchange,
* i.e. "https://example.com/"; may include a port * i.e. "https://example.com/"; may include a port
* @param[out] subject set to the wire transfer identifier * @param[out] wtid set to the wire transfer identifier
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
int int
@ -235,24 +226,35 @@ TALER_FAKEBANK_check_debit (struct TALER_FAKEBANK_Handle *h,
const char *want_debit, const char *want_debit,
const char *want_credit, const char *want_credit,
const char *exchange_base_url, const char *exchange_base_url,
struct TALER_WireTransferIdentifierRawP **subject) struct TALER_WireTransferIdentifierRawP *wtid)
{ {
for (struct Transaction *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) && if ( (0 == strcasecmp (want_debit,
(want_credit == t->credit_account) && t->debit_account)) &&
(0 == strcasecmp (want_credit,
t->credit_account)) &&
(0 == TALER_amount_cmp (want_amount, (0 == TALER_amount_cmp (want_amount,
&t->amount)) && &t->amount)) &&
(GNUNET_NO == t->checked) && (GNUNET_NO == t->checked) &&
(T_DEBIT == t->type) &&
(0 == strcasecmp (exchange_base_url, (0 == strcasecmp (exchange_base_url,
t->exchange_base_url)) ) t->subject.debit.exchange_base_url)) )
{ {
*subject = GNUNET_strdup (t->subject); *wtid = t->subject.debit.wtid;
t->checked = GNUNET_YES; t->checked = GNUNET_YES;
return GNUNET_OK; return GNUNET_OK;
} }
} }
fprintf (stderr,
"Did not find matching transaction!\nI have:\n");
check_log (h); check_log (h);
fprintf (stderr,
"I wanted:\n%s -> %s (%s) from %s\n",
want_debit,
want_credit,
TALER_amount2s (want_amount),
exchange_base_url);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
@ -278,20 +280,30 @@ TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle *h,
{ {
for (struct Transaction *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) && if ( (0 == strcasecmp (want_debit,
(want_credit == t->credit_account) && t->debit_account)) &&
(0 == strcasecmp (want_credit,
t->credit_account)) &&
(0 == TALER_amount_cmp (want_amount, (0 == TALER_amount_cmp (want_amount,
&t->amount)) && &t->amount)) &&
(GNUNET_NO == t->checked) && (GNUNET_NO == t->checked) &&
(0 == strcasecmp (exchange_base_url, (T_CREDIT == t->type) &&
t->exchange_base_url)) ) (0 == GNUNET_memcmp (reserve_pub,
&t->subject.credit.reserve_pub)) )
{ {
*subject = GNUNET_strdup (t->subject);
t->checked = GNUNET_YES; t->checked = GNUNET_YES;
return GNUNET_OK; return GNUNET_OK;
} }
} }
fprintf (stderr,
"Did not find matching transaction!\nI have:\n");
check_log (h); check_log (h);
fprintf (stderr,
"I wanted:\n%llu -> %llu (%s) with subject %s\n",
(unsigned long long) want_debit,
(unsigned long long) want_credit,
TALER_amount2s (want_amount),
TALER_B2S (reserve_pub));
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
@ -323,7 +335,7 @@ TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
debit_account, debit_account,
credit_account, credit_account,
TALER_amount2s (amount), TALER_amount2s (amount),
subject, TALER_B2S (subject),
exchange_base_url); exchange_base_url);
t = GNUNET_new (struct Transaction); t = GNUNET_new (struct Transaction);
t->debit_account = GNUNET_strdup (debit_account); t->debit_account = GNUNET_strdup (debit_account);
@ -363,20 +375,19 @@ TALER_FAKEBANK_make_admin_transfer (struct TALER_FAKEBANK_Handle *h,
struct Transaction *t; struct Transaction *t;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Making transfer from %s to %s over %s and subject %s; for exchange: %s\n", "Making transfer from %s to %s over %s and subject %s\n",
debit_account, debit_account,
credit_account, credit_account,
TALER_amount2s (amount), TALER_amount2s (amount),
TALER_B2S (reserve_pub), TALER_B2S (reserve_pub));
exchange_base_url);
t = GNUNET_new (struct Transaction); t = GNUNET_new (struct Transaction);
t->debit_account = GNUNET_strdup (debit_account); t->debit_account = GNUNET_strdup (debit_account);
t->credit_account = GNUNET_strdup (credit_account); t->credit_account = GNUNET_strdup (credit_account);
t->amount = *amount; t->amount = *amount;
t->exchange_base_url = GNUNET_strdup (exchange_base_url);
t->row_id = ++h->serial_counter; t->row_id = ++h->serial_counter;
t->date = GNUNET_TIME_absolute_get (); t->date = GNUNET_TIME_absolute_get ();
t->subject = GNUNET_strdup (subject); t->type = T_CREDIT;
t->subject.credit.reserve_pub = *reserve_pub;
GNUNET_TIME_round_abs (&t->date); GNUNET_TIME_round_abs (&t->date);
GNUNET_CONTAINER_DLL_insert_tail (h->transactions_head, GNUNET_CONTAINER_DLL_insert_tail (h->transactions_head,
h->transactions_tail, h->transactions_tail,
@ -409,17 +420,7 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h)
return GNUNET_OK; return GNUNET_OK;
fprintf (stderr, fprintf (stderr,
"Expected empty transaction set, but I have:\n"); "Expected empty transaction set, but I have:\n");
while (NULL != t) check_log (h);
{
if (GNUNET_YES != t->checked)
fprintf (stderr,
"%s -> %s (%s) from %s\n",
t->debit_account,
t->credit_account,
TALER_amount2s (&t->amount),
t->exchange_base_url);
t = t->next;
}
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
@ -439,7 +440,6 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
GNUNET_CONTAINER_DLL_remove (h->transactions_head, GNUNET_CONTAINER_DLL_remove (h->transactions_head,
h->transactions_tail, h->transactions_tail,
t); t);
GNUNET_free (t->subject);
GNUNET_free (t->debit_account); GNUNET_free (t->debit_account);
GNUNET_free (t->credit_account); GNUNET_free (t->credit_account);
if (T_DEBIT == t->type) if (T_DEBIT == t->type)
@ -536,17 +536,15 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
break; break;
} }
{ {
const char *subject;
const char *debit_account; const char *debit_account;
const char *credit_account; const char *credit_account;
const char *base_url;
struct TALER_Amount amount; struct TALER_Amount amount;
struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("subject", &subject), GNUNET_JSON_spec_fixed_auto ("reserve_pub", &reserve_pub),
GNUNET_JSON_spec_string ("debit_account", &debit_account), GNUNET_JSON_spec_string ("debit_account", &debit_account),
GNUNET_JSON_spec_string ("credit_account", &credit_account), GNUNET_JSON_spec_string ("credit_account", &credit_account),
TALER_JSON_spec_amount ("amount", &amount), TALER_JSON_spec_amount ("amount", &amount),
GNUNET_JSON_spec_string ("exchange_url", &base_url),
GNUNET_JSON_spec_end () GNUNET_JSON_spec_end ()
}; };
if (GNUNET_OK != if (GNUNET_OK !=
@ -558,19 +556,17 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
json_decref (json); json_decref (json);
return MHD_NO; return MHD_NO;
} }
row_id = TALER_FAKEBANK_make_transfer (h, row_id = TALER_FAKEBANK_make_admin_transfer (h,
debit_account, debit_account,
credit_account, credit_account,
&amount, &amount,
subject, &reserve_pub);
base_url);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s, from %s\n", "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s\n",
debit_account, debit_account,
credit_account, credit_account,
subject, TALER_B2S (&reserve_pub),
TALER_amount2s (&amount), TALER_amount2s (&amount));
base_url);
} }
json_decref (json); json_decref (json);
@ -660,25 +656,20 @@ handle_transaction (struct TALER_FAKEBANK_Handle *h,
return MHD_NO; return MHD_NO;
} }
{ {
char *subject;
subject = GNUNET_STRINGS_data_to_string_alloc (&wtid,
sizeof (wtid));
// FIXME: use uuid here!!! // FIXME: use uuid here!!!
row_id = TALER_FAKEBANK_make_transfer (h, row_id = TALER_FAKEBANK_make_transfer (h,
account, account,
credit_account, credit_account,
&amount, &amount,
subject, &wtid,
base_url); base_url);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s, from %s\n", "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s, from %s\n",
account, account,
credit_account, credit_account,
subject, TALER_B2S (&wtid),
TALER_amount2s (&amount), TALER_amount2s (&amount),
base_url); base_url);
GNUNET_free (subject);
} }
} }
json_decref (json); json_decref (json);

View File

@ -113,7 +113,7 @@ TALER_FAKEBANK_make_admin_transfer (struct TALER_FAKEBANK_Handle *h,
* @param want_debit account that should have been credited * @param want_debit account that should have been credited
* @param exchange_base_url expected base URL of the exchange, * @param exchange_base_url expected base URL of the exchange,
* i.e. "https://example.com/"; may include a port * i.e. "https://example.com/"; may include a port
* @param[out] subject set to the wire transfer identifier * @param[out] wtid set to the wire transfer identifier
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
int int
@ -122,7 +122,7 @@ TALER_FAKEBANK_check_debit (struct TALER_FAKEBANK_Handle *h,
const char *want_debit, const char *want_debit,
const char *want_credit, const char *want_credit,
const char *exchange_base_url, const char *exchange_base_url,
struct TALER_WireTransferIdentifierRawP **subject); struct TALER_WireTransferIdentifierRawP *wtid);
/** /**