From c98d960d1badd1eeb834bacbc133960e2f86d304 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 22 Aug 2023 23:15:08 +0200 Subject: add currency to amounts in merchant DB --- src/backenddb/plugin_merchantdb_postgres.c | 144 +++++++++++++---------------- 1 file changed, 63 insertions(+), 81 deletions(-) (limited to 'src/backenddb/plugin_merchantdb_postgres.c') diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 016cb4e2..70a3e644 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -284,7 +284,6 @@ lookup_deposits_by_order_cb (void *cls, unsigned int num_results) { struct LookupDepositsByOrderContext *ldoc = cls; - struct PostgresClosure *pg = ldoc->pg; for (unsigned int i = 0; ipg; for (unsigned int i = 0; ipg; for (unsigned int i = 0; iwire), - TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee", - &fees->closing), + TALER_PQ_result_spec_amount_with_currency ("wire_fee", + &fees->wire), + TALER_PQ_result_spec_amount_with_currency ("closing_fee", + &fees->closing), GNUNET_PQ_result_spec_timestamp ("start_date", start_date), GNUNET_PQ_result_spec_timestamp ("end_date", @@ -971,7 +968,6 @@ lookup_deposits_by_contract_and_coin_cb (void *cls, unsigned int num_results) { struct LookupDepositsByCnCContext *ldcc = cls; - struct PostgresClosure *pg = ldcc->pg; for (unsigned int i = 0; ipg; for (unsigned int i = 0; ipg; for (unsigned int i = 0; ipg; for (unsigned int i = 0; i < num_results; i++) { @@ -1478,8 +1471,8 @@ lookup_pending_reserves_cb (void *cls, &instance_id), GNUNET_PQ_result_spec_string ("exchange_url", &exchange_url), - TALER_PQ_RESULT_SPEC_AMOUNT ("merchant_initial_balance", - &merchant_initial_balance), + TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance", + &merchant_initial_balance), GNUNET_PQ_result_spec_end }; @@ -1579,7 +1572,6 @@ lookup_reserve_rewards_cb (void *cls, unsigned int num_results) { struct LookupRewardsContext *ltc = cls; - struct PostgresClosure *pg = ltc->pg; GNUNET_array_grow (ltc->rewards, ltc->rewards_length, @@ -1592,8 +1584,8 @@ lookup_reserve_rewards_cb (void *cls, &td->reason), GNUNET_PQ_result_spec_auto_from_type ("reward_id", &td->reward_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &td->total_amount), + TALER_PQ_result_spec_amount_with_currency ("amount", + &td->total_amount), GNUNET_PQ_result_spec_end }; @@ -1653,14 +1645,14 @@ postgres_lookup_reserve (void *cls, &creation_time), GNUNET_PQ_result_spec_timestamp ("expiration", &expiration_time), - TALER_PQ_RESULT_SPEC_AMOUNT ("merchant_initial_balance", - &merchant_initial_balance), - TALER_PQ_RESULT_SPEC_AMOUNT ("exchange_initial_balance", - &exchange_initial_balance), - TALER_PQ_RESULT_SPEC_AMOUNT ("rewards_picked_up", - &pickup_amount), - TALER_PQ_RESULT_SPEC_AMOUNT ("rewards_committed", - &committed_amount), + TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance", + &merchant_initial_balance), + TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance", + &exchange_initial_balance), + TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up", + &pickup_amount), + TALER_PQ_result_spec_amount_with_currency ("rewards_committed", + &committed_amount), GNUNET_PQ_result_spec_auto_from_type ("master_pub", &master_pub), GNUNET_PQ_result_spec_bool ("active", @@ -1955,10 +1947,10 @@ postgres_lookup_reward (void *cls, GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - total_authorized), - TALER_PQ_RESULT_SPEC_AMOUNT ("picked_up", - total_picked_up), + TALER_PQ_result_spec_amount_with_currency ("amount", + total_authorized), + TALER_PQ_result_spec_amount_with_currency ("picked_up", + total_picked_up), GNUNET_PQ_result_spec_timestamp ("expiration", expiration), GNUNET_PQ_result_spec_string ("exchange_url", @@ -2018,7 +2010,6 @@ lookup_rewards_cb (void *cls, unsigned int num_results) { struct LookupMerchantRewardsContext *plc = cls; - struct PostgresClosure *pg = plc->pg; for (unsigned int i = 0; i < num_results; i++) { @@ -2030,8 +2021,8 @@ lookup_rewards_cb (void *cls, &row_id), GNUNET_PQ_result_spec_auto_from_type ("reward_id", &reward_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &reward_amount), + TALER_PQ_result_spec_amount_with_currency ("amount", + &reward_amount), GNUNET_PQ_result_spec_end }; @@ -2154,7 +2145,6 @@ lookup_pickup_details_cb (void *cls, unsigned int num_results) { struct LookupRewardDetailsContext *ltdc = cls; - struct PostgresClosure *pg = ltdc->pg; *ltdc->pickups_length = num_results; *ltdc->pickups = GNUNET_new_array (num_results, @@ -2166,8 +2156,8 @@ lookup_pickup_details_cb (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("pickup_id", &pd->pickup_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &pd->requested_amount), + TALER_PQ_result_spec_amount_with_currency ("amount", + &pd->requested_amount), GNUNET_PQ_result_spec_uint64 ("num_planchets", &num_planchets), GNUNET_PQ_result_spec_end @@ -2232,10 +2222,10 @@ postgres_lookup_reward_details (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("reward_serial", &reward_serial), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - total_authorized), - TALER_PQ_RESULT_SPEC_AMOUNT ("picked_up", - total_picked_up), + TALER_PQ_result_spec_amount_with_currency ("amount", + total_authorized), + TALER_PQ_result_spec_amount_with_currency ("picked_up", + total_picked_up), GNUNET_PQ_result_spec_string ("justification", justification), GNUNET_PQ_result_spec_timestamp ("expiration", @@ -3550,10 +3540,11 @@ postgres_connect (void *cls) ",merchant_id" ",exchange_url" ",merchant_initial_balance" - " FROM merchant_reward_reserves" + " FROM merchant_reward_reserves mrr" " JOIN merchant_instances USING (merchant_serial)" " JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE exchange_initial_balance=CAST((0,0) AS taler_amount)"), + " WHERE (mrr.exchange_initial_balance).val=0" + " AND (mrr.exchange_initial_balance).frac=0"), /* For postgres_lookup_reserve() */ GNUNET_PQ_make_prepare ("lookup_reserve", "SELECT" @@ -4000,14 +3991,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } - if (GNUNET_OK != - TALER_config_get_currency (cfg, - &pg->currency)) - { - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin); plugin->cls = pg; plugin->connect = &postgres_connect; @@ -4213,7 +4196,6 @@ libtaler_plugin_merchantdb_postgres_done (void *cls) pg->conn = NULL; } GNUNET_free (pg->sql_dir); - GNUNET_free (pg->currency); GNUNET_free (pg); GNUNET_free (plugin); return NULL; -- cgit v1.2.3