summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-06-15 20:49:39 +0200
committerChristian Grothoff <christian@grothoff.org>2022-06-15 20:49:39 +0200
commiteccf37e450918e554425b7a9daef324cdaaa37a5 (patch)
tree5af1d86d3d2bb002d4aac687cdc8bf6c43a33ed2
parent83be3173d4933d00a7826bb05c6a661515b0e6f9 (diff)
downloadexchange-eccf37e450918e554425b7a9daef324cdaaa37a5.tar.gz
exchange-eccf37e450918e554425b7a9daef324cdaaa37a5.tar.bz2
exchange-eccf37e450918e554425b7a9daef324cdaaa37a5.zip
-more DB prep work towards reserve auditing with p2p payments
-rw-r--r--src/auditor/taler-helper-auditor-reserves.c116
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c137
-rw-r--r--src/include/taler_exchangedb_plugin.h121
3 files changed, 370 insertions, 4 deletions
diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c
index 5bfb4853..5ccd06a3 100644
--- a/src/auditor/taler-helper-auditor-reserves.c
+++ b/src/auditor/taler-helper-auditor-reserves.c
@@ -1309,6 +1309,111 @@ verify_reserve_balance (void *cls,
/**
+ * Function called with details about purse deposits that have been made, with
+ * the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param deposit deposit details
+ * @param denom_pub denomination public key of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_deposits (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
+ const struct TALER_DenominationPublicKey *denom_pub)
+{
+ GNUNET_break (0); // FIXME
+ /* Credit purse value (if last op)! */
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called with details about purse
+ * merges that have been made, with
+ * the goal of auditing the purse merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_merged (
+ void *cls,
+ uint64_t rowid,
+ const char *partner_base_url,
+ const struct TALER_Amount *amount,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp merge_timestamp)
+{
+ GNUNET_break (0); // FIXME
+ /* Credit purse value (if last op)! */
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called with details about
+ * account merge requests that have been made, with
+ * the goal of auditing the account merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_account_merged (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ struct TALER_ReserveSignatureP *reserve_sig)
+{
+ GNUNET_break (0); // FIXME
+ /* Debit purse fee */
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called with details about
+ * history requests that have been made, with
+ * the goal of auditing the history request execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_history_request (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *history_fee,
+ const struct GNUNET_TIME_Timestamp ts,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ GNUNET_break (0); // FIXME
+ /* Debit purse fee */
+ return GNUNET_SYSERR;
+}
+
+
+/**
* Analyze reserves for being well-formed.
*
* @param cls NULL
@@ -1410,10 +1515,10 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-#if FIXME
+ /* Credit purse value (if last op)! */
qs = TALER_ARL_edb->select_purse_merges_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_purse_merge_serial_id,
+ ppr.last_purse_merges_serial_id,
&handle_purse_merged,
&rc);
if (qs < 0)
@@ -1421,7 +1526,6 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-
qs = TALER_ARL_edb->select_purse_deposits_above_serial_id (
TALER_ARL_edb->cls,
ppr.last_purse_deposits_serial_id,
@@ -1432,9 +1536,10 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
+ /* Charge purse fee! */
qs = TALER_ARL_edb->select_account_merges_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_account_merge_serial_id,
+ ppr.last_account_merges_serial_id,
&handle_account_merged,
&rc);
if (qs < 0)
@@ -1442,6 +1547,7 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
+ /* Charge history fee! */
qs = TALER_ARL_edb->select_history_requests_above_serial_id (
TALER_ARL_edb->cls,
ppr.last_history_requests_serial_id,
@@ -1452,6 +1558,8 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
+#if FIXME
+ /* TODO: do we even care about these? */
qs = TALER_ARL_edb->select_close_requests_above_serial_id (
TALER_ARL_edb->cls,
ppr.last_close_requests_serial_id,
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 20b3ba36..eab50e10 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1521,6 +1521,71 @@ prepare_statements (struct PostgresClosure *pg)
" )"
" ORDER BY purse_deposit_serial_id ASC;",
1),
+
+ GNUNET_PQ_make_prepare (
+ "audit_get_account_merges_incr",
+ "SELECT"
+ " am.account_merge_request_serial_id"
+ ",am.reserve_pub"
+ ",am.purse_pub"
+ ",pr.h_contract_terms"
+ ",pr.purse_expiration"
+ ",pr.amount_with_fee_val"
+ ",pr.amount_with_fee_frac"
+ ",pr.age_limit"
+ ",pr.flags"
+ ",pr.purse_fee_val"
+ ",pr.purse_fee_frac"
+ ",pm.merge_timestamp"
+ ",am.reserve_sig"
+ " FROM account_merges am"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " JOIN purse_merges pm USING (purse_pub)"
+ " WHERE ("
+ " (account_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY account_merge_request_serial_id ASC;",
+ 1),
+
+ GNUNET_PQ_make_prepare (
+ "audit_get_purse_merges_incr",
+ "SELECT"
+ " pm.purse_merge_request_serial_id"
+ ",partner_base_url"
+ ",pr.amount_with_fee_val"
+ ",pr.amount_with_fee_frac"
+ ",pr.flags"
+ ",pr.merge_pub"
+ ",pm.reserve_pub"
+ ",pm.merge_sig"
+ ",pm.purse_pub"
+ ",pm.merge_timestamp"
+ " FROM purse_merges pm"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " LEFT JOIN partners USING (partner_serial_id)"
+ " WHERE ("
+ " (purse_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_merge_request_serial_id ASC;",
+ 1),
+
+ GNUNET_PQ_make_prepare (
+ "audit_get_history_requests_incr",
+ "SELECT"
+ " history_request_serial_id"
+ ",history_fee_val"
+ ",history_fee_frac"
+ ",request_timestamp"
+ ",reserve_pub"
+ ",reserve_sig"
+ " FROM history_requests"
+ " WHERE ("
+ " (history_request_serial_id>=$1)"
+ " )"
+ " ORDER BY history_request_serial_id ASC;",
+ 1),
+
+
GNUNET_PQ_make_prepare (
"audit_get_purse_deposits_by_purse",
"SELECT"
@@ -10559,6 +10624,72 @@ postgres_select_purse_deposits_above_serial_id (
/**
+ * Select account merges above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_select_account_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback cb,
+ void *cb_cls)
+{
+ GNUNET_break (0); // FIXME: not implemented
+ return GNUNET_DB_STATUS_HARD_ERROR;
+}
+
+
+/**
+ * Select purse merges deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_select_purse_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback cb,
+ void *cb_cls)
+{
+ GNUNET_break (0); // FIXME: not implemented
+ return GNUNET_DB_STATUS_HARD_ERROR;
+}
+
+
+/**
+ * Select history requests above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_select_history_requests_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_HistoryRequestCallback cb,
+ void *cb_cls)
+{
+ GNUNET_break (0); // FIXME: not implemented
+ return GNUNET_DB_STATUS_HARD_ERROR;
+}
+
+
+/**
* Closure for #purse_refund_serial_helper_cb().
*/
struct PurseRefundSerialContext
@@ -15553,6 +15684,12 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_select_deposits_above_serial_id;
plugin->select_purse_deposits_above_serial_id
= &postgres_select_purse_deposits_above_serial_id;
+ plugin->select_account_merges_above_serial_id
+ = &postgres_select_account_merges_above_serial_id;
+ plugin->select_purse_merges_above_serial_id
+ = &postgres_select_purse_merges_above_serial_id;
+ plugin->select_history_requests_above_serial_id
+ = &postgres_select_history_requests_above_serial_id;
plugin->select_purse_refunds_above_serial_id
= &postgres_select_purse_refunds_above_serial_id;
plugin->select_purse_deposits_by_purse
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index eaac5cd3..afd850ad 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -2002,6 +2002,73 @@ typedef enum GNUNET_GenericReturnValue
/**
+ * Function called with details about
+ * account merge requests that have been made, with
+ * the goal of auditing the account merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_AccountMergeCallback)(
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
+ * Function called with details about purse
+ * merges that have been made, with
+ * the goal of auditing the purse merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseMergeCallback)(
+ void *cls,
+ uint64_t rowid,
+ const char *partner_base_url,
+ const struct TALER_Amount *amount,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp merge_timestamp);
+
+
+/**
+ * Function called with details about
+ * history requests that have been made, with
+ * the goal of auditing the history request execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_HistoryRequestCallback)(
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *history_fee,
+ const struct GNUNET_TIME_Timestamp ts,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
* Function called with details about purse refunds that have been made, with
* the goal of auditing the purse refund's execution.
*
@@ -4102,6 +4169,60 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Select account merges above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_account_merges_above_serial_id)(
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Select purse merges deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_purse_merges_above_serial_id)(
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Select history requests above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_history_requests_above_serial_id)(
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_HistoryRequestCallback cb,
+ void *cb_cls);
+
+
+ /**
* Select purse refunds above @a serial_id in monotonically increasing
* order.
*