summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c172
1 files changed, 114 insertions, 58 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 48e0d63c..f8ef6efb 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1694,8 +1694,6 @@ postgres_delete_order (void *cls,
* @param[out] h_post_data set to the hash of the POST data that created the order
* @param[out] contract_terms where to store the retrieved contract terms,
* NULL to only test if the order exists
- * @param pos_key encoded key for payment verification
- * @param pricing_algorithm to show the price in the payment verification
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
@@ -1704,9 +1702,7 @@ postgres_lookup_order (void *cls,
const char *order_id,
struct TALER_ClaimTokenP *claim_token,
struct TALER_MerchantPostDataHashP *h_post_data,
- json_t **contract_terms,
- char *pos_key,
- uint64_t pricing_algorithm)
+ json_t **contract_terms)
{
struct PostgresClosure *pg = cls;
json_t *j;
@@ -1724,14 +1720,6 @@ postgres_lookup_order (void *cls,
&ct),
GNUNET_PQ_result_spec_auto_from_type ("h_post_data",
h_post_data),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("pos_key",
- &pos_key),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 ("pricing_algorithm",
- &pricing_algorithm),
- NULL),
GNUNET_PQ_result_spec_end
};
@@ -1950,7 +1938,7 @@ postgres_lookup_orders (void *cls,
* @param claim_token token to use for access control
* @param contract_terms proposal data to store
* @param pos_key encoded key for payment verification
- * @param pricing_algorithm to show the price in the payment verification
+ * @param pos_algorithm algorithm to compute the payment verification
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
@@ -1962,10 +1950,11 @@ postgres_insert_order (void *cls,
const struct TALER_ClaimTokenP *claim_token,
const json_t *contract_terms,
const char *pos_key,
- uint64_t pricing_algorithm)
+ enum TALER_MerchantConfirmationAlgorithm pos_algorithm)
{
struct PostgresClosure *pg = cls;
struct GNUNET_TIME_Timestamp now;
+ uint32_t pos32 = (uint32_t) pos_algorithm;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_string (order_id),
@@ -1977,9 +1966,7 @@ postgres_insert_order (void *cls,
(NULL == pos_key)
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_string (pos_key),
- (NULL == pos_key)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_uint64 (&pricing_algorithm),
+ GNUNET_PQ_query_param_uint32 (&pos32),
GNUNET_PQ_query_param_end
};
@@ -2071,15 +2058,16 @@ postgres_insert_order_lock (void *cls,
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
-postgres_lookup_contract_terms (void *cls,
- const char *instance_id,
- const char *order_id,
- json_t **contract_terms,
- uint64_t *order_serial,
- bool *paid,
- struct TALER_ClaimTokenP *claim_token,
- char *pos_key,
- uint64_t pricing_algorithm)
+postgres_lookup_contract_terms2 (
+ void *cls,
+ const char *instance_id,
+ const char *order_id,
+ json_t **contract_terms,
+ uint64_t *order_serial,
+ bool *paid,
+ struct TALER_ClaimTokenP *claim_token,
+ char **pos_key,
+ enum TALER_MerchantConfirmationAlgorithm *pos_algorithm)
{
struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs;
@@ -2089,6 +2077,7 @@ postgres_lookup_contract_terms (void *cls,
GNUNET_PQ_query_param_string (order_id),
GNUNET_PQ_query_param_end
};
+ uint32_t pos32;
struct GNUNET_PQ_ResultSpec rs[] = {
/* contract_terms must be first! */
TALER_PQ_result_spec_json ("contract_terms",
@@ -2101,12 +2090,68 @@ postgres_lookup_contract_terms (void *cls,
&ct),
GNUNET_PQ_result_spec_allow_null (
GNUNET_PQ_result_spec_string ("pos_key",
- &pos_key),
- NULL),
+ pos_key),
+ NULL),
GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint64 ("pricing_algorithm",
- &pricing_algorithm),
- NULL),
+ GNUNET_PQ_result_spec_uint32 ("pos_algorithm",
+ &pos32),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_contract_terms2",
+ params,
+ (NULL != contract_terms)
+ ? rs
+ : &rs[1]);
+ *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32;
+ if (NULL != claim_token)
+ *claim_token = ct;
+ return qs;
+}
+
+
+/**
+ * Retrieve contract terms given its @a order_id
+ *
+ * @param cls closure
+ * @param instance_id instance's identifier
+ * @param order_id order_id used to lookup.
+ * @param[out] contract_terms where to store the result, NULL to only check for existence
+ * @param[out] order_serial set to the order's serial number
+ * @param[out] paid set to true if the order is fully paid
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_contract_terms (
+ void *cls,
+ const char *instance_id,
+ const char *order_id,
+ json_t **contract_terms,
+ uint64_t *order_serial,
+ bool *paid,
+ struct TALER_ClaimTokenP *claim_token)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_ClaimTokenP ct;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_string (order_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ /* contract_terms must be first! */
+ TALER_PQ_result_spec_json ("contract_terms",
+ contract_terms),
+ GNUNET_PQ_result_spec_uint64 ("order_serial",
+ order_serial),
+ GNUNET_PQ_result_spec_bool ("paid",
+ paid),
+ GNUNET_PQ_result_spec_auto_from_type ("claim_token",
+ &ct),
GNUNET_PQ_result_spec_end
};
@@ -2137,18 +2182,17 @@ postgres_lookup_contract_terms (void *cls,
* @param contract_terms contract terms to store
* @param[out] order_serial set to the serial of the order
* @param pos_key encoded key for payment verification
- * @param pricing_algorithm to show the price in the payment verification
+ * @param pos_algorithm algorithm to compute the payment verification
* @return transaction status, #GNUNET_DB_STATUS_HARD_ERROR if @a contract_terms
* is malformed
*/
static enum GNUNET_DB_QueryStatus
-postgres_insert_contract_terms (void *cls,
- const char *instance_id,
- const char *order_id,
- json_t *contract_terms,
- uint64_t *order_serial,
- const char *pos_key,
- uint64_t pricing_algorithm)
+postgres_insert_contract_terms (
+ void *cls,
+ const char *instance_id,
+ const char *order_id,
+ json_t *contract_terms,
+ uint64_t *order_serial)
{
struct PostgresClosure *pg = cls;
struct GNUNET_TIME_Timestamp pay_deadline;
@@ -2199,12 +2243,6 @@ postgres_insert_contract_terms (void *cls,
(NULL == fulfillment_url)
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_string (fulfillment_url),
- (NULL == pos_key)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (pos_key),
- (NULL == pos_key)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_uint64 (&pricing_algorithm),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -2810,12 +2848,12 @@ postgres_refund_coin (void *cls,
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
-postgres_lookup_order_status (void *cls,
- const char *instance_id,
- const char *order_id,
- struct TALER_PrivateContractHashP *
- h_contract_terms,
- bool *paid)
+postgres_lookup_order_status (
+ void *cls,
+ const char *instance_id,
+ const char *order_id,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ bool *paid)
{
struct PostgresClosure *pg = cls;
uint8_t paid8;
@@ -3655,7 +3693,7 @@ process_deposits_for_refund_cb (void *cls,
* Although this should be checked as the business should never
* issue a refund bigger than the contract's actual price, we cannot
* rely upon the frontend being correct.
- *///
+ */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"The refund of %s is bigger than the order's value\n",
TALER_amount2s (ctx->refund));
@@ -9028,9 +9066,10 @@ postgres_connect (void *cls)
",h_post_data"
",creation_time"
",contract_terms"
- ",pos_key)"
+ ",pos_key"
+ ",pos_algorithm)"
" SELECT merchant_serial,"
- " $2, $3, $4, $5, $6, $7, $8"
+ " $2, $3, $4, $5, $6, $7, $8, $9"
" FROM merchant_instances"
" WHERE merchant_id=$1"),
/* for postgres_unlock_inventory() */
@@ -9075,7 +9114,21 @@ postgres_connect (void *cls)
",order_serial"
",claim_token"
",paid"
+ " FROM merchant_contract_terms"
+ " WHERE order_id=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)"),
+ /* for postgres_lookup_contract_terms() */
+ GNUNET_PQ_make_prepare ("lookup_contract_terms2",
+ "SELECT"
+ " contract_terms"
+ ",order_serial"
+ ",claim_token"
+ ",paid"
",pos_key"
+ ",pos_algorithm"
" FROM merchant_contract_terms"
" WHERE order_id=$2"
" AND merchant_serial="
@@ -9095,7 +9148,8 @@ postgres_connect (void *cls)
",refund_deadline"
",fulfillment_url"
",claim_token"
- ",pos_key)"
+ ",pos_key"
+ ",pos_algorithm)"
"SELECT"
" mo.order_serial"
",mo.merchant_serial"
@@ -9106,8 +9160,9 @@ postgres_connect (void *cls)
",$5" /* pay_deadline */
",$6" /* refund_deadline */
",$7" /* fulfillment_url */
- ",$8" /* pos_key */
- ",mo.claim_token "
+ ",mo.claim_token"
+ ",mo.pos_key"
+ ",mo.pos_algorithm"
"FROM merchant_orders mo"
" WHERE order_id=$2"
" AND merchant_serial="
@@ -10600,6 +10655,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->unlock_inventory = &postgres_unlock_inventory;
plugin->insert_order_lock = &postgres_insert_order_lock;
plugin->lookup_contract_terms = &postgres_lookup_contract_terms;
+ plugin->lookup_contract_terms2 = &postgres_lookup_contract_terms2;
plugin->insert_contract_terms = &postgres_insert_contract_terms;
plugin->update_contract_terms = &postgres_update_contract_terms;
plugin->delete_contract_terms = &postgres_delete_contract_terms;