aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-12-28 12:58:30 +0100
committerChristian Grothoff <christian@grothoff.org>2022-12-28 12:58:30 +0100
commitf864d66d930690449e855d0a7aa0b146174f4388 (patch)
treecadc2c9ed624b57ba86adc7b32682e425dfa3060
parent1e7e0058e85e7399ff39e1fc9eaa4316afd5b91c (diff)
handle case where purse was already deleted on merge
-rw-r--r--src/exchangedb/exchange_do_delete_purse.sql4
-rw-r--r--src/exchangedb/exchange_do_purse_merge.sql31
2 files changed, 26 insertions, 9 deletions
diff --git a/src/exchangedb/exchange_do_delete_purse.sql b/src/exchangedb/exchange_do_delete_purse.sql
index 1e6540ecf..a57f25454 100644
--- a/src/exchangedb/exchange_do_delete_purse.sql
+++ b/src/exchangedb/exchange_do_delete_purse.sql
@@ -62,6 +62,10 @@ THEN
RETURN;
END IF;
+-- Delete contract associated with purse, if it exists.
+DELETE FROM contracts
+ WHERE purse_pub=in_purse_pub;
+
-- store purse decision
INSERT INTO purse_decision
(purse_pub
diff --git a/src/exchangedb/exchange_do_purse_merge.sql b/src/exchangedb/exchange_do_purse_merge.sql
index 2e799c9f2..f02dd5dcd 100644
--- a/src/exchangedb/exchange_do_purse_merge.sql
+++ b/src/exchangedb/exchange_do_purse_merge.sql
@@ -42,6 +42,7 @@ DECLARE
my_in_reserve_quota BOOLEAN;
BEGIN
+
IF in_partner_url IS NULL
THEN
my_partner_serial_id=NULL;
@@ -124,6 +125,27 @@ THEN
out_conflict=FALSE;
RETURN;
END IF;
+
+
+-- Remember how this purse was finished. This will conflict
+-- if the purse was already decided previously.
+INSERT INTO purse_decision
+ (purse_pub
+ ,action_timestamp
+ ,refunded)
+VALUES
+ (in_purse_pub
+ ,in_merge_timestamp
+ ,FALSE)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Purse was already decided (possibly deleted or merged differently).
+ out_conflict=TRUE;
+ RETURN;
+END IF;
+
out_conflict=FALSE;
@@ -138,15 +160,6 @@ INSERT INTO reserves
,in_expiration_date)
ON CONFLICT DO NOTHING;
--- Remember how this purse was finished.
-INSERT INTO purse_decision
- (purse_pub
- ,action_timestamp
- ,refunded)
-VALUES
- (in_purse_pub
- ,in_merge_timestamp
- ,FALSE);
IF (my_in_reserve_quota)
THEN