aboutsummaryrefslogtreecommitdiff
path: root/src/lib/merchant_api_post_order_pay.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/merchant_api_post_order_pay.c')
-rw-r--r--src/lib/merchant_api_post_order_pay.c104
1 files changed, 74 insertions, 30 deletions
diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c
index c74113b6..39e4e35b 100644
--- a/src/lib/merchant_api_post_order_pay.c
+++ b/src/lib/merchant_api_post_order_pay.c
@@ -34,6 +34,7 @@
#include "taler_merchant_service.h"
#include "merchant_api_common.h"
#include "merchant_api_curl_defaults.h"
+#include <stdio.h>
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
#include <taler/taler_exchange_service.h>
@@ -82,11 +83,6 @@ struct TALER_MERCHANT_OrderPayHandle
struct TALER_MERCHANT_PaidCoin *coins;
/**
- * The tokens we are using as inputs.
- */
- struct TALER_MERCHANT_UsedToken *tokens;
-
- /**
* Hash of the contract we are paying, set
* if @e am_wallet is true.
*/
@@ -121,11 +117,6 @@ struct TALER_MERCHANT_OrderPayHandle
unsigned int num_coins;
/**
- * Number of @e tokens we are using.
- */
- unsigned int num_tokens;
-
- /**
* Set to true if this is the wallet API and we have
* initialized @e h_contract_terms and @e merchant_pub.
*/
@@ -136,10 +127,14 @@ struct TALER_MERCHANT_OrderPayHandle
/**
* Parse blindly signed output tokens from response.
+ *
+ * @param token_sigs the JSON array with the token signatures. Can be NULL.
+ * @param tokens where to store the parsed tokens.
+ * @param num_tokens where to store the length of the @a tokens array.
*/
static enum GNUNET_GenericReturnValue
parse_tokens (const json_t *token_sigs,
- struct TALER_MERCHANT_PrivateTokenDetails **tokens,
+ struct TALER_MERCHANT_OutputToken **tokens,
unsigned int *num_tokens)
{
GNUNET_array_grow (*tokens,
@@ -148,22 +143,25 @@ parse_tokens (const json_t *token_sigs,
for (unsigned int i = 0; i<(*num_tokens); i++)
{
- struct TALER_MERCHANT_PrivateTokenDetails *token = &(*tokens)[i];
- const json_t *js = json_array_get (token_sigs,
+ struct TALER_MERCHANT_OutputToken *token = &(*tokens)[i];
+ const json_t *jtoken = json_array_get (token_sigs,
i);
- if (NULL == js)
+ if (NULL == jtoken)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_token_issue_sig ("blind_sig",
- &token->issue_sig),
+ TALER_JSON_spec_blinded_token_issue_sig ("blind_sig",
+ &token->blinded_sig),
+ GNUNET_JSON_spec_fixed_auto ("h_issue",
+ &token->h_issue),
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse (js,
+ GNUNET_JSON_parse (jtoken,
spec,
NULL, NULL))
{
@@ -172,7 +170,7 @@ parse_tokens (const json_t *token_sigs,
}
}
- return GNUNET_NO;
+ return GNUNET_YES;
}
@@ -196,6 +194,14 @@ handle_pay_finished (void *cls,
.hr.reply = json
};
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received /pay response with status code %u\n",
+ (unsigned int) response_code);
+
+ json_dumpf (json,
+ stderr,
+ JSON_INDENT (2));
+
oph->job = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"/pay completed with response code %u\n",
@@ -235,19 +241,16 @@ handle_pay_finished (void *cls,
break;
}
- if (NULL != token_sigs)
+ if (GNUNET_OK !=
+ parse_tokens (token_sigs,
+ &pr.details.ok.tokens,
+ &pr.details.ok.num_tokens))
{
- if (GNUNET_OK !=
- parse_tokens (token_sigs,
- &pr.details.ok.tokens,
- &pr.details.ok.num_tokens))
- {
- GNUNET_break_op (0);
- pr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- pr.hr.http_status = 0;
- pr.hr.hint = "failed to parse token_sigs field in response";
- break;
- }
+ GNUNET_break_op (0);
+ pr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ pr.hr.http_status = 0;
+ pr.hr.hint = "failed to parse token_sigs field in response";
+ break;
}
if (GNUNET_OK !=
@@ -381,6 +384,8 @@ 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],
TALER_MERCHANT_OrderPayCallback pay_cb,
void *pay_cb_cls)
{
@@ -388,6 +393,7 @@ 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;
@@ -496,6 +502,31 @@ 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),
@@ -503,12 +534,19 @@ 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_allow_null (
GNUNET_JSON_pack_object_incref ("wallet_data",
(json_t *) wallet_data)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("session_id",
session_id)));
+ json_dumpf (pay_obj,
+ stderr,
+ JSON_INDENT (2));
+
oph = GNUNET_new (struct TALER_MERCHANT_OrderPayHandle);
oph->ctx = ctx;
oph->pay_cb = pay_cb;
@@ -538,6 +576,8 @@ 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
+ can be unblinded in the callback. */
eh = TALER_MERCHANT_curl_easy_get_ (oph->url);
if (GNUNET_OK !=
@@ -582,6 +622,8 @@ TALER_MERCHANT_order_pay (
const struct TALER_MERCHANT_PayCoin coins[static num_coins],
unsigned int num_tokens,
const struct TALER_MERCHANT_UseToken tokens[static num_tokens],
+ unsigned int num_output_tokens,
+ const struct TALER_MERCHANT_OutputToken output_tokens[static num_output_tokens],
TALER_MERCHANT_OrderPayCallback pay_cb,
void *pay_cb_cls)
{
@@ -678,6 +720,8 @@ TALER_MERCHANT_order_pay (
pc,
num_tokens,
ut,
+ num_output_tokens,
+ output_tokens,
pay_cb,
pay_cb_cls);
if (NULL == oph)