summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/exchange-0001-part.sql21
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c7
2 files changed, 19 insertions, 9 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index a8aebfbaa..f5276d0b8 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -2855,6 +2855,10 @@ DECLARE
DECLARE
psi INT8; -- partner's serial ID (set if merged)
DECLARE
+ my_amount_val INT8; -- total in purse
+DECLARE
+ my_amount_frac INT4; -- total in purse
+DECLARE
was_paid BOOLEAN;
DECLARE
my_reserve_pub BYTEA;
@@ -2881,8 +2885,7 @@ IF NOT FOUND
THEN
-- Idempotency check: check if coin_sig is the same,
-- if so, success, otherwise conflict!
- SELECT
- 1
+ PERFORM
FROM purse_deposits
WHERE coin_pub = in_coin_pub
AND purse_pub = in_purse_pub
@@ -2961,7 +2964,11 @@ THEN
END IF;
SELECT
- 1
+ amount_with_fee_val
+ ,amount_with_fee_frac
+ INTO
+ my_amount_val
+ ,my_amount_frac
FROM purse_requests
WHERE (purse_pub=in_purse_pub)
AND ( ( ( (amount_with_fee_val <= balance_val)
@@ -2983,15 +2990,15 @@ ELSE
-- This is a local reserve, update balance immediately.
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 83a64be8a..aaf38ea42 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3538,6 +3538,7 @@ prepare_statements (struct PostgresClosure *pg)
"INSERT INTO purse_requests"
" (purse_pub"
" ,merge_pub"
+ " ,purse_creation"
" ,purse_expiration"
" ,h_contract_terms"
" ,age_limit"
@@ -3549,9 +3550,9 @@ prepare_statements (struct PostgresClosure *pg)
" ,purse_fee_frac"
" ,purse_sig"
" ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"
+ " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
" ON CONFLICT DO NOTHING;",
- 12),
+ 13),
/* Used in #postgres_select_purse */
GNUNET_PQ_make_prepare (
"select_purse",
@@ -13511,12 +13512,14 @@ postgres_insert_purse_request (
{
struct PostgresClosure *pg = cls;
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
== (flags & TALER_WAMF_MERGE_MODE_MASK));
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
GNUNET_PQ_query_param_auto_from_type (merge_pub),
+ GNUNET_PQ_query_param_timestamp (&now),
GNUNET_PQ_query_param_timestamp (&purse_expiration),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
GNUNET_PQ_query_param_uint32 (&age_limit),