aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-07-05 14:32:26 +0200
committerChristian Grothoff <christian@grothoff.org>2015-07-05 14:32:26 +0200
commitf623214c1292b93fa8672361dfa978a506f4bef3 (patch)
tree702954d01103167aa6fd3d3d499c81134a815eea
parentac8420a66140aa850b1573a3503ed3a7f3cc974c (diff)
downloadexchange-f623214c1292b93fa8672361dfa978a506f4bef3.tar.gz
exchange-f623214c1292b93fa8672361dfa978a506f4bef3.tar.bz2
exchange-f623214c1292b93fa8672361dfa978a506f4bef3.zip
minor bugfixes, towards /deposit in test interpreter
-rw-r--r--src/mint-lib/mint_api_deposit.c4
-rw-r--r--src/mint-lib/mint_api_withdraw.c7
-rw-r--r--src/mint-lib/test_mint_api.c121
3 files changed, 121 insertions, 11 deletions
diff --git a/src/mint-lib/mint_api_deposit.c b/src/mint-lib/mint_api_deposit.c
index 671e2a9dc..3c6939668 100644
--- a/src/mint-lib/mint_api_deposit.c
+++ b/src/mint-lib/mint_api_deposit.c
@@ -672,6 +672,10 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint,
dh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 1LL));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
dh->json_enc));
GNUNET_assert (CURLE_OK ==
diff --git a/src/mint-lib/mint_api_withdraw.c b/src/mint-lib/mint_api_withdraw.c
index 91734611c..157d2db72 100644
--- a/src/mint-lib/mint_api_withdraw.c
+++ b/src/mint-lib/mint_api_withdraw.c
@@ -811,9 +811,6 @@ handle_withdraw_sign_finished (void *cls,
GNUNET_break (0);
response_code = 0;
}
- fprintf (stderr,
- "Response code: %u\n",
- (unsigned int) response_code);
if ( (0 == wsh->eno) &&
(0 != response_code) )
{
@@ -1039,10 +1036,6 @@ TALER_MINT_withdraw_sign (struct TALER_MINT_Handle *mint,
wsh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
- CURLOPT_VERBOSE,
- 1LL));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
wsh->json_enc));
GNUNET_assert (CURLE_OK ==
diff --git a/src/mint-lib/test_mint_api.c b/src/mint-lib/test_mint_api.c
index 6fca26ccc..c59d4a03b 100644
--- a/src/mint-lib/test_mint_api.c
+++ b/src/mint-lib/test_mint_api.c
@@ -222,7 +222,7 @@ struct Command
* Set (by the interpreter) to a fresh private key of the merchant,
* if @e refund_deadline is non-zero.
*/
- struct TALER_MerchantPublicKeyP merchant_priv;
+ struct TALER_MerchantPrivateKeyP merchant_priv;
/**
* Deposit handle while operation is running.
@@ -407,6 +407,37 @@ withdraw_sign_cb (void *cls,
/**
+ * Function called with the result of a /deposit operation.
+ *
+ * @param cls closure with the interpreter state
+ * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit;
+ * 0 if the mint's reply is bogus (fails to follow the protocol)
+ * @param obj the received JSON reply, should be kept as proof (and, in case of errors,
+ * be forwarded to the customer)
+ */
+static void
+deposit_cb (void *cls,
+ unsigned int http_status,
+ json_t *obj)
+{
+ struct InterpreterState *is = cls;
+ struct Command *cmd = &is->commands[is->ip];
+
+ cmd->details.deposit.dh = NULL;
+ if (MHD_HTTP_OK != http_status)
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ is->ip++;
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
+ is);
+
+}
+
+
+/**
* Find denomination key matching the given amount.
*
* @param keys array of keys to search
@@ -601,9 +632,91 @@ interpreter_run (void *cls,
trigger_context_task ();
return;
case OC_DEPOSIT:
- GNUNET_break (0); // to be implemented!
- is->ip++;
- break;
+ {
+ struct GNUNET_HashCode h_contract;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct GNUNET_TIME_Absolute refund_deadline;
+ struct GNUNET_TIME_Absolute timestamp;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ json_t *wire;
+
+ GNUNET_assert (NULL !=
+ cmd->details.deposit.coin_ref);
+ ref = find_command (is,
+ cmd->details.deposit.coin_ref);
+ GNUNET_assert (NULL != ref);
+ GNUNET_assert (OC_WITHDRAW_SIGN == ref->oc);
+ if (GNUNET_OK !=
+ TALER_string_to_amount (cmd->details.deposit.amount,
+ &amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %u\n",
+ cmd->details.deposit.amount,
+ is->ip);
+ fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_hash (cmd->details.deposit.contract,
+ strlen (cmd->details.deposit.contract),
+ &h_contract);
+ wire = json_loads (cmd->details.deposit.wire_details,
+ JSON_REJECT_DUPLICATES,
+ NULL);
+ if (NULL == wire)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse wire details `%s' at %u\n",
+ cmd->details.deposit.wire_details,
+ is->ip);
+ fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&ref->details.withdraw_sign.coin_priv.eddsa_priv,
+ &coin_pub.eddsa_pub);
+
+ if (0 != cmd->details.deposit.refund_deadline.rel_value_us)
+ {
+ struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
+
+ priv = GNUNET_CRYPTO_eddsa_key_create ();
+ cmd->details.deposit.merchant_priv.eddsa_priv = *priv;
+ GNUNET_free (priv);
+ refund_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.deposit.refund_deadline);
+ }
+ else
+ {
+ refund_deadline = GNUNET_TIME_UNIT_ZERO_ABS;
+ }
+ timestamp = GNUNET_TIME_absolute_get ();
+
+ /* FIXME: init "coin_sig" here! */
+
+ cmd->details.deposit.dh
+ = TALER_MINT_deposit (mint,
+ &amount,
+ wire,
+ &h_contract,
+ &coin_pub,
+ &ref->details.withdraw_sign.sig,
+ &ref->details.withdraw_sign.pk->key,
+ timestamp,
+ cmd->details.deposit.transaction_id,
+ &merchant_pub,
+ refund_deadline,
+ &coin_sig,
+ &deposit_cb,
+ is);
+ if (NULL == cmd->details.deposit.dh)
+ {
+ GNUNET_break (0);
+ json_decref (wire);
+ fail (is);
+ return;
+ }
+ return;
+ }
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",