From f623214c1292b93fa8672361dfa978a506f4bef3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Jul 2015 14:32:26 +0200 Subject: minor bugfixes, towards /deposit in test interpreter --- src/mint-lib/mint_api_deposit.c | 4 ++ src/mint-lib/mint_api_withdraw.c | 7 --- src/mint-lib/test_mint_api.c | 121 +++++++++++++++++++++++++++++++++++++-- 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 @@ -670,6 +670,10 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint, curl_easy_setopt (eh, CURLOPT_URL, dh->url)); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_VERBOSE, + 1LL)); GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_POSTFIELDS, 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) ) { @@ -1037,10 +1034,6 @@ TALER_MINT_withdraw_sign (struct TALER_MINT_Handle *mint, curl_easy_setopt (eh, CURLOPT_URL, wsh->url)); - GNUNET_assert (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_VERBOSE, - 1LL)); GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_POSTFIELDS, 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. @@ -406,6 +406,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. * @@ -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", -- cgit v1.2.3