aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend-lib/taler-merchant-httpd_contract.c2
-rw-r--r--src/backend/taler-merchant-httpd.c87
-rw-r--r--src/tests/merchant-contract-test.c8
3 files changed, 71 insertions, 26 deletions
diff --git a/src/backend-lib/taler-merchant-httpd_contract.c b/src/backend-lib/taler-merchant-httpd_contract.c
index 61315653..0a6ed0de 100644
--- a/src/backend-lib/taler-merchant-httpd_contract.c
+++ b/src/backend-lib/taler-merchant-httpd_contract.c
@@ -116,7 +116,7 @@ MERCHANT_handle_contract (json_t *j_contract,
/* needed for DB stuff */
TALER_json_to_amount (j_amount, &amount);
/* temporary way of getting this value. To be adapted to the expanded contract
- format. See 'TODO' above. */
+ format. (This value is now supplied in the 'item' object!!) See 'TODO' above. */
product_id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
/* adding the generated values in this JSON */
root = json_pack ("{s:o, s:I, s:s, s:o, s:o}",
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 05ab51b4..5c17274a 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -129,6 +129,17 @@ struct Mint
*/
static struct GNUNET_CONTAINER_MultiPeerMap *mints_map;
+/**
+ * Mints' URL,port,key triples
+ */
+struct MERCHANT_MintInfo *mint_infos;
+
+/**
+ * The number of accepted mints
+ */
+unsigned int nmints;
+
+
#if FUTURE_USE
/**
* Return the given message to the other end of connection
@@ -334,6 +345,15 @@ url_handler (void *cls,
json_t *j_sig_enc;
json_t *eddsa_pub_enc;
json_t *response;
+ json_t *j_mints;
+ json_t *j_mint;
+ int cnt; /* loop counter */
+ #if 0
+ json_t *root_tmp;
+ json_t *j_amount_tmp;
+ json_t *j_details_tmp;
+ json_int_t *j_trans_id_tmp;
+ #endif
int res = GNUNET_SYSERR;
@@ -386,6 +406,33 @@ url_handler (void *cls,
/* The frontend should supply a JSON in the format described in
http://link-to-specs : */
+ /* TODO Specifying the accepted mints, in the contract */
+ j_mints = json_array ();
+ for (cnt = 0; cnt < nmints; cnt++)
+ {
+ j_mint = json_pack ("{s:s}",
+ mint_infos[cnt].hostname,
+ GNUNET_CRYPTO_eddsa_public_key_to_string (&mint_infos[cnt].pubkey));
+ json_array_append_new (j_mints, j_mint);
+ #ifdef DEBUG
+ printf ("mint(s): url %s, key %s", mint_infos[cnt].hostname,
+ GNUNET_CRYPTO_eddsa_public_key_to_string (&mint_infos[cnt].pubkey));
+ #endif
+
+ }
+
+ json_object_set (root, "mints", j_mints);
+
+ TMH_RESPONSE_reply_json (connection, root, MHD_HTTP_OK);
+ return MHD_YES;
+
+ #if 0
+ root_tmp = json_unpack ("{s:o, s:I, s:o}",
+ "amount", &j_amount_tmp,
+ "trans_id", &j_trans_id_tmp,
+ "details", &j_details_tmp);
+ #endif
+
if (NULL == (j_contract_complete = MERCHANT_handle_contract (root,
db_conn,
wire,
@@ -505,9 +552,7 @@ run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
- unsigned int nmints;
unsigned int cnt;
- struct MERCHANT_MintInfo *mint_infos;
void *keys_mgmt_cls;
keys_mgmt_cls = NULL;
@@ -541,26 +586,26 @@ run (void *cls, char *const *args, const char *cfgfile,
EXITIF (NULL == (mints_map = GNUNET_CONTAINER_multipeermap_create (nmints, GNUNET_YES)));
for (cnt = 0; cnt < nmints; cnt++)
- {
- struct Mint *mint;
+ {
+ struct Mint *mint;
- mint = GNUNET_new (struct Mint);
- mint->pubkey = mint_infos[cnt].pubkey;
- /* port this to the new API */
- mint->conn = TALER_MINT_connect (mctx,
- mint_infos[cnt].hostname,
- &keys_mgmt_cb,
- keys_mgmt_cls); /*<- safe?segfault friendly?*/
-
- /* NOTE: the keys mgmt callback should roughly do what the following lines do */
- EXITIF (NULL == mint->conn);
-
- EXITIF (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put
- (mints_map,
- (struct GNUNET_PeerIdentity *) /* to retrieve now from cb's args -> */&mint->pubkey,
- mint,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- }
+ mint = GNUNET_new (struct Mint);
+ mint->pubkey = mint_infos[cnt].pubkey;
+ /* port this to the new API */
+ mint->conn = TALER_MINT_connect (mctx,
+ mint_infos[cnt].hostname,
+ &keys_mgmt_cb,
+ keys_mgmt_cls); /*<- safe?segfault friendly?*/
+
+ /* NOTE: the keys mgmt callback should roughly do what the following lines do */
+ EXITIF (NULL == mint->conn);
+
+ EXITIF (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put
+ (mints_map,
+ (struct GNUNET_PeerIdentity *) /* to retrieve now from cb's args -> */&mint->pubkey,
+ mint,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ }
mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY,
diff --git a/src/tests/merchant-contract-test.c b/src/tests/merchant-contract-test.c
index e382b88c..2a68bb48 100644
--- a/src/tests/merchant-contract-test.c
+++ b/src/tests/merchant-contract-test.c
@@ -78,6 +78,7 @@ run (void *cls, char *const *args, const char *cfgfile,
json_t *j_amount;
json_t *j_tax_amount;
json_t *j_item_price;
+ json_t *j_max_fee;
json_t *j_teatax;
json_t *j_id; // trans id
json_t *j_pid; // product id
@@ -163,6 +164,7 @@ run (void *cls, char *const *args, const char *cfgfile,
/* Description */
desc = "Fake purchase";
+ j_max_fee = TALER_json_from_amount (&amount);
/* Quantity: OPTIONAL FIELD */
j_quantity = json_integer (3);
@@ -182,8 +184,9 @@ run (void *cls, char *const *args, const char *cfgfile,
j_teatax = json_pack ("{s:o}",
"teatax", j_tax_amount);
- if (NULL == (j_item = json_pack ("{s:s, s:I, s:o, s:I, s:[o]}",
+ if (NULL == (j_item = json_pack ("{s:s, s:o, s:I, s:o, s:I, s:[o]}",
"description", desc,
+ "max fee", j_max_fee,
"quantity", json_integer_value (j_quantity),
"itemprice", j_item_price,
"product_id", json_integer_value (j_pid),
@@ -244,9 +247,6 @@ run (void *cls, char *const *args, const char *cfgfile,
"trans_id", json_integer_value (j_id),
"details", j_details);
-
-
-
j_root = MERCHANT_handle_contract (j_fake_contract,
db_conn,
wire,