diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 33 | ||||
-rw-r--r-- | src/exchangedb/lrbt_callbacks.c | 60 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 37 | ||||
-rw-r--r-- | src/exchangedb/procedures.sql | 12 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 1 |
5 files changed, 113 insertions, 30 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index ba54f6f7..7e2547db 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -539,10 +539,10 @@ SELECT add_constraints_to_refresh_transfer_keys_partition('default'); -- ------------------------------ policy_fulfilments ------------------------------------- CREATE TABLE IF NOT EXISTS policy_fulfilments - (policy_fulfilments_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY + (fulfilment_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,fulfilment_timestamp INT8 NOT NULL ,fulfilment_proof VARCHAR) - PARTITION BY HASH (policy_fulfilments_serial_id); + 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 @@ -554,14 +554,14 @@ CREATE TABLE IF NOT EXISTS policy_fulfilments_default PARTITION OF policy_fulfilments FOR VALUES WITH (MODULUS 1, REMAINDER 0); - -- ------------------------------ 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 - ,fulfilment_serial_id BIGINT REFERENCES policy_fulfilments(policy_fulfilments_serial_id) ON DELETE CASCADE) + ,deadline INT8 NOT NULL + ,fulfilment_state INT4 NOT NULL CHECK(fulfilment_state between 0 and 3)) PARTITION BY HASH (serial_id); COMMENT ON TABLE policy_details IS 'Policies that were provided with deposits via policy extensions.'; @@ -569,13 +569,34 @@ COMMENT ON COLUMN policy_details.serial_id 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 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.fulfilment_serial_id - IS 'If not NULL, refers to the proof of fulfilment of this policy'; +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.fulfilment_state + IS 'State of the fulfilment: 0 (PENDING), 1 (FULFILLED), 2 (NOT FULFILLED), 3 (TIMED OUT)'; 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); + + -- ------------------------------ deposits ---------------------------------------- SELECT create_table_deposits(); diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/lrbt_callbacks.c index 023f61cc..a2c654f4 100644 --- a/src/exchangedb/lrbt_callbacks.c +++ b/src/exchangedb/lrbt_callbacks.c @@ -1442,7 +1442,6 @@ lrbt_cb_table_policy_details (void *cls, for (unsigned int i = 0; i<num_results; i++) { bool no_config = false; - bool no_fulfilment = false; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("policy_details_serial_id", &td.serial), @@ -1454,11 +1453,12 @@ lrbt_cb_table_policy_details (void *cls, &td.details.policy_details. policy_options), &no_config), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("fulfilment_serial_id", - &td.details.policy_details. - fulfilment_serial_id), - &no_fulfilment), + GNUNET_PQ_result_spec_timestamp ("deadline", + &td.details.policy_details. + deadline), + GNUNET_PQ_result_spec_uint64 ("fulfilment_state", + &td.details.policy_details. + fulfilment_state), GNUNET_PQ_result_spec_end }; @@ -1500,7 +1500,7 @@ lrbt_cb_table_policy_fulfilments (void *cls, bool no_config = false; bool no_timestamp = false; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("policy_fulfilment_serial_id", + GNUNET_PQ_result_spec_uint64 ("fulfilment_id", &td.serial), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_string ("fulfilment_proof", @@ -1532,6 +1532,52 @@ lrbt_cb_table_policy_fulfilments (void *cls, /** + * Function called with policy_details_fulfilments table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_policy_details_fulfilments (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_POLICY_DETAILS_FULFILMENTS + }; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("fulfilment_id", + &td.details.policy_details_fulfilments. + fulfilment_id), + GNUNET_PQ_result_spec_auto_from_type ("serial_id", + &td.details. + policy_details_fulfilments. + serial_id), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** * Function called with purse_requests table entries. * * @param cls closure diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index e03713c3..ebac70ea 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3932,20 +3932,29 @@ prepare_statements (struct PostgresClosure *pg) "(policy_details_serial_id" ",serial_id" ",policy_options" - ",fulfilment_serial_id" + ",deadline" + ",fulfilment_state" ") VALUES " - "($1, $2, $3, $4);", - 4), + "($1, $2, $3, $4, $5);", + 5), GNUNET_PQ_make_prepare ( "insert_into_table_policy_fulfilments", "INSERT INTO policy_fulfilments" - "(policy_fulfilments_serial_id" + "(fulfilment_id" ",fulfilment_timestamp" ",fulfilment_proof" ") VALUES " "($1, $2, $3);", 3), GNUNET_PQ_make_prepare ( + "insert_into_table_policy_details_fulfilments", + "INSERT INTO policy_details_fulfilments" + "(fulfilment_id" + ",serial_id" + ") VALUES " + "($1, $2);", + 2), + GNUNET_PQ_make_prepare ( "insert_into_table_purse_requests", "INSERT INTO purse_requests" "(purse_requests_serial_id" @@ -6273,16 +6282,16 @@ postgres_do_deposit ( GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub), GNUNET_PQ_query_param_auto_from_type (&deposit->csig), GNUNET_PQ_query_param_uint64 (&deposit_shard), - GNUNET_PQ_query_param_bool (! deposit->no_policy_details), - (deposit->no_policy_details) - ? GNUNET_PQ_query_param_null () - : TALER_PQ_query_param_json (deposit->policy_details), - (deposit->no_policy_details) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_auto_from_type (&deposit->policy_serial_id), - (deposit->no_policy_details) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_timestamp (&deposit->policy_deadline), + GNUNET_PQ_query_param_bool (deposit->has_policy_details), + (deposit->has_policy_details) + ? TALER_PQ_query_param_json (deposit->policy_details) + : GNUNET_PQ_query_param_null (), + (deposit->has_policy_details) + ? GNUNET_PQ_query_param_auto_from_type (&deposit->policy_serial_id) + : GNUNET_PQ_query_param_null (), + (deposit->has_policy_details) + ? GNUNET_PQ_query_param_timestamp (&deposit->policy_deadline) + : GNUNET_PQ_query_param_null (), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql index 22130adc..646eaa44 100644 --- a/src/exchangedb/procedures.sql +++ b/src/exchangedb/procedures.sql @@ -512,6 +512,8 @@ CREATE OR REPLACE FUNCTION exchange_do_deposit( IN in_shard INT8, IN in_policy_blocked BOOLEAN, IN in_policy_details VARCHAR, + IN in_policy_serial_id BYTEA, + IN in_policy_deadline INT8, OUT out_exchange_timestamp INT8, OUT out_balance_ok BOOLEAN, OUT out_conflict BOOLEAN) @@ -530,9 +532,15 @@ BEGIN IF NOT NULL in_policy_details THEN INSERT INTO exchange.policy_details - (policy_options) + (serial_id + ,policy_options + ,deadline + ,fulfilment_state) VALUES - (in_policy_details) + (in_policy_serial_id + ,in_policy_details + ,in_policy_deadline + ,'pending') RETURNING policy_details_serial_id INTO xdi; ELSE xdi=NULL; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 5508e0ae..6acf0136 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1500,7 +1500,6 @@ run (void *cls) &deposit, known_coin_id, &h_payto, - false, &deposit_timestamp, &balance_ok, &in_conflict)); |