fix for foreign key constraint problem for free purses on purse creation from reserve

This commit is contained in:
Christian Grothoff 2023-01-16 15:45:35 +01:00
parent 402ca17600
commit 6596e6c723
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 24 additions and 3 deletions

View File

@ -18,6 +18,8 @@ CREATE OR REPLACE FUNCTION exchange_do_reserve_purse(
IN in_purse_pub BYTEA, IN in_purse_pub BYTEA,
IN in_merge_sig BYTEA, IN in_merge_sig BYTEA,
IN in_merge_timestamp INT8, IN in_merge_timestamp INT8,
IN in_reserve_expiration INT8,
IN in_reserve_gc INT8,
IN in_reserve_sig BYTEA, IN in_reserve_sig BYTEA,
IN in_reserve_quota BOOLEAN, IN in_reserve_quota BOOLEAN,
IN in_purse_fee_val INT8, IN in_purse_fee_val INT8,
@ -105,6 +107,14 @@ ELSE
out_no_funds=TRUE; out_no_funds=TRUE;
RETURN; RETURN;
END IF; END IF;
INSERT INTO exchange.reserves
(reserve_pub
,expiration_date
,gc_date)
VALUES
(in_reserve_pub
,in_reserve_expiration
,in_reserve_gc);
ELSE ELSE
UPDATE exchange.reserves UPDATE exchange.reserves
SET SET
@ -149,7 +159,7 @@ INSERT INTO exchange.account_merges
END $$; END $$;
COMMENT ON FUNCTION exchange_do_reserve_purse(BYTEA, BYTEA, INT8, BYTEA, BOOLEAN, INT8, INT4, BYTEA, BYTEA) COMMENT ON FUNCTION exchange_do_reserve_purse(BYTEA, BYTEA, INT8, INT8, INT8, BYTEA, BOOLEAN, INT8, INT4, BYTEA, BYTEA)
IS 'Create a purse for a reserve.'; IS 'Create a purse for a reserve.';

View File

@ -57,10 +57,21 @@ TEH_PG_do_reserve_purse (
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
struct TALER_Amount zero_fee; struct TALER_Amount zero_fee;
struct TALER_PaytoHashP h_payto; struct TALER_PaytoHashP h_payto;
struct GNUNET_TIME_Timestamp reserve_expiration
= GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
pg->idle_reserve_expiration_time));
struct GNUNET_TIME_Timestamp reserve_gc
= GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
pg->legal_reserve_expiration_time));
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub), GNUNET_PQ_query_param_auto_from_type (purse_pub),
GNUNET_PQ_query_param_auto_from_type (merge_sig), GNUNET_PQ_query_param_auto_from_type (merge_sig),
GNUNET_PQ_query_param_timestamp (&merge_timestamp), GNUNET_PQ_query_param_timestamp (&merge_timestamp),
GNUNET_PQ_query_param_timestamp (&reserve_expiration),
GNUNET_PQ_query_param_timestamp (&reserve_gc),
GNUNET_PQ_query_param_auto_from_type (reserve_sig), GNUNET_PQ_query_param_auto_from_type (reserve_sig),
GNUNET_PQ_query_param_bool (NULL == purse_fee), GNUNET_PQ_query_param_bool (NULL == purse_fee),
TALER_PQ_query_param_amount (NULL == purse_fee TALER_PQ_query_param_amount (NULL == purse_fee