diff options
-rw-r--r-- | src/backend/taler-merchant-httpd_history.c | 28 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 71 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 11 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 20 |
4 files changed, 128 insertions, 2 deletions
diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c index f863a236..fb0c0cca 100644 --- a/src/backend/taler-merchant-httpd_history.c +++ b/src/backend/taler-merchant-httpd_history.c @@ -141,6 +141,34 @@ MH_handler_history (struct TMH_RequestHandler *rh, "instance"); } + /* Here goes the cherry-picking logic */ + + str = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "order_id"); + + if (NULL != str) + { + + ret = db->find_proposal_data_history (db->cls, + str, + &mi->pubkey, + pd_cb, + response); + if (GNUNET_SYSERR == ret) + { + json_decref (response); + return TMH_RESPONSE_reply_internal_error (connection, + TALER_EC_HISTORY_DB_FETCH_ERROR, + "db error to get history"); + } + ret = TMH_RESPONSE_reply_json (connection, + response, + MHD_HTTP_OK); + json_decref (response); + return ret; + } + delta = 20; str = MHD_lookup_connection_value (connection, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index f0e91380..0f2ed732 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -831,6 +831,76 @@ postgres_store_transfer_to_proof (void *cls, } /** + * Lookup for a proposal, respecting the signature used by the + * /history's db methods. + * + * @param cls db plugin handle + * @param order_id order id used to search for the proposal data + * @param merchant_pub public key of the merchant using this method + * @param cb the callback + * @param cb_cls closure to pass to the callback + * @return GNUNET_YES, GNUNET_NO, GNUNET_SYSERR according to the + * query being successful, unsuccessful, or generated errors. + */ +static int +postgres_find_proposal_data_history (void *cls, + const char *order_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_MERCHANTDB_ProposalDataCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + PGresult *result; + unsigned int i; + json_t *proposal_data; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_end + }; + + result = GNUNET_PQ_exec_prepared (pg->conn, + "find_proposal_data", + params); + i = PQntuples (result); + if (1 < i) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Mupltiple proposal data share the same hashcode.\n"); + return GNUNET_SYSERR; + } + + if (0 == i) + return GNUNET_NO; + + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_json ("proposal_data", + &proposal_data), + GNUNET_PQ_result_spec_end + }; + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + 0)) + { + GNUNET_break (0); + PQclear (result); + return GNUNET_SYSERR; + } + + cb (cb_cls, + order_id, + 0, + proposal_data); + + PQclear (result); + return GNUNET_OK; + +} + + +/** * Return proposals whose timestamp are older than `date`. * Among those proposals, only those ones being between the * start-th and (start-nrows)-th record are returned. The rows @@ -1597,6 +1667,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->find_proof_by_wtid = &postgres_find_proof_by_wtid; plugin->insert_proposal_data = &postgres_insert_proposal_data; plugin->find_proposal_data = &postgres_find_proposal_data; + plugin->find_proposal_data_history = &postgres_find_proposal_data_history; plugin->find_proposal_data_by_date = &postgres_find_proposal_data_by_date; plugin->find_proposal_data_by_date_and_range = &postgres_find_proposal_data_by_date_and_range; plugin->find_proposal_data_from_hash = &postgres_find_proposal_data_from_hash; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index c65f8004..011ec9ea 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -376,13 +376,20 @@ run (void *cls) FAILIF (GNUNET_OK != plugin->find_proposal_data (plugin->cls, - &out, // plain data + &out, order_id, &merchant_pub)); FAILIF (GNUNET_OK != + plugin->find_proposal_data_history (plugin->cls, + order_id, + &merchant_pub, + pd_cb, + NULL)); + + FAILIF (GNUNET_OK != plugin->find_proposal_data_from_hash (plugin->cls, - &out, // plain data + &out, &h_proposal_data2, &merchant_pub)); FAILIF (1 != diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index f0b8ccbf..71f14002 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -243,6 +243,26 @@ struct TALER_MERCHANTDB_Plugin void *cb_cls); /** + * Lookup for a proposal, respecting the signature used by the + * /history's db methods. + * + * @param cls db plugin handle + * @param order_id order id used to search for the proposal data + * @param merchant_pub public key of the merchant using this method + * @param cb the callback + * @param cb_cls closure to pass to the callback + * @return GNUNET_YES, GNUNET_NO, GNUNET_SYSERR according to the + * query being successful, unsuccessful, or generated errors. + */ + int + (*find_proposal_data_history) (void *cls, + const char *order_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_MERCHANTDB_ProposalDataCallback cb, + void *cb_cls); + + + /** * Return proposals whose timestamp are older than `date`. * The rows are sorted having the youngest first.* * |