-fix purse merge when done against non-existing reserve

This commit is contained in:
Christian Grothoff 2022-08-24 09:38:53 +02:00
parent 580c9b794b
commit 4edb5050d9
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 34 additions and 22 deletions

View File

@ -380,7 +380,10 @@ purse_transaction (void *cls,
GNUNET_free (partner_url); GNUNET_free (partner_url);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
if (no_reserve) if ( (no_reserve) &&
( (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
== rpc->flags) ||
(! TALER_amount_is_zero (&rpc->gf->fees.purse)) ) )
{ {
*mhd_ret *mhd_ret
= TALER_MHD_REPLY_JSON_PACK ( = TALER_MHD_REPLY_JSON_PACK (

View File

@ -1850,17 +1850,16 @@ PERFORM
FROM exchange.reserves FROM exchange.reserves
WHERE reserve_pub=in_reserve_pub; WHERE reserve_pub=in_reserve_pub;
IF NOT FOUND out_no_reserve = NOT FOUND;
THEN
out_no_reserve=TRUE;
out_no_funds=TRUE;
RETURN;
END IF;
out_no_reserve=FALSE;
IF (in_reserve_quota) IF (in_reserve_quota)
THEN THEN
-- Increment active purses per reserve (and check this is allowed) -- Increment active purses per reserve (and check this is allowed)
IF (out_no_reserve)
THEN
out_no_funds=TRUE;
RETURN;
END IF;
UPDATE reserves UPDATE reserves
SET purses_active=purses_active+1 SET purses_active=purses_active+1
WHERE reserve_pub=in_reserve_pub WHERE reserve_pub=in_reserve_pub
@ -1872,28 +1871,38 @@ THEN
END IF; END IF;
ELSE ELSE
-- UPDATE reserves balance (and check if balance is enough to pay the fee) -- UPDATE reserves balance (and check if balance is enough to pay the fee)
UPDATE reserves IF (out_no_reserve)
SET THEN
current_balance_frac=current_balance_frac-in_purse_fee_frac IF ( (0 != in_purse_fee_val) OR
+ CASE (0 != in_purse_fee_frac) )
THEN
out_no_funds=TRUE;
RETURN;
END IF;
ELSE
UPDATE reserves
SET
current_balance_frac=current_balance_frac-in_purse_fee_frac
+ CASE
WHEN current_balance_frac < in_purse_fee_frac WHEN current_balance_frac < in_purse_fee_frac
THEN 100000000 THEN 100000000
ELSE 0 ELSE 0
END, END,
current_balance_val=current_balance_val-in_purse_fee_val current_balance_val=current_balance_val-in_purse_fee_val
- CASE - CASE
WHEN current_balance_frac < in_purse_fee_frac WHEN current_balance_frac < in_purse_fee_frac
THEN 1 THEN 1
ELSE 0 ELSE 0
END END
WHERE reserve_pub=in_reserve_pub WHERE reserve_pub=in_reserve_pub
AND ( (current_balance_val > in_purse_fee_val) OR AND ( (current_balance_val > in_purse_fee_val) OR
( (current_balance_frac >= in_purse_fee_frac) AND ( (current_balance_frac >= in_purse_fee_frac) AND
(current_balance_val >= in_purse_fee_val) ) ); (current_balance_val >= in_purse_fee_val) ) );
IF NOT FOUND IF NOT FOUND
THEN THEN
out_no_funds=TRUE; out_no_funds=TRUE;
RETURN; RETURN;
END IF;
END IF; END IF;
END IF; END IF;