summaryrefslogtreecommitdiff
path: root/src/lib/test_merchant_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/test_merchant_api.c')
-rw-r--r--src/lib/test_merchant_api.c193
1 files changed, 136 insertions, 57 deletions
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 162557c1..80f4fb8e 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -253,33 +253,6 @@ struct MeltDetails
/**
- * Information about a fresh coin generated by the refresh operation.
- */
-struct FreshCoin
-{
-
- /**
- * If @e amount is NULL, this specifies the denomination key to
- * use. Otherwise, this will be set (by the interpreter) to the
- * denomination PK matching @e amount.
- */
- const struct TALER_EXCHANGE_DenomPublicKey *pk;
-
- /**
- * Set (by the interpreter) to the exchange's signature over the
- * coin's public key.
- */
- struct TALER_DenominationSignature sig;
-
- /**
- * Set (by the interpreter) to the coin's private key.
- */
- struct TALER_CoinSpendPrivateKeyP coin_priv;
-
-};
-
-
-/**
* Details for a exchange operation to execute.
*/
struct Command
@@ -425,14 +398,9 @@ struct Command
struct TALER_DenominationSignature sig;
/**
- * Set (by the interpreter) to the coin's private key.
+ * Set (by the interpreter) to the planchet's secrets.
*/
- struct TALER_CoinSpendPrivateKeyP coin_priv;
-
- /**
- * Blinding key used for the operation.
- */
- struct TALER_DenominationBlindingKeyP blinding_key;
+ struct TALER_PlanchetSecretsP ps;
/**
* Withdraw handle (while operation is running).
@@ -806,15 +774,17 @@ struct Command
*/
struct TALER_MERCHANT_TipPickupOperation *tpo;
- /* FIXME: will need some other temporary data structure here
- to store the blinding keys while the pickup operation
- runs. */
+ /**
+ * Temporary data structure to store the blinding keys while the
+ * pickup operation runs.
+ */
+ struct TALER_PlanchetSecretsP *psa;
/**
* Set (by the interpreter) to an array of @a num_coins coins
* created from the (successful) tip operation.
*/
- struct FreshCoin *coins;
+ struct TALER_FreshCoin *coins;
/**
* EC expected for the operation.
@@ -1488,7 +1458,7 @@ refund_lookup_cb (void *cls,
GNUNET_assert (NULL != (icoin =
find_command (is,
icoin_ref)));
- GNUNET_CRYPTO_eddsa_key_get_public (&icoin->details.reserve_withdraw.coin_priv.eddsa_priv,
+ GNUNET_CRYPTO_eddsa_key_get_public (&icoin->details.reserve_withdraw.ps.coin_priv.eddsa_priv,
&icoin_pub.eddsa_pub);
GNUNET_CRYPTO_hash (&icoin_pub,
sizeof (struct TALER_CoinSpendPublicKeyP),
@@ -1829,6 +1799,83 @@ tip_authorize_cb (void *cls,
/**
+ * Create a planchet for tipping.
+ *
+ * @param keys the exchange's denominations
+ * @param amount the desired amount
+ * @param[out] pd blinded planchet (to be set)
+ * @param[out] ps secret details needed to extract the coin later (set)
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if @a amount is not in @a keys
+ */
+static int
+make_planchet (const struct TALER_EXCHANGE_Keys *keys,
+ const char *amount,
+ struct TALER_PlanchetDetail *pd,
+ struct TALER_PlanchetSecretsP *ps)
+{
+ struct TALER_Amount a;
+ const struct TALER_EXCHANGE_DenomPublicKey *dk;
+
+ if (GNUNET_OK !=
+ TALER_string_to_amount (amount,
+ &a))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ dk = NULL;
+ for (unsigned int i=0;i<keys->num_denom_keys;i++)
+ {
+ if (0 ==
+ TALER_amount_cmp (&a,
+ &keys->denom_keys[i].value))
+ {
+ dk = &keys->denom_keys[i];
+ break;
+ }
+ }
+ if (NULL == dk)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return TALER_planchet_prepare (&dk->key,
+ ps,
+ pd);
+}
+
+
+/**
+ * Callback for a /tip-pickup request. Returns the result of
+ * the operation.
+ *
+ * @param cls closure
+ * @param http_status HTTP status returned by the merchant backend, "200 OK" on success
+ * @param ec taler-specific error code
+ * @param reserve_pub public key of the reserve that made the @a reserve_sigs, NULL on error
+ * @param num_reserve_sigs length of the @a reserve_sigs array, 0 on error
+ * @param reserve_sigs array of signatures authorizing withdrawals, NULL on error
+ * @param json original json response
+ */
+static void
+pickup_cb (void *cls,
+ unsigned int http_status,
+ enum TALER_ErrorCode ec,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ unsigned int num_reserve_sigs,
+ const struct TALER_ReserveSignatureP *reserve_sigs,
+ const json_t *json)
+{
+ struct InterpreterState *is = cls;
+ struct Command *cmd = &is->commands[is->ip];
+
+ cmd->details.tip_pickup.tpo = NULL;
+ // FIXME: implement!
+ next_command (is);
+}
+
+
+/**
* Find denomination key matching the given amount.
*
* @param keys array of keys to search
@@ -2053,6 +2100,11 @@ cleanup_state (struct InterpreterState *is)
TALER_MERCHANT_tip_pickup_cancel (cmd->details.tip_pickup.tpo);
cmd->details.tip_pickup.tpo = NULL;
}
+ if (NULL != cmd->details.tip_pickup.psa)
+ {
+ GNUNET_free (cmd->details.tip_pickup.psa);
+ cmd->details.tip_pickup.psa = NULL;
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2079,7 +2131,6 @@ interpreter_run (void *cls)
struct Command *cmd = &is->commands[is->ip];
const struct Command *ref;
struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_Amount amount;
struct GNUNET_TIME_Absolute execution_date;
json_t *sender_details;
@@ -2268,27 +2319,14 @@ interpreter_run (void *cls)
GNUNET_assert (NULL != (cmd->details.reserve_withdraw.pk
= find_pk (is->keys,
&amount)));
- /* create coin's private key */
- {
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
-
- priv = GNUNET_CRYPTO_eddsa_key_create ();
- cmd->details.reserve_withdraw.coin_priv.eddsa_priv = *priv;
- GNUNET_free (priv);
- }
- GNUNET_CRYPTO_eddsa_key_get_public (&cmd->details.reserve_withdraw.coin_priv.eddsa_priv,
- &coin_pub.eddsa_pub);
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- &cmd->details.reserve_withdraw.blinding_key,
- sizeof (cmd->details.reserve_withdraw.blinding_key));
+ TALER_planchet_setup_random (&cmd->details.reserve_withdraw.ps);
cmd->details.reserve_withdraw.wsh
= TALER_EXCHANGE_reserve_withdraw
(exchange,
cmd->details.reserve_withdraw.pk,
&ref->details.admin_add_incoming.reserve_priv,
- &cmd->details.reserve_withdraw.coin_priv,
- &cmd->details.reserve_withdraw.blinding_key,
+ &cmd->details.reserve_withdraw.ps,
&reserve_withdraw_cb,
is);
if (NULL == cmd->details.reserve_withdraw.wsh)
@@ -2404,7 +2442,7 @@ interpreter_run (void *cls)
switch (coin_ref->oc)
{
case OC_WITHDRAW_SIGN:
- icoin->coin_priv = coin_ref->details.reserve_withdraw.coin_priv;
+ icoin->coin_priv = coin_ref->details.reserve_withdraw.ps.coin_priv;
icoin->denom_pub = coin_ref->details.reserve_withdraw.pk->key;
icoin->denom_sig = coin_ref->details.reserve_withdraw.sig;
icoin->denom_value = coin_ref->details.reserve_withdraw.pk->value;
@@ -2587,7 +2625,8 @@ interpreter_run (void *cls)
{
struct TALER_Amount refund_amount;
- GNUNET_assert (GNUNET_OK == TALER_string_to_amount
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount
(cmd->details.refund_increase.refund_amount,
&refund_amount));
if (NULL == (cmd->details.refund_increase.rio
@@ -2633,6 +2672,7 @@ interpreter_run (void *cls)
ref = find_command (is,
cmd->details.tip_enable.admin_add_incoming_ref);
GNUNET_assert (NULL != ref);
+ GNUNET_assert (OC_ADMIN_ADD_INCOMING == ref->oc);
}
else
{
@@ -2717,6 +2757,45 @@ interpreter_run (void *cls)
}
break;
}
+ case OC_TIP_PICKUP:
+ {
+ unsigned int num_planchets = cmd->details.tip_pickup.num_coins;
+ struct TALER_PlanchetDetail planchets[num_planchets];
+
+ ref = find_command (is,
+ cmd->details.tip_pickup.authorize_ref);
+ GNUNET_assert (NULL != ref);
+ GNUNET_assert (OC_TIP_AUTHORIZE == ref->oc);
+ cmd->details.tip_pickup.psa = GNUNET_new_array (num_planchets,
+ struct TALER_PlanchetSecretsP);
+
+ for (unsigned int i=0;i<num_planchets;i++)
+ if (GNUNET_OK !=
+ make_planchet (is->keys,
+ cmd->details.tip_pickup.amounts[i],
+ &planchets[i],
+ &cmd->details.tip_pickup.psa[i]))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+
+ if (NULL == (cmd->details.tip_pickup.tpo
+ = TALER_MERCHANT_tip_pickup
+ (ctx,
+ MERCHANT_URI,
+ &ref->details.tip_authorize.tip_id,
+ num_planchets,
+ planchets,
+ &pickup_cb,
+ is)))
+ {
+ GNUNET_break (0);
+ fail (is);
+ }
+ break;
+ }
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",