diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-12-12 13:28:19 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-12-12 13:28:19 +0100 |
commit | 8d7d9231a6544b7bc04b81559367fa082f5385dc (patch) | |
tree | f1a804e973f3f8a95eb2c4df179bcb84f12b282e | |
parent | 06cbd85ce434285cf6f22987ea0aa6885ac2afab (diff) | |
download | merchant-8d7d9231a6544b7bc04b81559367fa082f5385dc.tar.gz merchant-8d7d9231a6544b7bc04b81559367fa082f5385dc.tar.bz2 merchant-8d7d9231a6544b7bc04b81559367fa082f5385dc.zip |
Not handling unique_violation as error within postgres_store_map()
-rw-r--r-- | src/backend/taler-merchant-httpd_map.c | 2 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 20 | ||||
-rw-r--r-- | src/lib/merchant_api_map.c | 4 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 12 |
4 files changed, 29 insertions, 9 deletions
diff --git a/src/backend/taler-merchant-httpd_map.c b/src/backend/taler-merchant-httpd_map.c index 7c92f6a3..e508dee1 100644 --- a/src/backend/taler-merchant-httpd_map.c +++ b/src/backend/taler-merchant-httpd_map.c @@ -164,8 +164,6 @@ MH_handler_map_in (struct TMH_RequestHandler *rh, &h_contract, contract)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Data was good, but could not store it into db\n"); return TMH_RESPONSE_reply_internal_error (connection, TALER_EC_MAP_IN_STORE_DB_ERROR, "Could not store data into db"); diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 751c3658..572c0f5e 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -41,6 +41,14 @@ struct PostgresClosure }; +/** + * Extract error code. + * + * @param res postgres result object with error details + */ +#define EXTRACT_DB_ERROR(res) \ + PQresultErrorField(res, PG_DIAG_SQLSTATE) + /** * Log error from PostGres. @@ -475,7 +483,17 @@ postgres_store_map (void *cls, result = GNUNET_PQ_exec_prepared (pg->conn, "insert_map", params); - if (PGRES_COMMAND_OK != PQresultStatus (result)) + + /** + * We don't treat a unique_violation (code '23505') error as + * an actual error, since there is no problem if a frontend tries + * to store twice the same contract. That is especially needed + * when DB-less frontends perform replayed payments. + */ + if (PGRES_COMMAND_OK != PQresultStatus (result) + && (0 != memcmp ("23505", + EXTRACT_DB_ERROR (result), + 5))) { ret = GNUNET_SYSERR; BREAK_DB_ERR (result); diff --git a/src/lib/merchant_api_map.c b/src/lib/merchant_api_map.c index d97a2528..8185ffd2 100644 --- a/src/lib/merchant_api_map.c +++ b/src/lib/merchant_api_map.c @@ -93,6 +93,7 @@ handle_map_in_finished (void *cls, long response_code, const json_t *json) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "|\n"); struct TALER_MERCHANT_MapInOperation *mio = cls; /** @@ -101,9 +102,6 @@ handle_map_in_finished (void *cls, */ mio->cb (mio->cb_cls, response_code); - - /* Right to call this here? */ - TALER_MERCHANT_map_in_cancel (mio); } /** diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index e509f350..602f3469 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -1525,9 +1525,7 @@ interpreter_run (void *cls) struct GNUNET_HashCode h_proposal; json_error_t error; json_t *proposal; - // get contract (proposal) - // hash it - // call lib + GNUNET_assert (NULL != cmd->details.map_in.contract_reference); ref = find_command (is, cmd->details.map_in.contract_reference); GNUNET_assert (NULL != ref); @@ -2341,6 +2339,14 @@ run (void *cls) .details.admin_add_incoming.transfer_details = "{ \"uuid\": 2}", .details.admin_add_incoming.amount = "EUR:1" }, + /* Store contract-1 */ + { + .oc = OC_MAP_IN, + .label = "store-contract-2", + .expected_response_code = MHD_HTTP_OK, + .details.map_in.contract_reference = "create-contract-2", + }, + /* Add another 4.01 EUR to reserve #2 */ { .oc = OC_ADMIN_ADD_INCOMING, .label = "create-reserve-2b", |