aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-05-06 21:08:58 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-05-06 21:08:58 +0200
commitd1461b2485cb8a633e93f4ed59c560619f08af72 (patch)
tree4f02bc539ebd9fbe5aeb2b0ae75a2250b437a549 /src/lib
parent4a3145fca389fca1bbfc7ba61b7cafd1156ef656 (diff)
work on tokens
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/merchant_api_post_order_pay.c89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c
index 39e4e35b..ca4e8a18 100644
--- a/src/lib/merchant_api_post_order_pay.c
+++ b/src/lib/merchant_api_post_order_pay.c
@@ -384,8 +384,7 @@ TALER_MERCHANT_order_pay_frontend (
const struct TALER_MERCHANT_PaidCoin coins[static num_coins],
unsigned int num_tokens,
const struct TALER_MERCHANT_UsedToken tokens[static num_tokens],
- unsigned int num_output_tokens,
- const struct TALER_MERCHANT_OutputToken output_tokens[static num_output_tokens],
+ json_t *j_output_tokens,
TALER_MERCHANT_OrderPayCallback pay_cb,
void *pay_cb_cls)
{
@@ -393,7 +392,6 @@ TALER_MERCHANT_order_pay_frontend (
json_t *pay_obj;
json_t *j_coins;
json_t *j_tokens = NULL;
- json_t *j_output_tokens = NULL;
CURL *eh;
struct TALER_Amount total_fee;
struct TALER_Amount total_amount;
@@ -502,31 +500,6 @@ TALER_MERCHANT_order_pay_frontend (
}
}
- if (0 < num_output_tokens)
- {
- j_output_tokens = json_array ();
- GNUNET_assert (NULL != j_output_tokens);
- for (unsigned int i = 0; i<num_output_tokens; i++)
- {
- json_t *j_token_ev;
- const struct TALER_MERCHANT_OutputToken *ev = &output_tokens[i];
-
- j_token_ev = GNUNET_JSON_PACK (
- TALER_JSON_pack_token_envelope ("token_ev",
- &ev->envelope),
- GNUNET_JSON_pack_data_auto ("h_issue",
- &ev->h_issue.hash));
- if (0 !=
- json_array_append_new (j_output_tokens,
- j_token_ev))
- {
- GNUNET_break (0);
- json_decref (j_output_tokens);
- return NULL;
- }
- }
- }
-
pay_obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_steal ("coins",
j_coins),
@@ -534,8 +507,8 @@ TALER_MERCHANT_order_pay_frontend (
GNUNET_JSON_pack_array_steal ("tokens",
j_tokens)),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_array_steal ("tokens_evs",
- j_output_tokens)),
+ GNUNET_JSON_pack_array_incref ("tokens_evs",
+ j_output_tokens)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("wallet_data",
(json_t *) wallet_data)),
@@ -576,7 +549,7 @@ TALER_MERCHANT_order_pay_frontend (
GNUNET_memcpy (oph->coins,
coins,
num_coins * sizeof (struct TALER_MERCHANT_PaidCoin));
- /* TODO: Copy token_evs to pay handle so they
+ /* TODO: Copy tokens_evs to pay handle so they
can be unblinded in the callback. */
eh = TALER_MERCHANT_curl_easy_get_ (oph->url);
@@ -608,7 +581,7 @@ TALER_MERCHANT_order_pay (
const char *merchant_url,
const char *session_id,
const struct TALER_PrivateContractHashP *h_contract_terms,
- const json_t *wallet_data,
+ int choice_index,
const struct TALER_Amount *amount,
const struct TALER_Amount *max_fee,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -627,6 +600,9 @@ TALER_MERCHANT_order_pay (
TALER_MERCHANT_OrderPayCallback pay_cb,
void *pay_cb_cls)
{
+ json_t *j_output_tokens = NULL;
+ const json_t *wallet_data = NULL;
+ struct GNUNET_HashCode h_outputs;
struct GNUNET_HashCode wallet_data_hash;
if (GNUNET_YES !=
@@ -636,17 +612,51 @@ TALER_MERCHANT_order_pay (
GNUNET_break (0);
return NULL;
}
- if (0 < num_tokens && NULL == wallet_data)
+ if ((0 < num_tokens || 0 < num_output_tokens) && 0 > choice_index)
{
- /* Since the wallet has to sign over the wallet_data_hash
- to use tokens, wallet data must not be NULL if input
- tokens are provided */
+ /* Tokens (input or output) require a valid choice_index to be set.
+ Only contracts with coices can use or issue tokens. */
GNUNET_break (0);
return NULL;
}
- if (NULL != wallet_data)
+ if (0 < num_output_tokens)
+ {
+ /* Build token envelopes json array. */
+ j_output_tokens = json_array ();
+ GNUNET_assert (NULL != j_output_tokens);
+ for (unsigned int i = 0; i<num_output_tokens; i++)
+ {
+ json_t *j_token_ev;
+ const struct TALER_MERCHANT_OutputToken *ev = &output_tokens[i];
+
+ j_token_ev = GNUNET_JSON_PACK (
+ TALER_JSON_pack_token_envelope ("token_ev",
+ &ev->envelope),
+ GNUNET_JSON_pack_data_auto ("h_issue",
+ &ev->h_issue.hash));
+ if (0 !=
+ json_array_append_new (j_output_tokens,
+ j_token_ev))
+ {
+ GNUNET_break (0);
+ json_decref (j_output_tokens);
+ return NULL;
+ }
+ }
+
+ TALER_json_hash (j_output_tokens, &h_outputs);
+ }
+ if (0 <= choice_index)
+ {
+ wallet_data = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_int64 ("choice_index",
+ choice_index),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("h_outputs",
+ &h_outputs)));
TALER_json_hash (wallet_data,
- &wallet_data_hash);
+ &wallet_data_hash);
+ }
{
struct TALER_MERCHANT_PaidCoin pc[num_coins];
struct TALER_MERCHANT_UsedToken ut[num_tokens];
@@ -720,8 +730,7 @@ TALER_MERCHANT_order_pay (
pc,
num_tokens,
ut,
- num_output_tokens,
- output_tokens,
+ j_output_tokens,
pay_cb,
pay_cb_cls);
if (NULL == oph)