[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 156/277: implement lookup tip details
From: |
gnunet |
Subject: |
[taler-merchant] 156/277: implement lookup tip details |
Date: |
Sun, 05 Jul 2020 20:51:09 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit e0991aa684c7a4e9895834286dfdf98007e8cfa6
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat May 30 12:48:57 2020 +0200
implement lookup tip details
---
.../taler-merchant-httpd_private-get-tips-ID.c | 4 +-
src/backenddb/plugin_merchantdb_postgres.c | 167 +++++++++++++++++++--
src/include/taler_merchantdb_plugin.h | 17 +--
3 files changed, 161 insertions(+), 27 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.c
b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
index 6276189..fc9ef06 100644
--- a/src/backend/taler-merchant-httpd_private-get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
@@ -125,13 +125,11 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler
*rh,
{
json_array_append_new (
pickups_json,
- json_pack ("{s:o,s:o,s:o,s:I}",
+ json_pack ("{s:o,s:o,s:I}",
"pickup_id",
GNUNET_JSON_from_data_auto (&pickups[i].pickup_id),
"requested_amount",
TALER_JSON_from_amount (&pickups[i].requested_amount),
- "exchange_amount",
- TALER_JSON_from_amount (&pickups[i].exchange_amount),
"num_planchets",
(json_int_t) pickups[i].num_planchets));
}
diff --git a/src/backenddb/plugin_merchantdb_postgres.c
b/src/backenddb/plugin_merchantdb_postgres.c
index 756071a..a0490c5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4708,6 +4708,82 @@ postgres_lookup_tip (void *cls,
}
+/**
+ * Closure for #lookup_pickup_details_cb().
+ */
+struct LookupTipDetailsContext
+{
+ /**
+ * Length of the @e sigs array
+ */
+ unsigned int *pickups_length;
+
+ /**
+ * Where to store the signatures.
+ */
+ struct TALER_MERCHANTDB_PickupDetails **pickups;
+
+ /**
+ * Database handle.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Transaction status.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about pickups.
+ *
+ * @param[in,out] cls of type `struct LookupTipDetailsContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_pickup_details_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupTipDetailsContext *ltdc = cls;
+ struct PostgresClosure *pg = ltdc->pg;
+
+ *ltdc->pickups_length = num_results;
+ *ltdc->pickups = GNUNET_new_array (num_results,
+ struct TALER_MERCHANTDB_PickupDetails);
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_MERCHANTDB_PickupDetails *pd = &((*ltdc->pickups)[i]);
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("pickup_id",
+ &pd->pickup_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &pd->requested_amount),
+ GNUNET_PQ_result_spec_uint32 ("num_planchets",
+ &pd->num_planchets),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_array_grow (*ltdc->pickups,
+ *ltdc->pickups_length,
+ 0);
+ return;
+ }
+ }
+}
+
+
/**
* Lookup tip details for tip @a tip_id.
*
@@ -4723,17 +4799,11 @@ postgres_lookup_tip (void *cls,
* @param[out] pickups_length set to the length of @e pickups
* @param[out] pickups if @a fpu is true, set to details about the pickup
operations
* @return transaction status,
- * #TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED if the reserve is known but
has expired
- * #TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN if the reserve is not known
- * #TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS if the reserve has
insufficient funds left
- * #TALER_EC_TIP_AUTHORIZE_DB_HARD_ERROR on hard DB errors
- * #TALER_EC_TIP_AUTHORIZE_DB_SOFT_ERROR on soft DB errors (client should
retry)
- * #TALER_EC_NONE upon success
*/
-static enum TALER_ErrorCode
+static enum GNUNET_DB_QueryStatus
postgres_lookup_tip_details (void *cls,
const char *instance_id,
- const struct GNUNET_HashCode tip_id,
+ const struct GNUNET_HashCode *tip_id,
bool fpu,
struct TALER_Amount *total_authorized,
struct TALER_Amount *total_picked_up,
@@ -4743,7 +4813,66 @@ postgres_lookup_tip_details (void *cls,
unsigned int *pickups_length,
struct TALER_MERCHANTDB_PickupDetails **pickups)
{
- // FIXME!
+ struct PostgresClosure *pg = cls;
+ uint64_t tip_serial;
+ enum GNUNET_DB_QueryStatus qs;
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_auto_from_type (tip_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("tip_serial",
+ &tip_serial),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ total_authorized),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("picked_up",
+ total_picked_up),
+ GNUNET_PQ_result_spec_string ("justification",
+ justification),
+ GNUNET_PQ_result_spec_absolute_time ("expiration",
+ expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ reserve_pub),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_tip_details",
+ params,
+ rs);
+ if (qs <= 0)
+ return qs;
+ if (! fpu)
+ {
+ *pickups_length = 0;
+ *pickups = NULL;
+ return qs;
+ }
+ }
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&tip_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ struct LookupTipDetailsContext ltdc = {
+ .pickups_length = pickups_length,
+ .pickups = pickups,
+ .pg = pg
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_pickup_details",
+ params,
+ &lookup_pickup_details_cb,
+ <dc);
+ if (qs <= 0)
+ return qs;
+ return ltdc.qs;
+ }
}
@@ -7618,7 +7747,25 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" WHERE merchant_id=$1)",
2),
/* for postgres_lookup_tip_details() */
- // FIXME!
+ GNUNET_PQ_make_prepare ("lookup_tip_details",
+ "SELECT"
+ " tip_serial"
+ ",amount_val"
+ ",amount_frac"
+ ",picked_up_val"
+ ",picked_up_frac"
+ ",justification"
+ ",merchant_tips.expiration"
+ ",exchange_url"
+ ",reserve_pub"
+ " FROM merchant_tips"
+ " JOIN merchant_tip_reserves USING
(reserve_serial)"
+ " WHERE tip_id = $2"
+ " AND merchant_serial ="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)",
+ 2),
/* for postgres_lookup_tip_details() */
// FIXME!
diff --git a/src/include/taler_merchantdb_plugin.h
b/src/include/taler_merchantdb_plugin.h
index 3262c35..fe306b7 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -649,11 +649,6 @@ struct TALER_MERCHANTDB_PickupDetails
*/
struct TALER_Amount requested_amount;
- /**
- * Total amount we successfully obtained from the exchange.
- */
- struct TALER_Amount exchange_amount;
-
/**
* Number of planchets involved in the request.
*/
@@ -1755,18 +1750,12 @@ struct TALER_MERCHANTDB_Plugin
* @param[out] reserve_pub set to which reserve is debited
* @param[out] pickups_length set to the length of @e pickups
* @param[out] pickups if @a fpu is true, set to details about the pickup
operations
- * @return transaction status,
- * #TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED if the reserve is known but
has expired
- * #TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN if the reserve is not known
- * #TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS if the reserve has
insufficient funds left
- * #TALER_EC_TIP_AUTHORIZE_DB_HARD_ERROR on hard DB errors
- * #TALER_EC_TIP_AUTHORIZE_DB_SOFT_ERROR on soft DB errors (client
should retry)
- * #TALER_EC_NONE upon success
+ * @return transaction status
*/
- enum TALER_ErrorCode
+ enum GNUNET_DB_QueryStatus
(*lookup_tip_details)(void *cls,
const char *instance_id,
- const struct GNUNET_HashCode tip_id,
+ const struct GNUNET_HashCode *tip_id,
bool fpu,
struct TALER_Amount *total_authorized,
struct TALER_Amount *total_picked_up,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 153/277: fixed test for increase_refund, (continued)
- [taler-merchant] 153/277: fixed test for increase_refund, gnunet, 2020/07/05
- [taler-merchant] 108/277: sketch for GET /transfers cmd, gnunet, 2020/07/05
- [taler-merchant] 134/277: finished writing db tests for products, gnunet, 2020/07/05
- [taler-merchant] 137/277: implement POST /tips/ID/pickup, gnunet, 2020/07/05
- [taler-merchant] 141/277: Merge branch 'protocolV1' of git+ssh://git.taler.net/merchant into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 143/277: more SQL for tips, gnunet, 2020/07/05
- [taler-merchant] 148/277: fixed inventory locking, test code for transfer lookups, gnunet, 2020/07/05
- [taler-merchant] 155/277: fix ftbfs, gnunet, 2020/07/05
- [taler-merchant] 154/277: return creation_time instead of leaving it uninitizlied, mark problematic missing lines, gnunet, 2020/07/05
- [taler-merchant] 158/277: work on tip APIs, gnunet, 2020/07/05
- [taler-merchant] 156/277: implement lookup tip details,
gnunet <=
- [taler-merchant] 159/277: add POST /tips logic, gnunet, 2020/07/05
- [taler-merchant] 164/277: fixed db test building and added test for wire fee storage, gnunet, 2020/07/05
- [taler-merchant] 163/277: implement filter, gnunet, 2020/07/05
- [taler-merchant] 165/277: add logic for activation of reserves to merchant backend DB, gnunet, 2020/07/05
- [taler-merchant] 147/277: added more tests for contract terms, deposits, and transfers, gnunet, 2020/07/05
- [taler-merchant] 160/277: address DB fixes for missing EC values, gnunet, 2020/07/05
- [taler-merchant] 157/277: fix DB use, gnunet, 2020/07/05
- [taler-merchant] 166/277: SQL fixing, gnunet, 2020/07/05
- [taler-merchant] 152/277: wrote db tests for tips/lookups, gnunet, 2020/07/05
- [taler-merchant] 145/277: refactored the existing product and order tests, gnunet, 2020/07/05