fix fakebank account vs. full payto confusion

This commit is contained in:
Christian Grothoff 2020-01-15 11:48:41 +01:00
parent 4c488a1d0e
commit 4547bfb318
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 76 additions and 47 deletions

View File

@ -54,12 +54,12 @@ struct Transaction
struct TALER_Amount amount; struct TALER_Amount amount;
/** /**
* Account to debit. * Account to debit (string, not payto!)
*/ */
char *debit_account; char *debit_account;
/** /**
* Account to credit. * Account to credit (string, not payto!)
*/ */
char *credit_account; char *credit_account;
@ -197,27 +197,6 @@ struct TALER_FAKEBANK_Handle
}; };
/**
* Return account string from an x-taler-bank payto:// URL.
*
* @param payto:// URL of method x-taler-bank
* @return account_name the account name
*/
char *
get_xtalerbank_payto_account (const char *payto_url)
{
const char *beg;
GNUNET_assert (0 == strncasecmp (payto_url,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")));
beg = strchr (&payto_url[strlen ("payto://x-taler-bank/")],
'/');
GNUNET_assert (NULL != beg);
return GNUNET_strdup (&beg[1]);
}
/** /**
* Generate log messages for failed check operation. * Generate log messages for failed check operation.
* *
@ -346,8 +325,8 @@ TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle *h,
* Tell the fakebank to create another wire transfer. * Tell the fakebank to create another wire transfer.
* *
* @param h fake bank handle * @param h fake bank handle
* @param debit_account account to debit * @param debit_account account to debit, not payto://!
* @param credit_account account to credit * @param credit_account account to credit, not payto://!
* @param amount amount to transfer * @param amount amount to transfer
* @param subject wire transfer subject to use * @param subject wire transfer subject to use
* @param exchange_base_url exchange URL * @param exchange_base_url exchange URL
@ -366,6 +345,12 @@ TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
{ {
struct Transaction *t; struct Transaction *t;
GNUNET_break (0 != strncasecmp ("payto://",
debit_account,
strlen ("payto://")));
GNUNET_break (0 != strncasecmp ("payto://",
credit_account,
strlen ("payto://")));
if (NULL != request_uid) if (NULL != request_uid)
{ {
for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next) for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next)
@ -431,6 +416,12 @@ TALER_FAKEBANK_make_admin_transfer (struct TALER_FAKEBANK_Handle *h,
{ {
struct Transaction *t; struct Transaction *t;
GNUNET_break (0 != strncasecmp ("payto://",
debit_account,
strlen ("payto://")));
GNUNET_break (0 != strncasecmp ("payto://",
credit_account,
strlen ("payto://")));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Making transfer from %s to %s over %s and subject %s\n", "Making transfer from %s to %s over %s and subject %s\n",
debit_account, debit_account,
@ -616,7 +607,7 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
json_decref (json); json_decref (json);
return MHD_NO; return MHD_NO;
} }
debit = get_xtalerbank_payto_account (debit_account); debit = TALER_xtalerbank_account_from_payto (debit_account);
row_id = TALER_FAKEBANK_make_admin_transfer (h, row_id = TALER_FAKEBANK_make_admin_transfer (h,
debit, debit,
account, account,
@ -692,6 +683,7 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
struct GNUNET_HashCode uuid; struct GNUNET_HashCode uuid;
struct TALER_WireTransferIdentifierRawP wtid; struct TALER_WireTransferIdentifierRawP wtid;
const char *credit_account; const char *credit_account;
char *credit;
const char *base_url; const char *base_url;
struct TALER_Amount amount; struct TALER_Amount amount;
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
@ -718,9 +710,10 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
return MHD_NO; return MHD_NO;
} }
{ {
credit = TALER_xtalerbank_account_from_payto (credit_account);
row_id = TALER_FAKEBANK_make_transfer (h, row_id = TALER_FAKEBANK_make_transfer (h,
account, account,
credit_account, credit,
&amount, &amount,
&wtid, &wtid,
base_url, base_url,
@ -728,10 +721,11 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
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,
TALER_B2S (&wtid), TALER_B2S (&wtid),
TALER_amount2s (&amount), TALER_amount2s (&amount),
base_url); base_url);
GNUNET_free (credit);
} }
} }
json_decref (json); json_decref (json);
@ -972,14 +966,6 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
else else
ha.delta++; ha.delta++;
} }
else
{
fprintf (stderr,
"Skipping transaction %s->%s: only care about %s\n",
pos->debit_account,
pos->credit_account,
account);
}
if (ha.delta > 0) if (ha.delta > 0)
pos = pos->prev; pos = pos->prev;
else else
@ -1088,14 +1074,6 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h,
else else
ha.delta++; ha.delta++;
} }
else
{
fprintf (stderr,
"Skipping transaction %s->%s: only care about %s\n",
pos->debit_account,
pos->credit_account,
account);
}
if (ha.delta > 0) if (ha.delta > 0)
pos = pos->prev; pos = pos->prev;
else else

View File

@ -280,4 +280,15 @@ char *
TALER_xtalerbank_account_url_from_payto (const char *payto); TALER_xtalerbank_account_url_from_payto (const char *payto);
/**
* Obtain the account name from a payto URL.
*
* @param payto an x-taler-bank payto URL
* @return only the account name from the @a payto URL, NULL if not an x-taler-bank
* payto URL
*/
char *
TALER_xtalerbank_account_from_payto (const char *payto);
#endif #endif

View File

@ -129,9 +129,10 @@ check_bank_transfer_run (void *cls,
if (NULL == deposit_cmd) if (NULL == deposit_cmd)
TALER_TESTING_FAIL (is); TALER_TESTING_FAIL (is);
GNUNET_assert GNUNET_assert (GNUNET_OK ==
(GNUNET_OK == TALER_TESTING_get_trait_amount_obj TALER_TESTING_get_trait_amount_obj (deposit_cmd,
(deposit_cmd, 0, &amount_ptr)); 0,
&amount_ptr));
amount = *amount_ptr; amount = *amount_ptr;
GNUNET_assert GNUNET_assert

View File

@ -78,6 +78,14 @@ main (int argc,
"payto://x-taler-bank/localhost:1080/alice"); "payto://x-taler-bank/localhost:1080/alice");
CHECK ("http://localhost:1080/alice", CHECK ("http://localhost:1080/alice",
r); r);
r = TALER_xtalerbank_account_from_payto (
"payto://x-taler-bank/localhost:1080/alice");
CHECK ("alice",
r);
r = TALER_xtalerbank_account_from_payto (
"payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
CHECK ("alice",
r);
return 0; return 0;
} }

View File

@ -710,4 +710,35 @@ TALER_xtalerbank_account_url_from_payto (const char *payto)
} }
/**
* Obtain the account name from a payto URL.
*
* @param payto an x-taler-bank payto URL
* @return only the account name from the @a payto URL, NULL if not an x-taler-bank
* payto URL
*/
char *
TALER_xtalerbank_account_from_payto (const char *payto)
{
const char *beg;
const char *end;
if (0 != strncasecmp (payto,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
return NULL;
beg = strchr (&payto[strlen ("payto://x-taler-bank/")],
'/');
if (NULL == beg)
return NULL;
beg++;
end = strchr (beg,
'?');
if (NULL == end)
return GNUNET_strdup (beg);
return GNUNET_strndup (beg,
end - beg);
}
/* end of util.c */ /* end of util.c */