merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 2458b8452a5e28518481af5dd44f8d7ea7878709
parent d1881c09978a43fc9da9e6f9041e8f1d31e4fa98
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Wed, 16 Jul 2025 21:41:53 +0200

Merge branch 'master' into dev/bohdan-potuzhnyi/donau-integration

Diffstat:
Msrc/backend/taler-merchant-httpd_private-get-instances-ID-tokens.c | 8++------
Msrc/backenddb/pg_lookup_statistics_amount_by_interval.c | 104++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
Msrc/backenddb/pg_lookup_statistics_counter_by_interval.c | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
3 files changed, 159 insertions(+), 44 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID-tokens.c b/src/backend/taler-merchant-httpd_private-get-instances-ID-tokens.c @@ -56,7 +56,7 @@ add_token (void *cls, GNUNET_JSON_PACK ( GNUNET_JSON_pack_timestamp ("creation_time", creation_time), - GNUNET_JSON_pack_timestamp ("expiration_time", + GNUNET_JSON_pack_timestamp ("expiration", expiration_time), GNUNET_JSON_pack_string ("scope", as), @@ -77,16 +77,12 @@ TMH_private_get_instances_ID_tokens (const struct TMH_RequestHandler *rh, json_t *ta; enum GNUNET_DB_QueryStatus qs; int64_t limit; - uint64_t offset; + uint64_t offset = 0; limit = -20; /* default */ TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) - offset = INT64_MAX; - else - offset = 0; TALER_MHD_parse_request_number (connection, "offset", &offset); diff --git a/src/backenddb/pg_lookup_statistics_amount_by_interval.c b/src/backenddb/pg_lookup_statistics_amount_by_interval.c @@ -46,12 +46,57 @@ struct LookupAmountStatisticsContext * Did database result extraction fail? */ bool extract_failed; + + /** + * Description of statistic + */ + char*description; }; +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_amount_by_interval_desc_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupAmountStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + tflc->description = GNUNET_strdup (description); + + GNUNET_PQ_cleanup_result (rs); + } +} + /** * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. + * that has returned @a num_results results about statistics. * * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` * @param result the postgres result @@ -65,23 +110,16 @@ lookup_statistics_amount_by_interval_cb (void *cls, struct LookupAmountStatisticsContext *tflc = cls; struct TALER_Amount *amounts = NULL; char *resp_desc = NULL; - uint64_t cur_interval_start_epoch; - uint64_t bmeta_id_current; + uint64_t cur_interval_start_ago; unsigned int amounts_len = 0; for (unsigned int i = 0; i < num_results; i++) { - char *description; struct TALER_Amount cumulative_amount; - uint64_t interval_start_epoch; - uint64_t bmeta_id; + uint64_t interval_start_ago; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bmeta_serial_id", - &bmeta_id), - GNUNET_PQ_result_spec_string ("description", - &description), GNUNET_PQ_result_spec_uint64 ("range", - &interval_start_epoch), + &interval_start_ago), TALER_PQ_result_spec_amount_with_currency ("rvalue", &cumulative_amount), GNUNET_PQ_result_spec_end @@ -98,13 +136,12 @@ lookup_statistics_amount_by_interval_cb (void *cls, } /* Call callback if the bucket changed */ - if ( (NULL != resp_desc) && - ( (bmeta_id != bmeta_id_current) || - (interval_start_epoch != cur_interval_start_epoch)) ) + if (interval_start_ago != cur_interval_start_ago) { struct GNUNET_TIME_Timestamp interval_start; - interval_start = GNUNET_TIME_timestamp_from_s (cur_interval_start_epoch); + interval_start = GNUNET_TIME_timestamp_get (); + interval_start.abs_time.abs_value_us -= interval_start_ago * 1000 * 1000; tflc->cb (tflc->cb_cls, resp_desc, interval_start, @@ -115,12 +152,7 @@ lookup_statistics_amount_by_interval_cb (void *cls, 0); GNUNET_free (resp_desc); } - if (NULL == resp_desc) - { - cur_interval_start_epoch = interval_start_epoch; - resp_desc = GNUNET_strdup (description); - bmeta_id_current = bmeta_id; - } + cur_interval_start_ago = interval_start_ago; GNUNET_array_append (amounts, amounts_len, cumulative_amount); @@ -130,7 +162,7 @@ lookup_statistics_amount_by_interval_cb (void *cls, { struct GNUNET_TIME_Timestamp interval_start; - interval_start = GNUNET_TIME_timestamp_from_s (cur_interval_start_epoch); + interval_start = GNUNET_TIME_timestamp_from_s (cur_interval_start_ago); tflc->cb (tflc->cb_cls, resp_desc, interval_start, @@ -158,6 +190,11 @@ TMH_PG_lookup_statistics_amount_by_interval ( .cb_cls = cb_cls, /* Can be overwritten by the lookup_statistics_amount_by_interval_cb */ .extract_failed = false, + .description = NULL + }; + struct GNUNET_PQ_QueryParam descParams[] = { + GNUNET_PQ_query_param_string (slug), + GNUNET_PQ_query_param_end }; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), @@ -168,17 +205,34 @@ TMH_PG_lookup_statistics_amount_by_interval ( check_connection (pg); PREPARE (pg, + "lookup_statistics_amount_by_interval_description", + "SELECT description" + " FROM merchant_statistic_interval_meta" + " WHERE slug=$1 LIMIT 1"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "lookup_statistics_amount_by_interval_description", + descParams, + &lookup_statistics_amount_by_interval_desc_cb, + &context); + /* If there was an error inside the cb, return a hard error. */ + if (context.extract_failed) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + PREPARE (pg, "lookup_statistics_amount_by_interval", "SELECT *" - " FROM merchant_statistic_interval_amount_get($1,$2)" - " JOIN merchant_statistic_bucket_meta" - " ON slug=$2"); + " FROM merchant_statistic_interval_amount_get($2,$1)"); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, "lookup_statistics_amount_by_interval", params, &lookup_statistics_amount_by_interval_cb, &context); + if (NULL != context.description) + GNUNET_free (context.description); /* If there was an error inside the cb, return a hard error. */ if (context.extract_failed) { diff --git a/src/backenddb/pg_lookup_statistics_counter_by_interval.c b/src/backenddb/pg_lookup_statistics_counter_by_interval.c @@ -46,12 +46,57 @@ struct LookupCounterStatisticsContext * Did database result extraction fail? */ bool extract_failed; + + /** + * Description of statistic + */ + char*description; }; +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about statistics. + * + * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_statistics_counter_by_interval_desc_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCounterStatisticsContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + tflc->description = GNUNET_strdup (description); + + GNUNET_PQ_cleanup_result (rs); + } +} + /** * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. + * that has returned @a num_results results about statistics. * * @param[in,out] cls of type `struct LookupTokenFamiliesContext *` * @param result the postgres result @@ -66,15 +111,12 @@ lookup_statistics_counter_by_interval_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - char *description; uint64_t cumulative_number; - uint64_t interval_start_epoch; + uint64_t interval_start_ago; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_uint64 ("start_time", - &interval_start_epoch), - GNUNET_PQ_result_spec_uint64 ("cumulative_number", + GNUNET_PQ_result_spec_uint64 ("range", + &interval_start_ago), + GNUNET_PQ_result_spec_uint64 ("rvalue", &cumulative_number), GNUNET_PQ_result_spec_end }; @@ -90,9 +132,10 @@ lookup_statistics_counter_by_interval_cb (void *cls, return; } - interval_start = GNUNET_TIME_timestamp_from_s (interval_start_epoch); + interval_start = GNUNET_TIME_timestamp_get (); + interval_start.abs_time.abs_value_us -= interval_start_ago * 1000 * 1000; tflc->cb (tflc->cb_cls, - description, + tflc->description, interval_start, cumulative_number); GNUNET_PQ_cleanup_result (rs); @@ -114,6 +157,11 @@ TMH_PG_lookup_statistics_counter_by_interval ( .cb_cls = cb_cls, /* Can be overwritten by the lookup_token_families_cb */ .extract_failed = false, + .description = NULL + }; + struct GNUNET_PQ_QueryParam descParams[] = { + GNUNET_PQ_query_param_string (slug), + GNUNET_PQ_query_param_end }; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), @@ -124,17 +172,34 @@ TMH_PG_lookup_statistics_counter_by_interval ( check_connection (pg); PREPARE (pg, + "lookup_statistics_counter_by_interval_description", + "SELECT description" + " FROM merchant_statistic_interval_meta" + " WHERE slug=$1 LIMIT 1"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "lookup_statistics_counter_by_interval_description", + descParams, + &lookup_statistics_counter_by_interval_desc_cb, + &context); + /* If there was an error inside the cb, return a hard error. */ + if (context.extract_failed) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + PREPARE (pg, "lookup_statistics_counter_by_interval", "SELECT *" - " FROM merchant_statistic_interval_number_get($1,$2)" - " JOIN merchant_statistic_bucket_meta" - " ON slug=$2"); + " FROM merchant_statistic_interval_number_get($2,$1)"); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, "lookup_statistics_counter_by_interval", params, &lookup_statistics_counter_by_interval_cb, &context); + if (NULL != context.description) + GNUNET_free (context.description); /* If there was an error inside the cb, return a hard error. */ if (context.extract_failed) {