diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-06-18 21:47:05 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-06-19 00:17:15 +0200 |
commit | 2ec1b055a0f574e3837f2fbbb38098db4eb65f6f (patch) | |
tree | 8070390b91f43d07f68b7f2d785a3dd68c593658 /src/exchangedb | |
parent | d2c7ef54a7eb906b40032969b5bc45c180003f4b (diff) | |
download | exchange-2ec1b055a0f574e3837f2fbbb38098db4eb65f6f.tar.gz exchange-2ec1b055a0f574e3837f2fbbb38098db4eb65f6f.tar.bz2 exchange-2ec1b055a0f574e3837f2fbbb38098db4eb65f6f.zip |
refactoring /deposit towards new transaction style (#5010)
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/perf_taler_exchangedb_interpreter.c | 4 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 129 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 8 |
3 files changed, 58 insertions, 83 deletions
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c index e378fc932..054df58db 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.c +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c @@ -1350,7 +1350,7 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) case PERF_TALER_EXCHANGEDB_CMD_GET_DEPOSIT: { unsigned int source_index; - int ret; + enum GNUNET_DB_QueryStatus ret; struct PERF_TALER_EXCHANGEDB_Data *data; source_index = state->cmd[state->i].details.get_deposit.index_deposit; @@ -1358,7 +1358,7 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) ret = state->plugin->have_deposit (state->plugin->cls, state->session, data->data.deposit); - GNUNET_assert (GNUNET_SYSERR != ret); + GNUNET_assert (0 >= ret); } break; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index d56afed35..954fca389 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -2698,11 +2698,11 @@ postgres_get_reserve_history (void *cls, * @param cls the `struct PostgresClosure` with the plugin-specific state * @param session database connection * @param deposit deposit to search for - * @return #GNUNET_YES if we know this operation, - * #GNUNET_NO if this exact deposit is unknown to us - * #GNUNET_SYSERR on DB error + * @return 1 if we know this operation, + * 0 if this exact deposit is unknown to us, + * otherwise transaction error status */ -static int +static enum GNUNET_DB_QueryStatus postgres_have_deposit (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_EXCHANGEDB_Deposit *deposit) @@ -2713,75 +2713,52 @@ postgres_have_deposit (void *cls, GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub), GNUNET_PQ_query_param_end }; - PGresult *result; - - result = GNUNET_PQ_exec_prepared (session->conn, - "get_deposit", - params); - if (PGRES_TUPLES_OK != - PQresultStatus (result)) - { - BREAK_DB_ERR (result, session->conn); - PQclear (result); - return GNUNET_SYSERR; - } - if (0 == PQntuples (result)) - { - PQclear (result); - return GNUNET_NO; - } + struct TALER_EXCHANGEDB_Deposit deposit2; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_amount ("amount_with_fee", + &deposit2.amount_with_fee), + GNUNET_PQ_result_spec_absolute_time ("timestamp", + &deposit2.timestamp), + GNUNET_PQ_result_spec_absolute_time ("refund_deadline", + &deposit2.refund_deadline), + GNUNET_PQ_result_spec_absolute_time ("wire_deadline", + &deposit2.wire_deadline), + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + &deposit2.h_contract_terms), + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &deposit2.h_wire), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, + "get_deposit", + params, + rs); + if (0 >= qs) + return qs; /* Now we check that the other information in @a deposit also matches, and if not report inconsistencies. */ - { - struct TALER_EXCHANGEDB_Deposit deposit2; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("amount_with_fee", - &deposit2.amount_with_fee), - GNUNET_PQ_result_spec_absolute_time ("timestamp", - &deposit2.timestamp), - GNUNET_PQ_result_spec_absolute_time ("refund_deadline", - &deposit2.refund_deadline), - GNUNET_PQ_result_spec_absolute_time ("wire_deadline", - &deposit2.wire_deadline), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &deposit2.h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &deposit2.h_wire), - GNUNET_PQ_result_spec_end - }; - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - 0)) - { - GNUNET_break (0); - PQclear (result); - return GNUNET_SYSERR; - } - if ( (0 != TALER_amount_cmp (&deposit->amount_with_fee, - &deposit2.amount_with_fee)) || - (deposit->timestamp.abs_value_us != - deposit2.timestamp.abs_value_us) || - (deposit->refund_deadline.abs_value_us != - deposit2.refund_deadline.abs_value_us) || - (0 != memcmp (&deposit->h_contract_terms, - &deposit2.h_contract_terms, - sizeof (struct GNUNET_HashCode))) || - (0 != memcmp (&deposit->h_wire, - &deposit2.h_wire, - sizeof (struct GNUNET_HashCode))) ) - { - /* Inconsistencies detected! Does not match! (We might want to - expand the API with a 'get_deposit' function to return the - original transaction details to be used for an error message - in the future!) #3838 */ - PQclear (result); - return GNUNET_NO; - } - } - PQclear (result); - return GNUNET_YES; + if ( (0 != TALER_amount_cmp (&deposit->amount_with_fee, + &deposit2.amount_with_fee)) || + (deposit->timestamp.abs_value_us != + deposit2.timestamp.abs_value_us) || + (deposit->refund_deadline.abs_value_us != + deposit2.refund_deadline.abs_value_us) || + (0 != memcmp (&deposit->h_contract_terms, + &deposit2.h_contract_terms, + sizeof (struct GNUNET_HashCode))) || + (0 != memcmp (&deposit->h_wire, + &deposit2.h_wire, + sizeof (struct GNUNET_HashCode))) ) + { + /* Inconsistencies detected! Does not match! (We might want to + expand the API with a 'get_deposit' function to return the + original transaction details to be used for an error message + in the future!) #3838 */ + return 0; /* Counts as if the transaction was not there */ + } + return 1; } @@ -3267,11 +3244,9 @@ postgres_insert_deposit (void *cls, * @param cls the @e cls of this struct with the plugin-specific state * @param session connection to the database * @param refund refund information to store - * @return #GNUNET_OK on success - * #GNUNET_NO on transient error - * #GNUNET_SYSERR on error + * @return query result status */ -static int +static enum GNUNET_DB_QueryStatus postgres_insert_refund (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_EXCHANGEDB_Refund *refund) @@ -3289,9 +3264,9 @@ postgres_insert_refund (void *cls, GNUNET_assert (GNUNET_YES == TALER_amount_cmp_currency (&refund->refund_amount, &refund->refund_fee)); - return execute_prepared_non_select (session, - "insert_refund", - params); + return GNUNET_PQ_eval_prepared_non_select (session->conn, + "insert_refund", + params); } diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 319b4dc11..ba47c2d3c 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1772,7 +1772,7 @@ run (void *cls) plugin->insert_deposit (plugin->cls, session, &deposit)); - FAILIF (GNUNET_YES != + FAILIF (1 != plugin->have_deposit (plugin->cls, session, &deposit)); @@ -1839,13 +1839,13 @@ run (void *cls) result = 10; deposit2 = deposit; RND_BLK (&deposit2.merchant_pub); /* should fail if merchant is different */ - FAILIF (GNUNET_NO != + FAILIF (0 != plugin->have_deposit (plugin->cls, session, &deposit2)); deposit2.merchant_pub = deposit.merchant_pub; RND_BLK (&deposit2.coin.coin_pub); /* should fail if coin is different */ - FAILIF (GNUNET_NO != + FAILIF (0 != plugin->have_deposit (plugin->cls, session, &deposit2)); @@ -1860,7 +1860,7 @@ run (void *cls) refund.rtransaction_id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); refund.refund_amount = deposit.amount_with_fee; refund.refund_fee = fee_refund; - FAILIF (GNUNET_OK != + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_refund (plugin->cls, session, &refund)); |