aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange-0001-part.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/exchange-0001-part.sql')
-rw-r--r--src/exchangedb/exchange-0001-part.sql111
1 files changed, 52 insertions, 59 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index 4a116d12..c57eb454 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -536,76 +536,69 @@ CREATE TABLE IF NOT EXISTS refresh_transfer_keys_default
SELECT add_constraints_to_refresh_transfer_keys_partition('default');
--- ------------------------------ policy_fulfilments -------------------------------------
-
-CREATE TABLE IF NOT EXISTS policy_fulfilments
- (fulfilment_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
- ,fulfilment_timestamp INT8 NOT NULL
- ,fulfilment_proof VARCHAR)
- PARTITION BY HASH (fulfilment_id);
-COMMENT ON TABLE policy_fulfilments
- IS 'Proofs of fulfilment of policies that were set in deposits';
-COMMENT ON COLUMN policy_fulfilments.fulfilment_timestamp
- IS 'Timestamp of the arrival of a proof of fulfilment';
-COMMENT ON COLUMN policy_fulfilments.fulfilment_proof
- IS 'JSON object with a proof of the fulfilment of a policy. Supported details depend on the policy extensions supported by the exchange.';
-
-CREATE TABLE IF NOT EXISTS policy_fulfilments_default
- PARTITION OF policy_fulfilments
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
+-- ------------------------------ policy_fulfillments -------------------------------------
+
+CREATE TABLE IF NOT EXISTS policy_fulfillments
+ (fulfillment_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY
+ ,fulfillment_timestamp INT8 NOT NULL
+ ,fulfillment_proof VARCHAR
+ ,h_fulfillment_proof BYTEA NOT NULL CHECK(LENGTH(h_fulfillment_proof) = 64) UNIQUE
+ ,policy_hash_codes BYTEA NOT NULL CHECK(0 = MOD(LENGTH(policy_hash_codes), 16))
+ );
+COMMENT ON TABLE policy_fulfillments
+ IS 'Proofs of fulfillment of policies that were set in deposits';
+COMMENT ON COLUMN policy_fulfillments.fulfillment_timestamp
+ IS 'Timestamp of the arrival of a proof of fulfillment';
+COMMENT ON COLUMN policy_fulfillments.fulfillment_proof
+ IS 'JSON object with a proof of the fulfillment of a policy. Supported details depend on the policy extensions supported by the exchange.';
+COMMENT ON COLUMN policy_fulfillments.h_fulfillment_proof
+ IS 'Hash of the fulfillment_proof';
+COMMENT ON COLUMN policy_fulfillments.policy_hash_codes
+ IS 'Concatenation of the policy_hash_code of all policy_details that are fulfilled by this proof';
-- ------------------------------ policy_details ----------------------------------------
CREATE TABLE IF NOT EXISTS policy_details
(policy_details_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY
- ,serial_id BYTEA PRIMARY KEY CHECK(LENGTH(serial_id)=64)
- ,policy_options VARCHAR
+ ,policy_hash_code BYTEA PRIMARY KEY CHECK(LENGTH(policy_hash_code)=16)
+ ,policy_json VARCHAR
,deadline INT8 NOT NULL
- ,timeout_fulfilment_state smallint NOT NULL CHECK(timeout_fulfilment_state in (5, 6))
- ,fulfilment_state smallint NOT NULL CHECK(fulfilment_state between 0 and 6))
- PARTITION BY HASH (serial_id);
+ ,commitment_val INT8 NOT NULL
+ ,commitment_frac INT4 NOT NULL
+ ,accumulated_total_val INT8 NOT NULL
+ ,accumulated_total_frac INT4 NOT NULL
+ ,fee_val INT8 NOT NULL
+ ,fee_frac INT4 NOT NULL
+ ,transferable_val INT8 NOT NULL
+ ,transferable_frac INT8 NOT NULL
+ ,fulfillment_state smallint NOT NULL CHECK(fulfillment_state between 0 and 5)
+ ,fulfillment_id BIGINT NULL REFERENCES policy_fulfillments (fulfillment_id) ON DELETE CASCADE
+ );
COMMENT ON TABLE policy_details
IS 'Policies that were provided with deposits via policy extensions.';
-COMMENT ON COLUMN policy_details.serial_id
+COMMENT ON COLUMN policy_details.policy_hash_code
IS 'ID (GNUNET_HashCode) that identifies a policy. Will be calculated by the policy extension based on the content';
-COMMENT ON COLUMN policy_details.policy_options
+COMMENT ON COLUMN policy_details.policy_json
IS 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the policy extensions supported by the exchange.';
COMMENT ON COLUMN policy_details.deadline
- IS 'Deadline until the policy must be marked as fulfilled or unfulfilled (maybe "forever")';
-COMMENT ON COLUMN policy_details.timeout_fulfilment_state
- IS 'State that a pending policy should be put into, once the deadline is reached. Allowed values are 5 (TIMEOUT, transfer coins) or 6 (TIMEOUT, coins refreshable)';
-COMMENT ON COLUMN policy_details.fulfilment_state
- IS 'State of the fulfilment:
- - 0 (PENDING)
- - 1 (SUCCESS, transfer coins)
- - 2 (SUCCESS, coins refreshable)
- - 3 (FAILURE, transfer coins)
- - 4 (FAILURE, coins refreshable)
- - 5 (TIMEOUT, tranfer coins)
- - 6 (TIMEOUT, coins refrehsable)';
-
-CREATE TABLE IF NOT EXISTS policy_details_default
- PARTITION OF policy_details
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
--- ------------------------------ policy_details_fulfilments -----------------------------
-
-CREATE TABLE IF NOT EXISTS policy_details_fulfilments
- (fulfilment_id BIGINT NOT NULL REFERENCES policy_fulfilments(fulfilment_id) ON DELETE CASCADE
- ,serial_id BYTEA NOT NULL UNIQUE REFERENCES policy_details(serial_id) ON DELETE CASCADE)
- PARTITION BY HASH (serial_id); -- FIXME: choose other thing to hash here?
--- FIXME: define a primary key here?
-COMMENT ON TABLE policy_details_fulfilments
- IS 'Links policy_details.serial_id''s with policy_fulfilments.id''s. The same proof of fulfilment can be associated with multiple serial-id''s';
-COMMENT ON COLUMN policy_details_fulfilments.fulfilment_id
- IS 'ID of the proof of fulfilment';
-COMMENT ON COLUMN policy_details_fulfilments.serial_id
- IS 'Serial-ID of the corresponding policy_detail';
-
-CREATE TABLE IF NOT EXISTS policy_details_fulfilments_default
- PARTITION OF policy_details_fulfilments
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
+ IS 'Deadline until the policy must be marked as fulfilled (maybe "forever")';
+COMMENT ON COLUMN policy_details.commitment_val
+ IS 'The amount that this policy commits to. Invariant: commitment >= fee';
+COMMENT ON COLUMN policy_details.accumulated_total_val
+ IS 'The sum of all contributions of all deposit that reference this policy. Invariant: The fulfilment_state must be Insufficient as long as accumulated_total < commitment';
+COMMENT ON COLUMN policy_details.fee_val
+ IS 'The fee for this policy, due when the policy is fulfilled or timed out';
+COMMENT ON COLUMN policy_details.transferable_val
+ IS 'The amount that on fulfilment or timeout will be transfered to the payto-URI''s of the corresponding deposit''s. The policy fees must have been already deducted from it. Invariant: fee+transferable <= accumulated_total. The remaining amount (accumulated_total - fee - transferable) can be refreshed by the owner of the coins when the state is Timeout or Success.';
+COMMENT ON COLUMN policy_details.fulfillment_state
+ IS 'State of the fulfillment:
+ - 0 (Failure)
+ - 1 (Insufficient)
+ - 2 (Ready)
+ - 4 (Success)
+ - 5 (Timeout)';
+COMMENT ON COLUMN policy_details.fulfillment_id
+ IS 'Reference to the proof of the fulfillment of this policy, if it exists. Invariant: If not NULL, this entry''s .hash_code MUST be part of the corresponding policy_fulfillments.policy_hash_codes array.';
-- ------------------------------ deposits ----------------------------------------