summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-07-31 21:54:29 +0200
committerChristian Grothoff <christian@grothoff.org>2022-07-31 21:54:29 +0200
commit31bfe5234e9f1031306ce7cfae9a8a3fee5aa304 (patch)
tree0cda3cc1ef29226156c2774cd1d9f6f1957c495d
parentaf6a9a95469f98172c53ca10167210d41803bfb9 (diff)
downloadexchange-31bfe5234e9f1031306ce7cfae9a8a3fee5aa304.tar.gz
exchange-31bfe5234e9f1031306ce7cfae9a8a3fee5aa304.tar.bz2
exchange-31bfe5234e9f1031306ce7cfae9a8a3fee5aa304.zip
-update auditor schema in preparation to fix #4960
-rw-r--r--src/auditordb/auditor-0001.sql4
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c30
-rw-r--r--src/auditordb/test_auditordb.c19
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c68
-rw-r--r--src/include/taler_auditordb_plugin.h12
-rw-r--r--src/include/taler_exchangedb_plugin.h24
6 files changed, 143 insertions, 14 deletions
diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql
index 233ad6864..483f4f1e3 100644
--- a/src/auditordb/auditor-0001.sql
+++ b/src/auditordb/auditor-0001.sql
@@ -267,9 +267,11 @@ CREATE TABLE IF NOT EXISTS auditor_predicted_result
(master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
,balance_val INT8 NOT NULL
,balance_frac INT4 NOT NULL
+ ,drained_val INT8 NOT NULL
+ ,drained_frac INT4 NOT NULL
);
COMMENT ON TABLE auditor_predicted_result
- IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance. This is the final amount that the exchange should have in its bank account right now.';
+ IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance and the drained profits. This is the final amount that the exchange should have in its bank account right now (and the total amount drained as profits to non-escrow accounts).';
-- Finally, commit everything
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 8ddfbee68..46c2eb1ef 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -670,20 +670,26 @@ setup_connection (struct PostgresClosure *pg)
"(master_pub"
",balance_val"
",balance_frac"
- ") VALUES ($1,$2,$3);",
- 3),
+ ",drained_val"
+ ",drained_frac"
+ ") VALUES ($1,$2,$3,$4,$5);",
+ 5),
/* Used in #postgres_update_predicted_result() */
GNUNET_PQ_make_prepare ("auditor_predicted_result_update",
"UPDATE auditor_predicted_result SET"
" balance_val=$1"
",balance_frac=$2"
- " WHERE master_pub=$3;",
- 3),
+ ",drained_val=$3"
+ ",drained_frac=$4"
+ " WHERE master_pub=$5;",
+ 5),
/* Used in #postgres_get_predicted_balance() */
GNUNET_PQ_make_prepare ("auditor_predicted_result_select",
"SELECT"
" balance_val"
",balance_frac"
+ ",drained_val"
+ ",drained_frac"
" FROM auditor_predicted_result"
" WHERE master_pub=$1;",
1),
@@ -2833,18 +2839,21 @@ postgres_select_historic_reserve_revenue (
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param balance what the bank account balance of the exchange should show
+ * @param drained amount that was drained in profits
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_insert_predicted_result (
void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance)
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *drained)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_amount (drained),
GNUNET_PQ_query_param_end
};
@@ -2861,17 +2870,20 @@ postgres_insert_predicted_result (
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param balance what the bank account balance of the exchange should show
+ * @param drained amount that was drained in profits
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_update_predicted_result (
void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance)
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *drained)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (balance),
+ TALER_PQ_query_param_amount (drained),
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
@@ -2888,12 +2900,14 @@ postgres_update_predicted_result (
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param[out] balance expected bank account balance of the exchange
+ * @param[out] drained amount drained so far
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_get_predicted_balance (void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance)
+ struct TALER_Amount *balance,
+ struct TALER_Amount *drained)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -2903,6 +2917,8 @@ postgres_get_predicted_balance (void *cls,
struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("drained",
+ drained),
GNUNET_PQ_result_spec_end
};
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
index f2fad2bc6..1e5ca7553 100644
--- a/src/auditordb/test_auditordb.c
+++ b/src/auditordb/test_auditordb.c
@@ -347,7 +347,9 @@ run (void *cls)
struct TALER_Amount melt_fee_balance2;
struct TALER_Amount refund_fee_balance2;
struct TALER_Amount rbalance;
+ struct TALER_Amount dbalance;
struct TALER_Amount rbalance2;
+ struct TALER_Amount dbalance2;
struct TALER_Amount loss;
struct TALER_Amount loss2;
struct TALER_Amount iirp;
@@ -373,6 +375,9 @@ run (void *cls)
TALER_string_to_amount (CURRENCY ":13.57986",
&rbalance));
GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":12.57986",
+ &dbalance));
+ GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":1.6",
&loss));
GNUNET_assert (GNUNET_OK ==
@@ -613,7 +618,8 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_predicted_result (plugin->cls,
&master_pub,
- &rbalance));
+ &rbalance,
+ &dbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_predicted_result\n");
@@ -621,11 +627,15 @@ run (void *cls)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":78.901234",
&rbalance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":73.901234",
+ &dbalance));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->update_predicted_result (plugin->cls,
&master_pub,
- &rbalance));
+ &rbalance,
+ &dbalance));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_wire_fee_summary (plugin->cls,
@@ -659,7 +669,8 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_predicted_balance (plugin->cls,
&master_pub,
- &rbalance2));
+ &rbalance2,
+ &dbalance2));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->del_reserve_info (plugin->cls,
@@ -668,6 +679,8 @@ run (void *cls)
FAILIF (0 != TALER_amount_cmp (&rbalance2,
&rbalance));
+ FAILIF (0 != TALER_amount_cmp (&dbalance2,
+ &dbalance));
plugin->rollback (plugin->cls);
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 5adb9d62b..f08c1184a 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -706,6 +706,20 @@ prepare_statements (struct PostgresClosure *pg)
" WHERE NOT executed"
" ORDER BY trigger_date ASC;",
0),
+ /* Used in #postgres_profit_drains_get() */
+ GNUNET_PQ_make_prepare (
+ "get_profit_drain",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount_val"
+ ",amount_frac"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE wtid=$1;",
+ 1),
/* Used in #postgres_profit_drains_set_finished() */
GNUNET_PQ_make_prepare (
"drain_profit_set_finished",
@@ -16323,6 +16337,58 @@ postgres_profit_drains_get_pending (
/**
+ * Function called to get information about a profit drain event.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to look up drain event for
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_get_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
+ serial),
+ GNUNET_PQ_result_spec_string ("account_section",
+ account_section),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ GNUNET_PQ_result_spec_timestamp ("trigger_date",
+ request_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ amount),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_profit_drain",
+ params,
+ rs);
+}
+
+
+/**
* Set profit drain operation to finished.
*
* @param cls the @e cls of this struct with the plugin-specific state
@@ -16666,6 +16732,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_insert_drain_profit;
plugin->profit_drains_get_pending
= &postgres_profit_drains_get_pending;
+ plugin->get_drain_profit
+ = &postgres_get_drain_profit;
plugin->profit_drains_set_finished
= &postgres_profit_drains_set_finished;
return plugin;
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index 0c01d1c47..dff96700f 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -1335,12 +1335,14 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param balance what the bank account balance of the exchange should show
+ * @param drained_profits total profits drained by the exchange so far
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*insert_predicted_result)(void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance);
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *drained_profits);
/**
@@ -1350,12 +1352,14 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param balance what the bank account balance of the exchange should show
+ * @param drained_profits total profits drained by the exchange so far
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*update_predicted_result)(void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance);
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *drained_profits);
/**
@@ -1364,12 +1368,14 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param master_pub master key of the exchange
* @param[out] balance expected bank account balance of the exchange
+ * @param[out] drained_profits total profits drained by the exchange so far
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*get_predicted_balance)(void *cls,
const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance);
+ struct TALER_Amount *balance,
+ struct TALER_Amount *drained_profits);
};
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 2ffa84866..5a5e8cab2 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -5546,6 +5546,30 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Function called to get information about a profit drain event.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to look up drain event for
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_drain_profit)(void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+
+ /**
* Get profit drain operation ready to execute.
*
* @param cls the @e cls of this struct with the plugin-specific state