From 75888adff2549fc8fa9aec9b4e80a37a214345e6 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Sat, 30 Jul 2022 10:12:48 +0200
Subject: setup drain_profits table (#4960)

---
 src/exchangedb/exchange-0001-part.sql | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 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 60b45b440..97f5829e6 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -63,6 +63,37 @@ COMMENT ON TABLE denomination_revocations
   IS 'remembering which denomination keys have been revoked';
 
 
+-- ------------------------------ profit drains ----------------------------------------
+
+CREATE TABLE IF NOT EXISTS profit_drains
+  (profit_drain_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+  ,wtid BYTEA PRIMARY KEY CHECK (LENGTH(wtid)=32)
+  ,account_section VARCHAR NOT NULL
+  ,payto_uri VARCHAR NOT NULL
+  ,trigger_date INT8 NOT NULL
+  ,amount_val INT8 NOT NULL
+  ,amount_frac INT8 NOT NULL
+  ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+  ,executed BOOLEAN NOT NULL DEFAULT FALSE
+  );
+COMMENT ON TABLE profit_drains
+  IS 'transactions to be performed to move profits from the escrow account of the exchange to a regular account';
+COMMENT ON COLUMN profit_drains.wtid
+  IS 'randomly chosen nonce, unique to prevent double-submission';
+COMMENT ON COLUMN profit_drains.account_section
+  IS 'specifies the configuration section in the taler-exchange-drain configuration with the wire account to drain';
+COMMENT ON COLUMN profit_drains.payto_uri
+  IS 'specifies the account to be credited';
+COMMENT ON COLUMN profit_drains.trigger_date
+  IS 'set by taler-exchange-offline at the time of making the signature; not necessarily the exact date of execution of the wire transfer, just for orientation';
+COMMENT ON COLUMN profit_drains.amount_val
+  IS 'amount to be transferred';
+COMMENT ON COLUMN profit_drains.master_sig
+  IS 'EdDSA signature of type TALER_SIGNATURE_MASTER_DRAIN_PROFIT';
+COMMENT ON COLUMN profit_drains.executed
+  IS 'set to TRUE by taler-exchange-drain on execution of the transaction, not replicated to auditor';
+
+
 -- ------------------------------ wire_targets ----------------------------------------
 
 SELECT create_table_wire_targets();
-- 
cgit v1.2.3

