no purse fee if purse is successfully merged

This commit is contained in:
Christian Grothoff 2022-06-05 21:00:41 +02:00
parent 60f609135d
commit bdbd2a464d
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 44 additions and 44 deletions

View File

@ -113,7 +113,7 @@ currency = TESTKUDOS
[merchant-exchange-default]
CURRENCY = TESTKUDOS
EXCHANGE_BASE_URL = http://localhost:8081/
MASTER_KEY = W2824S2YNKFZDR0P57Q005J23XGFWSE2GB24A1YS0157NE3F24NG
MASTER_KEY = EQ73PAPVK53KV6QPBDXPD0DTAWR2TPTQQFFTT9AYSB73ZNYW0AD0
[merchant-account-merchant]
ACTIVE_default = YES
@ -157,7 +157,7 @@ CONFIG = postgres:///auditor-basedb
[exchange]
LOOKAHEAD_SIGN = 32 weeks 1 day
SIGNKEY_DURATION = 4 weeks
MASTER_PUBLIC_KEY = W2824S2YNKFZDR0P57Q005J23XGFWSE2GB24A1YS0157NE3F24NG
MASTER_PUBLIC_KEY = EQ73PAPVK53KV6QPBDXPD0DTAWR2TPTQQFFTT9AYSB73ZNYW0AD0
SIGNKEY_LEGAL_DURATION = 4 weeks
UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
@ -175,7 +175,7 @@ DATABASE = postgres:///auditor-basedb
CONFIG = postgres:///auditor-basedb
[auditor]
PUBLIC_KEY = MSF4QDJMZTT9CC5EMHS480F652QAS40SEXEPAW0GGB9G9RB9B5T0
PUBLIC_KEY = AAJ7CB4EV8MRZVCAR57B549SX1W7SPR50RFQ1ZV0GKZQMTJB4Z5G
TINY_AMOUNT = TESTKUDOS:0.01
BASE_URL = http://localhost:8083/

View File

@ -778,12 +778,7 @@ TEH_RESPONSE_compile_reserve_history (
{
const struct TALER_EXCHANGEDB_PurseMerge *merge =
pos->details.merge;
struct TALER_Amount amount;
GNUNET_assert (0 <=
TALER_amount_subtract (&amount,
&merge->amount_with_fee,
&merge->purse_fee));
if (0 !=
json_array_append_new (
json_history,
@ -807,7 +802,7 @@ TEH_RESPONSE_compile_reserve_history (
GNUNET_JSON_pack_timestamp ("purse_expiration",
merge->purse_expiration),
TALER_JSON_pack_amount ("amount",
&amount),
&merge->amount_with_fee),
TALER_JSON_pack_amount ("purse_fee",
&merge->purse_fee),
GNUNET_JSON_pack_bool ("merged",

View File

@ -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

View File

@ -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),

View File

@ -399,7 +399,6 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
const json_t *transaction)
{
uint32_t flags32;
struct TALER_Amount total;
struct GNUNET_JSON_Specification merge_spec[] = {
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
&rh->details.merge_details.h_contract_terms),
@ -435,21 +434,13 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
}
rh->details.merge_details.flags =
(enum TALER_WalletAccountMergeFlags) flags32;
if (0 >
TALER_amount_add (&total,
&rh->amount,
&rh->details.merge_details.purse_fee))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
TALER_wallet_account_merge_verify (
rh->details.merge_details.merge_timestamp,
&rh->details.merge_details.purse_pub,
rh->details.merge_details.purse_expiration,
&rh->details.merge_details.h_contract_terms,
&total,
&rh->amount,
&rh->details.merge_details.purse_fee,
rh->details.merge_details.min_age,
rh->details.merge_details.flags,
@ -471,6 +462,8 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
return GNUNET_SYSERR;
}
}
else
{
if (0 >
TALER_amount_add (uc->total_out,
uc->total_out,
@ -480,6 +473,7 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
}
return GNUNET_OK;
}

View File

@ -212,19 +212,14 @@ deposit_cb (void *cls,
GNUNET_assert (NULL != gf);
/* Note: change when flags below changes! */
ds->reserve_history.amount
= dr->details.success.purse_value_after_fees;
if (true)
{
/* If we paid a purse fee, we need to subtract the
purse fee from the reserve history amount */
TALER_amount_subtract (&ds->reserve_history.amount,
&dr->details.success.purse_value_after_fees,
&gf->fees.purse);
ds->reserve_history.details.merge_details.purse_fee = gf->fees.purse;
}
else
{
ds->reserve_history.amount
= dr->details.success.purse_value_after_fees;
TALER_amount_set_zero (
ds->reserve_history.amount.currency,
&ds->reserve_history.details.merge_details.purse_fee);