diff options
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 0de83602..a5f6818b 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -4516,7 +4516,7 @@ RETRY: postgres_rollback (pg); return TALER_EC_TIP_AUTHORIZE_DB_RESERVE_INVARIANT_FAILURE; } - if (0 < + if (0 > TALER_amount_cmp (&remaining, amount)) { @@ -4555,13 +4555,18 @@ RETRY: tip_id, sizeof (*tip_id)); { + struct TALER_Amount amount_zero; + TALER_amount_get_zero (pg->currency, + &amount_zero); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), GNUNET_PQ_query_param_auto_from_type (reserve_pubp), GNUNET_PQ_query_param_auto_from_type (tip_id), GNUNET_PQ_query_param_string (justification), GNUNET_PQ_query_param_string (next_url), + GNUNET_PQ_query_param_absolute_time (expiration), TALER_PQ_query_param_amount (amount), + TALER_PQ_query_param_amount (&amount_zero), GNUNET_PQ_query_param_end }; @@ -5041,14 +5046,14 @@ RETRY: { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (&tip_id), + GNUNET_PQ_query_param_auto_from_type (tip_id), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("tips_picked_up", - &reserve_picked_up), GNUNET_PQ_result_spec_uint64 ("reserve_serial", &reserve_serial), + TALER_PQ_RESULT_SPEC_AMOUNT ("tips_picked_up", + &reserve_picked_up), GNUNET_PQ_result_spec_end }; @@ -5066,12 +5071,13 @@ RETRY: return qs; } } - if (0 <= + if (0 >= TALER_amount_add (&reserve_picked_up, &reserve_picked_up, total_requested)) { GNUNET_break (0); + postgres_rollback (pg); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -6902,7 +6908,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) GNUNET_PQ_make_prepare ("activate_reserve", "UPDATE merchant_tip_reserves SET" " exchange_initial_balance_val=$3" - " exchange_initial_balance_frac=$4" + ",exchange_initial_balance_frac=$4" " WHERE reserve_pub=$2" " AND merchant_serial=" " (SELECT merchant_serial" @@ -7052,17 +7058,20 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) GNUNET_PQ_make_prepare ("insert_tip", "INSERT INTO merchant_tips" "(reserve_serial" + ",tip_id" ",justification" ",next_url" ",expiration" ",amount_val" ",amount_frac" + ",picked_up_val" + ",picked_up_frac" ") " "SELECT" - " reserve_serial, $3, $4, $5, $6, $7" + " reserve_serial, $3, $4, $5, $6, $7, $8, $9, $10" " FROM merchant_tip_reserves" " WHERE reserve_pub=$2" - " AND reserve_serial = " + " AND merchant_serial = " " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)", @@ -7077,8 +7086,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " JOIN merchant_tips USING (tip_serial)" " JOIN merchant_tip_reserves USING (reserve_serial)" " JOIN merchant_tip_reserve_keys USING (reserve_serial)" - " WHERE pickup_id = $2" - " AND tip_id = $3" + " WHERE pickup_id = $3" + " AND tip_id = $2" " AND merchant_serial =" " (SELECT merchant_serial" " FROM merchant_instances" @@ -7137,9 +7146,13 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " pickup_id" ",amount_val" ",amount_frac" - ",COUNT(blind_sig) AS num_planchets" + ",(SELECT" + " COUNT(blind_sig)" + " FROM merchant_tip_pickups" + " JOIN merchant_tip_pickup_signatures USING (pickup_serial)" + " WHERE tip_serial = $1)" + " AS num_planchets" " FROM merchant_tip_pickups" - " JOIN merchant_tip_pickup_signatures USING (pickup_serial)" " WHERE tip_serial = $1", 1), /* for postgres_insert_pickup() */ @@ -7153,8 +7166,9 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) "SELECT" " tip_serial, $3, $4, $5" " FROM merchant_tips" + " JOIN merchant_tip_reserves USING (reserve_serial)" " WHERE tip_id=$2" - " AND reserve_serial = " + " AND merchant_serial = " " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)", |