donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 7fd7414a5849f792a9bd8edf3ef80f2a7272bcd4
parent 51a70e09bfb0a28dae8790e07465daead69170d1
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Fri, 11 Apr 2025 10:51:12 +0200

making DONAU_keys_to_json and DONAU_keys_from_json inverse functions

Diffstat:
Msrc/lib/donau_api_handle.c | 104++++++++++++++++++-------------------------------------------------------------
1 file changed, 23 insertions(+), 81 deletions(-)

diff --git a/src/lib/donau_api_handle.c b/src/lib/donau_api_handle.c @@ -711,13 +711,11 @@ add_grp (void *cls, json_t * DONAU_keys_to_json (const struct DONAU_Keys *kd) { + // --- Create the array of signkeys (unchanged) --- + json_t *signkeys = json_array (); json_t *keys; - json_t *signkeys; - json_t *donation_units_by_group; - - signkeys = json_array (); GNUNET_assert (NULL != signkeys); - for (unsigned int i = 0; i<kd->num_sign_keys; i++) + for (unsigned int i = 0; i < kd->num_sign_keys; i++) { const struct DONAU_SigningPublicKeyAndValidity *sk = &kd->sign_keys[i]; json_t *signkey; @@ -735,89 +733,33 @@ DONAU_keys_to_json (const struct DONAU_Keys *kd) signkey)); } - donation_units_by_group = json_array (); - GNUNET_assert (NULL != donation_units_by_group); + // --- Create the array of donation_units --- + json_t *donation_units = json_array (); + GNUNET_assert (NULL != donation_units); + for (unsigned int i = 0; i < kd->num_donation_unit_keys; i++) { - struct GNUNET_CONTAINER_MultiHashMap *dbg; + const struct DONAU_DonationUnitInformation *du = &kd->donation_unit_keys[i]; + + // Build the JSON for one donation unit + json_t *donation_unit_obj = GNUNET_JSON_PACK ( + DONAU_JSON_pack_donation_unit_pub ("donation_unit_pub", &du->key), + GNUNET_JSON_pack_uint64 ("year", du->year), + GNUNET_JSON_pack_bool ("lost", du->lost), + TALER_JSON_pack_amount ("value", &du->value) + ); - dbg = GNUNET_CONTAINER_multihashmap_create (128, - false); - for (unsigned int i = 0; i<kd->num_donation_unit_keys; i++) - { - const struct DONAU_DonationUnitInformation *dk = - &kd->donation_unit_keys[i]; - struct DONAU_DonationUnitGroup meta = { - .cipher = dk->key.bsign_pub_key->cipher, - .value = dk->value - }; - struct GNUNET_HashCode key; - struct GroupData *gd; - json_t *donation_unit; - struct GNUNET_JSON_PackSpec key_spec; - - // get hash of meta data - DONAU_donation_unit_group_get_key (&meta, - &key); - gd = GNUNET_CONTAINER_multihashmap_get (dbg, - &key); - - // If group (differentiated in value and cipher) does not exist - // add a new one to the map. - if (NULL == gd) - { - gd = GNUNET_new (struct GroupData); - gd->meta = meta; - gd->json = json_array (); - GNUNET_assert (NULL != gd->json); - GNUNET_assert ( - GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (dbg, - &key, - gd, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - - } - - switch (meta.cipher) - { - case GNUNET_CRYPTO_BSA_RSA: - key_spec = - GNUNET_JSON_pack_rsa_public_key ( - "rsa_pub", - dk->key.bsign_pub_key->details.rsa_public_key); - break; - case GNUNET_CRYPTO_BSA_CS: - key_spec = - GNUNET_JSON_pack_data_varsize ( - "cs_pub", - &dk->key.bsign_pub_key->details.cs_public_key, - sizeof (dk->key.bsign_pub_key->details.cs_public_key)); - break; - default: - GNUNET_assert (false); - } - donation_unit = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_uint64 ("year", - dk->year), - key_spec - ); - // add entry into the donation unit group - GNUNET_assert (0 == - json_array_append_new (gd->json, - donation_unit)); - } - // every donation unit group of the map is added to the array donation_units_by_group - GNUNET_CONTAINER_multihashmap_iterate (dbg, - &add_grp, - donation_units_by_group); - GNUNET_CONTAINER_multihashmap_destroy (dbg); + GNUNET_assert (NULL != donation_unit_obj); + GNUNET_assert (0 == + json_array_append_new (donation_units, + donation_unit_obj)); } json_t *currency_spec = NULL; if (NULL != kd->currency_specification.name) { currency_spec = TALER_CONFIG_currency_specs_to_json ( - &kd->currency_specification); + &kd->currency_specification + ); } keys = GNUNET_JSON_PACK ( @@ -828,7 +770,7 @@ DONAU_keys_to_json (const struct DONAU_Keys *kd) GNUNET_JSON_pack_array_steal ("signkeys", signkeys), GNUNET_JSON_pack_array_steal ("donation_units", - donation_units_by_group) + donation_units) ); if (NULL != currency_spec)