summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-07 20:14:02 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-07 20:14:02 +0200
commit1c14e3319d3f82363a3bfd935410748eb8afb597 (patch)
tree2fa196ffdf27aaf64c4d0e16493f9fcd6328b9e0 /src/backenddb/plugin_merchantdb_postgres.c
parent4344f16b33bad868e8aea32f4921640950068332 (diff)
downloadmerchant-1c14e3319d3f82363a3bfd935410748eb8afb597.tar.gz
merchant-1c14e3319d3f82363a3bfd935410748eb8afb597.tar.bz2
merchant-1c14e3319d3f82363a3bfd935410748eb8afb597.zip
more work on post /transfers and the like
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c177
1 files changed, 174 insertions, 3 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index acb32e9b..60cbc7a5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1683,6 +1683,7 @@ postgres_insert_exchange_signkey (
*
* @param cls closure
* @param instance_id instance to lookup deposits for
+ * @param deposit_timestamp time when the exchange generated the deposit confirmation
* @param h_contract_terms proposal data's hashcode
* @param coin_pub public key of the coin
* @param exchange_url URL of the exchange that issued @a coin_pub
@@ -1698,6 +1699,7 @@ postgres_insert_exchange_signkey (
static enum GNUNET_DB_QueryStatus
postgres_insert_deposit (void *cls,
const char *instance_id,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
@@ -1710,11 +1712,10 @@ postgres_insert_deposit (void *cls,
const struct TALER_ExchangePublicKeyP *exchange_pub)
{
struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_absolute_time (&now), /* $3 */
+ GNUNET_PQ_query_param_absolute_time (&deposit_timestamp), /* $3 */
GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_string (exchange_url),
TALER_PQ_query_param_amount (amount_with_fee), /* $6/$7 */
@@ -2557,7 +2558,7 @@ postgres_lookup_refunds_detailed (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (instance_id),
+ GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
GNUNET_PQ_query_param_end
};
@@ -2960,6 +2961,173 @@ postgres_lookup_wire_fee (void *cls,
}
+/**
+ * Closure for #lookup_deposits_by_contract_and_coin_cb().
+ */
+struct LookupDepositsByCnCContext
+{
+ /**
+ * Function to call for each deposit.
+ */
+ TALER_MERCHANTDB_CoinDepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Transaction result.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls of type `struct LookupDepositsByCnCContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_deposits_by_contract_and_coin_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupDepositsByCnCContext *ldcc = cls;
+ struct PostgresClosure *pg = ldcc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ // WIP!
+ uint64_t refund_serial;
+ struct GNUNET_TIME_Absolute timestamp;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ uint64_t rtransaction_id;
+ struct TALER_Amount refund_amount;
+ char *reason;
+ char *exchange_url;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("refund_serial",
+ &refund_serial),
+ GNUNET_PQ_result_spec_absolute_time ("refund_timestamp",
+ &timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_string ("exchange_url",
+ &exchange_url),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &rtransaction_id),
+ GNUNET_PQ_result_spec_string ("reason",
+ &reason),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("refund_amount",
+ &refund_amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ lrdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ ldcc->qs = i + 1;
+ ldcc->rc (ldcc->rc_cls,
+ ...);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Lookup information about coin payments by @a h_contract_terms and
+ * @a coin_pub.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup payments for
+ * @param h_contract_terms proposal data's hashcode
+ * @param coin_pub public key to use for the search
+ * @param cb function to call with payment data
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_deposits_by_contract_and_coin (
+ void *cls,
+ const char *instance_id,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ TALER_MERCHANTDB_CoinDepositCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string_type (instance_id),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct LookupDepositsByCnCContext ldcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_deposits_by_contract_and_coin",
+ params,
+ &
+ lookup_deposits_by_contract_and_coin_cb,
+ &ldcc);
+ if (0 >= qs)
+ return qs;
+ return ldcc.qs;
+}
+
+
+/**
+ * Lookup transfer details.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup payments for
+ * @param exchange_url
+ * @param payto_uri
+ * @param wtid
+ * @param total_amount
+ * @param wire_fee
+ * @param execution_time
+ * @param cb function to call with detailed transfer data
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_transfer_details (
+ void *cls,
+ const char *instance_id,
+ const char *exchange_url,
+ const char *payto_uri,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_Amount *wire_fee,
+ struct GNUNET_TIME_Absolute execution_time,
+ TALER_MERCHANTDB_TransferDetailsCallback cb,
+ void *cb_cls)
+{
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -6181,6 +6349,9 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->lookup_account = &postgres_lookup_account;
plugin->insert_transfer_details = &postgres_insert_transfer_details;
plugin->lookup_wire_fee = &postgres_lookup_wire_fee;
+ plugin->lookup_deposits_by_contract_and_coin =
+ &postgres_lookup_deposits_by_contract_and_coin;
+ plugin->lookup_transfer_details = &postgres_lookup_transfer_details;
/* OLD API: */
plugin->store_coin_to_transfer = &postgres_store_coin_to_transfer;