aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange-0001-part.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-11-27 00:16:00 +0100
committerChristian Grothoff <christian@grothoff.org>2022-11-27 00:16:00 +0100
commit9580dd19c23e5591cc022dce717eca7bc745c5b0 (patch)
tree8c63bab63f6cf7673dd68fc214ea8c4022f46ef8 /src/exchangedb/exchange-0001-part.sql
parent746a8a0cdb7b3494230d41e870173936120cd34b (diff)
intermediate step in major SQL refactoring (not done at all)
Diffstat (limited to 'src/exchangedb/exchange-0001-part.sql')
-rw-r--r--src/exchangedb/exchange-0001-part.sql122
1 files changed, 1 insertions, 121 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index 59e684e11..7855c996e 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -14,68 +14,9 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
--- ------------------------------ denominations ----------------------------------------
--- ------------------------------ denomination_revocations ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS denomination_revocations
- (denom_revocations_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,denominations_serial INT8 PRIMARY KEY REFERENCES denominations (denominations_serial) ON DELETE CASCADE
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- );
-COMMENT ON TABLE denomination_revocations
- IS 'remembering which denomination keys have been revoked';
-
-
-
--- -------------------------- kyc_alerts ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS kyc_alerts
- (h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=32)
- ,trigger_type INT4 NOT NULL
- ,UNIQUE(trigger_type,h_payto)
- );
-COMMENT ON TABLE kyc_alerts
- IS 'alerts about completed KYC events reliably notifying other components (even if they are not running)';
-COMMENT ON COLUMN kyc_alerts.h_payto
- IS 'hash of the payto://-URI for which the KYC status changed';
-COMMENT ON COLUMN kyc_alerts.trigger_type
- IS 'identifies the receiver of the alert, as the same h_payto may require multiple components to be notified';
-
-
--- ------------------------------ 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 INT4 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();
@@ -87,6 +28,7 @@ COMMENT ON COLUMN wire_targets.payto_uri
COMMENT ON COLUMN wire_targets.wire_target_h_payto
IS 'Unsalted hash of payto_uri';
+
CREATE TABLE IF NOT EXISTS wire_targets_default
PARTITION OF wire_targets
FOR VALUES WITH (MODULUS 1, REMAINDER 0);
@@ -1423,66 +1365,4 @@ SELECT add_constraints_to_wad_in_entries_partition('default');
-- ------------------------------ partner_accounts ----------------------------------------
-CREATE TABLE IF NOT EXISTS partner_accounts
- (payto_uri VARCHAR PRIMARY KEY
- ,partner_serial_id INT8 REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ,partner_master_sig BYTEA CHECK (LENGTH(partner_master_sig)=64)
- ,last_seen INT8 NOT NULL
- );
-CREATE INDEX IF NOT EXISTS partner_accounts_index_by_partner_and_time
- ON partner_accounts (partner_serial_id,last_seen);
-COMMENT ON TABLE partner_accounts
- IS 'Table with bank accounts of the partner exchange. Entries never expire as we need to remember the signature for the auditor.';
-COMMENT ON COLUMN partner_accounts.payto_uri
- IS 'payto URI (RFC 8905) with the bank account of the partner exchange.';
-COMMENT ON COLUMN partner_accounts.partner_master_sig
- IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS by the partner master public key';
-COMMENT ON COLUMN partner_accounts.last_seen
- IS 'Last time we saw this account as being active at the partner exchange. Used to select the most recent entry, and to detect when we should check again.';
-
-
----------------------- router helper table (not synchronzied) ------------------------
-
-CREATE TABLE IF NOT EXISTS purse_actions
- (purse_pub BYTEA NOT NULL PRIMARY KEY CHECK(LENGTH(purse_pub)=32)
- ,action_date INT8 NOT NULL
- ,partner_serial_id INT8
- );
-COMMENT ON TABLE purse_actions
- IS 'purses awaiting some action by the router';
-COMMENT ON COLUMN purse_actions.purse_pub
- IS 'public (contract) key of the purse';
-COMMENT ON COLUMN purse_actions.action_date
- IS 'when is the purse ready for action';
-COMMENT ON COLUMN purse_actions.partner_serial_id
- IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
-
-CREATE INDEX IF NOT EXISTS purse_action_by_target
- ON purse_actions
- (partner_serial_id,action_date);
-
-
-CREATE OR REPLACE FUNCTION purse_requests_insert_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO
- purse_actions
- (purse_pub
- ,action_date)
- VALUES
- (NEW.purse_pub
- ,NEW.purse_expiration);
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION purse_requests_insert_trigger()
- IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
-
-CREATE TRIGGER purse_requests_on_insert
- AFTER INSERT
- ON purse_requests
- FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
-COMMENT ON TRIGGER purse_requests_on_insert
- ON purse_requests
- IS 'Here we install an entry for the purse expiration.';