From 58a0882909f2b1ede572ae575b83c18746f96cff Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Mon, 13 Jun 2022 15:31:52 +0200
Subject: -towards coin audits with purse deposits

---
 src/exchangedb/exchange-0001-part.sql | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'src/exchangedb/exchange-0001-part.sql')

diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index 75f65ffb6..cc34b6be3 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -1040,6 +1040,21 @@ CREATE TABLE IF NOT EXISTS purse_requests_default
 SELECT add_constraints_to_purse_requests_partition('default');
 
 
+-- ------------------------------ purse_refunds ----------------------------------------
+
+SELECT create_table_purse_refunds();
+
+COMMENT ON TABLE purse_refunds
+  IS 'Purses that were refunded due to expiration';
+COMMENT ON COLUMN purse_refunds.purse_pub
+  IS 'Public key of the purse';
+
+CREATE TABLE IF NOT EXISTS purse_refunds_default
+  PARTITION OF purse_refunds
+  FOR VALUES WITH (MODULUS 1, REMAINDER 0);
+
+SELECT add_constraints_to_purse_refunds_partition('default');
+
 
 -- ------------------------------ purse_merges ----------------------------------------
 
@@ -3485,6 +3500,11 @@ UPDATE purse_requests
      finished=TRUE
  WHERE purse_pub=my_purse_pub;
 
+INSERT INTO purse_refunds
+ (purse_pub)
+ VALUES
+ (my_purse_pub);
+
 -- restore balance to each coin deposited into the purse
 FOR my_deposit IN
   SELECT coin_pub
-- 
cgit v1.2.3

