diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/common-0001.sql | 6 | ||||
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 68 | ||||
-rw-r--r-- | src/exchangedb/irbt_callbacks.c | 22 | ||||
-rw-r--r-- | src/exchangedb/lrbt_callbacks.c | 96 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 64 | ||||
-rw-r--r-- | src/exchangedb/procedures.sql | 22 |
6 files changed, 189 insertions, 89 deletions
diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql index 21f53110..02aa3ffb 100644 --- a/src/exchangedb/common-0001.sql +++ b/src/exchangedb/common-0001.sql @@ -885,8 +885,8 @@ BEGIN ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)' ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)' ',done BOOLEAN NOT NULL DEFAULT FALSE' - ',extension_blocked BOOLEAN NOT NULL DEFAULT FALSE' - ',extension_details_serial_id INT8' -- REFERENCES extension_details (extension_details_serial_id) ON DELETE CASCADE' + ',policy_blocked BOOLEAN NOT NULL DEFAULT FALSE' + ',policy_details_serial_id INT8' -- REFERENCES policy_details (policy_details_serial_id) ON DELETE CASCADE' ') %s ;' ,table_name ,'PARTITION BY HASH (coin_pub)' @@ -2617,7 +2617,7 @@ BEGIN ALTER TABLE IF EXISTS deposits DROP CONSTRAINT IF EXISTS deposits_pkey CASCADE - ,DROP CONSTRAINT IF EXISTS deposits_extension_details_serial_id_fkey + ,DROP CONSTRAINT IF EXISTS deposits_policy_details_serial_id_fkey ,DROP CONSTRAINT IF EXISTS deposits_coin_pub_merchant_pub_h_contract_terms_key CASCADE ; diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index c9c3e2f0..ba54f6f7 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -432,14 +432,14 @@ COMMENT ON TABLE signkey_revocations CREATE TABLE IF NOT EXISTS extensions (extension_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE ,name VARCHAR NOT NULL UNIQUE - ,config BYTEA + ,manifest BYTEA ); COMMENT ON TABLE extensions IS 'Configurations of the activated extensions'; COMMENT ON COLUMN extensions.name IS 'Name of the extension'; -COMMENT ON COLUMN extensions.config - IS 'Configuration of the extension as JSON-blob, maybe NULL'; +COMMENT ON COLUMN extensions.manifest + IS 'Manifest of the extension as JSON-blob, maybe NULL'; -- ------------------------------ known_coins ---------------------------------------- @@ -536,22 +536,46 @@ CREATE TABLE IF NOT EXISTS refresh_transfer_keys_default SELECT add_constraints_to_refresh_transfer_keys_partition('default'); --- ------------------------------ extension_details ---------------------------------------- +-- ------------------------------ policy_fulfilments ------------------------------------- -CREATE TABLE IF NOT EXISTS extension_details - (extension_details_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY - ,extension_options VARCHAR) - PARTITION BY HASH (extension_details_serial_id); -COMMENT ON TABLE extension_details - IS 'Extensions that were provided with deposits (not yet used).'; -COMMENT ON COLUMN extension_details.extension_options - IS 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the extensions supported by the exchange.'; +CREATE TABLE IF NOT EXISTS policy_fulfilments + (policy_fulfilments_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY + ,fulfilment_timestamp INT8 NOT NULL + ,fulfilment_proof VARCHAR) + PARTITION BY HASH (policy_fulfilments_serial_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 extension_details_default - PARTITION OF extension_details +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) + PARTITION BY HASH (serial_id); +COMMENT ON TABLE policy_details + IS 'Policies that were provided with deposits via policy extensions.'; +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'; + +CREATE TABLE IF NOT EXISTS policy_details_default + PARTITION OF policy_details + FOR VALUES WITH (MODULUS 1, REMAINDER 0); + -- ------------------------------ deposits ---------------------------------------- SELECT create_table_deposits(); @@ -568,10 +592,10 @@ COMMENT ON COLUMN deposits.wire_salt IS 'Salt used when hashing the payto://-URI to get the h_wire'; COMMENT ON COLUMN deposits.done IS 'Set to TRUE once we have included this deposit in some aggregate wire transfer to the merchant'; -COMMENT ON COLUMN deposits.extension_blocked - IS 'True if the aggregation of the deposit is currently blocked by some extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.'; -COMMENT ON COLUMN deposits.extension_details_serial_id - IS 'References extensions table, NULL if extensions are not used'; +COMMENT ON COLUMN deposits.policy_blocked + IS 'True if the aggregation of the deposit is currently blocked by some policy extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.'; +COMMENT ON COLUMN deposits.policy_details_serial_id + IS 'References policy extensions table, NULL if policy extensions are not used'; CREATE TABLE IF NOT EXISTS deposits_default PARTITION OF deposits @@ -607,7 +631,7 @@ CREATE OR REPLACE FUNCTION deposits_insert_trigger() DECLARE is_ready BOOLEAN; BEGIN - is_ready = NOT (NEW.done OR NEW.extension_blocked); + is_ready = NOT (NEW.done OR NEW.policy_blocked); IF (is_ready) THEN @@ -651,8 +675,8 @@ DECLARE DECLARE is_ready BOOLEAN; BEGIN - was_ready = NOT (OLD.done OR OLD.extension_blocked); - is_ready = NOT (NEW.done OR NEW.extension_blocked); + was_ready = NOT (OLD.done OR OLD.policy_blocked); + is_ready = NOT (NEW.done OR NEW.policy_blocked); IF (was_ready AND NOT is_ready) THEN DELETE FROM exchange.deposits_by_ready @@ -706,7 +730,7 @@ CREATE OR REPLACE FUNCTION deposits_delete_trigger() DECLARE was_ready BOOLEAN; BEGIN - was_ready = NOT (OLD.done OR OLD.extension_blocked); + was_ready = NOT (OLD.done OR OLD.policy_blocked); IF (was_ready) THEN diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c index 570d4221..7c494418 100644 --- a/src/exchangedb/irbt_callbacks.c +++ b/src/exchangedb/irbt_callbacks.c @@ -669,11 +669,11 @@ irbt_cb_table_deposits (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.wire_salt), GNUNET_PQ_query_param_auto_from_type ( &td->details.deposits.wire_target_h_payto), - GNUNET_PQ_query_param_bool (td->details.deposits.extension_blocked), - 0 == td->details.deposits.extension_details_serial_id + GNUNET_PQ_query_param_bool (td->details.deposits.policy_blocked), + 0 == td->details.deposits.policy_details_serial_id ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_uint64 ( - &td->details.deposits.extension_details_serial_id), + &td->details.deposits.policy_details_serial_id), GNUNET_PQ_query_param_end }; @@ -905,9 +905,9 @@ irbt_cb_table_extensions (struct PostgresClosure *pg, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_string (td->details.extensions.name), - NULL == td->details.extensions.config ? + NULL == td->details.extensions.manifest ? GNUNET_PQ_query_param_null () : - GNUNET_PQ_query_param_string (td->details.extensions.config), + GNUNET_PQ_query_param_string (td->details.extensions.manifest), GNUNET_PQ_query_param_end }; @@ -918,27 +918,27 @@ irbt_cb_table_extensions (struct PostgresClosure *pg, /** - * Function called with extension_details records to insert into table. + * Function called with policy_details records to insert into table. * * @param pg plugin context * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_extension_details (struct PostgresClosure *pg, - const struct TALER_EXCHANGEDB_TableData *td) +irbt_cb_table_policy_details (struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), NULL == - td->details.extension_details.extension_options ? + td->details.policy_details.policy_options ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_string ( - td->details.extension_details.extension_options), + td->details.policy_details.policy_options), GNUNET_PQ_query_param_end }; return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_extension_details", + "insert_into_table_policy_details", params); } diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/lrbt_callbacks.c index a8f68f4c..023f61cc 100644 --- a/src/exchangedb/lrbt_callbacks.c +++ b/src/exchangedb/lrbt_callbacks.c @@ -895,7 +895,7 @@ lrbt_cb_table_deposits (void *cls, for (unsigned int i = 0; i<num_results; i++) { - bool no_extension; + bool no_policy; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( "serial", @@ -940,13 +940,13 @@ lrbt_cb_table_deposits (void *cls, "wire_target_h_payto", &td.details.deposits.wire_target_h_payto), GNUNET_PQ_result_spec_auto_from_type ( - "extension_blocked", - &td.details.deposits.extension_blocked), + "policy_blocked", + &td.details.deposits.policy_blocked), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_uint64 ( - "extension_details_serial_id", - &td.details.deposits.extension_details_serial_id), - &no_extension), + "policy_details_serial_id", + &td.details.deposits.policy_details_serial_id), + &no_policy), GNUNET_PQ_result_spec_end }; @@ -1400,8 +1400,8 @@ lrbt_cb_table_extensions (void *cls, GNUNET_PQ_result_spec_string ("name", &td.details.extensions.name), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("config", - &td.details.extensions.config), + GNUNET_PQ_result_spec_string ("manifest", + &td.details.extensions.manifest), &no_config), GNUNET_PQ_result_spec_end }; @@ -1423,33 +1423,95 @@ lrbt_cb_table_extensions (void *cls, /** - * Function called with extension_details table entries. + * Function called with policy_details 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_extension_details (void *cls, - PGresult *result, - unsigned int num_results) +lrbt_cb_table_policy_details (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_POLICY_DETAILS + }; + + 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), + GNUNET_PQ_result_spec_auto_from_type ("serial_id", + &td.details.policy_details. + serial_id), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("policy_options", + &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_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 policy_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_fulfilments (void *cls, + PGresult *result, + unsigned int num_results) { struct LookupRecordsByTableContext *ctx = cls; struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_EXTENSION_DETAILS + .table = TALER_EXCHANGEDB_RT_POLICY_FULFILMENTS }; for (unsigned int i = 0; i<num_results; i++) { bool no_config = false; + bool no_timestamp = false; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("extension_details_serial_id", + GNUNET_PQ_result_spec_uint64 ("policy_fulfilment_serial_id", &td.serial), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("extension_options", - &td.details.extension_details. - extension_options), + GNUNET_PQ_result_spec_string ("fulfilment_proof", + &td.details.policy_fulfilments. + fulfilment_proof), &no_config), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("fulfilment_timestamp", + &td.details.policy_fulfilments. + fulfilment_timestamp), + &no_timestamp), GNUNET_PQ_result_spec_end }; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index a50cbcfc..34ff0bd5 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -2993,11 +2993,11 @@ prepare_statements (struct PostgresClosure *pg) " LIMIT 1;", 0), GNUNET_PQ_make_prepare ( - "select_serial_by_table_extension_details", + "select_serial_by_table_policy_details", "SELECT" - " extension_details_serial_id AS serial" - " FROM extension_details" - " ORDER BY extension_details_serial_id DESC" + " policy_details_serial_id AS serial" + " FROM policy_details" + " ORDER BY policy_details_serial_id DESC" " LIMIT 1;", 0), GNUNET_PQ_make_prepare ( @@ -3318,8 +3318,8 @@ prepare_statements (struct PostgresClosure *pg) ",wire_salt" ",wire_target_h_payto" ",done" - ",extension_blocked" - ",extension_details_serial_id" + ",policy_blocked" + ",policy_details_serial_id" " FROM deposits" " WHERE deposit_serial_id > $1" " ORDER BY deposit_serial_id ASC;", @@ -3821,8 +3821,8 @@ prepare_statements (struct PostgresClosure *pg) ",coin_sig" ",wire_salt" ",wire_target_h_payto" - ",extension_blocked" - ",extension_details_serial_id" + ",policy_blocked" + ",policy_details_serial_id" ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," " $11, $12, $13, $14, $15, $16, $17);", @@ -3927,14 +3927,24 @@ prepare_statements (struct PostgresClosure *pg) "($1, $2, $3);", 3), GNUNET_PQ_make_prepare ( - "insert_into_table_extension_details", - "INSERT INTO extension_details" - "(extension_details_serial_id" - ",extension_options" + "insert_into_table_policy_details", + "INSERT INTO policy_details" + "(policy_details_serial_id" + ",serial_id" + ",policy_options" + ",fulfilment_serial_id" ") VALUES " - "($1, $2);", - 2), - + "($1, $2, $3, $4);", + 4), + GNUNET_PQ_make_prepare ( + "insert_into_table_policy_fulfilments", + "INSERT INTO policy_fulfilments" + "(policy_fulfilments_serial_id" + ",fulfilment_timestamp" + ",fulfilment_proof" + ") VALUES " + "($1, $2, $3);", + 3), GNUNET_PQ_make_prepare ( "insert_into_table_purse_requests", "INSERT INTO purse_requests" @@ -6230,7 +6240,7 @@ compute_shard (const struct TALER_MerchantPublicKeyP *merchant_pub) * @param deposit deposit operation details * @param known_coin_id row of the coin in the known_coins table * @param h_payto hash of the merchant's bank account details - * @param extension_blocked true if an extension is blocking the wire transfer + * @param policy_blocked true if an extension is blocking the wire transfer * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated) * @param[out] balance_ok set to true if the balance was sufficient * @param[out] in_conflict set to true if the deposit conflicted @@ -6242,7 +6252,7 @@ postgres_do_deposit ( const struct TALER_EXCHANGEDB_Deposit *deposit, uint64_t known_coin_id, const struct TALER_PaytoHashP *h_payto, - bool extension_blocked, + bool policy_blocked, struct GNUNET_TIME_Timestamp *exchange_timestamp, bool *balance_ok, bool *in_conflict) @@ -6264,7 +6274,7 @@ 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 (extension_blocked), + GNUNET_PQ_query_param_bool (policy_blocked), (NULL == deposit->policy_details) ? GNUNET_PQ_query_param_null () : TALER_PQ_query_param_json (deposit->policy_details), @@ -14225,8 +14235,8 @@ postgres_lookup_serial_by_table (void *cls, case TALER_EXCHANGEDB_RT_EXTENSIONS: statement = "select_serial_by_table_extensions"; break; - case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: - statement = "select_serial_by_table_extension_details"; + case TALER_EXCHANGEDB_RT_POLICY_DETAILS: + statement = "select_serial_by_table_policy_details"; break; case TALER_EXCHANGEDB_RT_PURSE_REQUESTS: statement = "select_serial_by_table_purse_requests"; @@ -14437,9 +14447,13 @@ postgres_lookup_records_by_table (void *cls, statement = "select_above_serial_by_table_extensions"; rh = &lrbt_cb_table_extensions; break; - case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: - statement = "select_above_serial_by_table_extension_details"; - rh = &lrbt_cb_table_extension_details; + case TALER_EXCHANGEDB_RT_POLICY_DETAILS: + statement = "select_above_serial_by_table_policy_details"; + rh = &lrbt_cb_table_policy_details; + break; + case TALER_EXCHANGEDB_RT_POLICY_FULFILMENTS: + statement = "select_above_serial_by_table_policy_fulfilments"; + rh = &lrbt_cb_table_policy_fulfilments; break; case TALER_EXCHANGEDB_RT_PURSE_REQUESTS: statement = "select_above_serial_by_table_purse_requests"; @@ -14620,8 +14634,8 @@ postgres_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_EXTENSIONS: rh = &irbt_cb_table_extensions; break; - case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: - rh = &irbt_cb_table_extension_details; + case TALER_EXCHANGEDB_RT_POLICY_DETAILS: + rh = &irbt_cb_table_policy_details; break; case TALER_EXCHANGEDB_RT_PURSE_REQUESTS: rh = &irbt_cb_table_purse_requests; diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql index 1e9b6b16..22130adc 100644 --- a/src/exchangedb/procedures.sql +++ b/src/exchangedb/procedures.sql @@ -510,8 +510,8 @@ CREATE OR REPLACE FUNCTION exchange_do_deposit( IN in_coin_pub BYTEA, IN in_coin_sig BYTEA, IN in_shard INT8, - IN in_extension_blocked BOOLEAN, - IN in_extension_details VARCHAR, + IN in_policy_blocked BOOLEAN, + IN in_policy_details VARCHAR, OUT out_exchange_timestamp INT8, OUT out_balance_ok BOOLEAN, OUT out_conflict BOOLEAN) @@ -522,18 +522,18 @@ DECLARE DECLARE xdi INT8; -- eXstension details serial id BEGIN --- Shards: INSERT extension_details (by extension_details_serial_id) +-- Shards: INSERT policy_details (by policy_details_serial_id) -- INSERT wire_targets (by h_payto), on CONFLICT DO NOTHING; -- INSERT deposits (by coin_pub, shard), ON CONFLICT DO NOTHING; -- UPDATE known_coins (by coin_pub) -IF NOT NULL in_extension_details +IF NOT NULL in_policy_details THEN - INSERT INTO exchange.extension_details - (extension_options) + INSERT INTO exchange.policy_details + (policy_options) VALUES - (in_extension_details) - RETURNING extension_details_serial_id INTO xdi; + (in_policy_details) + RETURNING policy_details_serial_id INTO xdi; ELSE xdi=NULL; END IF; @@ -572,8 +572,8 @@ INSERT INTO exchange.deposits ,coin_sig ,wire_salt ,wire_target_h_payto - ,extension_blocked - ,extension_details_serial_id + ,policy_blocked + ,policy_details_serial_id ) VALUES (in_shard @@ -590,7 +590,7 @@ INSERT INTO exchange.deposits ,in_coin_sig ,in_wire_salt ,in_h_payto - ,in_extension_blocked + ,in_policy_blocked ,xdi) ON CONFLICT DO NOTHING; |