From 4f237e8aae9b67a0bdb9363934dcbbb3a7742daa Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Fri, 10 Apr 2020 21:01:08 +0200
Subject: add API to store refund proofs

---
 src/backenddb/merchant-0001.sql | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

(limited to 'src/backenddb/merchant-0001.sql')

diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index bfcc828a..63eb4bf7 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -59,7 +59,8 @@ CREATE TABLE IF NOT EXISTS merchant_deposits
   ,signkey_pub BYTEA NOT NULL CHECK (LENGTH(signkey_pub)=32)
   ,exchange_proof BYTEA NOT NULL
   ,PRIMARY KEY (h_contract_terms, coin_pub)
-  ,FOREIGN KEY (h_contract_terms, merchant_pub) REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+  ,FOREIGN KEY (h_contract_terms, merchant_pub)
+   REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
   );
 
 CREATE TABLE IF NOT EXISTS merchant_proofs
@@ -109,10 +110,25 @@ CREATE TABLE IF NOT EXISTS merchant_refunds
   ,reason VARCHAR NOT NULL
   ,refund_amount_val INT8 NOT NULL
   ,refund_amount_frac INT4 NOT NULL
-  ,FOREIGN KEY (h_contract_terms, coin_pub) REFERENCES merchant_deposits (h_contract_terms, coin_pub)
-  ,FOREIGN KEY (h_contract_terms, merchant_pub) REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+  ,FOREIGN KEY (h_contract_terms, coin_pub)
+   REFERENCES merchant_deposits (h_contract_terms, coin_pub)
+  ,FOREIGN KEY (h_contract_terms, merchant_pub)
+   REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+  ,PRIMARY KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
   );
 
+CREATE TABLE IF NOT EXISTS merchant_refund_proofs
+  (rtransaction_id BIGSERIAL UNIQUE
+  ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
+  ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
+  ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
+  ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
+  ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
+  ,FOREIGN KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+   REFERENCES merchant_refunds (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+  ,PRIMARY KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+);
+
 -- balances of the reserves available for tips
 CREATE TABLE IF NOT EXISTS merchant_tip_reserves
   (reserve_priv BYTEA NOT NULL CHECK (LENGTH(reserve_priv)=32)
-- 
cgit v1.2.3

