summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-22 21:59:27 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-22 21:59:27 +0100
commit0a0fe09e9b144e96d4c6b7f1dab937f49de58f08 (patch)
tree95345d7dc156a7e0ca811e270f6e1b127d9b6c1e /src/backenddb
parentbd799135b4368144a87f4b596899f443f91bea69 (diff)
downloadmerchant-0a0fe09e9b144e96d4c6b7f1dab937f49de58f08.tar.gz
merchant-0a0fe09e9b144e96d4c6b7f1dab937f49de58f08.tar.bz2
merchant-0a0fe09e9b144e96d4c6b7f1dab937f49de58f08.zip
fix #5262
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c59
-rw-r--r--src/backenddb/test_merchantdb.c10
2 files changed, 62 insertions, 7 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 1a97670a..0a3ce5f5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -378,6 +378,14 @@ postgres_initialize (void *cls)
" WHERE h_contract_terms=$1"
" AND merchant_pub=$2",
2),
+ GNUNET_PQ_make_prepare ("find_paid_contract_terms_from_hash",
+ "SELECT"
+ " contract_terms"
+ " FROM merchant_contract_terms"
+ " WHERE h_contract_terms=$1"
+ " AND merchant_pub=$2"
+ " AND paid=TRUE",
+ 2),
GNUNET_PQ_make_prepare ("end_transaction",
"COMMIT",
0),
@@ -796,9 +804,9 @@ postgres_commit (void *cls)
*/
static enum GNUNET_DB_QueryStatus
postgres_find_contract_terms_from_hash (void *cls,
- json_t **contract_terms,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct TALER_MerchantPublicKeyP *merchant_pub)
+ json_t **contract_terms,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_MerchantPublicKeyP *merchant_pub)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -821,6 +829,41 @@ postgres_find_contract_terms_from_hash (void *cls,
/**
+ * Retrieve proposal data given its proposal data's hashcode
+ *
+ * @param cls closure
+ * @param contract_terms where to store the retrieved proposal data
+ * @param h_contract_terms proposal data's hashcode that will be used to
+ * perform the lookup
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_find_paid_contract_terms_from_hash (void *cls,
+ json_t **contract_terms,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_MerchantPublicKeyP *merchant_pub)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_json ("contract_terms",
+ contract_terms),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "find_paid_contract_terms_from_hash",
+ params,
+ rs);
+}
+
+
+/**
* Retrieve proposal data given its order id. Ignores if the
* proposal has been paid or not.
*
@@ -1232,10 +1275,11 @@ postgres_find_contract_terms_history (void *cls,
rs);
if (qs <= 0)
return qs;
- cb (cb_cls,
- order_id,
- 0,
- contract_terms);
+ if (NULL != cb)
+ cb (cb_cls,
+ order_id,
+ 0,
+ contract_terms);
GNUNET_PQ_cleanup_result (rs);
return qs;
}
@@ -3363,6 +3407,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->find_contract_terms_by_date = &postgres_find_contract_terms_by_date;
plugin->find_contract_terms_by_date_and_range = &postgres_find_contract_terms_by_date_and_range;
plugin->find_contract_terms_from_hash = &postgres_find_contract_terms_from_hash;
+ plugin->find_paid_contract_terms_from_hash = &postgres_find_paid_contract_terms_from_hash;
plugin->get_refunds_from_contract_terms_hash = &postgres_get_refunds_from_contract_terms_hash;
plugin->lookup_wire_fee = &postgres_lookup_wire_fee;
plugin->increase_refund_for_contract = &postgres_increase_refund_for_contract;
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index d9128382..cbf51b31 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -838,6 +838,11 @@ run (void *cls)
timestamp,
contract_terms));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->find_paid_contract_terms_from_hash (plugin->cls,
+ &out,
+ &h_contract_terms,
+ &merchant_pub));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->mark_proposal_paid (plugin->cls,
&h_contract_terms,
@@ -858,6 +863,11 @@ run (void *cls)
NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->find_paid_contract_terms_from_hash (plugin->cls,
+ &out,
+ &h_contract_terms,
+ &merchant_pub));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->find_contract_terms_from_hash (plugin->cls,
&out,
&h_contract_terms,