aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-07-30 10:12:48 +0200
committerChristian Grothoff <christian@grothoff.org>2022-07-30 10:12:48 +0200
commit75888adff2549fc8fa9aec9b4e80a37a214345e6 (patch)
tree1f1a3347af6f11187a7f1143348cacbaea0a2caa /src
parentba0ab58cdd4bd767f3944dcde1dc16676220d136 (diff)
setup drain_profits table (#4960)
Diffstat (limited to 'src')
-rw-r--r--src/exchange/taler-exchange-httpd_management_drain.c4
-rw-r--r--src/exchangedb/exchange-0001-part.sql31
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c54
-rw-r--r--src/include/taler_exchangedb_plugin.h22
4 files changed, 107 insertions, 4 deletions
diff --git a/src/exchange/taler-exchange-httpd_management_drain.c b/src/exchange/taler-exchange-httpd_management_drain.c
index a611b83ab..565c292f4 100644
--- a/src/exchange/taler-exchange-httpd_management_drain.c
+++ b/src/exchange/taler-exchange-httpd_management_drain.c
@@ -92,7 +92,6 @@ drain (void *cls,
struct DrainContext *dc = cls;
enum GNUNET_DB_QueryStatus qs;
-#if 0
qs = TEH_plugin->insert_drain_profit (
TEH_plugin->cls,
&dc->wtid,
@@ -101,9 +100,6 @@ drain (void *cls,
dc->date,
&dc->amount,
&dc->master_sig);
-#else
- qs = -1;
-#endif
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index 60b45b440..97f5829e6 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -63,6 +63,37 @@ COMMENT ON TABLE denomination_revocations
IS 'remembering which denomination keys have been revoked';
+-- ------------------------------ profit drains ----------------------------------------
+
+CREATE TABLE IF NOT EXISTS profit_drains
+ (profit_drain_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,wtid BYTEA PRIMARY KEY CHECK (LENGTH(wtid)=32)
+ ,account_section VARCHAR NOT NULL
+ ,payto_uri VARCHAR NOT NULL
+ ,trigger_date INT8 NOT NULL
+ ,amount_val INT8 NOT NULL
+ ,amount_frac INT8 NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,executed BOOLEAN NOT NULL DEFAULT FALSE
+ );
+COMMENT ON TABLE profit_drains
+ IS 'transactions to be performed to move profits from the escrow account of the exchange to a regular account';
+COMMENT ON COLUMN profit_drains.wtid
+ IS 'randomly chosen nonce, unique to prevent double-submission';
+COMMENT ON COLUMN profit_drains.account_section
+ IS 'specifies the configuration section in the taler-exchange-drain configuration with the wire account to drain';
+COMMENT ON COLUMN profit_drains.payto_uri
+ IS 'specifies the account to be credited';
+COMMENT ON COLUMN profit_drains.trigger_date
+ IS 'set by taler-exchange-offline at the time of making the signature; not necessarily the exact date of execution of the wire transfer, just for orientation';
+COMMENT ON COLUMN profit_drains.amount_val
+ IS 'amount to be transferred';
+COMMENT ON COLUMN profit_drains.master_sig
+ IS 'EdDSA signature of type TALER_SIGNATURE_MASTER_DRAIN_PROFIT';
+COMMENT ON COLUMN profit_drains.executed
+ IS 'set to TRUE by taler-exchange-drain on execution of the transaction, not replicated to auditor';
+
+
-- ------------------------------ wire_targets ----------------------------------------
SELECT create_table_wire_targets();
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 9fb9192c7..ca9ae4214 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -677,6 +677,19 @@ prepare_statements (struct PostgresClosure *pg)
",closing_fee_frac"
") VALUES ($1, $2, $3, $4, $5, $6, $7, $8);",
8),
+ /* Used in #postgres_insert_drain_profit() */
+ GNUNET_PQ_make_prepare (
+ "drain_profit_insert",
+ "INSERT INTO profit_drains "
+ "(wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount_val"
+ ",amount_frac"
+ ",master_sig"
+ ") VALUES ($1, $2, $3, $4, $5, $6, $7);",
+ 7),
/* Used in #reserves_update() when the reserve is updated */
GNUNET_PQ_make_prepare (
"reserve_update",
@@ -16147,6 +16160,45 @@ postgres_insert_close_request (
/**
+ * Function called to persist a request to drain profits.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to use
+ * @param account_section account to drain
+ * @param payto_uri account to wire funds to
+ * @param date time of the signature
+ * @param amount amount to wire
+ * @param master_sig signature affirming the opearation
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_insert_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const 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_string (account_section),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_timestamp (&request_timestamp),
+ TALER_PQ_query_param_amount (amount),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "drain_profit_insert",
+ params);
+}
+
+
+/**
* Initialize Postgres database subsystem.
*
* @param cls a configuration instance
@@ -16462,6 +16514,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_insert_history_request;
plugin->insert_close_request
= &postgres_insert_close_request;
+ plugin->insert_drain_profit
+ = &postgres_insert_drain_profit;
return plugin;
}
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index ae221c8cd..41ef75a65 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -5512,6 +5512,28 @@ struct TALER_EXCHANGEDB_Plugin
struct TALER_Amount *final_balance);
+ /**
+ * Function called to persist a request to drain profits.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to use
+ * @param account_section account to drain
+ * @param payto_uri account to wire funds to
+ * @param date time of the signature
+ * @param amount amount to wire
+ * @param master_sig signature affirming the opearation
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_drain_profit)(void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
};
#endif /* _TALER_EXCHANGE_DB_H */