diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-04-21 12:22:39 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-04-21 12:22:39 +0200 |
commit | be9027b172388cf0ccd89c1b1b6b57252b55bdd9 (patch) | |
tree | 29abc746140ae4befd5b7a5eb46b4951b79848f8 | |
parent | 602693bed8dc22c2477692a9e844b26b5476829b (diff) |
fix serialized json format of choices
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index e959b221..5473dec4 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1752,25 +1752,20 @@ serialize_order (struct OrderContext *oc) { struct TALER_MerchantContractInput *input = &choice->inputs[j]; + /* For now, only tokens are supported */ + GNUNET_assert (TALER_MCIT_TOKEN == input->type); + json_t *jinput = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_int64 ("type", - input->type) + GNUNET_JSON_pack_string ("kind", + TMH_string_from_contract_input_type (input->type)), + GNUNET_JSON_pack_string ("token_family_slug", + input->details.token.token_family_slug), + GNUNET_JSON_pack_int64 ("number", + input->details.token.count), + GNUNET_JSON_pack_timestamp ("valid_after", + input->details.token.valid_after) ); - if (TALER_MCIT_TOKEN == input->type) - { - GNUNET_assert(0 == - json_object_set_new(jinput, - "number", - json_integer ( - input->details.token.count))); - GNUNET_assert(0 == - json_object_set_new(jinput, - "token_family_slug", - json_string ( - input->details.token.token_family_slug))); - } - GNUNET_assert (0 == json_array_append_new (inputs, jinput)); } @@ -1778,26 +1773,20 @@ serialize_order (struct OrderContext *oc) { struct TALER_MerchantContractOutput *output = &choice->outputs[j]; + /* For now, only tokens are supported */ + GNUNET_assert (TALER_MCOT_TOKEN == output->type); + json_t *joutput = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_int64 ("type", - output->type) + GNUNET_JSON_pack_string ("kind", + TMH_string_from_contract_output_type (output->type)), + GNUNET_JSON_pack_string ("token_family_slug", + output->details.token.token_family_slug), + GNUNET_JSON_pack_int64 ("number", + output->details.token.count), + GNUNET_JSON_pack_timestamp ("valid_after", + output->details.token.valid_after) ); - if (TALER_MCOT_TOKEN == output->type) - { - GNUNET_assert(0 == - json_object_set_new(joutput, - "number", - json_integer ( - output->details.token.count))); - - GNUNET_assert(0 == - json_object_set_new(joutput, - "token_family_slug", - json_string ( - output->details.token.token_family_slug))); - } - GNUNET_assert (0 == json_array_append (outputs, joutput)); } @@ -2512,27 +2501,12 @@ parse_choices (struct OrderContext *oc) return; } - if (! json_is_array (jinputs) || - ! json_is_array (joutputs)) - { - GNUNET_break_op (0); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "inputs or outputs"); - return; - } - { // TODO: Maybe move to a separate function const json_t *jinput; size_t idx; json_array_foreach ((json_t *) jinputs, idx, jinput) { - // TODO: Assuming this struct would have more fields, would i use GNUNET_new then? - // Or should i use GNUNET_grow first and then get the element using the index? - // Assuming you add a field in the future, it's easier to that way, so you don't - // free it. struct TALER_MerchantContractInput input = {.details.token.count = 1}; const char *kind; const char *ierror_name; @@ -2569,7 +2543,7 @@ parse_choices (struct OrderContext *oc) return; } - input.type = TMH_string_to_contract_input_type (kind); + input.type = TMH_contract_input_type_from_string (kind); if (TALER_MCIT_INVALID == input.type) { @@ -2646,7 +2620,7 @@ parse_choices (struct OrderContext *oc) return; } - output.type = TMH_string_to_contract_output_type (kind); + output.type = TMH_contract_output_type_from_string (kind); if (TALER_MCOT_INVALID == output.type) { |