-fix purse merge when done against non-existing reserve
This commit is contained in:
parent
580c9b794b
commit
4edb5050d9
@ -380,7 +380,10 @@ purse_transaction (void *cls,
|
||||
GNUNET_free (partner_url);
|
||||
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
|
||||
= TALER_MHD_REPLY_JSON_PACK (
|
||||
|
@ -1850,17 +1850,16 @@ PERFORM
|
||||
FROM exchange.reserves
|
||||
WHERE reserve_pub=in_reserve_pub;
|
||||
|
||||
IF NOT FOUND
|
||||
THEN
|
||||
out_no_reserve=TRUE;
|
||||
out_no_funds=TRUE;
|
||||
RETURN;
|
||||
END IF;
|
||||
out_no_reserve=FALSE;
|
||||
out_no_reserve = NOT FOUND;
|
||||
|
||||
IF (in_reserve_quota)
|
||||
THEN
|
||||
-- Increment active purses per reserve (and check this is allowed)
|
||||
IF (out_no_reserve)
|
||||
THEN
|
||||
out_no_funds=TRUE;
|
||||
RETURN;
|
||||
END IF;
|
||||
UPDATE reserves
|
||||
SET purses_active=purses_active+1
|
||||
WHERE reserve_pub=in_reserve_pub
|
||||
@ -1872,28 +1871,38 @@ THEN
|
||||
END IF;
|
||||
ELSE
|
||||
-- UPDATE reserves balance (and check if balance is enough to pay the fee)
|
||||
UPDATE reserves
|
||||
SET
|
||||
current_balance_frac=current_balance_frac-in_purse_fee_frac
|
||||
+ CASE
|
||||
IF (out_no_reserve)
|
||||
THEN
|
||||
IF ( (0 != in_purse_fee_val) OR
|
||||
(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
|
||||
THEN 100000000
|
||||
ELSE 0
|
||||
END,
|
||||
current_balance_val=current_balance_val-in_purse_fee_val
|
||||
- CASE
|
||||
current_balance_val=current_balance_val-in_purse_fee_val
|
||||
- CASE
|
||||
WHEN current_balance_frac < in_purse_fee_frac
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
WHERE reserve_pub=in_reserve_pub
|
||||
AND ( (current_balance_val > in_purse_fee_val) OR
|
||||
( (current_balance_frac >= in_purse_fee_frac) AND
|
||||
(current_balance_val >= in_purse_fee_val) ) );
|
||||
IF NOT FOUND
|
||||
THEN
|
||||
out_no_funds=TRUE;
|
||||
RETURN;
|
||||
WHERE reserve_pub=in_reserve_pub
|
||||
AND ( (current_balance_val > in_purse_fee_val) OR
|
||||
( (current_balance_frac >= in_purse_fee_frac) AND
|
||||
(current_balance_val >= in_purse_fee_val) ) );
|
||||
IF NOT FOUND
|
||||
THEN
|
||||
out_no_funds=TRUE;
|
||||
RETURN;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user