aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-11-20 13:32:02 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-11-20 13:32:02 +0100
commit793c57317a90ec936a0649c79211ca34215c38fc (patch)
treea1f2580d0b37d1eb231a5538fe282a271aca3cd7
parentd3f73936ae5b5797531db8fe5e6b82cdd1e01ce3 (diff)
Offer contract terms trait as a JSON object.
-rw-r--r--src/auditor-lib/testing_auditor_api_cmd_deposit_confirmation.c7
-rw-r--r--src/exchange-lib/testing_api_cmd_deposit.c34
-rw-r--r--src/exchange-lib/testing_api_cmd_refund.c12
-rw-r--r--src/exchange-lib/testing_api_cmd_track.c11
-rw-r--r--src/exchange-lib/testing_api_trait_string.c4
-rw-r--r--src/include/taler_testing_lib.h4
6 files changed, 28 insertions, 44 deletions
diff --git a/src/auditor-lib/testing_auditor_api_cmd_deposit_confirmation.c b/src/auditor-lib/testing_auditor_api_cmd_deposit_confirmation.c
index 9a5c0bfb2..6a6e98571 100644
--- a/src/auditor-lib/testing_auditor_api_cmd_deposit_confirmation.c
+++ b/src/auditor-lib/testing_auditor_api_cmd_deposit_confirmation.c
@@ -206,7 +206,6 @@ deposit_confirmation_run (void *cls,
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
const struct TALER_EXCHANGE_Keys *keys;
const struct TALER_EXCHANGE_SigningPublicKey *spk;
- const char *contract_terms_s;
dcs->is = is;
GNUNET_assert (NULL != dcs->deposit_reference);
@@ -236,15 +235,11 @@ deposit_confirmation_run (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_contract_terms (deposit_cmd,
dcs->coin_index,
- &contract_terms_s));
- contract_terms = json_loads (contract_terms_s,
- JSON_REJECT_DUPLICATES,
- NULL);
+ &contract_terms));
/* Very unlikely to fail */
GNUNET_assert (NULL != contract_terms);
TALER_JSON_hash (contract_terms,
&h_contract_terms);
- json_decref (contract_terms);
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_wire_details (deposit_cmd,
dcs->coin_index,
diff --git a/src/exchange-lib/testing_api_cmd_deposit.c b/src/exchange-lib/testing_api_cmd_deposit.c
index c6c3c4330..18d409e23 100644
--- a/src/exchange-lib/testing_api_cmd_deposit.c
+++ b/src/exchange-lib/testing_api_cmd_deposit.c
@@ -63,7 +63,7 @@ struct DepositState
/**
* JSON string describing what a proposal is about.
*/
- const char *contract_terms;
+ json_t *contract_terms;
/**
* Relative time (to add to 'now') to compute the refund
@@ -257,7 +257,6 @@ deposit_run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv;
struct TALER_MerchantPublicKeyP merchant_pub;
struct GNUNET_HashCode h_contract_terms;
- json_t *contract_terms;
struct TALER_Amount amount;
ds->is = is;
@@ -302,21 +301,11 @@ deposit_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- contract_terms = json_loads (ds->contract_terms,
- JSON_REJECT_DUPLICATES,
- NULL);
- if (NULL == contract_terms)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse proposal data `%s' at %u/%s\n",
- ds->contract_terms, is->ip, this_cmd->label);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
+
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_hash (contract_terms,
+ TALER_JSON_hash (ds->contract_terms,
&h_contract_terms));
- json_decref (contract_terms);
+
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
@@ -427,6 +416,7 @@ deposit_cleanup (void *cls,
ds->retry_task = NULL;
}
json_decref (ds->wire_details);
+ json_decref (ds->contract_terms);
GNUNET_free (ds);
}
@@ -545,7 +535,19 @@ TALER_TESTING_cmd_deposit
ds->coin_reference = coin_reference;
ds->coin_index = coin_index;
ds->wire_details = wire_details;
- ds->contract_terms = contract_terms;
+ ds->contract_terms = json_loads (contract_terms,
+ JSON_REJECT_DUPLICATES,
+ NULL);
+ if (NULL == ds->contract_terms)
+ {
+ GNUNET_log
+ (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse contract terms `%s' for CMD `%s'\n",
+ contract_terms,
+ label);
+ GNUNET_assert (0);
+ }
+
ds->refund_deadline = refund_deadline;
ds->amount = amount;
ds->expected_response_code = expected_response_code;
diff --git a/src/exchange-lib/testing_api_cmd_refund.c b/src/exchange-lib/testing_api_cmd_refund.c
index de70da27b..3298d6ab0 100644
--- a/src/exchange-lib/testing_api_cmd_refund.c
+++ b/src/exchange-lib/testing_api_cmd_refund.c
@@ -145,9 +145,8 @@ refund_run (void *cls,
struct RefundState *rs = cls;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
struct TALER_CoinSpendPublicKeyP coin;
- const char *contract_terms;
+ const json_t *contract_terms;
struct GNUNET_HashCode h_contract_terms;
- json_t *j_contract_terms;
struct TALER_Amount refund_fee;
struct TALER_Amount refund_amount;
const struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv;
@@ -199,17 +198,10 @@ refund_run (void *cls,
return;
}
- j_contract_terms = json_loads
- (contract_terms, JSON_REJECT_DUPLICATES, NULL);
-
- /* Very unlikely to fail */
- GNUNET_assert (NULL != j_contract_terms);
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_hash (j_contract_terms,
+ TALER_JSON_hash (contract_terms,
&h_contract_terms));
- json_decref (j_contract_terms);
-
/* Hunting for a coin .. */
if (GNUNET_OK != TALER_TESTING_get_trait_coin_priv
(coin_cmd, 0, &coin_priv))
diff --git a/src/exchange-lib/testing_api_cmd_track.c b/src/exchange-lib/testing_api_cmd_track.c
index 6c9d9fd55..535d5e55e 100644
--- a/src/exchange-lib/testing_api_cmd_track.c
+++ b/src/exchange-lib/testing_api_cmd_track.c
@@ -269,9 +269,8 @@ track_transaction_run (void *cls,
const struct TALER_TESTING_Command *transaction_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
struct TALER_CoinSpendPublicKeyP coin_pub;
- const char *contract_terms;
+ const json_t *contract_terms;
const json_t *wire_details;
- json_t *j_contract_terms;
struct GNUNET_HashCode h_wire_details;
struct GNUNET_HashCode h_contract_terms;
const struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv;
@@ -315,11 +314,7 @@ track_transaction_run (void *cls,
return;
}
- /* Parse them.. */
- j_contract_terms = json_loads
- (contract_terms, JSON_REJECT_DUPLICATES, NULL);
-
- if ((NULL == wire_details) || (NULL == j_contract_terms))
+ if ((NULL == wire_details) || (NULL == contract_terms))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (tts->is);
@@ -332,7 +327,7 @@ track_transaction_run (void *cls,
TALER_JSON_merchant_wire_signature_hash (wire_details,
&h_wire_details)) &&
(GNUNET_OK ==
- TALER_JSON_hash (j_contract_terms,
+ TALER_JSON_hash (contract_terms,
&h_contract_terms)) );
if (GNUNET_OK != TALER_TESTING_get_trait_peer_key
diff --git a/src/exchange-lib/testing_api_trait_string.c b/src/exchange-lib/testing_api_trait_string.c
index d26f2e046..8b8f511a7 100644
--- a/src/exchange-lib/testing_api_trait_string.c
+++ b/src/exchange-lib/testing_api_trait_string.c
@@ -49,7 +49,7 @@ int
TALER_TESTING_get_trait_contract_terms
(const struct TALER_TESTING_Command *cmd,
unsigned int index,
- const char **contract_terms)
+ const json_t **contract_terms)
{
return cmd->traits (cmd->cls,
(const void **) contract_terms,
@@ -67,7 +67,7 @@ TALER_TESTING_get_trait_contract_terms
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_contract_terms
(unsigned int index,
- const char *contract_terms)
+ const json_t *contract_terms)
{
struct TALER_TESTING_Trait ret = {
.index = index,
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 0b3ba31f9..bf3191432 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1880,7 +1880,7 @@ int
TALER_TESTING_get_trait_contract_terms
(const struct TALER_TESTING_Command *cmd,
unsigned int index,
- const char **contract_terms);
+ const json_t **contract_terms);
/**
@@ -1893,7 +1893,7 @@ TALER_TESTING_get_trait_contract_terms
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_contract_terms
(unsigned int index,
- const char *contract_terms);
+ const json_t *contract_terms);
/**