diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-12-17 13:04:37 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-12-17 13:04:37 +0100 |
commit | b74612fc3362e64dcfb7eacad3602025ccfcf5ea (patch) | |
tree | b823ca6aa32f2e9ef5d5b191ab01c36e9a807d5b /src/auditordb | |
parent | ff27037d42625084a0b1fadea073389b530776c4 (diff) |
update auditordb and test logic to work with new key separation logic (#6175)
Diffstat (limited to 'src/auditordb')
-rw-r--r-- | src/auditordb/auditor-0001.sql | 24 | ||||
-rw-r--r-- | src/auditordb/plugin_auditordb_postgres.c | 231 | ||||
-rw-r--r-- | src/auditordb/test_auditordb.c | 61 |
3 files changed, 1 insertions, 315 deletions
diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql index b511a4d5b..3a0d7dd9d 100644 --- a/src/auditordb/auditor-0001.sql +++ b/src/auditordb/auditor-0001.sql @@ -41,28 +41,6 @@ COMMENT ON TABLE auditor_exchange_signkeys IS 'list of the online signing keys of exchanges we are auditing'; -CREATE TABLE IF NOT EXISTS auditor_denominations - (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64) - ,master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE - ,valid_from INT8 NOT NULL - ,expire_withdraw INT8 NOT NULL - ,expire_deposit INT8 NOT NULL - ,expire_legal INT8 NOT NULL - ,coin_val INT8 NOT NULL - ,coin_frac INT4 NOT NULL - ,fee_withdraw_val INT8 NOT NULL - ,fee_withdraw_frac INT4 NOT NULL - ,fee_deposit_val INT8 NOT NULL - ,fee_deposit_frac INT4 NOT NULL - ,fee_refresh_val INT8 NOT NULL - ,fee_refresh_frac INT4 NOT NULL - ,fee_refund_val INT8 NOT NULL - ,fee_refund_frac INT4 NOT NULL - ); -COMMENT ON TABLE auditor_denominations - IS 'denomination keys the auditor is aware of'; - - CREATE TABLE IF NOT EXISTS auditor_progress_reserve (master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE ,last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0 @@ -173,7 +151,7 @@ COMMENT ON TABLE auditor_wire_fee_balance CREATE TABLE IF NOT EXISTS auditor_denomination_pending - (denom_pub_hash BYTEA PRIMARY KEY REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE + (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64) ,denom_balance_val INT8 NOT NULL ,denom_balance_frac INT4 NOT NULL ,denom_loss_val INT8 NOT NULL diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index a475c46e1..151c93ad3 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -221,48 +221,6 @@ postgres_get_session (void *cls) ",master_sig" ") VALUES ($1,$2,$3,$4,$5,$6);", 6), - /* Used in #postgres_insert_denomination_info() */ - GNUNET_PQ_make_prepare ("auditor_denominations_insert", - "INSERT INTO auditor_denominations " - "(denom_pub_hash" - ",master_pub" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin_val" - ",coin_frac" - ",fee_withdraw_val" - ",fee_withdraw_frac" - ",fee_deposit_val" - ",fee_deposit_frac" - ",fee_refresh_val" - ",fee_refresh_frac" - ",fee_refund_val" - ",fee_refund_frac" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);", - 16), - /* Used in #postgres_insert_denomination_info() */ - GNUNET_PQ_make_prepare ("auditor_denominations_select", - "SELECT" - " denom_pub_hash" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin_val" - ",coin_frac" - ",fee_withdraw_val" - ",fee_withdraw_frac" - ",fee_deposit_val" - ",fee_deposit_frac" - ",fee_refresh_val" - ",fee_refresh_frac" - ",fee_refund_val" - ",fee_refund_frac" - " FROM auditor_denominations" - " WHERE master_pub=$1;", - 1), /* Used in #postgres_insert_deposit_confirmation() */ GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_insert", "INSERT INTO deposit_confirmations " @@ -1292,192 +1250,6 @@ postgres_get_deposit_confirmations ( /** - * Insert information about a denomination key and in particular - * the properties (value, fees, expiration times) the coins signed - * with this key have. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param session connection to use - * @param issue issuing information with value, fees and other info about the denomination - * @return operation status result - */ -static enum GNUNET_DB_QueryStatus -postgres_insert_denomination_info ( - void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_DenominationKeyValidityPS *issue) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&issue->denom_hash), - GNUNET_PQ_query_param_auto_from_type (&issue->master), - TALER_PQ_query_param_absolute_time_nbo (&issue->start), - TALER_PQ_query_param_absolute_time_nbo (&issue->expire_withdraw), - TALER_PQ_query_param_absolute_time_nbo (&issue->expire_deposit), - TALER_PQ_query_param_absolute_time_nbo (&issue->expire_legal), - TALER_PQ_query_param_amount_nbo (&issue->value), - TALER_PQ_query_param_amount_nbo (&issue->fee_withdraw), - TALER_PQ_query_param_amount_nbo (&issue->fee_deposit), - TALER_PQ_query_param_amount_nbo (&issue->fee_refresh), - TALER_PQ_query_param_amount_nbo (&issue->fee_refund), - GNUNET_PQ_query_param_end - }; - - (void) cls; - /* check fees match coin currency */ - GNUNET_assert (GNUNET_YES == - TALER_amount_cmp_currency_nbo (&issue->value, - &issue->fee_withdraw)); - GNUNET_assert (GNUNET_YES == - TALER_amount_cmp_currency_nbo (&issue->value, - &issue->fee_deposit)); - GNUNET_assert (GNUNET_YES == - TALER_amount_cmp_currency_nbo (&issue->value, - &issue->fee_refresh)); - GNUNET_assert (GNUNET_YES == - TALER_amount_cmp_currency_nbo (&issue->value, - &issue->fee_refund)); - return GNUNET_PQ_eval_prepared_non_select (session->conn, - "auditor_denominations_insert", - params); -} - - -/** - * Closure for #denomination_info_cb(). - */ -struct DenominationInfoContext -{ - - /** - * Master public key that is being used. - */ - const struct TALER_MasterPublicKeyP *master_pub; - - /** - * Function to call for each denomination. - */ - TALER_AUDITORDB_DenominationInfoDataCallback cb; - - /** - * Closure for @e cb - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Query status to return. - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Helper function for #postgres_select_denomination_info(). - * To be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct DenominationInfoContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -denomination_info_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct DenominationInfoContext *dic = cls; - struct PostgresClosure *pg = dic->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_DenominationKeyValidityPS issue = { - .master = *dic->master_pub - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &issue.denom_hash), - TALER_PQ_result_spec_absolute_time_nbo ("valid_from", &issue.start), - TALER_PQ_result_spec_absolute_time_nbo ("expire_withdraw", - &issue.expire_withdraw), - TALER_PQ_result_spec_absolute_time_nbo ("expire_deposit", - &issue.expire_deposit), - TALER_PQ_result_spec_absolute_time_nbo ("expire_legal", - &issue.expire_legal), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("coin", &issue.value), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_withdraw", &issue.fee_withdraw), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_deposit", &issue.fee_deposit), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refresh", &issue.fee_refresh), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("fee_refund", &issue.fee_refund), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - dic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - dic->qs = i + 1; - if (GNUNET_OK != - dic->cb (dic->cb_cls, - &issue)) - return; - } -} - - -/** - * Get information about denomination keys of a particular exchange. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param session connection to use - * @param master_pub master public key of the exchange - * @param cb function to call with the results - * @param cb_cls closure for @a cb - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_select_denomination_info ( - void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - TALER_AUDITORDB_DenominationInfoDataCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - struct DenominationInfoContext dic = { - .master_pub = master_pub, - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - (void) cls; - qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, - "auditor_denominations_select", - params, - &denomination_info_cb, - &dic); - if (qs > 0) - return dic.qs; - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); - return qs; -} - - -/** * Insert information about the auditor's progress with an exchange's * data. * @@ -3221,9 +2993,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->insert_deposit_confirmation = &postgres_insert_deposit_confirmation; plugin->get_deposit_confirmations = &postgres_get_deposit_confirmations; - plugin->select_denomination_info = &postgres_select_denomination_info; - plugin->insert_denomination_info = &postgres_insert_denomination_info; - plugin->get_auditor_progress_reserve = &postgres_get_auditor_progress_reserve; plugin->update_auditor_progress_reserve = &postgres_update_auditor_progress_reserve; diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c index 201d61b80..69328ee48 100644 --- a/src/auditordb/test_auditordb.c +++ b/src/auditordb/test_auditordb.c @@ -64,25 +64,6 @@ static int result = -1; static struct TALER_AUDITORDB_Plugin *plugin; -static int -select_denomination_info_result (void *cls, - const struct - TALER_DenominationKeyValidityPS *issue2) -{ - const struct TALER_DenominationKeyValidityPS *issue1 = cls; - - if (0 != GNUNET_memcmp (issue1, - issue2)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "select_denomination_info_result: issue does not match\n"); - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; -} - - /** * Main function that will be run by the scheduler. * @@ -189,48 +170,6 @@ run (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Test: insert_denomination_info\n"); - - struct TALER_DenominationKeyValidityPS issue = { 0 }; - issue.master = master_pub; - issue.denom_hash = denom_pub_hash; - - issue.start = GNUNET_TIME_absolute_hton (now); - issue.expire_withdraw = GNUNET_TIME_absolute_hton - (GNUNET_TIME_absolute_add (now, - GNUNET_TIME_UNIT_HOURS)); - issue.expire_deposit = GNUNET_TIME_absolute_hton - (GNUNET_TIME_absolute_add - (now, - GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_HOURS, 2))); - issue.expire_legal = GNUNET_TIME_absolute_hton - (GNUNET_TIME_absolute_add - (now, - GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_HOURS, 3))); - TALER_amount_hton (&issue.value, &value); - TALER_amount_hton (&issue.fee_withdraw, &fee_withdraw); - TALER_amount_hton (&issue.fee_deposit, &fee_deposit); - TALER_amount_hton (&issue.fee_refresh, &fee_refresh); - TALER_amount_hton (&issue.fee_refund, &fee_refund); - - FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->insert_denomination_info (plugin->cls, - session, - &issue)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Test: select_denomination_info\n"); - - FAILIF (0 >= - plugin->select_denomination_info (plugin->cls, - session, - &master_pub, - &select_denomination_info_result, - &issue)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: insert_auditor_progress\n"); struct TALER_AUDITORDB_ProgressPointCoin ppc = { |