summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-06-12 20:58:45 +0200
committerChristian Grothoff <christian@grothoff.org>2020-06-12 20:58:45 +0200
commit2c1a8504ccc3708d5bd7f8932cdadd4925a9172d (patch)
treeb6f3dd01e6ae596e7a308d843ddbbb35b775d183 /src/backenddb
parented7142edea9ecb6b57a72afb817bc37cabcb3fa6 (diff)
downloadmerchant-2c1a8504ccc3708d5bd7f8932cdadd4925a9172d.tar.gz
merchant-2c1a8504ccc3708d5bd7f8932cdadd4925a9172d.tar.bz2
merchant-2c1a8504ccc3708d5bd7f8932cdadd4925a9172d.zip
work on missing functions
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c257
1 files changed, 249 insertions, 8 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 70ff62ca..2fb1611f 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -2057,6 +2057,96 @@ postgres_lookup_payment_status (void *cls,
/**
+ * Closure for lookup_deposits_by_order_cb().
+ */
+struct LookupDepositsByOrderContext
+{
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Function to call with all results.
+ */
+ TALER_MERCHANTDB_DepositedCoinsCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Set to the query 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 LookupDepositsByOrderContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_deposits_by_order_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupDepositsByOrderContext *ldoc = cls;
+ struct PostgresClosure *pg = ldoc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t deposit_serial;
+ char *exchange_url;
+ struct GNUNET_HashCode h_wire;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount deposit_fee;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("deposit_serial",
+ &deposit_serial),
+ GNUNET_PQ_result_spec_string ("exchange_url",
+ &exchange_url),
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
+ &h_wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee",
+ &deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ldoc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ ldoc->qs = i + 1;
+ ldoc->cb (ldoc->cb_cls,
+ deposit_serial,
+ exchange_url,
+ &h_wire,
+ &amount_with_fee,
+ &deposit_fee,
+ &coin_pub);
+ GNUNET_PQ_cleanup_result (rs); /* technically useless here */
+ }
+}
+
+
+/**
* Retrieve details about coins that were deposited for an order.
*
* @param cls closure
@@ -2071,7 +2161,117 @@ postgres_lookup_deposits_by_order (void *cls,
TALER_MERCHANTDB_DepositedCoinsCallback cb,
void *cb_cls)
{
- // FIXME
+ struct PostgresClosure *pg = cls;
+ struct LookupDepositsByOrderContext ldoc = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&order_serial),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_deposits_by_order",
+ params,
+ &lookup_deposits_by_order_cb,
+ &ldoc);
+ if (qs < 0)
+ return qs;
+ return ldoc.qs;
+}
+
+
+/**
+ * Closure for lookup_deposits_by_order_cb().
+ */
+struct LookupTransferDetailsByOrderContext
+{
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Function to call with all results.
+ */
+ TALER_MERCHANTDB_OrderTransferDetailsCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Set to the query 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 LookupTransferDetailsByOrderContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_transfer_details_by_order_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupTransferDetailsByOrderContext *ltdo = cls;
+ struct PostgresClosure *pg = ltdo->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *exchange_url;
+ uint64_t deposit_serial;
+ struct GNUNET_TIME_Absolute execution_time;
+ struct TALER_Amount deposit_value;
+ struct TALER_Amount deposit_fee;
+ uint8_t transfer_confirmed;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("deposit_serial",
+ &deposit_serial),
+ GNUNET_PQ_result_spec_string ("exchange_url",
+ &exchange_url),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ &wtid),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_value",
+ &deposit_value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee",
+ &deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_confirmed",
+ &transfer_confirmed),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ltdo->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ ltdo->qs = i + 1;
+ ltdo->cb (ltdo->cb_cls,
+ &wtid,
+ exchange_url,
+ execution_time,
+ &deposit_value,
+ &deposit_fee,
+ (0 != transfer_confirmed));
+ GNUNET_PQ_cleanup_result (rs); /* technically useless here */
+ }
}
@@ -2092,7 +2292,27 @@ postgres_lookup_transfer_details_by_order (
TALER_MERCHANTDB_OrderTransferDetailsCallback cb,
void *cb_cls)
{
- // FIXME
+ struct PostgresClosure *pg = cls;
+ struct LookupTransferDetailsByOrderContext ltdo = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&order_serial),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "lookup_transfer_details_by_order",
+ params,
+ &lookup_transfer_details_by_order_cb,
+ &ltdo);
+ if (qs < 0)
+ return qs;
+ return ltdo.qs;
}
@@ -2105,12 +2325,25 @@ postgres_lookup_transfer_details_by_order (
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
-postgres_insert_deposit_to_transfer (void *cls,
- uint64_t deposit_serial,
- const struct
- TALER_EXCHANGE_DepositData *dd)
+postgres_insert_deposit_to_transfer (
+ void *cls,
+ uint64_t deposit_serial,
+ const struct TALER_EXCHANGE_DepositData *dd)
{
- // FIXME: not implemented yet!
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&deposit_serial),
+ GNUNET_PQ_query_param_auto_from_type (&dd->exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (&dd->exchange_sig),
+ GNUNET_PQ_query_param_auto_from_type (&dd->wtid),
+ GNUNET_PQ_query_param_absolute_time (&dd->execution_time),
+ TALER_PQ_query_param_amount (&dd->coin_contribution),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_deposit_to_transfer",
+ params);
}
@@ -2125,7 +2358,15 @@ static enum GNUNET_DB_QueryStatus
postgres_mark_order_wired (void *cls,
uint64_t order_serial)
{
- // FIXME: not implemented yet!
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&order_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "mark_order_wired",
+ params);
}