diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-06-05 21:00:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-06-05 21:00:49 +0200 |
commit | bdbd2a464df579c014d71800cf72571dc73ed645 (patch) | |
tree | 2c68b7a2b7bc95c2aaca0b4500fc79b4658d7d30 /src/exchangedb | |
parent | 60f609135d04ce3bb4ecad6405572bb6d601fa43 (diff) |
no purse fee if purse is successfully merged
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 36 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 2 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index c79fdf840..75f65ffb6 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -1354,7 +1354,7 @@ CREATE OR REPLACE FUNCTION purse_requests_on_update_trigger() LANGUAGE plpgsql AS $$ BEGIN - IF (NEW.finished) + IF (NEW.finished AND NOT OLD.finished) THEN -- If this purse counted against the reserve's -- quota of purses, decrement the reserve accounting. @@ -3099,9 +3099,13 @@ CREATE OR REPLACE FUNCTION exchange_do_purse_merge( LANGUAGE plpgsql AS $$ DECLARE - amount_val INT8; + my_amount_val INT8; DECLARE - amount_frac INT4; + my_amount_frac INT4; +DECLARE + my_purse_fee_val INT8; +DECLARE + my_purse_fee_frac INT4; DECLARE my_partner_serial_id INT8; DECLARE @@ -3136,9 +3140,13 @@ out_no_partner=FALSE; -- Check purse is 'full'. SELECT amount_with_fee_val ,amount_with_fee_frac + ,purse_fee_val + ,purse_fee_frac ,finished - INTO amount_val - ,amount_frac + INTO my_amount_val + ,my_amount_frac + ,my_purse_fee_val + ,my_purse_fee_frac ,my_finished FROM purse_requests WHERE purse_pub=in_purse_pub @@ -3246,18 +3254,26 @@ THEN ,partner_serial_id=my_partner_serial_id WHERE purse_pub=in_purse_pub; ELSE - -- This is a local reserve, update balance immediately. + -- This is a local reserve, update reserve balance immediately. + + -- Refund the purse fee, by adding it to the purse value: + my_amount_val = my_amount_val + my_purse_fee_val; + my_amount_frac = my_amount_frac + my_purse_fee_frac; + -- normalize result + my_amount_val = my_amount_val + my_amount_frac / 100000000; + my_amount_frac = my_amount_frac % 100000000; + UPDATE reserves SET - current_balance_frac=current_balance_frac+amount_frac + current_balance_frac=current_balance_frac+my_amount_frac - CASE - WHEN current_balance_frac + amount_frac >= 100000000 + WHEN current_balance_frac + my_amount_frac >= 100000000 THEN 100000000 ELSE 0 END, - current_balance_val=current_balance_val+amount_val + current_balance_val=current_balance_val+my_amount_val + CASE - WHEN current_balance_frac + amount_frac >= 100000000 + WHEN current_balance_frac + my_amount_frac >= 100000000 THEN 1 ELSE 0 END diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 4ff51ebcb..0dbd804bb 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -14149,7 +14149,7 @@ postgres_insert_purse_request ( enum GNUNET_DB_QueryStatus qs; struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); uint32_t flags32 = (uint32_t) flags; - bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE + bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA == (flags & TALER_WAMF_MERGE_MODE_MASK)); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (purse_pub), |