summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/exchange_do_purse_deposit.sql15
-rw-r--r--src/exchangedb/pg_do_purse_deposit.c4
-rw-r--r--src/exchangedb/pg_do_purse_deposit.h2
3 files changed, 17 insertions, 4 deletions
diff --git a/src/exchangedb/exchange_do_purse_deposit.sql b/src/exchangedb/exchange_do_purse_deposit.sql
index cddbd8d46..0ca4126af 100644
--- a/src/exchangedb/exchange_do_purse_deposit.sql
+++ b/src/exchangedb/exchange_do_purse_deposit.sql
@@ -26,6 +26,7 @@ CREATE OR REPLACE FUNCTION exchange_do_purse_deposit(
IN in_reserve_expiration INT8,
IN in_now INT8,
OUT out_balance_ok BOOLEAN,
+ OUT out_late BOOLEAN,
OUT out_conflict BOOLEAN)
LANGUAGE plpgsql
AS $$
@@ -75,6 +76,7 @@ THEN
THEN
-- Deposit exists, but with differences. Not allowed.
out_balance_ok=FALSE;
+ out_late=FALSE;
out_conflict=TRUE;
RETURN;
END IF;
@@ -106,6 +108,7 @@ IF NOT FOUND
THEN
-- Insufficient balance.
out_balance_ok=FALSE;
+ out_late=FALSE;
out_conflict=FALSE;
RETURN;
END IF;
@@ -141,6 +144,8 @@ SELECT COALESCE(partner_serial_id,0)
IF NOT FOUND
THEN
+ -- Purse was not yet merged. We are done.
+ out_late=FALSE;
RETURN;
END IF;
@@ -159,6 +164,7 @@ SELECT
OR (amount_with_fee_val < balance_val) ) );
IF NOT FOUND
THEN
+ out_late=FALSE;
RETURN;
END IF;
@@ -175,10 +181,13 @@ ON CONFLICT DO NOTHING;
IF NOT FOUND
THEN
- out_conflict=TRUE;
+ -- Purse already decided, likely expired.
+ out_late=TRUE;
RETURN;
END IF;
+out_late=FALSE;
+
IF (my_in_reserve_quota)
THEN
UPDATE reserves
@@ -216,7 +225,7 @@ ELSE
IF NOT FOUND
THEN
-
+ -- Reserve existed, thus UPDATE instead of INSERT.
UPDATE reserves
SET
current_balance_frac=current_balance_frac+my_amount_frac
@@ -240,5 +249,3 @@ END IF;
END $$;
-
-
diff --git a/src/exchangedb/pg_do_purse_deposit.c b/src/exchangedb/pg_do_purse_deposit.c
index 25496a262..ba6f03c11 100644
--- a/src/exchangedb/pg_do_purse_deposit.c
+++ b/src/exchangedb/pg_do_purse_deposit.c
@@ -35,6 +35,7 @@ TEH_PG_do_purse_deposit (
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_Amount *amount_minus_fee,
bool *balance_ok,
+ bool *too_late,
bool *conflict)
{
struct PostgresClosure *pg = cls;
@@ -57,6 +58,8 @@ TEH_PG_do_purse_deposit (
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_bool ("balance_ok",
balance_ok),
+ GNUNET_PQ_result_spec_bool ("too_late",
+ too_late),
GNUNET_PQ_result_spec_bool ("conflict",
conflict),
GNUNET_PQ_result_spec_end
@@ -72,6 +75,7 @@ TEH_PG_do_purse_deposit (
"SELECT "
" out_balance_ok AS balance_ok"
",out_conflict AS conflict"
+ ",out_late AS too_late"
" FROM exchange_do_purse_deposit"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
diff --git a/src/exchangedb/pg_do_purse_deposit.h b/src/exchangedb/pg_do_purse_deposit.h
index b4b9c35c8..779b6c0c8 100644
--- a/src/exchangedb/pg_do_purse_deposit.h
+++ b/src/exchangedb/pg_do_purse_deposit.h
@@ -43,6 +43,7 @@
* remaining balance is below @a amount;
* in this case, the return value will be
* #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
+ * @param[out] too_late set to true if it is too late to deposit into the purse
* @param[out] conflict set to true if the deposit failed due to a conflict (coin already spent,
* or deposited into this purse with a different amount)
* @return transaction status code
@@ -56,6 +57,7 @@ TEH_PG_do_purse_deposit (
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_Amount *amount_minus_fee,
bool *balance_ok,
+ bool *too_late,
bool *conflict);
#endif