diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-06-02 21:55:21 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-06-02 21:55:21 +0200 |
commit | 04c32eafb9194727876469c92b7cbedc008c51ec (patch) | |
tree | ae879e12757e0939c3bed52fad2c9b1ac33e769f /src/exchangedb | |
parent | 5dd03fe359f541f7e1e4849ed4bd38259200f4df (diff) |
-work on P2P payment details
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 2 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index 9b9828fe9..52a16cd9a 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -3464,7 +3464,7 @@ BEGIN SET current_balance_frac=current_balance_frac-in_history_fee_frac + CASE - WHEN reserve_frac < in_history_fee_frac + WHEN current_balance_frac < in_history_fee_frac THEN 100000000 ELSE 0 END, diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 61e16d30c..83f99f46f 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -2157,6 +2157,8 @@ prepare_statements (struct PostgresClosure *pg) "SELECT" " pr.amount_with_fee_val" ",pr.amount_with_fee_frac" + ",pr.balance_val" + ",pr.balance_frac" ",pr.purse_fee_val" ",pr.purse_fee_frac" ",pr.h_contract_terms" @@ -6515,9 +6517,12 @@ add_p2p_merge (void *cls, merge = GNUNET_new (struct TALER_EXCHANGEDB_PurseMerge); { uint32_t flags32; + struct TALER_Amount balance; struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee", &merge->purse_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("balance", + &balance), TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &merge->amount_with_fee), GNUNET_PQ_result_spec_timestamp ("merge_timestamp", @@ -6550,15 +6555,21 @@ add_p2p_merge (void *cls, return; } merge->flags = (enum TALER_WalletAccountMergeFlags) flags32; + if ( (! GNUNET_TIME_absolute_is_future ( + merge->merge_timestamp.abs_time)) && + (-1 != TALER_amount_cmp (&balance, + &merge->amount_with_fee)) ) + merge->merged = true; } + if (merge->merged) + GNUNET_assert (0 <= + TALER_amount_add (&rhc->balance_in, + &rhc->balance_in, + &merge->amount_with_fee)); GNUNET_assert (0 <= - TALER_amount_add (&rhc->balance_in, - &rhc->balance_in, - &merge->amount_with_fee)); - GNUNET_assert (0 <= - TALER_amount_subtract (&rhc->balance_out, - &rhc->balance_out, - &merge->purse_fee)); + TALER_amount_add (&rhc->balance_out, + &rhc->balance_out, + &merge->purse_fee)); merge->reserve_pub = *rhc->reserve_pub; tail = append_rh (rhc); tail->type = TALER_EXCHANGEDB_RO_PURSE_MERGE; |