diff options
-rw-r--r-- | src/backend-lib/merchant_db.c | 9 | ||||
-rw-r--r-- | src/backend-lib/taler-merchant-httpd_contract.c | 24 | ||||
-rw-r--r-- | src/backend-lib/taler_merchant_contract_lib.h | 10 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 6 | ||||
-rw-r--r-- | src/tests/merchant-contract-test.c | 39 |
5 files changed, 59 insertions, 29 deletions
diff --git a/src/backend-lib/merchant_db.c b/src/backend-lib/merchant_db.c index eef10f22..6ee0397b 100644 --- a/src/backend-lib/merchant_db.c +++ b/src/backend-lib/merchant_db.c @@ -138,9 +138,9 @@ MERCHANT_DB_initialize (PGconn *conn, int tmp) EXITIF (NULL == (res = PQprepare (conn, "get_contract_hash", - "SELECT (" - "nounce, edate" - ") FROM contracts " + "SELECT " + "nounce, edate " + "FROM contracts " "WHERE (" "hash=$1" ")", @@ -406,7 +406,7 @@ MERCHANT_DB_get_contract_values (PGconn *conn, TALER_PQ_result_spec_end }; - res = TALER_PQ_exec_prepared (conn, "get_checkout_product", params); + res = TALER_PQ_exec_prepared (conn, "get_contract_hash", params); status = PQresultStatus (res); EXITIF (PGRES_TUPLES_OK != status); @@ -415,6 +415,7 @@ MERCHANT_DB_get_contract_values (PGconn *conn, TALER_LOG_DEBUG ("Contract not found"); goto EXITIF_exit; } + EXITIF (1 != PQntuples (res)); EXITIF (GNUNET_YES != TALER_PQ_extract_result (res, rs, 0)); PQclear (res); diff --git a/src/backend-lib/taler-merchant-httpd_contract.c b/src/backend-lib/taler-merchant-httpd_contract.c index 7cfda21c..f746343b 100644 --- a/src/backend-lib/taler-merchant-httpd_contract.c +++ b/src/backend-lib/taler-merchant-httpd_contract.c @@ -99,27 +99,27 @@ MERCHANT_get_wire_json (const struct MERCHANT_WIREFORMAT_Sepa *wire, * @param edate when the merchant wants to receive the wire transfer corresponding * to this deal (this value is also a field inside the 'wire' JSON format) * @param nounce the nounce used to hash the wire details -* @param contract_str where to store the (stringified) contract -* @return GNUNET_OK on success; GNUNET_SYSERR upon errors +* @param contract_str where to store +* @return pointer to the (stringified) contract; NULL upon errors */ /** * TODO: inspect reference counting and, accordingly, free those json_t*(s) * still allocated */ -uint32_t +char * MERCHANT_handle_contract (const json_t *j_contract, PGconn *db_conn, struct Contract *contract, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute expiry, struct GNUNET_TIME_Absolute edate, - uint64_t nounce, - const char *contract_str) + uint64_t nounce) { json_t *j_amount; json_int_t j_product_id; json_int_t j_trans_id; + char *contract_str; struct TALER_Amount amount; @@ -134,12 +134,11 @@ MERCHANT_handle_contract (const json_t *j_contract, "product_id", &j_product_id)) { printf ("no unpacking\n"); - return GNUNET_SYSERR; + return NULL; } - /* needed for DB work */ - TALER_json_to_amount (j_amount, &amount); // produces a WARNING.. - + /* DB will store the amount */ + TALER_json_to_amount (j_amount, &amount); contract_str = json_dumps (j_contract, JSON_COMPACT | JSON_PRESERVE_ORDER); GNUNET_CRYPTO_hash (contract_str, strlen (contract_str) + 1, &contract->h_contract_details); @@ -157,7 +156,8 @@ MERCHANT_handle_contract (const json_t *j_contract, contract_str, nounce, (uint64_t) j_product_id)) - return GNUNET_SYSERR; - - return GNUNET_OK; + return NULL; + return contract_str; } + + diff --git a/src/backend-lib/taler_merchant_contract_lib.h b/src/backend-lib/taler_merchant_contract_lib.h index 9094e223..9bf99cb3 100644 --- a/src/backend-lib/taler_merchant_contract_lib.h +++ b/src/backend-lib/taler_merchant_contract_lib.h @@ -85,21 +85,19 @@ MERCHANT_get_wire_json (const struct MERCHANT_WIREFORMAT_Sepa *wire, * @param edate when the merchant wants to receive the wire transfer corresponding * to this deal (this value is also a field inside the 'wire' JSON format) * @param nounce the nounce used to hash the wire details -* @param contract_str where to store the hashed (stringified) contract -* @return GNUNET_OK on success; GNUNET_SYSERR upon errors +* @param contract_str where to store +* @return pointer to the (stringified) contract; NULL upon errors */ /** * TODO: inspect reference counting and, accordingly, free those json_t*(s) * still allocated */ -uint32_t +char * MERCHANT_handle_contract (const json_t *j_contract, PGconn *db_conn, struct Contract *contract, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute expiry, struct GNUNET_TIME_Absolute edate, - uint64_t nounce, - const char *contract_str); - + uint64_t nounce); diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index a4d076d4..98a7577e 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -563,9 +563,9 @@ url_handler (void *cls, eddsa_pub_enc = TALER_json_from_data ((void *) &pub, sizeof (pub)); if (NULL == (j_contract_add = json_pack ("{s:o, s:o, s:o}", - "merchant_pub", eddsa_pub_enc, - "H_wire", j_h_json_wire, - "timestamp", TALER_json_from_abs (now)))) + "merchant_pub", eddsa_pub_enc, + "H_wire", j_h_json_wire, + "timestamp", TALER_json_from_abs (now)))) { printf ("BAD contract enhancement\n"); goto end; diff --git a/src/tests/merchant-contract-test.c b/src/tests/merchant-contract-test.c index 4f1a4652..3483eacc 100644 --- a/src/tests/merchant-contract-test.c +++ b/src/tests/merchant-contract-test.c @@ -58,6 +58,13 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } +extern uint32_t +MERCHANT_DB_get_contract_values (PGconn *conn, + const struct GNUNET_HashCode *h_contract, + uint64_t *nounce, + struct GNUNET_TIME_Absolute *edate); + + /** * Main function that will be run by the scheduler. * @@ -104,8 +111,10 @@ run (void *cls, char *const *args, const char *cfgfile, struct Contract contract; #endif struct GNUNET_TIME_Absolute deldate; + struct GNUNET_TIME_Absolute edate; struct GNUNET_TIME_Absolute now; uint64_t nounce; + struct GNUNET_HashCode h_contract_str; db_conn = NULL; keyfile = NULL; @@ -114,7 +123,7 @@ run (void *cls, char *const *args, const char *cfgfile, db_conn = MERCHANT_DB_connect (config); - if (GNUNET_OK != MERCHANT_DB_initialize (db_conn, GNUNET_YES)) + if (GNUNET_OK != MERCHANT_DB_initialize (db_conn, GNUNET_NO)) { printf ("no db init'd\n"); result = GNUNET_SYSERR; @@ -272,17 +281,39 @@ run (void *cls, char *const *args, const char *cfgfile, j_wire = MERCHANT_get_wire_json (wire, nounce, now); - if (GNUNET_SYSERR == MERCHANT_handle_contract (j_fake_contract, + if (NULL == (contract_tmp_str = MERCHANT_handle_contract (j_fake_contract, db_conn, &contract, now, now, now, - nounce, - contract_tmp_str)) + nounce))) + printf ("errors in contract handling\n"); else printf ("handling contract fine\n"); + + + /* try to get from DB the generated contract + + printf ("contract string : %s\n", contract_tmp_str); + return; + + */ + + GNUNET_CRYPTO_hash (contract_tmp_str, strlen (contract_tmp_str) + 1, &h_contract_str); + + + + if (GNUNET_SYSERR == MERCHANT_DB_get_contract_values (db_conn, &h_contract_str, &nounce, &edate)) + printf ("no hash found\n"); + else + { + + char *late = GNUNET_STRINGS_absolute_time_to_string (edate); + printf ("hash found!, nounce is : %d\n", nounce, late); + printf ("hash found!, time is : %s\n", late); + } } |