summaryrefslogtreecommitdiff
path: root/src/auditordb
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditordb')
-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
3 files changed, 42 insertions, 11 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);