diff options
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 1291 |
1 files changed, 318 insertions, 973 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 8b805f6bc..95ea6a4bb 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c | |||
@@ -88,62 +88,6 @@ | |||
88 | 88 | ||
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Handler for a database session (per-thread, for transactions). | ||
92 | */ | ||
93 | struct TALER_EXCHANGEDB_Session | ||
94 | { | ||
95 | /** | ||
96 | * Postgres connection handle. | ||
97 | */ | ||
98 | struct GNUNET_PQ_Context *conn; | ||
99 | |||
100 | /** | ||
101 | * Name of the current transaction, for debugging. | ||
102 | */ | ||
103 | const char *transaction_name; | ||
104 | |||
105 | /** | ||
106 | * Did we initialize the prepared statements | ||
107 | * for this session? | ||
108 | */ | ||
109 | bool init; | ||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Event registration record. | ||
115 | */ | ||
116 | struct TALER_EXCHANGEDB_EventHandler | ||
117 | { | ||
118 | /** | ||
119 | * Underlying GNUnet event handler. | ||
120 | */ | ||
121 | struct GNUNET_DB_EventHandler *geh; | ||
122 | |||
123 | /** | ||
124 | * Entry in the heap. | ||
125 | */ | ||
126 | struct GNUNET_CONTAINER_HeapNode *hn; | ||
127 | |||
128 | /** | ||
129 | * Our timeout. | ||
130 | */ | ||
131 | struct GNUNET_TIME_Absolute timeout; | ||
132 | |||
133 | /** | ||
134 | * Callback to invoke (on @e timeout). | ||
135 | */ | ||
136 | GNUNET_DB_EventCallback cb; | ||
137 | |||
138 | /** | ||
139 | * Closure for @e cb. | ||
140 | */ | ||
141 | void *cb_cls; | ||
142 | |||
143 | }; | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Type of the "cls" argument given to each of the functions in | 91 | * Type of the "cls" argument given to each of the functions in |
148 | * our API. | 92 | * our API. |
149 | */ | 93 | */ |
@@ -151,12 +95,6 @@ struct PostgresClosure | |||
151 | { | 95 | { |
152 | 96 | ||
153 | /** | 97 | /** |
154 | * Thread-local database connection. | ||
155 | * Contains a pointer to `struct GNUNET_PQ_Context` or NULL. | ||
156 | */ | ||
157 | pthread_key_t db_conn_threadlocal; | ||
158 | |||
159 | /** | ||
160 | * Our configuration. | 98 | * Our configuration. |
161 | */ | 99 | */ |
162 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 100 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -167,12 +105,6 @@ struct PostgresClosure | |||
167 | char *sql_dir; | 105 | char *sql_dir; |
168 | 106 | ||
169 | /** | 107 | /** |
170 | * Heap of `struct TALER_EXCHANGEDB_EventHandler` | ||
171 | * by timeout. | ||
172 | */ | ||
173 | struct GNUNET_CONTAINER_Heap *event_heap; | ||
174 | |||
175 | /** | ||
176 | * After how long should idle reserves be closed? | 108 | * After how long should idle reserves be closed? |
177 | */ | 109 | */ |
178 | struct GNUNET_TIME_Relative idle_reserve_expiration_time; | 110 | struct GNUNET_TIME_Relative idle_reserve_expiration_time; |
@@ -189,25 +121,14 @@ struct PostgresClosure | |||
189 | char *currency; | 121 | char *currency; |
190 | 122 | ||
191 | /** | 123 | /** |
192 | * Session to be used if the thread is @e main_self. | 124 | * Postgres connection handle. |
193 | */ | ||
194 | struct TALER_EXCHANGEDB_Session *main_session; | ||
195 | |||
196 | /** | ||
197 | * Handle for the main() thread of the program. | ||
198 | */ | ||
199 | pthread_t main_self; | ||
200 | |||
201 | /** | ||
202 | * Thread responsible for processing database event | ||
203 | * notifications. | ||
204 | */ | 125 | */ |
205 | pthread_t event_thread; | 126 | struct GNUNET_PQ_Context *conn; |
206 | 127 | ||
207 | /** | 128 | /** |
208 | * Lock for @e listener_count access. | 129 | * Name of the current transaction, for debugging. |
209 | */ | 130 | */ |
210 | pthread_mutex_t event_lock; | 131 | const char *transaction_name; |
211 | 132 | ||
212 | /** | 133 | /** |
213 | * Number of registered listerners. @e event_thread | 134 | * Number of registered listerners. @e event_thread |
@@ -216,15 +137,11 @@ struct PostgresClosure | |||
216 | uint64_t listener_count; | 137 | uint64_t listener_count; |
217 | 138 | ||
218 | /** | 139 | /** |
219 | * Additional FD to signal the @e event_thread | 140 | * Did we initialize the prepared statements |
220 | * (used to stop it). | 141 | * for this session? |
221 | */ | 142 | */ |
222 | int event_fd; | 143 | bool init; |
223 | 144 | ||
224 | /** | ||
225 | * Current Postges socket we watch on for notifications. | ||
226 | */ | ||
227 | int pg_sock; | ||
228 | }; | 145 | }; |
229 | 146 | ||
230 | 147 | ||
@@ -237,10 +154,10 @@ struct PostgresClosure | |||
237 | static int | 154 | static int |
238 | postgres_drop_tables (void *cls) | 155 | postgres_drop_tables (void *cls) |
239 | { | 156 | { |
240 | struct PostgresClosure *pc = cls; | 157 | struct PostgresClosure *pg = cls; |
241 | struct GNUNET_PQ_Context *conn; | 158 | struct GNUNET_PQ_Context *conn; |
242 | 159 | ||
243 | conn = GNUNET_PQ_connect_with_cfg (pc->cfg, | 160 | conn = GNUNET_PQ_connect_with_cfg (pg->cfg, |
244 | "exchangedb-postgres", | 161 | "exchangedb-postgres", |
245 | "drop", | 162 | "drop", |
246 | NULL, | 163 | NULL, |
@@ -261,10 +178,10 @@ postgres_drop_tables (void *cls) | |||
261 | static int | 178 | static int |
262 | postgres_create_tables (void *cls) | 179 | postgres_create_tables (void *cls) |
263 | { | 180 | { |
264 | struct PostgresClosure *pc = cls; | 181 | struct PostgresClosure *pg = cls; |
265 | struct GNUNET_PQ_Context *conn; | 182 | struct GNUNET_PQ_Context *conn; |
266 | 183 | ||
267 | conn = GNUNET_PQ_connect_with_cfg (pc->cfg, | 184 | conn = GNUNET_PQ_connect_with_cfg (pg->cfg, |
268 | "exchangedb-postgres", | 185 | "exchangedb-postgres", |
269 | "exchange-", | 186 | "exchange-", |
270 | NULL, | 187 | NULL, |
@@ -277,34 +194,13 @@ postgres_create_tables (void *cls) | |||
277 | 194 | ||
278 | 195 | ||
279 | /** | 196 | /** |
280 | * Close thread-local database connection when a thread is destroyed. | ||
281 | * | ||
282 | * @param cls closure we get from pthreads (the db handle) | ||
283 | */ | ||
284 | static void | ||
285 | db_conn_destroy (void *cls) | ||
286 | { | ||
287 | struct TALER_EXCHANGEDB_Session *session = cls; | ||
288 | struct GNUNET_PQ_Context *db_conn; | ||
289 | |||
290 | if (NULL == session) | ||
291 | return; | ||
292 | db_conn = session->conn; | ||
293 | session->conn = NULL; | ||
294 | if (NULL != db_conn) | ||
295 | GNUNET_PQ_disconnect (db_conn); | ||
296 | GNUNET_free (session); | ||
297 | } | ||
298 | |||
299 | |||
300 | /** | ||
301 | * Initialize prepared statements for @a sess. | 197 | * Initialize prepared statements for @a sess. |
302 | * | 198 | * |
303 | * @param[in,out] sess session to initialize | 199 | * @param[in,out] sess session to initialize |
304 | * @return #GNUNET_OK on success | 200 | * @return #GNUNET_OK on success |
305 | */ | 201 | */ |
306 | static enum GNUNET_GenericReturnValue | 202 | static enum GNUNET_GenericReturnValue |
307 | init_session (struct TALER_EXCHANGEDB_Session *sess) | 203 | prepare_statements (struct PostgresClosure *pg) |
308 | { | 204 | { |
309 | enum GNUNET_GenericReturnValue ret; | 205 | enum GNUNET_GenericReturnValue ret; |
310 | struct GNUNET_PQ_PreparedStatement ps[] = { | 206 | struct GNUNET_PQ_PreparedStatement ps[] = { |
@@ -2541,41 +2437,27 @@ init_session (struct TALER_EXCHANGEDB_Session *sess) | |||
2541 | GNUNET_PQ_PREPARED_STATEMENT_END | 2437 | GNUNET_PQ_PREPARED_STATEMENT_END |
2542 | }; | 2438 | }; |
2543 | 2439 | ||
2544 | ret = GNUNET_PQ_prepare_statements (sess->conn, | 2440 | ret = GNUNET_PQ_prepare_statements (pg->conn, |
2545 | ps); | 2441 | ps); |
2546 | if (GNUNET_OK != ret) | 2442 | if (GNUNET_OK != ret) |
2547 | return ret; | 2443 | return ret; |
2548 | sess->init = true; | 2444 | pg->init = true; |
2549 | return GNUNET_OK; | 2445 | return GNUNET_OK; |
2550 | } | 2446 | } |
2551 | 2447 | ||
2552 | 2448 | ||
2553 | /** | 2449 | /** |
2554 | * Get the thread-local database-handle. | 2450 | * Connect to the database if the connection does not exist yet. |
2555 | * Connect to the db if the connection does not exist yet. | ||
2556 | * | 2451 | * |
2557 | * @param pc the plugin-specific state | 2452 | * @param pg the plugin-specific state |
2558 | * @param skip_prepare true if we should skip prepared statement setup | 2453 | * @param skip_prepare true if we should skip prepared statement setup |
2559 | * @return the database connection, or NULL on error | 2454 | * @return #GNUNET_OK on success |
2560 | */ | 2455 | */ |
2561 | static struct TALER_EXCHANGEDB_Session * | 2456 | static enum GNUNET_GenericReturnValue |
2562 | internal_get_session (struct PostgresClosure *pc, | 2457 | internal_setup (struct PostgresClosure *pg, |
2563 | bool skip_prepare) | 2458 | bool skip_prepare) |
2564 | { | 2459 | { |
2565 | struct GNUNET_PQ_Context *db_conn; | 2460 | if (NULL == pg->conn) |
2566 | struct TALER_EXCHANGEDB_Session *session; | ||
2567 | |||
2568 | if (pthread_equal (pc->main_self, | ||
2569 | pthread_self ())) | ||
2570 | session = pc->main_session; | ||
2571 | else | ||
2572 | session = pthread_getspecific (pc->db_conn_threadlocal); | ||
2573 | if (NULL != session) | ||
2574 | { | ||
2575 | if (NULL == session->transaction_name) | ||
2576 | GNUNET_PQ_reconnect_if_down (session->conn); | ||
2577 | return session; | ||
2578 | } | ||
2579 | { | 2461 | { |
2580 | #if AUTO_EXPLAIN | 2462 | #if AUTO_EXPLAIN |
2581 | /* Enable verbose logging to see where queries do not | 2463 | /* Enable verbose logging to see where queries do not |
@@ -2596,123 +2478,108 @@ internal_get_session (struct PostgresClosure *pc, | |||
2596 | #else | 2478 | #else |
2597 | struct GNUNET_PQ_ExecuteStatement *es = NULL; | 2479 | struct GNUNET_PQ_ExecuteStatement *es = NULL; |
2598 | #endif | 2480 | #endif |
2481 | struct GNUNET_PQ_Context *db_conn; | ||
2599 | 2482 | ||
2600 | db_conn = GNUNET_PQ_connect_with_cfg (pc->cfg, | 2483 | db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg, |
2601 | "exchangedb-postgres", | 2484 | "exchangedb-postgres", |
2602 | NULL, | 2485 | NULL, |
2603 | es, | 2486 | es, |
2604 | NULL); | 2487 | NULL); |
2488 | if (NULL == db_conn) | ||
2489 | return GNUNET_SYSERR; | ||
2490 | pg->conn = db_conn; | ||
2605 | } | 2491 | } |
2606 | if (NULL == db_conn) | 2492 | if (NULL == pg->transaction_name) |
2607 | return NULL; | 2493 | GNUNET_PQ_reconnect_if_down (pg->conn); |
2608 | session = GNUNET_new (struct TALER_EXCHANGEDB_Session); | 2494 | if (pg->init) |
2609 | session->conn = db_conn; | 2495 | return GNUNET_OK; |
2610 | if ( (! skip_prepare) && | 2496 | if (skip_prepare) |
2611 | (GNUNET_OK != | 2497 | return GNUNET_OK; |
2612 | init_session (session)) ) | 2498 | return prepare_statements (pg); |
2613 | { | ||
2614 | GNUNET_break (0); | ||
2615 | GNUNET_PQ_disconnect (db_conn); | ||
2616 | GNUNET_free (session); | ||
2617 | return NULL; | ||
2618 | } | ||
2619 | if (pthread_equal (pc->main_self, | ||
2620 | pthread_self ())) | ||
2621 | { | ||
2622 | pc->main_session = session; | ||
2623 | } | ||
2624 | else | ||
2625 | { | ||
2626 | if (0 != pthread_setspecific (pc->db_conn_threadlocal, | ||
2627 | session)) | ||
2628 | { | ||
2629 | GNUNET_break (0); | ||
2630 | GNUNET_PQ_disconnect (db_conn); | ||
2631 | GNUNET_free (session); | ||
2632 | return NULL; | ||
2633 | } | ||
2634 | } | ||
2635 | return session; | ||
2636 | } | 2499 | } |
2637 | 2500 | ||
2638 | 2501 | ||
2639 | /** | 2502 | /** |
2640 | * Get the thread-local database-handle. | 2503 | * Do a pre-flight check that we are not in an uncommitted transaction. |
2641 | * Connect to the db if the connection does not exist yet. | 2504 | * If we are, try to commit the previous transaction and output a warning. |
2505 | * Does not return anything, as we will continue regardless of the outcome. | ||
2642 | * | 2506 | * |
2643 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 2507 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
2644 | * @return the database connection, or NULL on error | 2508 | * @return #GNUNET_OK if everything is fine |
2509 | * #GNUNET_NO if a transaction was rolled back | ||
2510 | * #GNUNET_SYSERR on hard errors | ||
2645 | */ | 2511 | */ |
2646 | static struct TALER_EXCHANGEDB_Session * | 2512 | static enum GNUNET_GenericReturnValue |
2647 | postgres_get_session (void *cls) | 2513 | postgres_preflight (void *cls) |
2648 | { | 2514 | { |
2649 | struct PostgresClosure *pc = cls; | 2515 | struct PostgresClosure *pg = cls; |
2650 | struct TALER_EXCHANGEDB_Session *sess; | 2516 | struct GNUNET_PQ_ExecuteStatement es[] = { |
2517 | GNUNET_PQ_make_execute ("ROLLBACK"), | ||
2518 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
2519 | }; | ||
2651 | 2520 | ||
2652 | sess = internal_get_session (pc, | 2521 | if (! pg->init) |
2653 | false); | ||
2654 | if (! sess->init) | ||
2655 | { | 2522 | { |
2656 | if (GNUNET_OK != | 2523 | if (GNUNET_OK != |
2657 | init_session (sess)) | 2524 | internal_setup (pg, |
2658 | { | 2525 | false)) |
2659 | GNUNET_break (0); | 2526 | return GNUNET_SYSERR; |
2660 | return NULL; | ||
2661 | } | ||
2662 | } | 2527 | } |
2663 | return sess; | 2528 | if (NULL == pg->transaction_name) |
2529 | return GNUNET_OK; /* all good */ | ||
2530 | if (GNUNET_OK == | ||
2531 | GNUNET_PQ_exec_statements (pg->conn, | ||
2532 | es)) | ||
2533 | { | ||
2534 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2535 | "BUG: Preflight check rolled back transaction `%s'!\n", | ||
2536 | pg->transaction_name); | ||
2537 | } | ||
2538 | else | ||
2539 | { | ||
2540 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2541 | "BUG: Preflight check failed to rollback transaction `%s'!\n", | ||
2542 | pg->transaction_name); | ||
2543 | } | ||
2544 | pg->transaction_name = NULL; | ||
2545 | return GNUNET_NO; | ||
2664 | } | 2546 | } |
2665 | 2547 | ||
2666 | 2548 | ||
2667 | /** | 2549 | /** |
2668 | * Do a pre-flight check that we are not in an uncommitted transaction. | ||
2669 | * If we are, try to commit the previous transaction and output a warning. | ||
2670 | * Does not return anything, as we will continue regardless of the outcome. | ||
2671 | * | ||
2672 | * @param cls the `struct PostgresClosure` with the plugin-specific state | ||
2673 | * @param session the database connection | ||
2674 | */ | ||
2675 | static void | ||
2676 | postgres_preflight (void *cls, | ||
2677 | struct TALER_EXCHANGEDB_Session *session); | ||
2678 | |||
2679 | /** | ||
2680 | * Start a transaction. | 2550 | * Start a transaction. |
2681 | * | 2551 | * |
2682 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 2552 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
2683 | * @param session the database connection | ||
2684 | * @param name unique name identifying the transaction (for debugging) | 2553 | * @param name unique name identifying the transaction (for debugging) |
2685 | * must point to a constant | 2554 | * must point to a constant |
2686 | * @return #GNUNET_OK on success | 2555 | * @return #GNUNET_OK on success |
2687 | */ | 2556 | */ |
2688 | static int | 2557 | static int |
2689 | postgres_start (void *cls, | 2558 | postgres_start (void *cls, |
2690 | struct TALER_EXCHANGEDB_Session *session, | ||
2691 | const char *name) | 2559 | const char *name) |
2692 | { | 2560 | { |
2561 | struct PostgresClosure *pg = cls; | ||
2693 | struct GNUNET_PQ_ExecuteStatement es[] = { | 2562 | struct GNUNET_PQ_ExecuteStatement es[] = { |
2694 | GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"), | 2563 | GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"), |
2695 | GNUNET_PQ_EXECUTE_STATEMENT_END | 2564 | GNUNET_PQ_EXECUTE_STATEMENT_END |
2696 | }; | 2565 | }; |
2697 | 2566 | ||
2698 | (void) cls; | 2567 | if (GNUNET_SYSERR == |
2699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2568 | postgres_preflight (pg)) |
2700 | "Starting transaction named: %s\n", | 2569 | return GNUNET_SYSERR; |
2701 | name); | ||
2702 | postgres_preflight (cls, | ||
2703 | session); | ||
2704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2705 | "Starting transaction on %p\n", | 2571 | "Starting transaction named %s on %p\n", |
2706 | session->conn); | 2572 | name, |
2573 | pg->conn); | ||
2707 | if (GNUNET_OK != | 2574 | if (GNUNET_OK != |
2708 | GNUNET_PQ_exec_statements (session->conn, | 2575 | GNUNET_PQ_exec_statements (pg->conn, |
2709 | es)) | 2576 | es)) |
2710 | { | 2577 | { |
2711 | TALER_LOG_ERROR ("Failed to start transaction\n"); | 2578 | TALER_LOG_ERROR ("Failed to start transaction\n"); |
2712 | GNUNET_break (0); | 2579 | GNUNET_break (0); |
2713 | return GNUNET_SYSERR; | 2580 | return GNUNET_SYSERR; |
2714 | } | 2581 | } |
2715 | session->transaction_name = name; | 2582 | pg->transaction_name = name; |
2716 | return GNUNET_OK; | 2583 | return GNUNET_OK; |
2717 | } | 2584 | } |
2718 | 2585 | ||
@@ -2721,39 +2588,36 @@ postgres_start (void *cls, | |||
2721 | * Start a READ COMMITTED transaction. | 2588 | * Start a READ COMMITTED transaction. |
2722 | * | 2589 | * |
2723 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 2590 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
2724 | * @param session the database connection | ||
2725 | * @param name unique name identifying the transaction (for debugging) | 2591 | * @param name unique name identifying the transaction (for debugging) |
2726 | * must point to a constant | 2592 | * must point to a constant |
2727 | * @return #GNUNET_OK on success | 2593 | * @return #GNUNET_OK on success |
2728 | */ | 2594 | */ |
2729 | static int | 2595 | static int |
2730 | postgres_start_read_committed (void *cls, | 2596 | postgres_start_read_committed (void *cls, |
2731 | struct TALER_EXCHANGEDB_Session *session, | ||
2732 | const char *name) | 2597 | const char *name) |
2733 | { | 2598 | { |
2599 | struct PostgresClosure *pg = cls; | ||
2734 | struct GNUNET_PQ_ExecuteStatement es[] = { | 2600 | struct GNUNET_PQ_ExecuteStatement es[] = { |
2735 | GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"), | 2601 | GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"), |
2736 | GNUNET_PQ_EXECUTE_STATEMENT_END | 2602 | GNUNET_PQ_EXECUTE_STATEMENT_END |
2737 | }; | 2603 | }; |
2738 | 2604 | ||
2739 | (void) cls; | 2605 | if (GNUNET_SYSERR == |
2740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2606 | postgres_preflight (pg)) |
2741 | "Starting transaction named: %s\n", | 2607 | return GNUNET_SYSERR; |
2742 | name); | ||
2743 | postgres_preflight (cls, | ||
2744 | session); | ||
2745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2746 | "Starting transaction on %p\n", | 2609 | "Starting transaction named %s on %p\n", |
2747 | session->conn); | 2610 | name, |
2611 | pg->conn); | ||
2748 | if (GNUNET_OK != | 2612 | if (GNUNET_OK != |
2749 | GNUNET_PQ_exec_statements (session->conn, | 2613 | GNUNET_PQ_exec_statements (pg->conn, |
2750 | es)) | 2614 | es)) |
2751 | { | 2615 | { |
2752 | TALER_LOG_ERROR ("Failed to start transaction\n"); | 2616 | TALER_LOG_ERROR ("Failed to start transaction\n"); |
2753 | GNUNET_break (0); | 2617 | GNUNET_break (0); |
2754 | return GNUNET_SYSERR; | 2618 | return GNUNET_SYSERR; |
2755 | } | 2619 | } |
2756 | session->transaction_name = name; | 2620 | pg->transaction_name = name; |
2757 | return GNUNET_OK; | 2621 | return GNUNET_OK; |
2758 | } | 2622 | } |
2759 | 2623 | ||
@@ -2762,25 +2626,23 @@ postgres_start_read_committed (void *cls, | |||
2762 | * Roll back the current transaction of a database connection. | 2626 | * Roll back the current transaction of a database connection. |
2763 | * | 2627 | * |
2764 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 2628 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
2765 | * @param session the database connection | ||
2766 | */ | 2629 | */ |
2767 | static void | 2630 | static void |
2768 | postgres_rollback (void *cls, | 2631 | postgres_rollback (void *cls) |
2769 | struct TALER_EXCHANGEDB_Session *session) | ||
2770 | { | 2632 | { |
2633 | struct PostgresClosure *pg = cls; | ||
2771 | struct GNUNET_PQ_ExecuteStatement es[] = { | 2634 | struct GNUNET_PQ_ExecuteStatement es[] = { |
2772 | GNUNET_PQ_make_execute ("ROLLBACK"), | 2635 | GNUNET_PQ_make_execute ("ROLLBACK"), |
2773 | GNUNET_PQ_EXECUTE_STATEMENT_END | 2636 | GNUNET_PQ_EXECUTE_STATEMENT_END |
2774 | }; | 2637 | }; |
2775 | 2638 | ||
2776 | (void) cls; | ||
2777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2778 | "Rolling back transaction on %p\n", | 2640 | "Rolling back transaction on %p\n", |
2779 | session->conn); | 2641 | pg->conn); |
2780 | GNUNET_break (GNUNET_OK == | 2642 | GNUNET_break (GNUNET_OK == |
2781 | GNUNET_PQ_exec_statements (session->conn, | 2643 | GNUNET_PQ_exec_statements (pg->conn, |
2782 | es)); | 2644 | es)); |
2783 | session->transaction_name = NULL; | 2645 | pg->transaction_name = NULL; |
2784 | } | 2646 | } |
2785 | 2647 | ||
2786 | 2648 | ||
@@ -2788,180 +2650,26 @@ postgres_rollback (void *cls, | |||
2788 | * Commit the current transaction of a database connection. | 2650 | * Commit the current transaction of a database connection. |
2789 | * | 2651 | * |
2790 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 2652 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
2791 | * @param session the database connection | ||
2792 | * @return final transaction status | 2653 | * @return final transaction status |
2793 | */ | 2654 | */ |
2794 | static enum GNUNET_DB_QueryStatus | 2655 | static enum GNUNET_DB_QueryStatus |
2795 | postgres_commit (void *cls, | 2656 | postgres_commit (void *cls) |
2796 | struct TALER_EXCHANGEDB_Session *session) | ||
2797 | { | 2657 | { |
2658 | struct PostgresClosure *pg = cls; | ||
2798 | struct GNUNET_PQ_QueryParam params[] = { | 2659 | struct GNUNET_PQ_QueryParam params[] = { |
2799 | GNUNET_PQ_query_param_end | 2660 | GNUNET_PQ_query_param_end |
2800 | }; | 2661 | }; |
2801 | enum GNUNET_DB_QueryStatus qs; | 2662 | enum GNUNET_DB_QueryStatus qs; |
2802 | 2663 | ||
2803 | (void) cls; | 2664 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
2804 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
2805 | "do_commit", | 2665 | "do_commit", |
2806 | params); | 2666 | params); |
2807 | session->transaction_name = NULL; | 2667 | pg->transaction_name = NULL; |
2808 | return qs; | 2668 | return qs; |
2809 | } | 2669 | } |
2810 | 2670 | ||
2811 | 2671 | ||
2812 | /** | 2672 | /** |
2813 | * Do a pre-flight check that we are not in an uncommitted transaction. | ||
2814 | * If we are, try to commit the previous transaction and output a warning. | ||
2815 | * Does not return anything, as we will continue regardless of the outcome. | ||
2816 | * | ||
2817 | * @param cls the `struct PostgresClosure` with the plugin-specific state | ||
2818 | * @param session the database connection | ||
2819 | */ | ||
2820 | static void | ||
2821 | postgres_preflight (void *cls, | ||
2822 | struct TALER_EXCHANGEDB_Session *session) | ||
2823 | { | ||
2824 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
2825 | GNUNET_PQ_make_execute ("ROLLBACK"), | ||
2826 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
2827 | }; | ||
2828 | |||
2829 | (void) cls; | ||
2830 | if (NULL == session) | ||
2831 | { | ||
2832 | GNUNET_break (0); | ||
2833 | return; | ||
2834 | } | ||
2835 | if (NULL == session->transaction_name) | ||
2836 | return; /* all good */ | ||
2837 | if (GNUNET_OK == | ||
2838 | GNUNET_PQ_exec_statements (session->conn, | ||
2839 | es)) | ||
2840 | { | ||
2841 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2842 | "BUG: Preflight check rolled back transaction `%s'!\n", | ||
2843 | session->transaction_name); | ||
2844 | } | ||
2845 | else | ||
2846 | { | ||
2847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2848 | "BUG: Preflight check failed to rollback transaction `%s'!\n", | ||
2849 | session->transaction_name); | ||
2850 | } | ||
2851 | session->transaction_name = NULL; | ||
2852 | } | ||
2853 | |||
2854 | |||
2855 | /** | ||
2856 | * Main function of the thread that processes events. | ||
2857 | * | ||
2858 | * @param cls a `struct PostgresClosure *` | ||
2859 | */ | ||
2860 | static void * | ||
2861 | handle_events (void *cls) | ||
2862 | { | ||
2863 | struct PostgresClosure *pg = cls; | ||
2864 | struct pollfd pfds[] = { | ||
2865 | { | ||
2866 | .fd = pg->event_fd, | ||
2867 | .events = POLLIN | ||
2868 | }, | ||
2869 | { | ||
2870 | .fd = pg->pg_sock, | ||
2871 | .events = POLLIN | ||
2872 | } | ||
2873 | }; | ||
2874 | nfds_t nfds = (-1 == pg->pg_sock) ? 1 : 2; | ||
2875 | struct TALER_EXCHANGEDB_EventHandler *r; | ||
2876 | |||
2877 | GNUNET_assert (0 == | ||
2878 | pthread_mutex_lock (&pg->event_lock)); | ||
2879 | while (0 != pg->listener_count) | ||
2880 | { | ||
2881 | int ret; | ||
2882 | int timeout = -1; /* no timeout */ | ||
2883 | |||
2884 | GNUNET_assert (0 == | ||
2885 | pthread_mutex_unlock (&pg->event_lock)); | ||
2886 | while (1) | ||
2887 | { | ||
2888 | r = GNUNET_CONTAINER_heap_peek (pg->event_heap); | ||
2889 | if (NULL == r) | ||
2890 | break; | ||
2891 | if (GNUNET_TIME_absolute_is_future (r->timeout)) | ||
2892 | break; | ||
2893 | GNUNET_assert (r == | ||
2894 | GNUNET_CONTAINER_heap_remove_root (pg->event_heap)); | ||
2895 | r->hn = NULL; | ||
2896 | r->cb (r->cb_cls, | ||
2897 | NULL, | ||
2898 | 0); | ||
2899 | } | ||
2900 | if (NULL != r) | ||
2901 | { | ||
2902 | struct GNUNET_TIME_Relative rem; | ||
2903 | |||
2904 | rem = GNUNET_TIME_absolute_get_remaining (r->timeout); | ||
2905 | timeout = rem.rel_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; | ||
2906 | } | ||
2907 | ret = poll (pfds, | ||
2908 | nfds, | ||
2909 | timeout); | ||
2910 | if (-1 == ret) | ||
2911 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
2912 | "poll"); | ||
2913 | for (int i = 0; i<ret; i++) | ||
2914 | { | ||
2915 | if ( (pg->event_fd == pfds[i].fd) && | ||
2916 | (0 != (POLLIN & pfds[i].revents)) ) | ||
2917 | { | ||
2918 | /* consume signal */ | ||
2919 | uint64_t val; | ||
2920 | |||
2921 | GNUNET_break (sizeof (uint64_t) == | ||
2922 | read (pg->event_fd, | ||
2923 | &val, | ||
2924 | sizeof (val))); | ||
2925 | } | ||
2926 | if ( (pg->pg_sock == pfds[i].fd) && | ||
2927 | (0 != (POLLIN & pfds[i].revents)) ) | ||
2928 | { | ||
2929 | GNUNET_assert (NULL != pg->main_session); | ||
2930 | GNUNET_PQ_event_do_poll (pg->main_session->conn); | ||
2931 | } | ||
2932 | } | ||
2933 | GNUNET_assert (0 == | ||
2934 | pthread_mutex_lock (&pg->event_lock)); | ||
2935 | } | ||
2936 | GNUNET_assert (0 == | ||
2937 | pthread_mutex_unlock (&pg->event_lock)); | ||
2938 | return NULL; | ||
2939 | } | ||
2940 | |||
2941 | |||
2942 | /** | ||
2943 | * Function called whenever the socket needed for | ||
2944 | * notifications from postgres changes. | ||
2945 | * | ||
2946 | * @param cls closure | ||
2947 | * @param fd socket to listen on, -1 for none | ||
2948 | */ | ||
2949 | static void | ||
2950 | pq_socket_cb (void *cls, | ||
2951 | int fd) | ||
2952 | { | ||
2953 | struct PostgresClosure *pg = cls; | ||
2954 | uint64_t val = 1; | ||
2955 | |||
2956 | pg->pg_sock = fd; | ||
2957 | GNUNET_break (sizeof (uint64_t) == | ||
2958 | write (pg->event_fd, | ||
2959 | &val, | ||
2960 | sizeof (val))); | ||
2961 | } | ||
2962 | |||
2963 | |||
2964 | /** | ||
2965 | * Register callback to be invoked on events of type @a es. | 2673 | * Register callback to be invoked on events of type @a es. |
2966 | * | 2674 | * |
2967 | * @param cls database context to use | 2675 | * @param cls database context to use |
@@ -2972,7 +2680,7 @@ pq_socket_cb (void *cls, | |||
2972 | * @param cb_cls closure for @a cb | 2680 | * @param cb_cls closure for @a cb |
2973 | * @return handle useful to cancel the listener | 2681 | * @return handle useful to cancel the listener |
2974 | */ | 2682 | */ |
2975 | static struct TALER_EXCHANGEDB_EventHandler * | 2683 | static struct GNUNET_DB_EventHandler * |
2976 | postgres_event_listen (void *cls, | 2684 | postgres_event_listen (void *cls, |
2977 | struct GNUNET_TIME_Relative timeout, | 2685 | struct GNUNET_TIME_Relative timeout, |
2978 | const struct GNUNET_DB_EventHeaderP *es, | 2686 | const struct GNUNET_DB_EventHeaderP *es, |
@@ -2980,36 +2688,12 @@ postgres_event_listen (void *cls, | |||
2980 | void *cb_cls) | 2688 | void *cb_cls) |
2981 | { | 2689 | { |
2982 | struct PostgresClosure *pg = cls; | 2690 | struct PostgresClosure *pg = cls; |
2983 | struct TALER_EXCHANGEDB_EventHandler *eh; | 2691 | |
2984 | struct TALER_EXCHANGEDB_Session *session; | 2692 | return GNUNET_PQ_event_listen (pg->conn, |
2985 | 2693 | es, | |
2986 | session = postgres_get_session (pg); | 2694 | timeout, |
2987 | eh = GNUNET_new (struct TALER_EXCHANGEDB_EventHandler); | 2695 | cb, |
2988 | eh->cb = cb; | 2696 | cb_cls); |
2989 | eh->cb_cls = cb_cls; | ||
2990 | eh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
2991 | eh->geh = GNUNET_PQ_event_listen (session->conn, | ||
2992 | es, | ||
2993 | cb, | ||
2994 | cb_cls); | ||
2995 | GNUNET_assert (NULL != eh->geh); | ||
2996 | eh->hn = GNUNET_CONTAINER_heap_insert (pg->event_heap, | ||
2997 | eh, | ||
2998 | eh->timeout.abs_value_us); | ||
2999 | GNUNET_assert (0 == | ||
3000 | pthread_mutex_lock (&pg->event_lock)); | ||
3001 | pg->listener_count++; | ||
3002 | if (1 == pg->listener_count) | ||
3003 | { | ||
3004 | GNUNET_assert (0 == | ||
3005 | pthread_create (&pg->event_thread, | ||
3006 | NULL, | ||
3007 | &handle_events, | ||
3008 | pg)); | ||
3009 | } | ||
3010 | GNUNET_assert (0 == | ||
3011 | pthread_mutex_unlock (&pg->event_lock)); | ||
3012 | return eh; | ||
3013 | } | 2697 | } |
3014 | 2698 | ||
3015 | 2699 | ||
@@ -3021,35 +2705,10 @@ postgres_event_listen (void *cls, | |||
3021 | */ | 2705 | */ |
3022 | static void | 2706 | static void |
3023 | postgres_event_listen_cancel (void *cls, | 2707 | postgres_event_listen_cancel (void *cls, |
3024 | struct TALER_EXCHANGEDB_EventHandler *eh) | 2708 | struct GNUNET_DB_EventHandler *eh) |
3025 | { | 2709 | { |
3026 | struct PostgresClosure *pg = cls; | 2710 | (void) cls; |
3027 | 2711 | GNUNET_PQ_event_listen_cancel (eh); | |
3028 | GNUNET_assert (0 == | ||
3029 | pthread_mutex_lock (&pg->event_lock)); | ||
3030 | pg->listener_count--; | ||
3031 | if (0 == pg->listener_count) | ||
3032 | { | ||
3033 | uint64_t val = 1; | ||
3034 | void *ret; | ||
3035 | |||
3036 | GNUNET_break (sizeof (uint64_t) == | ||
3037 | write (pg->event_fd, | ||
3038 | &val, | ||
3039 | sizeof (val))); | ||
3040 | GNUNET_break (0 == | ||
3041 | pthread_join (pg->event_thread, | ||
3042 | &ret)); | ||
3043 | } | ||
3044 | GNUNET_assert (0 == | ||
3045 | pthread_mutex_unlock (&pg->event_lock)); | ||
3046 | if (NULL != eh->hn) | ||
3047 | { | ||
3048 | GNUNET_CONTAINER_heap_remove_node (eh->hn); | ||
3049 | eh->hn = NULL; | ||
3050 | } | ||
3051 | GNUNET_PQ_event_listen_cancel (eh->geh); | ||
3052 | GNUNET_free (eh); | ||
3053 | } | 2712 | } |
3054 | 2713 | ||
3055 | 2714 | ||
@@ -3057,22 +2716,19 @@ postgres_event_listen_cancel (void *cls, | |||
3057 | * Notify all that listen on @a es of an event. | 2716 | * Notify all that listen on @a es of an event. |
3058 | * | 2717 | * |
3059 | * @param cls database context to use | 2718 | * @param cls database context to use |
3060 | * @param session connection to use | ||
3061 | * @param es specification of the event to generate | 2719 | * @param es specification of the event to generate |
3062 | * @param extra additional event data provided | 2720 | * @param extra additional event data provided |
3063 | * @param extra_size number of bytes in @a extra | 2721 | * @param extra_size number of bytes in @a extra |
3064 | */ | 2722 | */ |
3065 | static void | 2723 | static void |
3066 | postgres_event_notify (void *cls, | 2724 | postgres_event_notify (void *cls, |
3067 | struct TALER_EXCHANGEDB_Session *session, | ||
3068 | const struct GNUNET_DB_EventHeaderP *es, | 2725 | const struct GNUNET_DB_EventHeaderP *es, |
3069 | const void *extra, | 2726 | const void *extra, |
3070 | size_t extra_size) | 2727 | size_t extra_size) |
3071 | { | 2728 | { |
3072 | struct PostgresClosure *pg = cls; | 2729 | struct PostgresClosure *pg = cls; |
3073 | 2730 | ||
3074 | (void) pg; | 2731 | GNUNET_PQ_event_notify (pg->conn, |
3075 | GNUNET_PQ_event_notify (session->conn, | ||
3076 | es, | 2732 | es, |
3077 | extra, | 2733 | extra, |
3078 | extra_size); | 2734 | extra_size); |
@@ -3084,7 +2740,6 @@ postgres_event_notify (void *cls, | |||
3084 | * reference by auditors and other consistency checks. | 2740 | * reference by auditors and other consistency checks. |
3085 | * | 2741 | * |
3086 | * @param cls the @e cls of this struct with the plugin-specific state | 2742 | * @param cls the @e cls of this struct with the plugin-specific state |
3087 | * @param session connection to use | ||
3088 | * @param denom_pub the public key used for signing coins of this denomination | 2743 | * @param denom_pub the public key used for signing coins of this denomination |
3089 | * @param issue issuing information with value, fees and other info about the coin | 2744 | * @param issue issuing information with value, fees and other info about the coin |
3090 | * @return status of the query | 2745 | * @return status of the query |
@@ -3092,10 +2747,10 @@ postgres_event_notify (void *cls, | |||
3092 | static enum GNUNET_DB_QueryStatus | 2747 | static enum GNUNET_DB_QueryStatus |
3093 | postgres_insert_denomination_info ( | 2748 | postgres_insert_denomination_info ( |
3094 | void *cls, | 2749 | void *cls, |
3095 | struct TALER_EXCHANGEDB_Session *session, | ||
3096 | const struct TALER_DenominationPublicKey *denom_pub, | 2750 | const struct TALER_DenominationPublicKey *denom_pub, |
3097 | const struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) | 2751 | const struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) |
3098 | { | 2752 | { |
2753 | struct PostgresClosure *pg = cls; | ||
3099 | struct GNUNET_PQ_QueryParam params[] = { | 2754 | struct GNUNET_PQ_QueryParam params[] = { |
3100 | GNUNET_PQ_query_param_auto_from_type (&issue->properties.denom_hash), | 2755 | GNUNET_PQ_query_param_auto_from_type (&issue->properties.denom_hash), |
3101 | GNUNET_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key), | 2756 | GNUNET_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key), |
@@ -3112,7 +2767,6 @@ postgres_insert_denomination_info ( | |||
3112 | GNUNET_PQ_query_param_end | 2767 | GNUNET_PQ_query_param_end |
3113 | }; | 2768 | }; |
3114 | 2769 | ||
3115 | (void) cls; | ||
3116 | GNUNET_assert (0 != GNUNET_TIME_absolute_ntoh ( | 2770 | GNUNET_assert (0 != GNUNET_TIME_absolute_ntoh ( |
3117 | issue->properties.start).abs_value_us); | 2771 | issue->properties.start).abs_value_us); |
3118 | GNUNET_assert (0 != GNUNET_TIME_absolute_ntoh ( | 2772 | GNUNET_assert (0 != GNUNET_TIME_absolute_ntoh ( |
@@ -3135,7 +2789,7 @@ postgres_insert_denomination_info ( | |||
3135 | TALER_amount_cmp_currency_nbo (&issue->properties.value, | 2789 | TALER_amount_cmp_currency_nbo (&issue->properties.value, |
3136 | &issue->properties.fee_refund)); | 2790 | &issue->properties.fee_refund)); |
3137 | 2791 | ||
3138 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 2792 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
3139 | "denomination_insert", | 2793 | "denomination_insert", |
3140 | params); | 2794 | params); |
3141 | } | 2795 | } |
@@ -3145,7 +2799,6 @@ postgres_insert_denomination_info ( | |||
3145 | * Fetch information about a denomination key. | 2799 | * Fetch information about a denomination key. |
3146 | * | 2800 | * |
3147 | * @param cls the @e cls of this struct with the plugin-specific state | 2801 | * @param cls the @e cls of this struct with the plugin-specific state |
3148 | * @param session connection to use | ||
3149 | * @param denom_pub_hash hash of the public key used for signing coins of this denomination | 2802 | * @param denom_pub_hash hash of the public key used for signing coins of this denomination |
3150 | * @param[out] issue set to issue information with value, fees and other info about the coin | 2803 | * @param[out] issue set to issue information with value, fees and other info about the coin |
3151 | * @return transaction status code | 2804 | * @return transaction status code |
@@ -3153,7 +2806,6 @@ postgres_insert_denomination_info ( | |||
3153 | static enum GNUNET_DB_QueryStatus | 2806 | static enum GNUNET_DB_QueryStatus |
3154 | postgres_get_denomination_info ( | 2807 | postgres_get_denomination_info ( |
3155 | void *cls, | 2808 | void *cls, |
3156 | struct TALER_EXCHANGEDB_Session *session, | ||
3157 | const struct GNUNET_HashCode *denom_pub_hash, | 2809 | const struct GNUNET_HashCode *denom_pub_hash, |
3158 | struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) | 2810 | struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) |
3159 | { | 2811 | { |
@@ -3190,7 +2842,7 @@ postgres_get_denomination_info ( | |||
3190 | memset (&issue->properties.master, | 2842 | memset (&issue->properties.master, |
3191 | 0, | 2843 | 0, |
3192 | sizeof (issue->properties.master)); | 2844 | sizeof (issue->properties.master)); |
3193 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 2845 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
3194 | "denomination_get", | 2846 | "denomination_get", |
3195 | params, | 2847 | params, |
3196 | rs); | 2848 | rs); |
@@ -3302,32 +2954,26 @@ domination_cb_helper (void *cls, | |||
3302 | * Fetch information about all known denomination keys. | 2954 | * Fetch information about all known denomination keys. |
3303 | * | 2955 | * |
3304 | * @param cls the @e cls of this struct with the plugin-specific state | 2956 | * @param cls the @e cls of this struct with the plugin-specific state |
3305 | * @param session connection to use | ||
3306 | * @param cb function to call on each denomination key | 2957 | * @param cb function to call on each denomination key |
3307 | * @param cb_cls closure for @a cb | 2958 | * @param cb_cls closure for @a cb |
3308 | * @return transaction status code | 2959 | * @return transaction status code |
3309 | */ | 2960 | */ |
3310 | static enum GNUNET_DB_QueryStatus | 2961 | static enum GNUNET_DB_QueryStatus |
3311 | postgres_iterate_denomination_info (void *cls, | 2962 | postgres_iterate_denomination_info (void *cls, |
3312 | struct TALER_EXCHANGEDB_Session *session, | ||
3313 | TALER_EXCHANGEDB_DenominationCallback cb, | 2963 | TALER_EXCHANGEDB_DenominationCallback cb, |
3314 | void *cb_cls) | 2964 | void *cb_cls) |
3315 | { | 2965 | { |
3316 | struct PostgresClosure *pc = cls; | 2966 | struct PostgresClosure *pg = cls; |
3317 | struct GNUNET_PQ_QueryParam params[] = { | 2967 | struct GNUNET_PQ_QueryParam params[] = { |
3318 | GNUNET_PQ_query_param_end | 2968 | GNUNET_PQ_query_param_end |
3319 | }; | 2969 | }; |
3320 | struct DenomIteratorContext dic = { | 2970 | struct DenomIteratorContext dic = { |
3321 | .cb = cb, | 2971 | .cb = cb, |
3322 | .cb_cls = cb_cls, | 2972 | .cb_cls = cb_cls, |
3323 | .pg = pc | 2973 | .pg = pg |
3324 | }; | 2974 | }; |
3325 | 2975 | ||
3326 | if (NULL == session) | 2976 | return GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
3327 | session = postgres_get_session (pc); | ||
3328 | if (NULL == session) | ||
3329 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
3330 | return GNUNET_PQ_eval_prepared_multi_select (session->conn, | ||
3331 | "denomination_iterate", | 2977 | "denomination_iterate", |
3332 | params, | 2978 | params, |
3333 | &domination_cb_helper, | 2979 | &domination_cb_helper, |
@@ -3432,7 +3078,7 @@ dominations_cb_helper (void *cls, | |||
3432 | /** | 3078 | /** |
3433 | * Function called to invoke @a cb on every known denomination key (revoked | 3079 | * Function called to invoke @a cb on every known denomination key (revoked |
3434 | * and non-revoked) that has been signed by the master key. Runs in its own | 3080 | * and non-revoked) that has been signed by the master key. Runs in its own |
3435 | * read-only transaction (hence no session provided). | 3081 | * read-only transaction. |
3436 | * | 3082 | * |
3437 | * | 3083 | * |
3438 | * @param cls the @e cls of this struct with the plugin-specific state | 3084 | * @param cls the @e cls of this struct with the plugin-specific state |
@@ -3445,21 +3091,17 @@ postgres_iterate_denominations (void *cls, | |||
3445 | TALER_EXCHANGEDB_DenominationsCallback cb, | 3091 | TALER_EXCHANGEDB_DenominationsCallback cb, |
3446 | void *cb_cls) | 3092 | void *cb_cls) |
3447 | { | 3093 | { |
3448 | struct PostgresClosure *pc = cls; | 3094 | struct PostgresClosure *pg = cls; |
3449 | struct GNUNET_PQ_QueryParam params[] = { | 3095 | struct GNUNET_PQ_QueryParam params[] = { |
3450 | GNUNET_PQ_query_param_end | 3096 | GNUNET_PQ_query_param_end |
3451 | }; | 3097 | }; |
3452 | struct DenomsIteratorContext dic = { | 3098 | struct DenomsIteratorContext dic = { |
3453 | .cb = cb, | 3099 | .cb = cb, |
3454 | .cb_cls = cb_cls, | 3100 | .cb_cls = cb_cls, |
3455 | .pg = pc | 3101 | .pg = pg |
3456 | }; | 3102 | }; |
3457 | struct TALER_EXCHANGEDB_Session *session; | ||
3458 | 3103 | ||
3459 | session = postgres_get_session (pc); | 3104 | return GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
3460 | if (NULL == session) | ||
3461 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
3462 | return GNUNET_PQ_eval_prepared_multi_select (session->conn, | ||
3463 | "select_denominations", | 3105 | "select_denominations", |
3464 | params, | 3106 | params, |
3465 | &dominations_cb_helper, | 3107 | &dominations_cb_helper, |
@@ -3538,8 +3180,7 @@ signkeys_cb_helper (void *cls, | |||
3538 | /** | 3180 | /** |
3539 | * Function called to invoke @a cb on every non-revoked exchange signing key | 3181 | * Function called to invoke @a cb on every non-revoked exchange signing key |
3540 | * that has been signed by the master key. Revoked and (for signing!) | 3182 | * that has been signed by the master key. Revoked and (for signing!) |
3541 | * expired keys are skipped. Runs in its own read-only transaction (hence no | 3183 | * expired keys are skipped. Runs in its own read-only transaction. |
3542 | * session provided). | ||
3543 | * | 3184 | * |
3544 | * @param cls the @e cls of this struct with the plugin-specific state | 3185 | * @param cls the @e cls of this struct with the plugin-specific state |
3545 | * @param cb function to call on each signing key | 3186 | * @param cb function to call on each signing key |
@@ -3551,7 +3192,7 @@ postgres_iterate_active_signkeys (void *cls, | |||
3551 | TALER_EXCHANGEDB_ActiveSignkeysCallback cb, | 3192 | TALER_EXCHANGEDB_ActiveSignkeysCallback cb, |
3552 | void *cb_cls) | 3193 | void *cb_cls) |
3553 | { | 3194 | { |
3554 | struct PostgresClosure *pc = cls; | 3195 | struct PostgresClosure *pg = cls; |
3555 | struct GNUNET_TIME_Absolute now; | 3196 | struct GNUNET_TIME_Absolute now; |
3556 | struct GNUNET_PQ_QueryParam params[] = { | 3197 | struct GNUNET_PQ_QueryParam params[] = { |
3557 | GNUNET_PQ_query_param_absolute_time (&now), | 3198 | GNUNET_PQ_query_param_absolute_time (&now), |
@@ -3561,13 +3202,9 @@ postgres_iterate_active_signkeys (void *cls, | |||
3561 | .cb = cb, | 3202 | .cb = cb, |
3562 | .cb_cls = cb_cls, | 3203 | .cb_cls = cb_cls, |
3563 | }; | 3204 | }; |
3564 | struct TALER_EXCHANGEDB_Session *session; | ||
3565 | 3205 | ||
3566 | now = GNUNET_TIME_absolute_get (); | 3206 | now = GNUNET_TIME_absolute_get (); |
3567 | session = postgres_get_session (pc); | 3207 | return GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
3568 | if (NULL == session) | ||
3569 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
3570 | return GNUNET_PQ_eval_prepared_multi_select (session->conn, | ||
3571 | "select_signkeys", | 3208 | "select_signkeys", |
3572 | params, | 3209 | params, |
3573 | &signkeys_cb_helper, | 3210 | &signkeys_cb_helper, |
@@ -3642,8 +3279,7 @@ auditors_cb_helper (void *cls, | |||
3642 | 3279 | ||
3643 | /** | 3280 | /** |
3644 | * Function called to invoke @a cb on every active auditor. Disabled | 3281 | * Function called to invoke @a cb on every active auditor. Disabled |
3645 | * auditors are skipped. Runs in its own read-only transaction (hence no | 3282 | * auditors are skipped. Runs in its own read-only transaction. |
3646 | * session provided). | ||
3647 | * | 3283 | * |
3648 | * @param cls the @e cls of this struct with the plugin-specific state | 3284 | * @param cls the @e cls of this struct with the plugin-specific state |
3649 | * @param cb function to call on each active auditor | 3285 | * @param cb function to call on each active auditor |
@@ -3655,7 +3291,7 @@ postgres_iterate_active_auditors (void *cls, | |||
3655 | TALER_EXCHANGEDB_AuditorsCallback cb, | 3291 | TALER_EXCHANGEDB_AuditorsCallback cb, |
3656 | void *cb_cls) | 3292 | void *cb_cls) |
3657 | { | 3293 | { |
3658 | struct PostgresClosure *pc = cls; | 3294 | struct PostgresClosure *pg = cls; |
3659 | struct GNUNET_PQ_QueryParam params[] = { | 3295 | struct GNUNET_PQ_QueryParam params[] = { |
3660 | GNUNET_PQ_query_param_end | 3296 | GNUNET_PQ_query_param_end |
3661 | }; | 3297 | }; |
@@ -3663,12 +3299,8 @@ postgres_iterate_active_auditors (void *cls, | |||
3663 | .cb = cb, | 3299 | .cb = cb, |
3664 | .cb_cls = cb_cls, | 3300 | .cb_cls = cb_cls, |
3665 | }; | 3301 | }; |
3666 | struct TALER_EXCHANGEDB_Session *session; | ||
3667 | 3302 | ||
3668 | session = postgres_get_session (pc); | 3303 | return GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
3669 | if (NULL == session) | ||
3670 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
3671 | return GNUNET_PQ_eval_prepared_multi_select (session->conn, | ||
3672 | "select_auditors", | 3304 | "select_auditors", |
3673 | params, | 3305 | params, |
3674 | &auditors_cb_helper, | 3306 | &auditors_cb_helper, |
@@ -3742,8 +3374,7 @@ auditor_denoms_cb_helper (void *cls, | |||
3742 | /** | 3374 | /** |
3743 | * Function called to invoke @a cb on every denomination with an active | 3375 | * Function called to invoke @a cb on every denomination with an active |
3744 | * auditor. Disabled auditors and denominations without auditor are | 3376 | * auditor. Disabled auditors and denominations without auditor are |
3745 | * skipped. Runs in its own read-only transaction (hence no session | 3377 | * skipped. Runs in its own read-only transaction. |
3746 | * provided). | ||
3747 | * | 3378 | * |
3748 | * @param cls the @e cls of this struct with the plugin-specific state | 3379 | * @param cls the @e cls of this struct with the plugin-specific state |
3749 | * @param cb function to call on each active auditor | 3380 | * @param cb function to call on each active auditor |
@@ -3756,7 +3387,7 @@ postgres_iterate_auditor_denominations ( | |||
3756 | TALER_EXCHANGEDB_AuditorDenominationsCallback cb, | 3387 | TALER_EXCHANGEDB_AuditorDenominationsCallback cb, |
3757 | void *cb_cls) | 3388 | void *cb_cls) |
3758 | { | 3389 | { |
3759 | struct PostgresClosure *pc = cls; | 3390 | struct PostgresClosure *pg = cls; |
3760 | struct GNUNET_PQ_QueryParam params[] = { | 3391 | struct GNUNET_PQ_QueryParam params[] = { |
3761 | GNUNET_PQ_query_param_end | 3392 | GNUNET_PQ_query_param_end |
3762 | }; | 3393 | }; |
@@ -3764,12 +3395,8 @@ postgres_iterate_auditor_denominations ( | |||
3764 | .cb = cb, | 3395 | .cb = cb, |
3765 | .cb_cls = cb_cls, | 3396 | .cb_cls = cb_cls, |
3766 | }; | 3397 | }; |
3767 | struct TALER_EXCHANGEDB_Session *session; | ||
3768 | 3398 | ||
3769 | session = postgres_get_session (pc); | 3399 | return GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
3770 | if (NULL == session) | ||
3771 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
3772 | return GNUNET_PQ_eval_prepared_multi_select (session->conn, | ||
3773 | "select_auditor_denoms", | 3400 | "select_auditor_denoms", |
3774 | params, | 3401 | params, |
3775 | &auditor_denoms_cb_helper, | 3402 | &auditor_denoms_cb_helper, |
@@ -3781,7 +3408,6 @@ postgres_iterate_auditor_denominations ( | |||
3781 | * Get the summary of a reserve. | 3408 | * Get the summary of a reserve. |
3782 | * | 3409 | * |
3783 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 3410 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
3784 | * @param session the database connection handle | ||
3785 | * @param[in,out] reserve the reserve data. The public key of the reserve should be | 3411 | * @param[in,out] reserve the reserve data. The public key of the reserve should be |
3786 | * set in this structure; it is used to query the database. The balance | 3412 | * set in this structure; it is used to query the database. The balance |
3787 | * and expiration are then filled accordingly. | 3413 | * and expiration are then filled accordingly. |
@@ -3789,7 +3415,6 @@ postgres_iterate_auditor_denominations ( | |||
3789 | */ | 3415 | */ |
3790 | static enum GNUNET_DB_QueryStatus | 3416 | static enum GNUNET_DB_QueryStatus |
3791 | postgres_reserves_get (void *cls, | 3417 | postgres_reserves_get (void *cls, |
3792 | struct TALER_EXCHANGEDB_Session *session, | ||
3793 | struct TALER_EXCHANGEDB_Reserve *reserve) | 3418 | struct TALER_EXCHANGEDB_Reserve *reserve) |
3794 | { | 3419 | { |
3795 | struct PostgresClosure *pg = cls; | 3420 | struct PostgresClosure *pg = cls; |
@@ -3804,7 +3429,7 @@ postgres_reserves_get (void *cls, | |||
3804 | GNUNET_PQ_result_spec_end | 3429 | GNUNET_PQ_result_spec_end |
3805 | }; | 3430 | }; |
3806 | 3431 | ||
3807 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 3432 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
3808 | "reserves_get", | 3433 | "reserves_get", |
3809 | params, | 3434 | params, |
3810 | rs); | 3435 | rs); |
@@ -3815,16 +3440,15 @@ postgres_reserves_get (void *cls, | |||
3815 | * Updates a reserve with the data from the given reserve structure. | 3440 | * Updates a reserve with the data from the given reserve structure. |
3816 | * | 3441 | * |
3817 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 3442 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
3818 | * @param session the database connection | ||
3819 | * @param reserve the reserve structure whose data will be used to update the | 3443 | * @param reserve the reserve structure whose data will be used to update the |
3820 | * corresponding record in the database. | 3444 | * corresponding record in the database. |
3821 | * @return transaction status | 3445 | * @return transaction status |
3822 | */ | 3446 | */ |
3823 | static enum GNUNET_DB_QueryStatus | 3447 | static enum GNUNET_DB_QueryStatus |
3824 | reserves_update (void *cls, | 3448 | reserves_update (void *cls, |
3825 | struct TALER_EXCHANGEDB_Session *session, | ||
3826 | const struct TALER_EXCHANGEDB_Reserve *reserve) | 3449 | const struct TALER_EXCHANGEDB_Reserve *reserve) |
3827 | { | 3450 | { |
3451 | struct PostgresClosure *pg = cls; | ||
3828 | struct GNUNET_PQ_QueryParam params[] = { | 3452 | struct GNUNET_PQ_QueryParam params[] = { |
3829 | TALER_PQ_query_param_absolute_time (&reserve->expiry), | 3453 | TALER_PQ_query_param_absolute_time (&reserve->expiry), |
3830 | TALER_PQ_query_param_absolute_time (&reserve->gc), | 3454 | TALER_PQ_query_param_absolute_time (&reserve->gc), |
@@ -3833,8 +3457,7 @@ reserves_update (void *cls, | |||
3833 | GNUNET_PQ_query_param_end | 3457 | GNUNET_PQ_query_param_end |
3834 | }; | 3458 | }; |
3835 | 3459 | ||
3836 | (void) cls; | 3460 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
3837 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
3838 | "reserve_update", | 3461 | "reserve_update", |
3839 | params); | 3462 | params); |
3840 | } | 3463 | } |
@@ -3844,12 +3467,11 @@ reserves_update (void *cls, | |||
3844 | * Generate event notification for the reserve | 3467 | * Generate event notification for the reserve |
3845 | * change. | 3468 | * change. |
3846 | * | 3469 | * |
3847 | * @param session database session to use | 3470 | * @param pg plugin state |
3848 | * @param reserve_pub reserve to notfiy on | 3471 | * @param reserve_pub reserve to notfiy on |
3849 | */ | 3472 | */ |
3850 | static void | 3473 | static void |
3851 | notify_on_reserve (struct PostgresClosure *pg, | 3474 | notify_on_reserve (struct PostgresClosure *pg, |
3852 | struct TALER_EXCHANGEDB_Session *session, | ||
3853 | const struct TALER_ReservePublicKeyP *reserve_pub) | 3475 | const struct TALER_ReservePublicKeyP *reserve_pub) |
3854 | { | 3476 | { |
3855 | struct TALER_ReserveEventP rep = { | 3477 | struct TALER_ReserveEventP rep = { |
@@ -3858,8 +3480,9 @@ notify_on_reserve (struct PostgresClosure *pg, | |||
3858 | .reserve_pub = *reserve_pub | 3480 | .reserve_pub = *reserve_pub |
3859 | }; | 3481 | }; |
3860 | 3482 | ||
3483 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3484 | "Notifying on reserve!\n"); | ||
3861 | postgres_event_notify (pg, | 3485 | postgres_event_notify (pg, |
3862 | session, | ||
3863 | &rep.header, | 3486 | &rep.header, |
3864 | NULL, | 3487 | NULL, |
3865 | 0); | 3488 | 0); |
@@ -3871,7 +3494,6 @@ notify_on_reserve (struct PostgresClosure *pg, | |||
3871 | * through this function. | 3494 | * through this function. |
3872 | * | 3495 | * |
3873 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 3496 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
3874 | * @param session the database connection handle | ||
3875 | * @param reserve_pub public key of the reserve | 3497 | * @param reserve_pub public key of the reserve |
3876 | * @param balance the amount that has to be added to the reserve | 3498 | * @param balance the amount that has to be added to the reserve |
3877 | * @param execution_time when was the amount added | 3499 | * @param execution_time when was the amount added |
@@ -3883,7 +3505,6 @@ notify_on_reserve (struct PostgresClosure *pg, | |||
3883 | */ | 3505 | */ |
3884 | static enum GNUNET_DB_QueryStatus | 3506 | static enum GNUNET_DB_QueryStatus |
3885 | postgres_reserves_in_insert (void *cls, | 3507 | postgres_reserves_in_insert (void *cls, |
3886 | struct TALER_EXCHANGEDB_Session *session, | ||
3887 | const struct TALER_ReservePublicKeyP *reserve_pub, | 3508 | const struct TALER_ReservePublicKeyP *reserve_pub, |
3888 | const struct TALER_Amount *balance, | 3509 | const struct TALER_Amount *balance, |
3889 | struct GNUNET_TIME_Absolute execution_time, | 3510 | struct GNUNET_TIME_Absolute execution_time, |
@@ -3936,7 +3557,7 @@ postgres_reserves_in_insert (void *cls, | |||
3936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3937 | "Reserve does not exist; creating a new one\n"); | 3558 | "Reserve does not exist; creating a new one\n"); |
3938 | /* Note: query uses 'on conflict do nothing' */ | 3559 | /* Note: query uses 'on conflict do nothing' */ |
3939 | qs1 = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 3560 | qs1 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
3940 | "reserve_create", | 3561 | "reserve_create", |
3941 | params, | 3562 | params, |
3942 | rs); | 3563 | rs); |
@@ -3961,7 +3582,7 @@ postgres_reserves_in_insert (void *cls, | |||
3961 | GNUNET_PQ_query_param_end | 3582 | GNUNET_PQ_query_param_end |
3962 | }; | 3583 | }; |
3963 | 3584 | ||
3964 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3585 | qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
3965 | "reserves_in_add_transaction", | 3586 | "reserves_in_add_transaction", |
3966 | params); | 3587 | params); |
3967 | } | 3588 | } |
@@ -3977,7 +3598,7 @@ postgres_reserves_in_insert (void *cls, | |||
3977 | GNUNET_PQ_query_param_end | 3598 | GNUNET_PQ_query_param_end |
3978 | }; | 3599 | }; |
3979 | 3600 | ||
3980 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3601 | qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
3981 | "reserves_in_add_by_uuid", | 3602 | "reserves_in_add_by_uuid", |
3982 | params); | 3603 | params); |
3983 | } | 3604 | } |
@@ -4002,7 +3623,6 @@ postgres_reserves_in_insert (void *cls, | |||
4002 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs1) | 3623 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs1) |
4003 | { | 3624 | { |
4004 | notify_on_reserve (pg, | 3625 | notify_on_reserve (pg, |
4005 | session, | ||
4006 | reserve_pub); | 3626 | reserve_pub); |
4007 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* new reserve, we are finished */ | 3627 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* new reserve, we are finished */ |
4008 | } | 3628 | } |
@@ -4012,13 +3632,11 @@ postgres_reserves_in_insert (void *cls, | |||
4012 | { | 3632 | { |
4013 | enum GNUNET_DB_QueryStatus cs; | 3633 | enum GNUNET_DB_QueryStatus cs; |
4014 | 3634 | ||
4015 | cs = postgres_commit (cls, | 3635 | cs = postgres_commit (pg); |
4016 | session); | ||
4017 | if (cs < 0) | 3636 | if (cs < 0) |
4018 | return cs; | 3637 | return cs; |
4019 | if (GNUNET_OK != | 3638 | if (GNUNET_OK != |
4020 | postgres_start (cls, | 3639 | postgres_start (pg, |
4021 | session, | ||
4022 | "reserve-update-serializable")) | 3640 | "reserve-update-serializable")) |
4023 | { | 3641 | { |
4024 | GNUNET_break (0); | 3642 | GNUNET_break (0); |
@@ -4028,8 +3646,7 @@ postgres_reserves_in_insert (void *cls, | |||
4028 | { | 3646 | { |
4029 | enum GNUNET_DB_QueryStatus reserve_exists; | 3647 | enum GNUNET_DB_QueryStatus reserve_exists; |
4030 | 3648 | ||
4031 | reserve_exists = postgres_reserves_get (cls, | 3649 | reserve_exists = postgres_reserves_get (pg, |
4032 | session, | ||
4033 | &reserve); | 3650 | &reserve); |
4034 | switch (reserve_exists) | 3651 | switch (reserve_exists) |
4035 | { | 3652 | { |
@@ -4074,8 +3691,7 @@ postgres_reserves_in_insert (void *cls, | |||
4074 | updated_reserve.gc = GNUNET_TIME_absolute_max (gc, | 3691 | updated_reserve.gc = GNUNET_TIME_absolute_max (gc, |
4075 | reserve.gc); | 3692 | reserve.gc); |
4076 | (void) GNUNET_TIME_round_abs (&updated_reserve.gc); | 3693 | (void) GNUNET_TIME_round_abs (&updated_reserve.gc); |
4077 | qs3 = reserves_update (cls, | 3694 | qs3 = reserves_update (pg, |
4078 | session, | ||
4079 | &updated_reserve); | 3695 | &updated_reserve); |
4080 | switch (qs3) | 3696 | switch (qs3) |
4081 | { | 3697 | { |
@@ -4094,19 +3710,16 @@ postgres_reserves_in_insert (void *cls, | |||
4094 | } | 3710 | } |
4095 | } | 3711 | } |
4096 | notify_on_reserve (pg, | 3712 | notify_on_reserve (pg, |
4097 | session, | ||
4098 | reserve_pub); | 3713 | reserve_pub); |
4099 | /* Go back to original transaction mode */ | 3714 | /* Go back to original transaction mode */ |
4100 | { | 3715 | { |
4101 | enum GNUNET_DB_QueryStatus cs; | 3716 | enum GNUNET_DB_QueryStatus cs; |
4102 | 3717 | ||
4103 | cs = postgres_commit (cls, | 3718 | cs = postgres_commit (pg); |
4104 | session); | ||
4105 | if (cs < 0) | 3719 | if (cs < 0) |
4106 | return cs; | 3720 | return cs; |
4107 | if (GNUNET_OK != | 3721 | if (GNUNET_OK != |
4108 | postgres_start_read_committed (cls, | 3722 | postgres_start_read_committed (pg, |
4109 | session, | ||
4110 | "reserve-insert-continued")) | 3723 | "reserve-insert-continued")) |
4111 | { | 3724 | { |
4112 | GNUNET_break (0); | 3725 | GNUNET_break (0); |
@@ -4121,7 +3734,6 @@ postgres_reserves_in_insert (void *cls, | |||
4121 | * Obtain the most recent @a wire_reference that was inserted via @e reserves_in_insert. | 3734 | * Obtain the most recent @a wire_reference that was inserted via @e reserves_in_insert. |
4122 | * | 3735 | * |
4123 | * @param cls the @e cls of this struct with the plugin-specific state | 3736 | * @param cls the @e cls of this struct with the plugin-specific state |
4124 | * @param session the database session handle | ||
4125 | * @param exchange_account_name name of the section in the exchange's configuration | 3737 | * @param exchange_account_name name of the section in the exchange's configuration |
4126 | * for the account that we are tracking here | 3738 | * for the account that we are tracking here |
4127 | * @param[out] wire_reference set to unique reference identifying the wire transfer | 3739 | * @param[out] wire_reference set to unique reference identifying the wire transfer |
@@ -4130,10 +3742,10 @@ postgres_reserves_in_insert (void *cls, | |||
4130 | static enum GNUNET_DB_QueryStatus | 3742 | static enum GNUNET_DB_QueryStatus |
4131 | postgres_get_latest_reserve_in_reference ( | 3743 | postgres_get_latest_reserve_in_reference ( |
4132 | void *cls, | 3744 | void *cls, |
4133 | struct TALER_EXCHANGEDB_Session *session, | ||
4134 | const char *exchange_account_name, | 3745 | const char *exchange_account_name, |
4135 | uint64_t *wire_reference) | 3746 | uint64_t *wire_reference) |
4136 | { | 3747 | { |
3748 | struct PostgresClosure *pg = cls; | ||
4137 | struct GNUNET_PQ_QueryParam params[] = { | 3749 | struct GNUNET_PQ_QueryParam params[] = { |
4138 | GNUNET_PQ_query_param_string (exchange_account_name), | 3750 | GNUNET_PQ_query_param_string (exchange_account_name), |
4139 | GNUNET_PQ_query_param_end | 3751 | GNUNET_PQ_query_param_end |
@@ -4144,8 +3756,7 @@ postgres_get_latest_reserve_in_reference ( | |||
4144 | GNUNET_PQ_result_spec_end | 3756 | GNUNET_PQ_result_spec_end |
4145 | }; | 3757 | }; |
4146 | 3758 | ||
4147 | (void) cls; | 3759 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
4148 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
4149 | "reserves_in_get_latest_wire_reference", | 3760 | "reserves_in_get_latest_wire_reference", |
4150 | params, | 3761 | params, |
4151 | rs); | 3762 | rs); |
@@ -4157,7 +3768,6 @@ postgres_get_latest_reserve_in_reference ( | |||
4157 | * key of the hash of the blinded message. | 3768 | * key of the hash of the blinded message. |
4158 | * | 3769 | * |
4159 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 3770 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
4160 | * @param session database connection to use | ||
4161 | * @param h_blind hash of the blinded coin to be signed (will match | 3771 | * @param h_blind hash of the blinded coin to be signed (will match |
4162 | * `h_coin_envelope` in the @a collectable to be returned) | 3772 | * `h_coin_envelope` in the @a collectable to be returned) |
4163 | * @param collectable corresponding collectable coin (blind signature) | 3773 | * @param collectable corresponding collectable coin (blind signature) |
@@ -4167,7 +3777,6 @@ postgres_get_latest_reserve_in_reference ( | |||
4167 | static enum GNUNET_DB_QueryStatus | 3777 | static enum GNUNET_DB_QueryStatus |
4168 | postgres_get_withdraw_info ( | 3778 | postgres_get_withdraw_info ( |
4169 | void *cls, | 3779 | void *cls, |
4170 | struct TALER_EXCHANGEDB_Session *session, | ||
4171 | const struct GNUNET_HashCode *h_blind, | 3780 | const struct GNUNET_HashCode *h_blind, |
4172 | struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable) | 3781 | struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable) |
4173 | { | 3782 | { |
@@ -4197,13 +3806,13 @@ postgres_get_withdraw_info ( | |||
4197 | }; | 3806 | }; |
4198 | enum GNUNET_DB_QueryStatus qs; | 3807 | enum GNUNET_DB_QueryStatus qs; |
4199 | 3808 | ||
4200 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3809 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
4201 | "lock_withdraw", | 3810 | "lock_withdraw", |
4202 | no_params))) | 3811 | no_params))) |
4203 | return qs; | 3812 | return qs; |
4204 | #endif | 3813 | #endif |
4205 | collectable->h_coin_envelope = *h_blind; | 3814 | collectable->h_coin_envelope = *h_blind; |
4206 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 3815 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
4207 | "get_withdraw_info", | 3816 | "get_withdraw_info", |
4208 | params, | 3817 | params, |
4209 | rs); | 3818 | rs); |
@@ -4215,7 +3824,6 @@ postgres_get_withdraw_info ( | |||
4215 | * hash of the blinded message. | 3824 | * hash of the blinded message. |
4216 | * | 3825 | * |
4217 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 3826 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
4218 | * @param session database connection to use | ||
4219 | * @param collectable corresponding collectable coin (blind signature) | 3827 | * @param collectable corresponding collectable coin (blind signature) |
4220 | * if a coin is found | 3828 | * if a coin is found |
4221 | * @return query execution status | 3829 | * @return query execution status |
@@ -4223,7 +3831,6 @@ postgres_get_withdraw_info ( | |||
4223 | static enum GNUNET_DB_QueryStatus | 3831 | static enum GNUNET_DB_QueryStatus |
4224 | postgres_insert_withdraw_info ( | 3832 | postgres_insert_withdraw_info ( |
4225 | void *cls, | 3833 | void *cls, |
4226 | struct TALER_EXCHANGEDB_Session *session, | ||
4227 | const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable) | 3834 | const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable) |
4228 | { | 3835 | { |
4229 | struct PostgresClosure *pg = cls; | 3836 | struct PostgresClosure *pg = cls; |
@@ -4244,7 +3851,7 @@ postgres_insert_withdraw_info ( | |||
4244 | 3851 | ||
4245 | now = GNUNET_TIME_absolute_get (); | 3852 | now = GNUNET_TIME_absolute_get (); |
4246 | (void) GNUNET_TIME_round_abs (&now); | 3853 | (void) GNUNET_TIME_round_abs (&now); |
4247 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3854 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
4248 | "insert_withdraw_info", | 3855 | "insert_withdraw_info", |
4249 | params); | 3856 | params); |
4250 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) | 3857 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) |
@@ -4256,8 +3863,7 @@ postgres_insert_withdraw_info ( | |||
4256 | /* update reserve balance */ | 3863 | /* update reserve balance */ |
4257 | reserve.pub = collectable->reserve_pub; | 3864 | reserve.pub = collectable->reserve_pub; |
4258 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != | 3865 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != |
4259 | (qs = postgres_reserves_get (cls, | 3866 | (qs = postgres_reserves_get (pg, |
4260 | session, | ||
4261 | &reserve))) | 3867 | &reserve))) |
4262 | { | 3868 | { |
4263 | /* Should have been checked before we got here... */ | 3869 | /* Should have been checked before we got here... */ |
@@ -4285,8 +3891,7 @@ postgres_insert_withdraw_info ( | |||
4285 | reserve.gc = GNUNET_TIME_absolute_max (gc, | 3891 | reserve.gc = GNUNET_TIME_absolute_max (gc, |
4286 | reserve.gc); | 3892 | reserve.gc); |
4287 | (void) GNUNET_TIME_round_abs (&reserve.gc); | 3893 | (void) GNUNET_TIME_round_abs (&reserve.gc); |
4288 | qs = reserves_update (cls, | 3894 | qs = reserves_update (pg, |
4289 | session, | ||
4290 | &reserve); | 3895 | &reserve); |
4291 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); | 3896 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); |
4292 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) | 3897 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) |
@@ -4590,14 +4195,12 @@ add_exchange_to_bank (void *cls, | |||
4590 | * reserve. | 4195 | * reserve. |
4591 | * | 4196 | * |
4592 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 4197 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
4593 | * @param session connection to use | ||
4594 | * @param reserve_pub public key of the reserve | 4198 | * @param reserve_pub public key of the reserve |
4595 | * @param[out] rhp set to known transaction history (NULL if reserve is unknown) | 4199 | * @param[out] rhp set to known transaction history (NULL if reserve is unknown) |
4596 | * @return transaction status | 4200 | * @return transaction status |
4597 | */ | 4201 | */ |
4598 | static enum GNUNET_DB_QueryStatus | 4202 | static enum GNUNET_DB_QueryStatus |
4599 | postgres_get_reserve_history (void *cls, | 4203 | postgres_get_reserve_history (void *cls, |
4600 | struct TALER_EXCHANGEDB_Session *session, | ||
4601 | const struct TALER_ReservePublicKeyP *reserve_pub, | 4204 | const struct TALER_ReservePublicKeyP *reserve_pub, |
4602 | struct TALER_EXCHANGEDB_ReserveHistory **rhp) | 4205 | struct TALER_EXCHANGEDB_ReserveHistory **rhp) |
4603 | { | 4206 | { |
@@ -4644,7 +4247,7 @@ postgres_get_reserve_history (void *cls, | |||
4644 | qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */ | 4247 | qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */ |
4645 | for (unsigned int i = 0; NULL != work[i].cb; i++) | 4248 | for (unsigned int i = 0; NULL != work[i].cb; i++) |
4646 | { | 4249 | { |
4647 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 4250 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
4648 | work[i].statement, | 4251 | work[i].statement, |
4649 | params, | 4252 | params, |
4650 | work[i].cb, | 4253 | work[i].cb, |
@@ -4674,7 +4277,6 @@ postgres_get_reserve_history (void *cls, | |||
4674 | * Check if we have the specified deposit already in the database. | 4277 | * Check if we have the specified deposit already in the database. |
4675 | * | 4278 | * |
4676 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 4279 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
4677 | * @param session database connection | ||
4678 | * @param deposit deposit to search for | 4280 | * @param deposit deposit to search for |
4679 | * @param check_extras whether to check extra fields match or not | 4281 | * @param check_extras whether to check extra fields match or not |
4680 | * @param[out] deposit_fee set to the deposit fee the exchange charged | 4282 | * @param[out] deposit_fee set to the deposit fee the exchange charged |
@@ -4685,7 +4287,6 @@ postgres_get_reserve_history (void *cls, | |||
4685 | */ | 4287 | */ |
4686 | static enum GNUNET_DB_QueryStatus | 4288 | static enum GNUNET_DB_QueryStatus |
4687 | postgres_have_deposit (void *cls, | 4289 | postgres_have_deposit (void *cls, |
4688 | struct TALER_EXCHANGEDB_Session *session, | ||
4689 | const struct TALER_EXCHANGEDB_Deposit *deposit, | 4290 | const struct TALER_EXCHANGEDB_Deposit *deposit, |
4690 | int check_extras, | 4291 | int check_extras, |
4691 | struct TALER_Amount *deposit_fee, | 4292 | struct TALER_Amount *deposit_fee, |
@@ -4722,7 +4323,7 @@ postgres_have_deposit (void *cls, | |||
4722 | GNUNET_PQ_query_param_end | 4323 | GNUNET_PQ_query_param_end |
4723 | }; | 4324 | }; |
4724 | 4325 | ||
4725 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 4326 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
4726 | "lock_deposit", | 4327 | "lock_deposit", |
4727 | no_params))) | 4328 | no_params))) |
4728 | return qs; | 4329 | return qs; |
@@ -4730,7 +4331,7 @@ postgres_have_deposit (void *cls, | |||
4730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4731 | "Getting deposits for coin %s\n", | 4332 | "Getting deposits for coin %s\n", |
4732 | TALER_B2S (&deposit->coin.coin_pub)); | 4333 | TALER_B2S (&deposit->coin.coin_pub)); |
4733 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 4334 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
4734 | "get_deposit", | 4335 | "get_deposit", |
4735 | params, | 4336 | params, |
4736 | rs); | 4337 | rs); |
@@ -4764,22 +4365,20 @@ postgres_have_deposit (void *cls, | |||
4764 | * @e iterate_ready_deposits() | 4365 | * @e iterate_ready_deposits() |
4765 | * | 4366 | * |
4766 | * @param cls the @e cls of this struct with the plugin-specific state | 4367 | * @param cls the @e cls of this struct with the plugin-specific state |
4767 | * @param session connection to the database | ||
4768 | * @param rowid identifies the deposit row to modify | 4368 | * @param rowid identifies the deposit row to modify |
4769 | * @return query result status | 4369 | * @return query result status |
4770 | */ | 4370 | */ |
4771 | static enum GNUNET_DB_QueryStatus | 4371 | static enum GNUNET_DB_QueryStatus |
4772 | postgres_mark_deposit_tiny (void *cls, | 4372 | postgres_mark_deposit_tiny (void *cls, |
4773 | struct TALER_EXCHANGEDB_Session *session, | ||
4774 | uint64_t rowid) | 4373 | uint64_t rowid) |
4775 | { | 4374 | { |
4375 | struct PostgresClosure *pg = cls; | ||
4776 | struct GNUNET_PQ_QueryParam params[] = { | 4376 | struct GNUNET_PQ_QueryParam params[] = { |
4777 | GNUNET_PQ_query_param_uint64 (&rowid), | 4377 | GNUNET_PQ_query_param_uint64 (&rowid), |
4778 | GNUNET_PQ_query_param_end | 4378 | GNUNET_PQ_query_param_end |
4779 | }; | 4379 | }; |
4780 | 4380 | ||
4781 | (void) cls; | 4381 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
4782 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
4783 | "mark_deposit_tiny", | 4382 | "mark_deposit_tiny", |
4784 | params); | 4383 | params); |
4785 | } | 4384 | } |
@@ -4790,7 +4389,6 @@ postgres_mark_deposit_tiny (void *cls, | |||
4790 | * refunded anymore. | 4389 | * refunded anymore. |
4791 | * | 4390 | * |
4792 | * @param cls the @e cls of this struct with the plugin-specific state | 4391 | * @param cls the @e cls of this struct with the plugin-specific state |
4793 | * @param session connection to the database | ||
4794 | * @param coin_pub the coin to check for deposit | 4392 | * @param coin_pub the coin to check for deposit |
4795 | * @param merchant_pub merchant to receive the deposit | 4393 | * @param merchant_pub merchant to receive the deposit |
4796 | * @param h_contract_terms contract terms of the deposit | 4394 | * @param h_contract_terms contract terms of the deposit |
@@ -4801,12 +4399,12 @@ postgres_mark_deposit_tiny (void *cls, | |||
4801 | */ | 4399 | */ |
4802 | static enum GNUNET_DB_QueryStatus | 4400 | static enum GNUNET_DB_QueryStatus |
4803 | postgres_test_deposit_done (void *cls, | 4401 | postgres_test_deposit_done (void *cls, |
4804 | struct TALER_EXCHANGEDB_Session *session, | ||
4805 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 4402 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
4806 | const struct TALER_MerchantPublicKeyP *merchant_pub, | 4403 | const struct TALER_MerchantPublicKeyP *merchant_pub, |
4807 | const struct GNUNET_HashCode *h_contract_terms, | 4404 | const struct GNUNET_HashCode *h_contract_terms, |
4808 | const struct GNUNET_HashCode *h_wire) | 4405 | const struct GNUNET_HashCode *h_wire) |
4809 | { | 4406 | { |
4407 | struct PostgresClosure *pg = cls; | ||
4810 | struct GNUNET_PQ_QueryParam params[] = { | 4408 | struct GNUNET_PQ_QueryParam params[] = { |
4811 | GNUNET_PQ_query_param_auto_from_type (coin_pub), | 4409 | GNUNET_PQ_query_param_auto_from_type (coin_pub), |
4812 | GNUNET_PQ_query_param_auto_from_type (merchant_pub), | 4410 | GNUNET_PQ_query_param_auto_from_type (merchant_pub), |
@@ -4822,8 +4420,7 @@ postgres_test_deposit_done (void *cls, | |||
4822 | }; | 4420 | }; |
4823 | enum GNUNET_DB_QueryStatus qs; | 4421 | enum GNUNET_DB_QueryStatus qs; |
4824 | 4422 | ||
4825 | (void) cls; | 4423 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
4826 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
4827 | "test_deposit_done", | 4424 | "test_deposit_done", |
4828 | params, | 4425 | params, |
4829 | rs); | 4426 | rs); |
@@ -4843,22 +4440,20 @@ postgres_test_deposit_done (void *cls, | |||
4843 | * @e iterate_ready_deposits() or @e iterate_matching_deposits(). | 4440 | * @e iterate_ready_deposits() or @e iterate_matching_deposits(). |
4844 | * | 4441 | * |
4845 | * @param cls the @e cls of this struct with the plugin-specific state | 4442 | * @param cls the @e cls of this struct with the plugin-specific state |
4846 | * @param session connection to the database | ||
4847 | * @param rowid identifies the deposit row to modify | 4443 | * @param rowid identifies the deposit row to modify |
4848 | * @return query result status | 4444 | * @return query result status |
4849 | */ | 4445 | */ |
4850 | static enum GNUNET_DB_QueryStatus | 4446 | static enum GNUNET_DB_QueryStatus |
4851 | postgres_mark_deposit_done (void *cls, | 4447 | postgres_mark_deposit_done (void *cls, |
4852 | struct TALER_EXCHANGEDB_Session *session, | ||
4853 | uint64_t rowid) | 4448 | uint64_t rowid) |
4854 | { | 4449 | { |
4450 | struct PostgresClosure *pg = cls; | ||
4855 | struct GNUNET_PQ_QueryParam params[] = { | 4451 | struct GNUNET_PQ_QueryParam params[] = { |
4856 | GNUNET_PQ_query_param_uint64 (&rowid), | 4452 | GNUNET_PQ_query_param_uint64 (&rowid), |
4857 | GNUNET_PQ_query_param_end | 4453 | GNUNET_PQ_query_param_end |
4858 | }; | 4454 | }; |
4859 | 4455 | ||
4860 | (void) cls; | 4456 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
4861 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
4862 | "mark_deposit_done", | 4457 | "mark_deposit_done", |
4863 | params); | 4458 | params); |
4864 | } | 4459 | } |
@@ -4870,14 +4465,12 @@ postgres_mark_deposit_done (void *cls, | |||
4870 | * execution time must be in the past. | 4465 | * execution time must be in the past. |
4871 | * | 4466 | * |
4872 | * @param cls the @e cls of this struct with the plugin-specific state | 4467 | * @param cls the @e cls of this struct with the plugin-specific state |
4873 | * @param session connection to the database | ||
4874 | * @param deposit_cb function to call for ONE such deposit | 4468 | * @param deposit_cb function to call for ONE such deposit |
4875 | * @param deposit_cb_cls closure for @a deposit_cb | 4469 | * @param deposit_cb_cls closure for @a deposit_cb |
4876 | * @return transaction status code | 4470 | * @return transaction status code |
4877 | */ | 4471 | */ |
4878 | static enum GNUNET_DB_QueryStatus | 4472 | static enum GNUNET_DB_QueryStatus |
4879 | postgres_get_ready_deposit (void *cls, | 4473 | postgres_get_ready_deposit (void *cls, |
4880 | struct TALER_EXCHANGEDB_Session *session, | ||
4881 | TALER_EXCHANGEDB_DepositIterator deposit_cb, | 4474 | TALER_EXCHANGEDB_DepositIterator deposit_cb, |
4882 | void *deposit_cb_cls) | 4475 | void *deposit_cb_cls) |
4883 | { | 4476 | { |
@@ -4928,7 +4521,7 @@ postgres_get_ready_deposit (void *cls, | |||
4928 | GNUNET_STRINGS_absolute_time_to_string (now), | 4521 | GNUNET_STRINGS_absolute_time_to_string (now), |
4929 | (unsigned long long) now.abs_value_us); | 4522 | (unsigned long long) now.abs_value_us); |
4930 | 4523 | ||
4931 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 4524 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
4932 | "deposits_get_ready", | 4525 | "deposits_get_ready", |
4933 | params, | 4526 | params, |
4934 | rs); | 4527 | rs); |
@@ -5065,7 +4658,6 @@ match_deposit_cb (void *cls, | |||
5065 | * destination. Those deposits must not already be "done". | 4658 | * destination. Those deposits must not already be "done". |
5066 | * | 4659 | * |
5067 | * @param cls the @e cls of this struct with the plugin-specific state | 4660 | * @param cls the @e cls of this struct with the plugin-specific state |
5068 | * @param session connection to the database | ||
5069 | * @param h_wire destination of the wire transfer | 4661 | * @param h_wire destination of the wire transfer |
5070 | * @param merchant_pub public key of the merchant | 4662 | * @param merchant_pub public key of the merchant |
5071 | * @param deposit_cb function to call for each deposit | 4663 | * @param deposit_cb function to call for each deposit |
@@ -5077,7 +4669,6 @@ match_deposit_cb (void *cls, | |||
5077 | static enum GNUNET_DB_QueryStatus | 4669 | static enum GNUNET_DB_QueryStatus |
5078 | postgres_iterate_matching_deposits ( | 4670 | postgres_iterate_matching_deposits ( |
5079 | void *cls, | 4671 | void *cls, |
5080 | struct TALER_EXCHANGEDB_Session *session, | ||
5081 | const struct GNUNET_HashCode *h_wire, | 4672 | const struct GNUNET_HashCode *h_wire, |
5082 | const struct TALER_MerchantPublicKeyP *merchant_pub, | 4673 | const struct TALER_MerchantPublicKeyP *merchant_pub, |
5083 | TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb, | 4674 | TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb, |
@@ -5099,7 +4690,7 @@ postgres_iterate_matching_deposits ( | |||
5099 | mdc.pg = pg; | 4690 | mdc.pg = pg; |
5100 | mdc.limit = limit; | 4691 | mdc.limit = limit; |
5101 | mdc.status = GNUNET_OK; | 4692 | mdc.status = GNUNET_OK; |
5102 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 4693 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
5103 | "deposits_iterate_matching", | 4694 | "deposits_iterate_matching", |
5104 | params, | 4695 | params, |
5105 | &match_deposit_cb, | 4696 | &match_deposit_cb, |
@@ -5119,18 +4710,16 @@ postgres_iterate_matching_deposits ( | |||
5119 | * Retrieve the record for a known coin. | 4710 | * Retrieve the record for a known coin. |
5120 | * | 4711 | * |
5121 | * @param cls the plugin closure | 4712 | * @param cls the plugin closure |
5122 | * @param session the database session handle | ||
5123 | * @param coin_pub the public key of the coin to search for | 4713 | * @param coin_pub the public key of the coin to search for |
5124 | * @param coin_info place holder for the returned coin information object | 4714 | * @param coin_info place holder for the returned coin information object |
5125 | * @return transaction status code | 4715 | * @return transaction status code |
5126 | */ | 4716 | */ |
5127 | static enum GNUNET_DB_QueryStatus | 4717 | static enum GNUNET_DB_QueryStatus |
5128 | postgres_get_known_coin (void *cls, | 4718 | postgres_get_known_coin (void *cls, |
5129 | struct TALER_EXCHANGEDB_Session *session, | ||
5130 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 4719 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
5131 | struct TALER_CoinPublicInfo *coin_info) | 4720 | struct TALER_CoinPublicInfo *coin_info) |
5132 | { | 4721 | { |
5133 | struct PostgresClosure *pc = cls; | 4722 | struct PostgresClosure *pg = cls; |
5134 | struct GNUNET_PQ_QueryParam params[] = { | 4723 | struct GNUNET_PQ_QueryParam params[] = { |
5135 | GNUNET_PQ_query_param_auto_from_type (coin_pub), | 4724 | GNUNET_PQ_query_param_auto_from_type (coin_pub), |
5136 | GNUNET_PQ_query_param_end | 4725 | GNUNET_PQ_query_param_end |
@@ -5147,11 +4736,7 @@ postgres_get_known_coin (void *cls, | |||
5147 | "Getting known coin data for coin %s\n", | 4736 | "Getting known coin data for coin %s\n", |
5148 | TALER_B2S (coin_pub)); | 4737 | TALER_B2S (coin_pub)); |
5149 | coin_info->coin_pub = *coin_pub; | 4738 | coin_info->coin_pub = *coin_pub; |
5150 | if (NULL == session) | 4739 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5151 | session = postgres_get_session (pc); | ||
5152 | if (NULL == session) | ||
5153 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
5154 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
5155 | "get_known_coin", | 4740 | "get_known_coin", |
5156 | params, | 4741 | params, |
5157 | rs); | 4742 | rs); |
@@ -5162,7 +4747,6 @@ postgres_get_known_coin (void *cls, | |||
5162 | * Retrieve the denomination of a known coin. | 4747 | * Retrieve the denomination of a known coin. |
5163 | * | 4748 | * |
5164 | * @param cls the plugin closure | 4749 | * @param cls the plugin closure |
5165 | * @param session the database session handle | ||
5166 | * @param coin_pub the public key of the coin to search for | 4750 | * @param coin_pub the public key of the coin to search for |
5167 | * @param[out] denom_hash where to store the hash of the coins denomination | 4751 | * @param[out] denom_hash where to store the hash of the coins denomination |
5168 | * @return transaction status code | 4752 | * @return transaction status code |
@@ -5170,11 +4754,10 @@ postgres_get_known_coin (void *cls, | |||
5170 | static enum GNUNET_DB_QueryStatus | 4754 | static enum GNUNET_DB_QueryStatus |
5171 | postgres_get_coin_denomination ( | 4755 | postgres_get_coin_denomination ( |
5172 | void *cls, | 4756 | void *cls, |
5173 | struct TALER_EXCHANGEDB_Session *session, | ||
5174 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 4757 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
5175 | struct GNUNET_HashCode *denom_hash) | 4758 | struct GNUNET_HashCode *denom_hash) |
5176 | { | 4759 | { |
5177 | struct PostgresClosure *pc = cls; | 4760 | struct PostgresClosure *pg = cls; |
5178 | struct GNUNET_PQ_QueryParam params[] = { | 4761 | struct GNUNET_PQ_QueryParam params[] = { |
5179 | GNUNET_PQ_query_param_auto_from_type (coin_pub), | 4762 | GNUNET_PQ_query_param_auto_from_type (coin_pub), |
5180 | GNUNET_PQ_query_param_end | 4763 | GNUNET_PQ_query_param_end |
@@ -5188,11 +4771,7 @@ postgres_get_coin_denomination ( | |||
5188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5189 | "Getting coin denomination of coin %s\n", | 4772 | "Getting coin denomination of coin %s\n", |
5190 | TALER_B2S (coin_pub)); | 4773 | TALER_B2S (coin_pub)); |
5191 | if (NULL == session) | 4774 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5192 | session = postgres_get_session (pc); | ||
5193 | if (NULL == session) | ||
5194 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
5195 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
5196 | "get_coin_denomination", | 4775 | "get_coin_denomination", |
5197 | params, | 4776 | params, |
5198 | rs); | 4777 | rs); |
@@ -5205,15 +4784,14 @@ postgres_get_coin_denomination ( | |||
5205 | * functionality. | 4784 | * functionality. |
5206 | * | 4785 | * |
5207 | * @param cls plugin closure | 4786 | * @param cls plugin closure |
5208 | * @param session the shared database session | ||
5209 | * @param coin_info the public coin info | 4787 | * @param coin_info the public coin info |
5210 | * @return query result status | 4788 | * @return query result status |
5211 | */ | 4789 | */ |
5212 | static enum GNUNET_DB_QueryStatus | 4790 | static enum GNUNET_DB_QueryStatus |
5213 | insert_known_coin (void *cls, | 4791 | insert_known_coin (void *cls, |
5214 | struct TALER_EXCHANGEDB_Session *session, | ||
5215 | const struct TALER_CoinPublicInfo *coin_info) | 4792 | const struct TALER_CoinPublicInfo *coin_info) |
5216 | { | 4793 | { |
4794 | struct PostgresClosure *pg = cls; | ||
5217 | struct GNUNET_PQ_QueryParam params[] = { | 4795 | struct GNUNET_PQ_QueryParam params[] = { |
5218 | GNUNET_PQ_query_param_auto_from_type (&coin_info->coin_pub), | 4796 | GNUNET_PQ_query_param_auto_from_type (&coin_info->coin_pub), |
5219 | GNUNET_PQ_query_param_auto_from_type (&coin_info->denom_pub_hash), | 4797 | GNUNET_PQ_query_param_auto_from_type (&coin_info->denom_pub_hash), |
@@ -5221,11 +4799,10 @@ insert_known_coin (void *cls, | |||
5221 | GNUNET_PQ_query_param_end | 4799 | GNUNET_PQ_query_param_end |
5222 | }; | 4800 | }; |
5223 | 4801 | ||
5224 | (void) cls; | ||
5225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5226 | "Creating known coin %s\n", | 4803 | "Creating known coin %s\n", |
5227 | TALER_B2S (&coin_info->coin_pub)); | 4804 | TALER_B2S (&coin_info->coin_pub)); |
5228 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 4805 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5229 | "insert_known_coin", | 4806 | "insert_known_coin", |
5230 | params); | 4807 | params); |
5231 | } | 4808 | } |
@@ -5235,15 +4812,14 @@ insert_known_coin (void *cls, | |||
5235 | * Count the number of known coins by denomination. | 4812 | * Count the number of known coins by denomination. |
5236 | * | 4813 | * |
5237 | * @param cls database connection plugin state | 4814 | * @param cls database connection plugin state |
5238 | * @param session database session | ||
5239 | * @param denom_pub_hash denomination to count by | 4815 | * @param denom_pub_hash denomination to count by |
5240 | * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus` | 4816 | * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus` |
5241 | */ | 4817 | */ |
5242 | static long long | 4818 | static long long |
5243 | postgres_count_known_coins (void *cls, | 4819 | postgres_count_known_coins (void *cls, |
5244 | struct TALER_EXCHANGEDB_Session *session, | ||
5245 | const struct GNUNET_HashCode *denom_pub_hash) | 4820 | const struct GNUNET_HashCode *denom_pub_hash) |
5246 | { | 4821 | { |
4822 | struct PostgresClosure *pg = cls; | ||
5247 | uint64_t count; | 4823 | uint64_t count; |
5248 | struct GNUNET_PQ_QueryParam params[] = { | 4824 | struct GNUNET_PQ_QueryParam params[] = { |
5249 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), | 4825 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), |
@@ -5256,8 +4832,7 @@ postgres_count_known_coins (void *cls, | |||
5256 | }; | 4832 | }; |
5257 | enum GNUNET_DB_QueryStatus qs; | 4833 | enum GNUNET_DB_QueryStatus qs; |
5258 | 4834 | ||
5259 | (void) cls; | 4835 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5260 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
5261 | "count_known_coins", | 4836 | "count_known_coins", |
5262 | params, | 4837 | params, |
5263 | rs); | 4838 | rs); |
@@ -5271,16 +4846,14 @@ postgres_count_known_coins (void *cls, | |||
5271 | * Make sure the given @a coin is known to the database. | 4846 | * Make sure the given @a coin is known to the database. |
5272 | * | 4847 | * |
5273 | * @param cls database connection plugin state | 4848 | * @param cls database connection plugin state |
5274 | * @param session database session | ||
5275 | * @param coin the coin that must be made known | 4849 | * @param coin the coin that must be made known |
5276 | * @return database transaction status, non-negative on success | 4850 | * @return database transaction status, non-negative on success |
5277 | */ | 4851 | */ |
5278 | static enum TALER_EXCHANGEDB_CoinKnownStatus | 4852 | static enum TALER_EXCHANGEDB_CoinKnownStatus |
5279 | postgres_ensure_coin_known (void *cls, | 4853 | postgres_ensure_coin_known (void *cls, |
5280 | struct TALER_EXCHANGEDB_Session *session, | ||
5281 | const struct TALER_CoinPublicInfo *coin) | 4854 | const struct TALER_CoinPublicInfo *coin) |
5282 | { | 4855 | { |
5283 | struct PostgresClosure *pc = cls; | 4856 | struct PostgresClosure *pg = cls; |
5284 | enum GNUNET_DB_QueryStatus qs; | 4857 | enum GNUNET_DB_QueryStatus qs; |
5285 | struct GNUNET_HashCode denom_pub_hash; | 4858 | struct GNUNET_HashCode denom_pub_hash; |
5286 | struct GNUNET_PQ_QueryParam params[] = { | 4859 | struct GNUNET_PQ_QueryParam params[] = { |
@@ -5297,13 +4870,13 @@ postgres_ensure_coin_known (void *cls, | |||
5297 | GNUNET_PQ_query_param_end | 4870 | GNUNET_PQ_query_param_end |
5298 | }; | 4871 | }; |
5299 | 4872 | ||
5300 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 4873 | if (0 > (qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5301 | "lock_known_coins", | 4874 | "lock_known_coins", |
5302 | no_params))) | 4875 | no_params))) |
5303 | return qs; | 4876 | return qs; |
5304 | #endif | 4877 | #endif |
5305 | /* check if the coin is already known */ | 4878 | /* check if the coin is already known */ |
5306 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 4879 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5307 | "get_known_coin_dh", | 4880 | "get_known_coin_dh", |
5308 | params, | 4881 | params, |
5309 | rs); | 4882 | rs); |
@@ -5324,8 +4897,7 @@ postgres_ensure_coin_known (void *cls, | |||
5324 | } | 4897 | } |
5325 | 4898 | ||
5326 | /* if not known, insert it */ | 4899 | /* if not known, insert it */ |
5327 | qs = insert_known_coin (pc, | 4900 | qs = insert_known_coin (pg, |
5328 | session, | ||
5329 | coin); | 4901 | coin); |
5330 | switch (qs) | 4902 | switch (qs) |
5331 | { | 4903 | { |
@@ -5347,17 +4919,16 @@ postgres_ensure_coin_known (void *cls, | |||
5347 | * Insert information about deposited coin into the database. | 4919 | * Insert information about deposited coin into the database. |
5348 | * | 4920 | * |
5349 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 4921 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
5350 | * @param session connection to the database | ||
5351 | * @param exchange_timestamp time the exchange received the deposit request | 4922 | * @param exchange_timestamp time the exchange received the deposit request |
5352 | * @param deposit deposit information to store | 4923 | * @param deposit deposit information to store |
5353 | * @return query result status | 4924 | * @return query result status |
5354 | */ | 4925 | */ |
5355 | static enum GNUNET_DB_QueryStatus | 4926 | static enum GNUNET_DB_QueryStatus |
5356 | postgres_insert_deposit (void *cls, | 4927 | postgres_insert_deposit (void *cls, |
5357 | struct TALER_EXCHANGEDB_Session *session, | ||
5358 | struct GNUNET_TIME_Absolute exchange_timestamp, | 4928 | struct GNUNET_TIME_Absolute exchange_timestamp, |
5359 | const struct TALER_EXCHANGEDB_Deposit *deposit) | 4929 | const struct TALER_EXCHANGEDB_Deposit *deposit) |
5360 | { | 4930 | { |
4931 | struct PostgresClosure *pg = cls; | ||
5361 | struct GNUNET_PQ_QueryParam params[] = { | 4932 | struct GNUNET_PQ_QueryParam params[] = { |
5362 | GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub), | 4933 | GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub), |
5363 | TALER_PQ_query_param_amount (&deposit->amount_with_fee), | 4934 | TALER_PQ_query_param_amount (&deposit->amount_with_fee), |
@@ -5373,13 +4944,12 @@ postgres_insert_deposit (void *cls, | |||
5373 | GNUNET_PQ_query_param_end | 4944 | GNUNET_PQ_query_param_end |
5374 | }; | 4945 | }; |
5375 | 4946 | ||
5376 | (void) cls; | ||
5377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4947 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
5378 | "Inserting deposit to be executed at %s (%llu/%llu)\n", | 4948 | "Inserting deposit to be executed at %s (%llu/%llu)\n", |
5379 | GNUNET_STRINGS_absolute_time_to_string (deposit->wire_deadline), | 4949 | GNUNET_STRINGS_absolute_time_to_string (deposit->wire_deadline), |
5380 | (unsigned long long) deposit->wire_deadline.abs_value_us, | 4950 | (unsigned long long) deposit->wire_deadline.abs_value_us, |
5381 | (unsigned long long) deposit->refund_deadline.abs_value_us); | 4951 | (unsigned long long) deposit->refund_deadline.abs_value_us); |
5382 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 4952 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5383 | "insert_deposit", | 4953 | "insert_deposit", |
5384 | params); | 4954 | params); |
5385 | } | 4955 | } |
@@ -5389,15 +4959,14 @@ postgres_insert_deposit (void *cls, | |||
5389 | * Insert information about refunded coin into the database. | 4959 | * Insert information about refunded coin into the database. |
5390 | * | 4960 | * |
5391 | * @param cls the @e cls of this struct with the plugin-specific state | 4961 | * @param cls the @e cls of this struct with the plugin-specific state |
5392 | * @param session connection to the database | ||
5393 | * @param refund refund information to store | 4962 | * @param refund refund information to store |
5394 | * @return query result status | 4963 | * @return query result status |
5395 | */ | 4964 | */ |
5396 | static enum GNUNET_DB_QueryStatus | 4965 | static enum GNUNET_DB_QueryStatus |
5397 | postgres_insert_refund (void *cls, | 4966 | postgres_insert_refund (void *cls, |
5398 | struct TALER_EXCHANGEDB_Session *session, | ||
5399 | const struct TALER_EXCHANGEDB_Refund *refund) | 4967 | const struct TALER_EXCHANGEDB_Refund *refund) |
5400 | { | 4968 | { |
4969 | struct PostgresClosure *pg = cls; | ||
5401 | struct GNUNET_PQ_QueryParam params[] = { | 4970 | struct GNUNET_PQ_QueryParam params[] = { |
5402 | GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub), | 4971 | GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub), |
5403 | GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub), | 4972 | GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub), |
@@ -5408,11 +4977,10 @@ postgres_insert_refund (void *cls, | |||
5408 | GNUNET_PQ_query_param_end | 4977 | GNUNET_PQ_query_param_end |
5409 | }; | 4978 | }; |
5410 | 4979 | ||
5411 | (void) cls; | ||
5412 | GNUNET_assert (GNUNET_YES == | 4980 | GNUNET_assert (GNUNET_YES == |
5413 | TALER_amount_cmp_currency (&refund->details.refund_amount, | 4981 | TALER_amount_cmp_currency (&refund->details.refund_amount, |
5414 | &refund->details.refund_fee)); | 4982 | &refund->details.refund_fee)); |
5415 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 4983 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5416 | "insert_refund", | 4984 | "insert_refund", |
5417 | params); | 4985 | params); |
5418 | } | 4986 | } |
@@ -5491,7 +5059,6 @@ get_refunds_cb (void *cls, | |||
5491 | * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract. | 5059 | * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract. |
5492 | * | 5060 | * |
5493 | * @param cls closure of plugin | 5061 | * @param cls closure of plugin |
5494 | * @param session database handle to use | ||
5495 | * @param coin_pub coin to get refunds for | 5062 | * @param coin_pub coin to get refunds for |
5496 | * @param merchant_pub merchant to get refunds for | 5063 | * @param merchant_pub merchant to get refunds for |
5497 | * @param h_contract contract (hash) to get refunds for | 5064 | * @param h_contract contract (hash) to get refunds for |
@@ -5502,7 +5069,6 @@ get_refunds_cb (void *cls, | |||
5502 | static enum GNUNET_DB_QueryStatus | 5069 | static enum GNUNET_DB_QueryStatus |
5503 | postgres_select_refunds_by_coin ( | 5070 | postgres_select_refunds_by_coin ( |
5504 | void *cls, | 5071 | void *cls, |
5505 | struct TALER_EXCHANGEDB_Session *session, | ||
5506 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 5072 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
5507 | const struct TALER_MerchantPublicKeyP *merchant_pub, | 5073 | const struct TALER_MerchantPublicKeyP *merchant_pub, |
5508 | const struct GNUNET_HashCode *h_contract, | 5074 | const struct GNUNET_HashCode *h_contract, |
@@ -5524,7 +5090,7 @@ postgres_select_refunds_by_coin ( | |||
5524 | .status = GNUNET_OK | 5090 | .status = GNUNET_OK |
5525 | }; | 5091 | }; |
5526 | 5092 | ||
5527 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 5093 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
5528 | "get_refunds_by_coin_and_contract", | 5094 | "get_refunds_by_coin_and_contract", |
5529 | params, | 5095 | params, |
5530 | &get_refunds_cb, | 5096 | &get_refunds_cb, |
@@ -5539,7 +5105,6 @@ postgres_select_refunds_by_coin ( | |||
5539 | * Lookup refresh melt commitment data under the given @a rc. | 5105 | * Lookup refresh melt commitment data under the given @a rc. |
5540 | * | 5106 | * |
5541 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 5107 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
5542 | * @param session database handle to use, NULL if not run in any transaction | ||
5543 | * @param rc commitment hash to use to locate the operation | 5108 | * @param rc commitment hash to use to locate the operation |
5544 | * @param[out] melt where to store the result; note that | 5109 | * @param[out] melt where to store the result; note that |
5545 | * melt->session.coin.denom_sig will be set to NULL | 5110 | * melt->session.coin.denom_sig will be set to NULL |
@@ -5548,7 +5113,6 @@ postgres_select_refunds_by_coin ( | |||
5548 | */ | 5113 | */ |
5549 | static enum GNUNET_DB_QueryStatus | 5114 | static enum GNUNET_DB_QueryStatus |
5550 | postgres_get_melt (void *cls, | 5115 | postgres_get_melt (void *cls, |
5551 | struct TALER_EXCHANGEDB_Session *session, | ||
5552 | const struct TALER_RefreshCommitmentP *rc, | 5116 | const struct TALER_RefreshCommitmentP *rc, |
5553 | struct TALER_EXCHANGEDB_Melt *melt) | 5117 | struct TALER_EXCHANGEDB_Melt *melt) |
5554 | { | 5118 | { |
@@ -5576,11 +5140,7 @@ postgres_get_melt (void *cls, | |||
5576 | enum GNUNET_DB_QueryStatus qs; | 5140 | enum GNUNET_DB_QueryStatus qs; |
5577 | 5141 | ||
5578 | melt->session.coin.denom_sig.rsa_signature = NULL; | 5142 | melt->session.coin.denom_sig.rsa_signature = NULL; |
5579 | if (NULL == session) | 5143 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5580 | session = postgres_get_session (pg); | ||
5581 | if (NULL == session) | ||
5582 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
5583 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
5584 | "get_melt", | 5144 | "get_melt", |
5585 | params, | 5145 | params, |
5586 | rs); | 5146 | rs); |
@@ -5594,7 +5154,6 @@ postgres_get_melt (void *cls, | |||
5594 | * @a rc. | 5154 | * @a rc. |
5595 | * | 5155 | * |
5596 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 5156 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
5597 | * @param session database handle to use | ||
5598 | * @param rc commitment hash to use to locate the operation | 5157 | * @param rc commitment hash to use to locate the operation |
5599 | * @param[out] noreveal_index returns the "gamma" value selected by the | 5158 | * @param[out] noreveal_index returns the "gamma" value selected by the |
5600 | * exchange which is the index of the transfer key that is | 5159 | * exchange which is the index of the transfer key that is |
@@ -5603,10 +5162,10 @@ postgres_get_melt (void *cls, | |||
5603 | */ | 5162 | */ |
5604 | static enum GNUNET_DB_QueryStatus | 5163 | static enum GNUNET_DB_QueryStatus |
5605 | postgres_get_melt_index (void *cls, | 5164 | postgres_get_melt_index (void *cls, |
5606 | struct TALER_EXCHANGEDB_Session *session, | ||
5607 | const struct TALER_RefreshCommitmentP *rc, | 5165 | const struct TALER_RefreshCommitmentP *rc, |
5608 | uint32_t *noreveal_index) | 5166 | uint32_t *noreveal_index) |
5609 | { | 5167 | { |
5168 | struct PostgresClosure *pg = cls; | ||
5610 | struct GNUNET_PQ_QueryParam params[] = { | 5169 | struct GNUNET_PQ_QueryParam params[] = { |
5611 | GNUNET_PQ_query_param_auto_from_type (rc), | 5170 | GNUNET_PQ_query_param_auto_from_type (rc), |
5612 | GNUNET_PQ_query_param_end | 5171 | GNUNET_PQ_query_param_end |
@@ -5617,8 +5176,7 @@ postgres_get_melt_index (void *cls, | |||
5617 | GNUNET_PQ_result_spec_end | 5176 | GNUNET_PQ_result_spec_end |
5618 | }; | 5177 | }; |
5619 | 5178 | ||
5620 | (void) cls; | 5179 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5621 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
5622 | "get_melt_index", | 5180 | "get_melt_index", |
5623 | params, | 5181 | params, |
5624 | rs); | 5182 | rs); |
@@ -5629,16 +5187,15 @@ postgres_get_melt_index (void *cls, | |||
5629 | * Store new refresh melt commitment data. | 5187 | * Store new refresh melt commitment data. |
5630 | * | 5188 | * |
5631 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 5189 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
5632 | * @param session database handle to use | ||
5633 | * @param refresh_session session data to store | 5190 | * @param refresh_session session data to store |
5634 | * @return query status for the transaction | 5191 | * @return query status for the transaction |
5635 | */ | 5192 | */ |
5636 | static enum GNUNET_DB_QueryStatus | 5193 | static enum GNUNET_DB_QueryStatus |
5637 | postgres_insert_melt ( | 5194 | postgres_insert_melt ( |
5638 | void *cls, | 5195 | void *cls, |
5639 | struct TALER_EXCHANGEDB_Session *session, | ||
5640 | const struct TALER_EXCHANGEDB_Refresh *refresh_session) | 5196 | const struct TALER_EXCHANGEDB_Refresh *refresh_session) |
5641 | { | 5197 | { |
5198 | struct PostgresClosure *pg = cls; | ||
5642 | struct GNUNET_PQ_QueryParam params[] = { | 5199 | struct GNUNET_PQ_QueryParam params[] = { |
5643 | GNUNET_PQ_query_param_auto_from_type (&refresh_session->rc), | 5200 | GNUNET_PQ_query_param_auto_from_type (&refresh_session->rc), |
5644 | GNUNET_PQ_query_param_auto_from_type (&refresh_session->coin.coin_pub), | 5201 | GNUNET_PQ_query_param_auto_from_type (&refresh_session->coin.coin_pub), |
@@ -5648,8 +5205,7 @@ postgres_insert_melt ( | |||
5648 | GNUNET_PQ_query_param_end | 5205 | GNUNET_PQ_query_param_end |
5649 | }; | 5206 | }; |
5650 | 5207 | ||
5651 | (void) cls; | 5208 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5652 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
5653 | "insert_melt", | 5209 | "insert_melt", |
5654 | params); | 5210 | params); |
5655 | } | 5211 | } |
@@ -5661,7 +5217,6 @@ postgres_insert_melt ( | |||
5661 | * we learned or created in the /refresh/reveal step. | 5217 | * we learned or created in the /refresh/reveal step. |
5662 | * | 5218 | * |
5663 | * @param cls the @e cls of this struct with the plugin-specific state | 5219 | * @param cls the @e cls of this struct with the plugin-specific state |
5664 | * @param session database connection | ||
5665 | * @param rc identify commitment and thus refresh operation | 5220 | * @param rc identify commitment and thus refresh operation |
5666 | * @param num_rrcs number of coins to generate, size of the @a rrcs array | 5221 | * @param num_rrcs number of coins to generate, size of the @a rrcs array |
5667 | * @param rrcs information about the new coins | 5222 | * @param rrcs information about the new coins |
@@ -5673,7 +5228,6 @@ postgres_insert_melt ( | |||
5673 | static enum GNUNET_DB_QueryStatus | 5228 | static enum GNUNET_DB_QueryStatus |
5674 | postgres_insert_refresh_reveal ( | 5229 | postgres_insert_refresh_reveal ( |
5675 | void *cls, | 5230 | void *cls, |
5676 | struct TALER_EXCHANGEDB_Session *session, | ||
5677 | const struct TALER_RefreshCommitmentP *rc, | 5231 | const struct TALER_RefreshCommitmentP *rc, |
5678 | uint32_t num_rrcs, | 5232 | uint32_t num_rrcs, |
5679 | const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs, | 5233 | const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs, |
@@ -5681,7 +5235,8 @@ postgres_insert_refresh_reveal ( | |||
5681 | const struct TALER_TransferPrivateKeyP *tprivs, | 5235 | const struct TALER_TransferPrivateKeyP *tprivs, |
5682 | const struct TALER_TransferPublicKeyP *tp) | 5236 | const struct TALER_TransferPublicKeyP *tp) |
5683 | { | 5237 | { |
5684 | (void) cls; | 5238 | struct PostgresClosure *pg = cls; |
5239 | |||
5685 | if (TALER_CNC_KAPPA != num_tprivs + 1) | 5240 | if (TALER_CNC_KAPPA != num_tprivs + 1) |
5686 | { | 5241 | { |
5687 | GNUNET_break (0); | 5242 | GNUNET_break (0); |
@@ -5710,7 +5265,7 @@ postgres_insert_refresh_reveal ( | |||
5710 | GNUNET_CRYPTO_hash (rrc->coin_ev, | 5265 | GNUNET_CRYPTO_hash (rrc->coin_ev, |
5711 | rrc->coin_ev_size, | 5266 | rrc->coin_ev_size, |
5712 | &h_coin_ev); | 5267 | &h_coin_ev); |
5713 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 5268 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5714 | "insert_refresh_revealed_coin", | 5269 | "insert_refresh_revealed_coin", |
5715 | params); | 5270 | params); |
5716 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) | 5271 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) |
@@ -5722,12 +5277,13 @@ postgres_insert_refresh_reveal ( | |||
5722 | GNUNET_PQ_query_param_auto_from_type (rc), | 5277 | GNUNET_PQ_query_param_auto_from_type (rc), |
5723 | GNUNET_PQ_query_param_auto_from_type (tp), | 5278 | GNUNET_PQ_query_param_auto_from_type (tp), |
5724 | GNUNET_PQ_query_param_fixed_size (tprivs, | 5279 | GNUNET_PQ_query_param_fixed_size (tprivs, |
5725 | num_tprivs * sizeof (struct | 5280 | num_tprivs |
5726 | TALER_TransferPrivateKeyP)), | 5281 | * sizeof (struct |
5282 | TALER_TransferPrivateKeyP)), | ||
5727 | GNUNET_PQ_query_param_end | 5283 | GNUNET_PQ_query_param_end |
5728 | }; | 5284 | }; |
5729 | 5285 | ||
5730 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 5286 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
5731 | "insert_refresh_transfer_keys", | 5287 | "insert_refresh_transfer_keys", |
5732 | params); | 5288 | params); |
5733 | } | 5289 | } |
@@ -5820,7 +5376,6 @@ add_revealed_coins (void *cls, | |||
5820 | * create in the given refresh operation. | 5376 | * create in the given refresh operation. |
5821 | * | 5377 | * |
5822 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 5378 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
5823 | * @param session database connection | ||
5824 | * @param rc identify commitment and thus refresh operation | 5379 | * @param rc identify commitment and thus refresh operation |
5825 | * @param cb function to call with the results | 5380 | * @param cb function to call with the results |
5826 | * @param cb_cls closure for @a cb | 5381 | * @param cb_cls closure for @a cb |
@@ -5828,11 +5383,11 @@ add_revealed_coins (void *cls, | |||
5828 | */ | 5383 | */ |
5829 | static enum GNUNET_DB_QueryStatus | 5384 | static enum GNUNET_DB_QueryStatus |
5830 | postgres_get_refresh_reveal (void *cls, | 5385 | postgres_get_refresh_reveal (void *cls, |
5831 | struct TALER_EXCHANGEDB_Session *session, | ||
5832 | const struct TALER_RefreshCommitmentP *rc, | 5386 | const struct TALER_RefreshCommitmentP *rc, |
5833 | TALER_EXCHANGEDB_RefreshCallback cb, | 5387 | TALER_EXCHANGEDB_RefreshCallback cb, |
5834 | void *cb_cls) | 5388 | void *cb_cls) |
5835 | { | 5389 | { |
5390 | struct PostgresClosure *pg = cls; | ||
5836 | struct GetRevealContext grctx; | 5391 | struct GetRevealContext grctx; |
5837 | enum GNUNET_DB_QueryStatus qs; | 5392 | enum GNUNET_DB_QueryStatus qs; |
5838 | struct TALER_TransferPublicKeyP tp; | 5393 | struct TALER_TransferPublicKeyP tp; |
@@ -5851,12 +5406,11 @@ postgres_get_refresh_reveal (void *cls, | |||
5851 | GNUNET_PQ_result_spec_end | 5406 | GNUNET_PQ_result_spec_end |
5852 | }; | 5407 | }; |
5853 | 5408 | ||
5854 | (void) cls; | ||
5855 | /* First get the coins */ | 5409 | /* First get the coins */ |
5856 | memset (&grctx, | 5410 | memset (&grctx, |
5857 | 0, | 5411 | 0, |
5858 | sizeof (grctx)); | 5412 | sizeof (grctx)); |
5859 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 5413 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
5860 | "get_refresh_revealed_coins", | 5414 | "get_refresh_revealed_coins", |
5861 | params, | 5415 | params, |
5862 | &add_revealed_coins, | 5416 | &add_revealed_coins, |
@@ -5882,7 +5436,7 @@ postgres_get_refresh_reveal (void *cls, | |||
5882 | } | 5436 | } |
5883 | 5437 | ||
5884 | /* now also get the transfer keys (public and private) */ | 5438 | /* now also get the transfer keys (public and private) */ |
5885 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 5439 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
5886 | "get_refresh_transfer_keys", | 5440 | "get_refresh_transfer_keys", |
5887 | params, | 5441 | params, |
5888 | rs); | 5442 | rs); |
@@ -5978,7 +5532,6 @@ free_link_data_list (void *cls, | |||
5978 | { | 5532 | { |
5979 | struct TALER_EXCHANGEDB_LinkList *next; | 5533 | struct TALER_EXCHANGEDB_LinkList *next; |
5980 | 5534 | ||
5981 | (void) cls; | ||
5982 | while (NULL != ldl) | 5535 | while (NULL != ldl) |
5983 | { | 5536 | { |
5984 | next = ldl->next; | 5537 | next = ldl->next; |
@@ -6065,7 +5618,6 @@ add_ldl (void *cls, | |||
6065 | * information, the denomination keys and the signatures. | 5618 | * information, the denomination keys and the signatures. |
6066 | * | 5619 | * |
6067 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 5620 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
6068 | * @param session database connection | ||
6069 | * @param coin_pub public key of the coin | 5621 | * @param coin_pub public key of the coin |
6070 | * @param ldc function to call for each session the coin was melted into | 5622 | * @param ldc function to call for each session the coin was melted into |
6071 | * @param ldc_cls closure for @a tdc | 5623 | * @param ldc_cls closure for @a tdc |
@@ -6073,11 +5625,11 @@ add_ldl (void *cls, | |||
6073 | */ | 5625 | */ |
6074 | static enum GNUNET_DB_QueryStatus | 5626 | static enum GNUNET_DB_QueryStatus |
6075 | postgres_get_link_data (void *cls, | 5627 | postgres_get_link_data (void *cls, |
6076 | struct TALER_EXCHANGEDB_Session *session, | ||
6077 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 5628 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
6078 | TALER_EXCHANGEDB_LinkCallback ldc, | 5629 | TALER_EXCHANGEDB_LinkCallback ldc, |
6079 | void *ldc_cls) | 5630 | void *ldc_cls) |
6080 | { | 5631 | { |
5632 | struct PostgresClosure *pg = cls; | ||
6081 | struct GNUNET_PQ_QueryParam params[] = { | 5633 | struct GNUNET_PQ_QueryParam params[] = { |
6082 | GNUNET_PQ_query_param_auto_from_type (coin_pub), | 5634 | GNUNET_PQ_query_param_auto_from_type (coin_pub), |
6083 | GNUNET_PQ_query_param_end | 5635 | GNUNET_PQ_query_param_end |
@@ -6089,7 +5641,7 @@ postgres_get_link_data (void *cls, | |||
6089 | ldctx.ldc_cls = ldc_cls; | 5641 | ldctx.ldc_cls = ldc_cls; |
6090 | ldctx.last = NULL; | 5642 | ldctx.last = NULL; |
6091 | ldctx.status = GNUNET_OK; | 5643 | ldctx.status = GNUNET_OK; |
6092 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 5644 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
6093 | "get_link", | 5645 | "get_link", |
6094 | params, | 5646 | params, |
6095 | &add_ldl, | 5647 | &add_ldl, |
@@ -6134,11 +5686,6 @@ struct CoinHistoryContext | |||
6134 | void *db_cls; | 5686 | void *db_cls; |
6135 | 5687 | ||
6136 | /** | 5688 | /** |
6137 | * Database session we are using. | ||
6138 | */ | ||
6139 | struct TALER_EXCHANGEDB_Session *session; | ||
6140 | |||
6141 | /** | ||
6142 | * Plugin context. | 5689 | * Plugin context. |
6143 | */ | 5690 | */ |
6144 | struct PostgresClosure *pg; | 5691 | struct PostgresClosure *pg; |
@@ -6578,7 +6125,6 @@ struct Work | |||
6578 | * (/refresh/melt, /deposit, /refund and /recoup operations). | 6125 | * (/refresh/melt, /deposit, /refund and /recoup operations). |
6579 | * | 6126 | * |
6580 | * @param cls the `struct PostgresClosure` with the plugin-specific state | 6127 | * @param cls the `struct PostgresClosure` with the plugin-specific state |
6581 | * @param session database connection | ||
6582 | * @param coin_pub coin to investigate | 6128 | * @param coin_pub coin to investigate |
6583 | * @param include_recoup should recoup transactions be included in the @a tlp | 6129 | * @param include_recoup should recoup transactions be included in the @a tlp |
6584 | * @param[out] tlp set to list of transactions, NULL if coin is fresh | 6130 | * @param[out] tlp set to list of transactions, NULL if coin is fresh |
@@ -6587,7 +6133,6 @@ struct Work | |||
6587 | static enum GNUNET_DB_QueryStatus | 6133 | static enum GNUNET_DB_QueryStatus |
6588 | postgres_get_coin_transactions ( | 6134 | postgres_get_coin_transactions ( |
6589 | void *cls, | 6135 | void *cls, |
6590 | struct TALER_EXCHANGEDB_Session *session, | ||
6591 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 6136 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
6592 | int include_recoup, | 6137 | int include_recoup, |
6593 | struct TALER_EXCHANGEDB_TransactionList **tlp) | 6138 | struct TALER_EXCHANGEDB_TransactionList **tlp) |
@@ -6635,7 +6180,6 @@ postgres_get_coin_transactions ( | |||
6635 | struct CoinHistoryContext chc = { | 6180 | struct CoinHistoryContext chc = { |
6636 | .head = NULL, | 6181 | .head = NULL, |
6637 | .coin_pub = coin_pub, | 6182 | .coin_pub = coin_pub, |
6638 | .session = session, | ||
6639 | .pg = pg, | 6183 | .pg = pg, |
6640 | .db_cls = cls | 6184 | .db_cls = cls |
6641 | }; | 6185 | }; |
@@ -6646,7 +6190,7 @@ postgres_get_coin_transactions ( | |||
6646 | TALER_B2S (coin_pub)); | 6190 | TALER_B2S (coin_pub)); |
6647 | for (unsigned int i = 0; NULL != work[i].statement; i++) | 6191 | for (unsigned int i = 0; NULL != work[i].statement; i++) |
6648 | { | 6192 | { |
6649 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 6193 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
6650 | work[i].statement, | 6194 | work[i].statement, |
6651 | params, | 6195 | params, |
6652 | work[i].cb, | 6196 | work[i].cb, |
@@ -6777,7 +6321,6 @@ handle_wt_result (void *cls, | |||
6777 | * into a wire transfer by the respective @a wtid. | 6321 | * into a wire transfer by the respective @a wtid. |
6778 | * | 6322 | * |
6779 | * @param cls closure | 6323 | * @param cls closure |
6780 | * @param session database connection | ||
6781 | * @param wtid the raw wire transfer identifier we used | 6324 | * @param wtid the raw wire transfer identifier we used |
6782 | * @param cb function to call on each transaction found | 6325 | * @param cb function to call on each transaction found |
6783 | * @param cb_cls closure for @a cb | 6326 | * @param cb_cls closure for @a cb |
@@ -6786,7 +6329,6 @@ handle_wt_result (void *cls, | |||
6786 | static enum GNUNET_DB_QueryStatus | 6329 | static enum GNUNET_DB_QueryStatus |
6787 | postgres_lookup_wire_transfer ( | 6330 | postgres_lookup_wire_transfer ( |
6788 | void *cls, | 6331 | void *cls, |
6789 | struct TALER_EXCHANGEDB_Session *session, | ||
6790 | const struct TALER_WireTransferIdentifierRawP *wtid, | 6332 | const struct TALER_WireTransferIdentifierRawP *wtid, |
6791 | TALER_EXCHANGEDB_AggregationDataCallback cb, | 6333 | TALER_EXCHANGEDB_AggregationDataCallback cb, |
6792 | void *cb_cls) | 6334 | void *cb_cls) |
@@ -6804,7 +6346,7 @@ postgres_lookup_wire_transfer ( | |||
6804 | ctx.pg = pg; | 6346 | ctx.pg = pg; |
6805 | ctx.status = GNUNET_OK; | 6347 | ctx.status = GNUNET_OK; |
6806 | /* check if the melt record exists and get it */ | 6348 | /* check if the melt record exists and get it */ |
6807 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 6349 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
6808 | "lookup_transactions", | 6350 | "lookup_transactions", |
6809 | params, | 6351 | params, |
6810 | &handle_wt_result, | 6352 | &handle_wt_result, |
@@ -6821,7 +6363,6 @@ postgres_lookup_wire_transfer ( | |||
6821 | * to be executed. | 6363 | * to be executed. |
6822 | * | 6364 | * |
6823 | * @param cls closure | 6365 | * @param cls closure |
6824 | * @param session database connection | ||
6825 | * @param h_contract_terms hash of the proposal data | 6366 | * @param h_contract_terms hash of the proposal data |
6826 | * @param h_wire hash of merchant wire details | 6367 | * @param h_wire hash of merchant wire details |
6827 | * @param coin_pub public key of deposited coin | 6368 | * @param coin_pub public key of deposited coin |
@@ -6833,7 +6374,6 @@ postgres_lookup_wire_transfer ( | |||
6833 | static enum GNUNET_DB_QueryStatus | 6374 | static enum GNUNET_DB_QueryStatus |
6834 | postgres_lookup_transfer_by_deposit ( | 6375 | postgres_lookup_transfer_by_deposit ( |
6835 | void *cls, | 6376 | void *cls, |
6836 | struct TALER_EXCHANGEDB_Session *session, | ||
6837 | const struct GNUNET_HashCode *h_contract_terms, | 6377 | const struct GNUNET_HashCode *h_contract_terms, |
6838 | const struct GNUNET_HashCode *h_wire, | 6378 | const struct GNUNET_HashCode *h_wire, |
6839 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 6379 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
@@ -6867,7 +6407,7 @@ postgres_lookup_transfer_by_deposit ( | |||
6867 | }; | 6407 | }; |
6868 | 6408 | ||
6869 | /* check if the melt record exists and get it */ | 6409 | /* check if the melt record exists and get it */ |
6870 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 6410 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
6871 | "lookup_deposit_wtid", | 6411 | "lookup_deposit_wtid", |
6872 | params, | 6412 | params, |
6873 | rs); | 6413 | rs); |
@@ -6907,7 +6447,7 @@ postgres_lookup_transfer_by_deposit ( | |||
6907 | GNUNET_PQ_result_spec_end | 6447 | GNUNET_PQ_result_spec_end |
6908 | }; | 6448 | }; |
6909 | 6449 | ||
6910 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 6450 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
6911 | "get_deposit_for_wtid", | 6451 | "get_deposit_for_wtid", |
6912 | params2, | 6452 | params2, |
6913 | rs2); | 6453 | rs2); |
@@ -6931,7 +6471,6 @@ postgres_lookup_transfer_by_deposit ( | |||
6931 | * Function called to insert aggregation information into the DB. | 6471 | * Function called to insert aggregation information into the DB. |
6932 | * | 6472 | * |
6933 | * @param cls closure | 6473 | * @param cls closure |
6934 | * @param session database connection | ||
6935 | * @param wtid the raw wire transfer identifier we used | 6474 | * @param wtid the raw wire transfer identifier we used |
6936 | * @param deposit_serial_id row in the deposits table for which this is aggregation data | 6475 | * @param deposit_serial_id row in the deposits table for which this is aggregation data |
6937 | * @return transaction status code | 6476 | * @return transaction status code |
@@ -6939,10 +6478,10 @@ postgres_lookup_transfer_by_deposit ( | |||
6939 | static enum GNUNET_DB_QueryStatus | 6478 | static enum GNUNET_DB_QueryStatus |
6940 | postgres_insert_aggregation_tracking ( | 6479 | postgres_insert_aggregation_tracking ( |
6941 | void *cls, | 6480 | void *cls, |
6942 | struct TALER_EXCHANGEDB_Session *session, | ||
6943 | const struct TALER_WireTransferIdentifierRawP *wtid, | 6481 | const struct TALER_WireTransferIdentifierRawP *wtid, |
6944 | unsigned long long deposit_serial_id) | 6482 | unsigned long long deposit_serial_id) |
6945 | { | 6483 | { |
6484 | struct PostgresClosure *pg = cls; | ||
6946 | uint64_t rid = deposit_serial_id; | 6485 | uint64_t rid = deposit_serial_id; |
6947 | struct GNUNET_PQ_QueryParam params[] = { | 6486 | struct GNUNET_PQ_QueryParam params[] = { |
6948 | GNUNET_PQ_query_param_uint64 (&rid), | 6487 | GNUNET_PQ_query_param_uint64 (&rid), |
@@ -6950,8 +6489,7 @@ postgres_insert_aggregation_tracking ( | |||
6950 | GNUNET_PQ_query_param_end | 6489 | GNUNET_PQ_query_param_end |
6951 | }; | 6490 | }; |
6952 | 6491 | ||
6953 | (void) cls; | 6492 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
6954 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
6955 | "insert_aggregation_tracking", | 6493 | "insert_aggregation_tracking", |
6956 | params); | 6494 | params); |
6957 | } | 6495 | } |
@@ -6961,7 +6499,6 @@ postgres_insert_aggregation_tracking ( | |||
6961 | * Obtain wire fee from database. | 6499 | * Obtain wire fee from database. |
6962 | * | 6500 | * |
6963 | * @param cls closure | 6501 | * @param cls closure |
6964 | * @param session database connection | ||
6965 | * @param type type of wire transfer the fee applies for | 6502 | * @param type type of wire transfer the fee applies for |
6966 | * @param date for which date do we want the fee? | 6503 | * @param date for which date do we want the fee? |
6967 | * @param[out] start_date when does the fee go into effect | 6504 | * @param[out] start_date when does the fee go into effect |
@@ -6973,7 +6510,6 @@ postgres_insert_aggregation_tracking ( | |||
6973 | */ | 6510 | */ |
6974 | static enum GNUNET_DB_QueryStatus | 6511 | static enum GNUNET_DB_QueryStatus |
6975 | postgres_get_wire_fee (void *cls, | 6512 | postgres_get_wire_fee (void *cls, |
6976 | struct TALER_EXCHANGEDB_Session *session, | ||
6977 | const char *type, | 6513 | const char *type, |
6978 | struct GNUNET_TIME_Absolute date, | 6514 | struct GNUNET_TIME_Absolute date, |
6979 | struct GNUNET_TIME_Absolute *start_date, | 6515 | struct GNUNET_TIME_Absolute *start_date, |
@@ -6997,7 +6533,7 @@ postgres_get_wire_fee (void *cls, | |||
6997 | GNUNET_PQ_result_spec_end | 6533 | GNUNET_PQ_result_spec_end |
6998 | }; | 6534 | }; |
6999 | 6535 | ||
7000 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | 6536 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
7001 | "get_wire_fee", | 6537 | "get_wire_fee", |
7002 | params, | 6538 | params, |
7003 | rs); | 6539 | rs); |
@@ -7008,7 +6544,6 @@ postgres_get_wire_fee (void *cls, | |||
7008 | * Insert wire transfer fee into database. | 6544 | * Insert wire transfer fee into database. |
7009 | * | 6545 | * |
7010 | * @param cls closure | 6546 | * @param cls closure |
7011 | * @param session database connection | ||
7012 | * @param type type of wire transfer this fee applies for | 6547 | * @param type type of wire transfer this fee applies for |
7013 | * @param start_date when does the fee go into effect | 6548 | * @param start_date when does the fee go into effect |
7014 | * @param end_date when does the fee end being valid | 6549 | * @param end_date when does the fee end being valid |
@@ -7019,7 +6554,6 @@ postgres_get_wire_fee (void *cls, | |||
7019 | */ | 6554 | */ |
7020 | static enum GNUNET_DB_QueryStatus | 6555 | static enum GNUNET_DB_QueryStatus |
7021 | postgres_insert_wire_fee (void *cls, | 6556 | postgres_insert_wire_fee (void *cls, |
7022 | struct TALER_EXCHANGEDB_Session *session, | ||
7023 | const char *type, | 6557 | const char *type, |
7024 | struct GNUNET_TIME_Absolute start_date, | 6558 | struct GNUNET_TIME_Absolute start_date, |
7025 | struct GNUNET_TIME_Absolute end_date, | 6559 | struct GNUNET_TIME_Absolute end_date, |
@@ -7045,7 +6579,6 @@ postgres_insert_wire_fee (void *cls, | |||
7045 | enum GNUNET_DB_QueryStatus qs; | 6579 | enum GNUNET_DB_QueryStatus qs; |
7046 | 6580 | ||
7047 | qs = postgres_get_wire_fee (pg, | 6581 | qs = postgres_get_wire_fee (pg, |
7048 | session, | ||
7049 | type, | 6582 | type, |
7050 | start_date, | 6583 | start_date, |
7051 | &sd, | 6584 | &sd, |
@@ -7085,7 +6618,7 @@ postgres_insert_wire_fee (void *cls, | |||
7085 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 6618 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
7086 | } | 6619 | } |
7087 | 6620 | ||
7088 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | 6621 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7089 | "insert_wire_fee", | 6622 | "insert_wire_fee", |
7090 | params); | 6623 | params); |
7091 | } | 6624 | } |
@@ -7181,7 +6714,6 @@ reserve_expired_cb (void *cls, | |||
7181 | * remaining balances. | 6714 | * remaining balances. |
7182 | * | 6715 | * |
7183 | * @param cls closure of the plugin | 6716 | * @param cls closure of the plugin |
7184 | * @param session database connection | ||
7185 | * @param now timestamp based on which we decide expiration | 6717 | * @param now timestamp based on which we decide expiration |
7186 | * @param rec function to call on expired reserves | 6718 | * @param rec function to call on expired reserves |
7187 | * @param rec_cls closure for @a rec | 6719 | * @param rec_cls closure for @a rec |
@@ -7189,7 +6721,6 @@ reserve_expired_cb (void *cls, | |||
7189 | */ | 6721 | */ |
7190 | static enum GNUNET_DB_QueryStatus | 6722 | static enum GNUNET_DB_QueryStatus |
7191 | postgres_get_expired_reserves (void *cls, | 6723 | postgres_get_expired_reserves (void *cls, |
7192 | struct TALER_EXCHANGEDB_Session *session, | ||
7193 | struct GNUNET_TIME_Absolute now, | 6724 | struct GNUNET_TIME_Absolute now, |
7194 | TALER_EXCHANGEDB_ReserveExpiredCallback rec, | 6725 | TALER_EXCHANGEDB_ReserveExpiredCallback rec, |
7195 | void *rec_cls) | 6726 | void *rec_cls) |
@@ -7206,7 +6737,7 @@ postgres_get_expired_reserves (void *cls, | |||
7206 | ectx.rec_cls = rec_cls; | 6737 | ectx.rec_cls = rec_cls; |
7207 | ectx.pg = pg; | 6738 | ectx.pg = pg; |
7208 | ectx.status = GNUNET_OK; | 6739 | ectx.status = GNUNET_OK; |
7209 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 6740 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
7210 | "get_expired_reserves", | 6741 | "get_expired_reserves", |
7211 | params, | 6742 | params, |
7212 | &reserve_expired_cb, | 6743 | &reserve_expired_cb, |
@@ -7221,7 +6752,6 @@ postgres_get_expired_reserves (void *cls, | |||
7221 | * Insert reserve close operation into database. | 6752 | * Insert reserve close operation into database. |
7222 | * | 6753 | * |
7223 | * @param cls closure | 6754 | * @param cls closure |
7224 | * @param session database connection | ||
7225 | * @param reserve_pub which reserve is this about? | 6755 | * @param reserve_pub which reserve is this about? |
7226 | * @param execution_date when did we perform the transfer? | 6756 | * @param execution_date when did we perform the transfer? |
7227 | * @param receiver_account to which account do we transfer? | 6757 | * @param receiver_account to which account do we transfer? |
@@ -7233,7 +6763,6 @@ postgres_get_expired_reserves (void *cls, | |||
7233 | static enum GNUNET_DB_QueryStatus | 6763 | static enum GNUNET_DB_QueryStatus |
7234 | postgres_insert_reserve_closed ( | 6764 | postgres_insert_reserve_closed ( |
7235 | void *cls, | 6765 | void *cls, |
7236 | struct TALER_EXCHANGEDB_Session *session, | ||
7237 | const struct TALER_ReservePublicKeyP *reserve_pub, | 6766 | const struct TALER_ReservePublicKeyP *reserve_pub, |
7238 | struct GNUNET_TIME_Absolute execution_date, | 6767 | struct GNUNET_TIME_Absolute execution_date, |
7239 | const char *receiver_account, | 6768 | const char *receiver_account, |
@@ -7241,6 +6770,7 @@ postgres_insert_reserve_closed ( | |||
7241 | const struct TALER_Amount *amount_with_fee, | 6770 | const struct TALER_Amount *amount_with_fee, |
7242 | const struct TALER_Amount *closing_fee) | 6771 | const struct TALER_Amount *closing_fee) |
7243 | { | 6772 | { |
6773 | struct PostgresClosure *pg = cls; | ||
7244 | struct TALER_EXCHANGEDB_Reserve reserve; | 6774 | struct TALER_EXCHANGEDB_Reserve reserve; |
7245 | struct GNUNET_PQ_QueryParam params[] = { | 6775 | struct GNUNET_PQ_QueryParam params[] = { |
7246 | GNUNET_PQ_query_param_auto_from_type (reserve_pub), | 6776 | GNUNET_PQ_query_param_auto_from_type (reserve_pub), |
@@ -7254,7 +6784,7 @@ postgres_insert_reserve_closed ( | |||
7254 | enum TALER_AmountArithmeticResult ret; | 6784 | enum TALER_AmountArithmeticResult ret; |
7255 | enum GNUNET_DB_QueryStatus qs; | 6785 | enum GNUNET_DB_QueryStatus qs; |
7256 | 6786 | ||
7257 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 6787 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7258 | "reserves_close_insert", | 6788 | "reserves_close_insert", |
7259 | params); | 6789 | params); |
7260 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) | 6790 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) |
@@ -7264,7 +6794,6 @@ postgres_insert_reserve_closed ( | |||
7264 | reserve.pub = *reserve_pub; | 6794 | reserve.pub = *reserve_pub; |
7265 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != | 6795 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != |
7266 | (qs = postgres_reserves_get (cls, | 6796 | (qs = postgres_reserves_get (cls, |
7267 | session, | ||
7268 | &reserve))) | 6797 | &reserve))) |
7269 | { | 6798 | { |
7270 | /* Existence should have been checked before we got here... */ | 6799 | /* Existence should have been checked before we got here... */ |
@@ -7288,7 +6817,6 @@ postgres_insert_reserve_closed ( | |||
7288 | } | 6817 | } |
7289 | GNUNET_break (TALER_AAR_RESULT_ZERO == ret); | 6818 | GNUNET_break (TALER_AAR_RESULT_ZERO == ret); |
7290 | return reserves_update (cls, | 6819 | return reserves_update (cls, |
7291 | session, | ||
7292 | &reserve); | 6820 | &reserve); |
7293 | } | 6821 | } |
7294 | 6822 | ||
@@ -7297,7 +6825,6 @@ postgres_insert_reserve_closed ( | |||
7297 | * Function called to insert wire transfer commit data into the DB. | 6825 | * Function called to insert wire transfer commit data into the DB. |
7298 | * | 6826 | * |
7299 | * @param cls closure | 6827 | * @param cls closure |
7300 | * @param session database connection | ||
7301 | * @param type type of the wire transfer (i.e. "iban") | 6828 | * @param type type of the wire transfer (i.e. "iban") |
7302 | * @param buf buffer with wire transfer preparation data | 6829 | * @param buf buffer with wire transfer preparation data |
7303 | * @param buf_size number of bytes in @a buf | 6830 | * @param buf_size number of bytes in @a buf |
@@ -7305,19 +6832,18 @@ postgres_insert_reserve_closed ( | |||
7305 | */ | 6832 | */ |
7306 | static enum GNUNET_DB_QueryStatus | 6833 | static enum GNUNET_DB_QueryStatus |
7307 | postgres_wire_prepare_data_insert (void *cls, | 6834 | postgres_wire_prepare_data_insert (void *cls, |
7308 | struct TALER_EXCHANGEDB_Session *session, | ||
7309 | const char *type, | 6835 | const char *type, |
7310 | const char *buf, | 6836 | const char *buf, |
7311 | size_t buf_size) | 6837 | size_t buf_size) |
7312 | { | 6838 | { |
6839 | struct PostgresClosure *pg = cls; | ||
7313 | struct GNUNET_PQ_QueryParam params[] = { | 6840 | struct GNUNET_PQ_QueryParam params[] = { |
7314 | GNUNET_PQ_query_param_string (type), | 6841 | GNUNET_PQ_query_param_string (type), |
7315 | GNUNET_PQ_query_param_fixed_size (buf, buf_size), | 6842 | GNUNET_PQ_query_param_fixed_size (buf, buf_size), |
7316 | GNUNET_PQ_query_param_end | 6843 | GNUNET_PQ_query_param_end |
7317 | }; | 6844 | }; |
7318 | 6845 | ||
7319 | (void) cls; | 6846 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7320 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
7321 | "wire_prepare_data_insert", | 6847 | "wire_prepare_data_insert", |
7322 | params); | 6848 | params); |
7323 | } | 6849 | } |
@@ -7327,23 +6853,21 @@ postgres_wire_prepare_data_insert (void *cls, | |||
7327 | * Function called to mark wire transfer commit data as finished. | 6853 | * Function called to mark wire transfer commit data as finished. |
7328 | * | 6854 | * |
7329 | * @param cls closure | 6855 | * @param cls closure |
7330 | * @param session database connection | ||
7331 | * @param rowid which entry to mark as finished | 6856 | * @param rowid which entry to mark as finished |
7332 | * @return transaction status code | 6857 | * @return transaction status code |
7333 | */ | 6858 | */ |
7334 | static enum GNUNET_DB_QueryStatus | 6859 | static enum GNUNET_DB_QueryStatus |
7335 | postgres_wire_prepare_data_mark_finished ( | 6860 | postgres_wire_prepare_data_mark_finished ( |
7336 | void *cls, | 6861 | void *cls, |
7337 | struct TALER_EXCHANGEDB_Session *session, | ||
7338 | uint64_t rowid) | 6862 | uint64_t rowid) |
7339 | { | 6863 | { |
6864 | struct PostgresClosure *pg = cls; | ||
7340 | struct GNUNET_PQ_QueryParam params[] = { | 6865 | struct GNUNET_PQ_QueryParam params[] = { |
7341 | GNUNET_PQ_query_param_uint64 (&rowid), | 6866 | GNUNET_PQ_query_param_uint64 (&rowid), |
7342 | GNUNET_PQ_query_param_end | 6867 | GNUNET_PQ_query_param_end |
7343 | }; | 6868 | }; |
7344 | 6869 | ||
7345 | (void) cls; | 6870 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7346 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
7347 | "wire_prepare_data_mark_done", | 6871 | "wire_prepare_data_mark_done", |
7348 | params); | 6872 | params); |
7349 | } | 6873 | } |
@@ -7353,23 +6877,21 @@ postgres_wire_prepare_data_mark_finished ( | |||
7353 | * Function called to mark wire transfer commit data as failed. | 6877 | * Function called to mark wire transfer commit data as failed. |
7354 | * | 6878 | * |
7355 | * @param cls closure | 6879 | * @param cls closure |
7356 | * @param session database connection | ||
7357 | * @param rowid which entry to mark as failed | 6880 | * @param rowid which entry to mark as failed |
7358 | * @return transaction status code | 6881 | * @return transaction status code |
7359 | */ | 6882 | */ |
7360 | static enum GNUNET_DB_QueryStatus | 6883 | static enum GNUNET_DB_QueryStatus |
7361 | postgres_wire_prepare_data_mark_failed ( | 6884 | postgres_wire_prepare_data_mark_failed ( |
7362 | void *cls, | 6885 | void *cls, |
7363 | struct TALER_EXCHANGEDB_Session *session, | ||
7364 | uint64_t rowid) | 6886 | uint64_t rowid) |
7365 | { | 6887 | { |
6888 | struct PostgresClosure *pg = cls; | ||
7366 | struct GNUNET_PQ_QueryParam params[] = { | 6889 | struct GNUNET_PQ_QueryParam params[] = { |
7367 | GNUNET_PQ_query_param_uint64 (&rowid), | 6890 | GNUNET_PQ_query_param_uint64 (&rowid), |
7368 | GNUNET_PQ_query_param_end | 6891 | GNUNET_PQ_query_param_end |
7369 | }; | 6892 | }; |
7370 | 6893 | ||
7371 | (void) cls; | 6894 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7372 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
7373 | "wire_prepare_data_mark_failed", | 6895 | "wire_prepare_data_mark_failed", |
7374 | params); | 6896 | params); |
7375 | } | 6897 | } |
@@ -7380,17 +6902,16 @@ postgres_wire_prepare_data_mark_failed ( | |||
7380 | * preparation data. Fetches at most one item. | 6902 | * preparation data. Fetches at most one item. |
7381 | * | 6903 | * |
7382 | * @param cls closure | 6904 | * @param cls closure |
7383 | * @param session database connection | ||
7384 | * @param cb function to call for ONE unfinished item | 6905 | * @param cb function to call for ONE unfinished item |
7385 | * @param cb_cls closure for @a cb | 6906 | * @param cb_cls closure for @a cb |
7386 | * @return transaction status code | 6907 | * @return transaction status code |
7387 | */ | 6908 | */ |
7388 | static enum GNUNET_DB_QueryStatus | 6909 | static enum GNUNET_DB_QueryStatus |
7389 | postgres_wire_prepare_data_get (void *cls, | 6910 | postgres_wire_prepare_data_get (void *cls, |
7390 | struct TALER_EXCHANGEDB_Session *session, | ||
7391 | TALER_EXCHANGEDB_WirePreparationIterator cb, | 6911 | TALER_EXCHANGEDB_WirePreparationIterator cb, |
7392 | void *cb_cls) | 6912 | void *cb_cls) |
7393 | { | 6913 | { |
6914 | struct PostgresClosure *pg = cls; | ||
7394 | enum GNUNET_DB_QueryStatus qs; | 6915 | enum GNUNET_DB_QueryStatus qs; |
7395 | struct GNUNET_PQ_QueryParam params[] = { | 6916 | struct GNUNET_PQ_QueryParam params[] = { |
7396 | GNUNET_PQ_query_param_end | 6917 | GNUNET_PQ_query_param_end |
@@ -7410,8 +6931,7 @@ postgres_wire_prepare_data_get (void *cls, | |||
7410 | GNUNET_PQ_result_spec_end | 6931 | GNUNET_PQ_result_spec_end |
7411 | }; | 6932 | }; |
7412 | 6933 | ||
7413 | (void) cls; | 6934 | qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
7414 | qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
7415 | "wire_prepare_data_get", | 6935 | "wire_prepare_data_get", |
7416 | params, | 6936 | params, |
7417 | rs); | 6937 | rs); |
@@ -7433,34 +6953,32 @@ postgres_wire_prepare_data_get (void *cls, | |||
7433 | * and only add the wire transfer out at the end. | 6953 | * and only add the wire transfer out at the end. |
7434 | * | 6954 | * |
7435 | * @param cls the @e cls of this struct with the plugin-specific state | 6955 | * @param cls the @e cls of this struct with the plugin-specific state |
7436 | * @param session connection to use | ||
7437 | * @return #GNUNET_OK on success | 6956 | * @return #GNUNET_OK on success |
7438 | */ | 6957 | */ |
7439 | static int | 6958 | static int |
7440 | postgres_start_deferred_wire_out (void *cls, | 6959 | postgres_start_deferred_wire_out (void *cls) |
7441 | struct TALER_EXCHANGEDB_Session *session) | ||
7442 | { | 6960 | { |
6961 | struct PostgresClosure *pg = cls; | ||
7443 | struct GNUNET_PQ_ExecuteStatement es[] = { | 6962 | struct GNUNET_PQ_ExecuteStatement es[] = { |
7444 | GNUNET_PQ_make_execute ("SET CONSTRAINTS wire_out_ref DEFERRED"), | 6963 | GNUNET_PQ_make_execute ("SET CONSTRAINTS wire_out_ref DEFERRED"), |
7445 | GNUNET_PQ_EXECUTE_STATEMENT_END | 6964 | GNUNET_PQ_EXECUTE_STATEMENT_END |
7446 | }; | 6965 | }; |
7447 | 6966 | ||
7448 | postgres_preflight (cls, | 6967 | if (GNUNET_SYSERR == |
7449 | session); | 6968 | postgres_preflight (pg)) |
6969 | return GNUNET_SYSERR; | ||
7450 | if (GNUNET_OK != | 6970 | if (GNUNET_OK != |
7451 | postgres_start (cls, | 6971 | postgres_start (pg, |
7452 | session, | ||
7453 | "deferred wire out")) | 6972 | "deferred wire out")) |
7454 | return GNUNET_SYSERR; | 6973 | return GNUNET_SYSERR; |
7455 | if (GNUNET_OK != | 6974 | if (GNUNET_OK != |
7456 | GNUNET_PQ_exec_statements (session->conn, | 6975 | GNUNET_PQ_exec_statements (pg->conn, |
7457 | es)) | 6976 | es)) |
7458 | { | 6977 | { |
7459 | TALER_LOG_ERROR ( | 6978 | TALER_LOG_ERROR ( |
7460 | "Failed to defer wire_out_ref constraint on transaction\n"); | 6979 | "Failed to defer wire_out_ref constraint on transaction\n"); |
7461 | GNUNET_break (0); | 6980 | GNUNET_break (0); |
7462 | postgres_rollback (cls, | 6981 | postgres_rollback (pg); |
7463 | session); | ||
7464 | return GNUNET_SYSERR; | 6982 | return GNUNET_SYSERR; |
7465 | } | 6983 | } |
7466 | return GNUNET_OK; | 6984 | return GNUNET_OK; |
@@ -7471,7 +6989,6 @@ postgres_start_deferred_wire_out (void *cls, | |||
7471 | * Store information about an outgoing wire transfer that was executed. | 6989 | * Store information about an outgoing wire transfer that was executed. |
7472 | * | 6990 | * |
7473 | * @param cls closure | 6991 | * @param cls closure |
7474 | * @param session database connection | ||
7475 | * @param date time of the wire transfer | 6992 | * @param date time of the wire transfer |
7476 | * @param wtid subject of the wire transfer | 6993 | * @param wtid subject of the wire transfer |
7477 | * @param wire_account details about the receiver account of the wire transfer | 6994 | * @param wire_account details about the receiver account of the wire transfer |
@@ -7483,13 +7000,13 @@ postgres_start_deferred_wire_out (void *cls, | |||
7483 | static enum GNUNET_DB_QueryStatus | 7000 | static enum GNUNET_DB_QueryStatus |
7484 | postgres_store_wire_transfer_out ( | 7001 | postgres_store_wire_transfer_out ( |
7485 | void *cls, | 7002 | void *cls, |
7486 | struct TALER_EXCHANGEDB_Session *session, | ||
7487 | struct GNUNET_TIME_Absolute date, | 7003 | struct GNUNET_TIME_Absolute date, |
7488 | const struct TALER_WireTransferIdentifierRawP *wtid, | 7004 | const struct TALER_WireTransferIdentifierRawP *wtid, |
7489 | const json_t *wire_account, | 7005 | const json_t *wire_account, |
7490 | const char *exchange_account_section, | 7006 | const char *exchange_account_section, |
7491 | const struct TALER_Amount *amount) | 7007 | const struct TALER_Amount *amount) |
7492 | { | 7008 | { |
7009 | struct PostgresClosure *pg = cls; | ||
7493 | struct GNUNET_PQ_QueryParam params[] = { | 7010 | struct GNUNET_PQ_QueryParam params[] = { |
7494 | TALER_PQ_query_param_absolute_time (&date), | 7011 | TALER_PQ_query_param_absolute_time (&date), |
7495 | GNUNET_PQ_query_param_auto_from_type (wtid), | 7012 | GNUNET_PQ_query_param_auto_from_type (wtid), |
@@ -7499,8 +7016,7 @@ postgres_store_wire_transfer_out ( | |||
7499 | GNUNET_PQ_query_param_end | 7016 | GNUNET_PQ_query_param_end |
7500 | }; | 7017 | }; |
7501 | 7018 | ||
7502 | (void) cls; | 7019 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
7503 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
7504 | "insert_wire_out", | 7020 | "insert_wire_out", |
7505 | params); | 7021 | params); |
7506 | } | 7022 | } |
@@ -7720,7 +7236,6 @@ deposit_serial_helper_cb (void *cls, | |||
7720 | * order. | 7236 | * order. |
7721 | * | 7237 | * |
7722 | * @param cls closure | 7238 | * @param cls closure |
7723 | * @param session database connection | ||
7724 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7239 | * @param serial_id highest serial ID to exclude (select strictly larger) |
7725 | * @param cb function to call on each result | 7240 | * @param cb function to call on each result |
7726 | * @param cb_cls closure for @a cb | 7241 | * @param cb_cls closure for @a cb |
@@ -7729,7 +7244,6 @@ deposit_serial_helper_cb (void *cls, | |||
7729 | static enum GNUNET_DB_QueryStatus | 7244 | static enum GNUNET_DB_QueryStatus |
7730 | postgres_select_deposits_above_serial_id ( | 7245 | postgres_select_deposits_above_serial_id ( |
7731 | void *cls, | 7246 | void *cls, |
7732 | struct TALER_EXCHANGEDB_Session *session, | ||
7733 | uint64_t serial_id, | 7247 | uint64_t serial_id, |
7734 | TALER_EXCHANGEDB_DepositCallback cb, | 7248 | TALER_EXCHANGEDB_DepositCallback cb, |
7735 | void *cb_cls) | 7249 | void *cb_cls) |
@@ -7747,7 +7261,7 @@ postgres_select_deposits_above_serial_id ( | |||
7747 | }; | 7261 | }; |
7748 | enum GNUNET_DB_QueryStatus qs; | 7262 | enum GNUNET_DB_QueryStatus qs; |
7749 | 7263 | ||
7750 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7264 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
7751 | "audit_get_deposits_incr", | 7265 | "audit_get_deposits_incr", |
7752 | params, | 7266 | params, |
7753 | &deposit_serial_helper_cb, | 7267 | &deposit_serial_helper_cb, |
@@ -7859,7 +7373,6 @@ refreshs_serial_helper_cb (void *cls, | |||
7859 | * order. | 7373 | * order. |
7860 | * | 7374 | * |
7861 | * @param cls closure | 7375 | * @param cls closure |
7862 | * @param session database connection | ||
7863 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7376 | * @param serial_id highest serial ID to exclude (select strictly larger) |
7864 | * @param cb function to call on each result | 7377 | * @param cb function to call on each result |
7865 | * @param cb_cls closure for @a cb | 7378 | * @param cb_cls closure for @a cb |
@@ -7868,7 +7381,6 @@ refreshs_serial_helper_cb (void *cls, | |||
7868 | static enum GNUNET_DB_QueryStatus | 7381 | static enum GNUNET_DB_QueryStatus |
7869 | postgres_select_refreshes_above_serial_id ( | 7382 | postgres_select_refreshes_above_serial_id ( |
7870 | void *cls, | 7383 | void *cls, |
7871 | struct TALER_EXCHANGEDB_Session *session, | ||
7872 | uint64_t serial_id, | 7384 | uint64_t serial_id, |
7873 | TALER_EXCHANGEDB_RefreshesCallback cb, | 7385 | TALER_EXCHANGEDB_RefreshesCallback cb, |
7874 | void *cb_cls) | 7386 | void *cb_cls) |
@@ -7886,7 +7398,7 @@ postgres_select_refreshes_above_serial_id ( | |||
7886 | }; | 7398 | }; |
7887 | enum GNUNET_DB_QueryStatus qs; | 7399 | enum GNUNET_DB_QueryStatus qs; |
7888 | 7400 | ||
7889 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7401 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
7890 | "audit_get_refresh_commitments_incr", | 7402 | "audit_get_refresh_commitments_incr", |
7891 | params, | 7403 | params, |
7892 | &refreshs_serial_helper_cb, | 7404 | &refreshs_serial_helper_cb, |
@@ -7997,7 +7509,6 @@ refunds_serial_helper_cb (void *cls, | |||
7997 | * order. | 7509 | * order. |
7998 | * | 7510 | * |
7999 | * @param cls closure | 7511 | * @param cls closure |
8000 | * @param session database connection | ||
8001 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7512 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8002 | * @param cb function to call on each result | 7513 | * @param cb function to call on each result |
8003 | * @param cb_cls closure for @a cb | 7514 | * @param cb_cls closure for @a cb |
@@ -8006,7 +7517,6 @@ refunds_serial_helper_cb (void *cls, | |||
8006 | static enum GNUNET_DB_QueryStatus | 7517 | static enum GNUNET_DB_QueryStatus |
8007 | postgres_select_refunds_above_serial_id ( | 7518 | postgres_select_refunds_above_serial_id ( |
8008 | void *cls, | 7519 | void *cls, |
8009 | struct TALER_EXCHANGEDB_Session *session, | ||
8010 | uint64_t serial_id, | 7520 | uint64_t serial_id, |
8011 | TALER_EXCHANGEDB_RefundCallback cb, | 7521 | TALER_EXCHANGEDB_RefundCallback cb, |
8012 | void *cb_cls) | 7522 | void *cb_cls) |
@@ -8024,7 +7534,7 @@ postgres_select_refunds_above_serial_id ( | |||
8024 | }; | 7534 | }; |
8025 | enum GNUNET_DB_QueryStatus qs; | 7535 | enum GNUNET_DB_QueryStatus qs; |
8026 | 7536 | ||
8027 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7537 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8028 | "audit_get_refunds_incr", | 7538 | "audit_get_refunds_incr", |
8029 | params, | 7539 | params, |
8030 | &refunds_serial_helper_cb, | 7540 | &refunds_serial_helper_cb, |
@@ -8132,7 +7642,6 @@ reserves_in_serial_helper_cb (void *cls, | |||
8132 | * in monotonically increasing order. | 7642 | * in monotonically increasing order. |
8133 | * | 7643 | * |
8134 | * @param cls closure | 7644 | * @param cls closure |
8135 | * @param session database connection | ||
8136 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7645 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8137 | * @param cb function to call on each result | 7646 | * @param cb function to call on each result |
8138 | * @param cb_cls closure for @a cb | 7647 | * @param cb_cls closure for @a cb |
@@ -8141,7 +7650,6 @@ reserves_in_serial_helper_cb (void *cls, | |||
8141 | static enum GNUNET_DB_QueryStatus | 7650 | static enum GNUNET_DB_QueryStatus |
8142 | postgres_select_reserves_in_above_serial_id ( | 7651 | postgres_select_reserves_in_above_serial_id ( |
8143 | void *cls, | 7652 | void *cls, |
8144 | struct TALER_EXCHANGEDB_Session *session, | ||
8145 | uint64_t serial_id, | 7653 | uint64_t serial_id, |
8146 | TALER_EXCHANGEDB_ReserveInCallback cb, | 7654 | TALER_EXCHANGEDB_ReserveInCallback cb, |
8147 | void *cb_cls) | 7655 | void *cb_cls) |
@@ -8159,7 +7667,7 @@ postgres_select_reserves_in_above_serial_id ( | |||
8159 | }; | 7667 | }; |
8160 | enum GNUNET_DB_QueryStatus qs; | 7668 | enum GNUNET_DB_QueryStatus qs; |
8161 | 7669 | ||
8162 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7670 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8163 | "audit_reserves_in_get_transactions_incr", | 7671 | "audit_reserves_in_get_transactions_incr", |
8164 | params, | 7672 | params, |
8165 | &reserves_in_serial_helper_cb, | 7673 | &reserves_in_serial_helper_cb, |
@@ -8175,7 +7683,6 @@ postgres_select_reserves_in_above_serial_id ( | |||
8175 | * in monotonically increasing order by account. | 7683 | * in monotonically increasing order by account. |
8176 | * | 7684 | * |
8177 | * @param cls closure | 7685 | * @param cls closure |
8178 | * @param session database connection | ||
8179 | * @param account_name name of the account to select by | 7686 | * @param account_name name of the account to select by |
8180 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7687 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8181 | * @param cb function to call on each result | 7688 | * @param cb function to call on each result |
@@ -8185,7 +7692,6 @@ postgres_select_reserves_in_above_serial_id ( | |||
8185 | static enum GNUNET_DB_QueryStatus | 7692 | static enum GNUNET_DB_QueryStatus |
8186 | postgres_select_reserves_in_above_serial_id_by_account ( | 7693 | postgres_select_reserves_in_above_serial_id_by_account ( |
8187 | void *cls, | 7694 | void *cls, |
8188 | struct TALER_EXCHANGEDB_Session *session, | ||
8189 | const char *account_name, | 7695 | const char *account_name, |
8190 | uint64_t serial_id, | 7696 | uint64_t serial_id, |
8191 | TALER_EXCHANGEDB_ReserveInCallback cb, | 7697 | TALER_EXCHANGEDB_ReserveInCallback cb, |
@@ -8205,7 +7711,7 @@ postgres_select_reserves_in_above_serial_id_by_account ( | |||
8205 | }; | 7711 | }; |
8206 | enum GNUNET_DB_QueryStatus qs; | 7712 | enum GNUNET_DB_QueryStatus qs; |
8207 | 7713 | ||
8208 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7714 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8209 | "audit_reserves_in_get_transactions_incr_by_account", | 7715 | "audit_reserves_in_get_transactions_incr_by_account", |
8210 | params, | 7716 | params, |
8211 | &reserves_in_serial_helper_cb, | 7717 | &reserves_in_serial_helper_cb, |
@@ -8317,7 +7823,6 @@ reserves_out_serial_helper_cb (void *cls, | |||
8317 | * in monotonically increasing order. | 7823 | * in monotonically increasing order. |
8318 | * | 7824 | * |
8319 | * @param cls closure | 7825 | * @param cls closure |
8320 | * @param session database connection | ||
8321 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7826 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8322 | * @param cb function to call on each result | 7827 | * @param cb function to call on each result |
8323 | * @param cb_cls closure for @a cb | 7828 | * @param cb_cls closure for @a cb |
@@ -8326,7 +7831,6 @@ reserves_out_serial_helper_cb (void *cls, | |||
8326 | static enum GNUNET_DB_QueryStatus | 7831 | static enum GNUNET_DB_QueryStatus |
8327 | postgres_select_withdrawals_above_serial_id ( | 7832 | postgres_select_withdrawals_above_serial_id ( |
8328 | void *cls, | 7833 | void *cls, |
8329 | struct TALER_EXCHANGEDB_Session *session, | ||
8330 | uint64_t serial_id, | 7834 | uint64_t serial_id, |
8331 | TALER_EXCHANGEDB_WithdrawCallback cb, | 7835 | TALER_EXCHANGEDB_WithdrawCallback cb, |
8332 | void *cb_cls) | 7836 | void *cb_cls) |
@@ -8344,7 +7848,7 @@ postgres_select_withdrawals_above_serial_id ( | |||
8344 | }; | 7848 | }; |
8345 | enum GNUNET_DB_QueryStatus qs; | 7849 | enum GNUNET_DB_QueryStatus qs; |
8346 | 7850 | ||
8347 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7851 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8348 | "audit_get_reserves_out_incr", | 7852 | "audit_get_reserves_out_incr", |
8349 | params, | 7853 | params, |
8350 | &reserves_out_serial_helper_cb, | 7854 | &reserves_out_serial_helper_cb, |
@@ -8448,7 +7952,6 @@ wire_out_serial_helper_cb (void *cls, | |||
8448 | * executed. | 7952 | * executed. |
8449 | * | 7953 | * |
8450 | * @param cls closure | 7954 | * @param cls closure |
8451 | * @param session database connection | ||
8452 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7955 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8453 | * @param cb function to call for ONE unfinished item | 7956 | * @param cb function to call for ONE unfinished item |
8454 | * @param cb_cls closure for @a cb | 7957 | * @param cb_cls closure for @a cb |
@@ -8457,7 +7960,6 @@ wire_out_serial_helper_cb (void *cls, | |||
8457 | static enum GNUNET_DB_QueryStatus | 7960 | static enum GNUNET_DB_QueryStatus |
8458 | postgres_select_wire_out_above_serial_id ( | 7961 | postgres_select_wire_out_above_serial_id ( |
8459 | void *cls, | 7962 | void *cls, |
8460 | struct TALER_EXCHANGEDB_Session *session, | ||
8461 | uint64_t serial_id, | 7963 | uint64_t serial_id, |
8462 | TALER_EXCHANGEDB_WireTransferOutCallback cb, | 7964 | TALER_EXCHANGEDB_WireTransferOutCallback cb, |
8463 | void *cb_cls) | 7965 | void *cb_cls) |
@@ -8475,7 +7977,7 @@ postgres_select_wire_out_above_serial_id ( | |||
8475 | }; | 7977 | }; |
8476 | enum GNUNET_DB_QueryStatus qs; | 7978 | enum GNUNET_DB_QueryStatus qs; |
8477 | 7979 | ||
8478 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 7980 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8479 | "audit_get_wire_incr", | 7981 | "audit_get_wire_incr", |
8480 | params, | 7982 | params, |
8481 | &wire_out_serial_helper_cb, | 7983 | &wire_out_serial_helper_cb, |
@@ -8491,7 +7993,6 @@ postgres_select_wire_out_above_serial_id ( | |||
8491 | * executed by account. | 7993 | * executed by account. |
8492 | * | 7994 | * |
8493 | * @param cls closure | 7995 | * @param cls closure |
8494 | * @param session database connection | ||
8495 | * @param account_name account to select | 7996 | * @param account_name account to select |
8496 | * @param serial_id highest serial ID to exclude (select strictly larger) | 7997 | * @param serial_id highest serial ID to exclude (select strictly larger) |
8497 | * @param cb function to call for ONE unfinished item | 7998 | * @param cb function to call for ONE unfinished item |
@@ -8501,7 +8002,6 @@ postgres_select_wire_out_above_serial_id ( | |||
8501 | static enum GNUNET_DB_QueryStatus | 8002 | static enum GNUNET_DB_QueryStatus |
8502 | postgres_select_wire_out_above_serial_id_by_account ( | 8003 | postgres_select_wire_out_above_serial_id_by_account ( |
8503 | void *cls, | 8004 | void *cls, |
8504 | struct TALER_EXCHANGEDB_Session *session, | ||
8505 | const char *account_name, | 8005 | const char *account_name, |
8506 | uint64_t serial_id, | 8006 | uint64_t serial_id, |
8507 | TALER_EXCHANGEDB_WireTransferOutCallback cb, | 8007 | TALER_EXCHANGEDB_WireTransferOutCallback cb, |
@@ -8521,7 +8021,7 @@ postgres_select_wire_out_above_serial_id_by_account ( | |||
8521 | }; | 8021 | }; |
8522 | enum GNUNET_DB_QueryStatus qs; | 8022 | enum GNUNET_DB_QueryStatus qs; |
8523 | 8023 | ||
8524 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 8024 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8525 | "audit_get_wire_incr_by_account", | 8025 | "audit_get_wire_incr_by_account", |
8526 | params, | 8026 | params, |
8527 | &wire_out_serial_helper_cb, | 8027 | &wire_out_serial_helper_cb, |
@@ -8644,7 +8144,6 @@ recoup_serial_helper_cb (void *cls, | |||
8644 | * received, ordered by serial ID (monotonically increasing). | 8144 | * received, ordered by serial ID (monotonically increasing). |
8645 | * | 8145 | * |
8646 | * @param cls closure | 8146 | * @param cls closure |
8647 | * @param session database connection | ||
8648 | * @param serial_id lowest serial ID to include (select larger or equal) | 8147 | * @param serial_id lowest serial ID to include (select larger or equal) |
8649 | * @param cb function to call for ONE unfinished item | 8148 | * @param cb function to call for ONE unfinished item |
8650 | * @param cb_cls closure for @a cb | 8149 | * @param cb_cls closure for @a cb |
@@ -8653,7 +8152,6 @@ recoup_serial_helper_cb (void *cls, | |||
8653 | static enum GNUNET_DB_QueryStatus | 8152 | static enum GNUNET_DB_QueryStatus |
8654 | postgres_select_recoup_above_serial_id ( | 8153 | postgres_select_recoup_above_serial_id ( |
8655 | void *cls, | 8154 | void *cls, |
8656 | struct TALER_EXCHANGEDB_Session *session, | ||
8657 | uint64_t serial_id, | 8155 | uint64_t serial_id, |
8658 | TALER_EXCHANGEDB_RecoupCallback cb, | 8156 | TALER_EXCHANGEDB_RecoupCallback cb, |
8659 | void *cb_cls) | 8157 | void *cb_cls) |
@@ -8671,7 +8169,7 @@ postgres_select_recoup_above_serial_id ( | |||
8671 | }; | 8169 | }; |
8672 | enum GNUNET_DB_QueryStatus qs; | 8170 | enum GNUNET_DB_QueryStatus qs; |
8673 | 8171 | ||
8674 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 8172 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8675 | "recoup_get_incr", | 8173 | "recoup_get_incr", |
8676 | params, | 8174 | params, |
8677 | &recoup_serial_helper_cb, | 8175 | &recoup_serial_helper_cb, |
@@ -8798,7 +8296,6 @@ recoup_refresh_serial_helper_cb (void *cls, | |||
8798 | * refreshed coins, ordered by serial ID (monotonically increasing). | 8296 | * refreshed coins, ordered by serial ID (monotonically increasing). |
8799 | * | 8297 | * |
8800 | * @param cls closure | 8298 | * @param cls closure |
8801 | * @param session database connection | ||
8802 | * @param serial_id lowest serial ID to include (select larger or equal) | 8299 | * @param serial_id lowest serial ID to include (select larger or equal) |
8803 | * @param cb function to call for ONE unfinished item | 8300 | * @param cb function to call for ONE unfinished item |
8804 | * @param cb_cls closure for @a cb | 8301 | * @param cb_cls closure for @a cb |
@@ -8807,7 +8304,6 @@ recoup_refresh_serial_helper_cb (void *cls, | |||
8807 | static enum GNUNET_DB_QueryStatus | 8304 | static enum GNUNET_DB_QueryStatus |
8808 | postgres_select_recoup_refresh_above_serial_id ( | 8305 | postgres_select_recoup_refresh_above_serial_id ( |
8809 | void *cls, | 8306 | void *cls, |
8810 | struct TALER_EXCHANGEDB_Session *session, | ||
8811 | uint64_t serial_id, | 8307 | uint64_t serial_id, |
8812 | TALER_EXCHANGEDB_RecoupRefreshCallback cb, | 8308 | TALER_EXCHANGEDB_RecoupRefreshCallback cb, |
8813 | void *cb_cls) | 8309 | void *cb_cls) |
@@ -8825,7 +8321,7 @@ postgres_select_recoup_refresh_above_serial_id ( | |||
8825 | }; | 8321 | }; |
8826 | enum GNUNET_DB_QueryStatus qs; | 8322 | enum GNUNET_DB_QueryStatus qs; |
8827 | 8323 | ||
8828 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 8324 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8829 | "recoup_refresh_get_incr", | 8325 | "recoup_refresh_get_incr", |
8830 | params, | 8326 | params, |
8831 | &recoup_refresh_serial_helper_cb, | 8327 | &recoup_refresh_serial_helper_cb, |
@@ -8937,7 +8433,6 @@ reserve_closed_serial_helper_cb (void *cls, | |||
8937 | * triggered, ordered by serial ID (monotonically increasing). | 8433 | * triggered, ordered by serial ID (monotonically increasing). |
8938 | * | 8434 | * |
8939 | * @param cls closure | 8435 | * @param cls closure |
8940 | * @param session database connection | ||
8941 | * @param serial_id lowest serial ID to include (select larger or equal) | 8436 | * @param serial_id lowest serial ID to include (select larger or equal) |
8942 | * @param cb function to call for ONE unfinished item | 8437 | * @param cb function to call for ONE unfinished item |
8943 | * @param cb_cls closure for @a cb | 8438 | * @param cb_cls closure for @a cb |
@@ -8946,7 +8441,6 @@ reserve_closed_serial_helper_cb (void *cls, | |||
8946 | static enum GNUNET_DB_QueryStatus | 8441 | static enum GNUNET_DB_QueryStatus |
8947 | postgres_select_reserve_closed_above_serial_id ( | 8442 | postgres_select_reserve_closed_above_serial_id ( |
8948 | void *cls, | 8443 | void *cls, |
8949 | struct TALER_EXCHANGEDB_Session *session, | ||
8950 | uint64_t serial_id, | 8444 | uint64_t serial_id, |
8951 | TALER_EXCHANGEDB_ReserveClosedCallback cb, | 8445 | TALER_EXCHANGEDB_ReserveClosedCallback cb, |
8952 | void *cb_cls) | 8446 | void *cb_cls) |
@@ -8964,7 +8458,7 @@ postgres_select_reserve_closed_above_serial_id ( | |||
8964 | }; | 8458 | }; |
8965 | enum GNUNET_DB_QueryStatus qs; | 8459 | enum GNUNET_DB_QueryStatus qs; |
8966 | 8460 | ||
8967 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 8461 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
8968 | "reserves_close_get_incr", | 8462 | "reserves_close_get_incr", |
8969 | params, | 8463 | params, |
8970 | &reserve_closed_serial_helper_cb, | 8464 | &reserve_closed_serial_helper_cb, |
@@ -8982,7 +8476,6 @@ postgres_select_reserve_closed_above_serial_id ( | |||
8982 | * wire transfer back to the customer's account for the reserve. | 8476 | * wire transfer back to the customer's account for the reserve. |
8983 | * | 8477 | * |
8984 | * @param cls closure | 8478 | * @param cls closure |
8985 | * @param session database connection | ||
8986 | * @param reserve_pub public key of the reserve that is being refunded | 8479 | * @param reserve_pub public key of the reserve that is being refunded |
8987 | * @param coin information about the coin | 8480 | * @param coin information about the coin |
8988 | * @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_RECOUP | 8481 | * @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_RECOUP |
@@ -8995,7 +8488,6 @@ postgres_select_reserve_closed_above_serial_id ( | |||
8995 | static enum GNUNET_DB_QueryStatus | 8488 | static enum GNUNET_DB_QueryStatus |
8996 | postgres_insert_recoup_request ( | 8489 | postgres_insert_recoup_request ( |
8997 | void *cls, | 8490 | void *cls, |
8998 | struct TALER_EXCHANGEDB_Session *session, | ||
8999 | const struct TALER_ReservePublicKeyP *reserve_pub, | 8491 | const struct TALER_ReservePublicKeyP *reserve_pub, |
9000 | const struct TALER_CoinPublicInfo *coin, | 8492 | const struct TALER_CoinPublicInfo *coin, |
9001 | const struct TALER_CoinSpendSignatureP *coin_sig, | 8493 | const struct TALER_CoinSpendSignatureP *coin_sig, |
@@ -9020,7 +8512,7 @@ postgres_insert_recoup_request ( | |||
9020 | enum GNUNET_DB_QueryStatus qs; | 8512 | enum GNUNET_DB_QueryStatus qs; |
9021 | 8513 | ||
9022 | /* now store actual recoup information */ | 8514 | /* now store actual recoup information */ |
9023 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 8515 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
9024 | "recoup_insert", | 8516 | "recoup_insert", |
9025 | params); | 8517 | params); |
9026 | if (0 > qs) | 8518 | if (0 > qs) |
@@ -9031,8 +8523,7 @@ postgres_insert_recoup_request ( | |||
9031 | 8523 | ||
9032 | /* Update reserve balance */ | 8524 | /* Update reserve balance */ |
9033 | reserve.pub = *reserve_pub; | 8525 | reserve.pub = *reserve_pub; |
9034 | qs = postgres_reserves_get (cls, | 8526 | qs = postgres_reserves_get (pg, |
9035 | session, | ||
9036 | &reserve); | 8527 | &reserve); |
9037 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) | 8528 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) |
9038 | { | 8529 | { |
@@ -9060,8 +8551,7 @@ postgres_insert_recoup_request ( | |||
9060 | reserve.expiry = GNUNET_TIME_absolute_max (expiry, | 8551 | reserve.expiry = GNUNET_TIME_absolute_max (expiry, |
9061 | reserve.expiry); | 8552 | reserve.expiry); |
9062 | (void) GNUNET_TIME_round_abs (&reserve.expiry); | 8553 | (void) GNUNET_TIME_round_abs (&reserve.expiry); |
9063 | qs = reserves_update (cls, | 8554 | qs = reserves_update (pg, |
9064 | session, | ||
9065 | &reserve); | 8555 | &reserve); |
9066 | if (0 >= qs) | 8556 | if (0 >= qs) |
9067 | { | 8557 | { |
@@ -9079,7 +8569,6 @@ postgres_insert_recoup_request ( | |||
9079 | * "recoup_by_old_coin" used in #postgres_get_coin_transactions()). | 8569 | * "recoup_by_old_coin" used in #postgres_get_coin_transactions()). |
9080 | * | 8570 | * |
9081 | * @param cls closure | 8571 | * @param cls closure |
9082 | * @param session database connection | ||
9083 | * @param coin public information about the refreshed coin | 8572 | * @param coin public information about the refreshed coin |
9084 | * @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_RECOUP | 8573 | * @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_RECOUP |
9085 | * @param coin_blind blinding key of the coin | 8574 | * @param coin_blind blinding key of the coin |
@@ -9092,7 +8581,6 @@ postgres_insert_recoup_request ( | |||
9092 | static enum GNUNET_DB_QueryStatus | 8581 | static enum GNUNET_DB_QueryStatus |
9093 | postgres_insert_recoup_refresh_request ( | 8582 | postgres_insert_recoup_refresh_request ( |
9094 | void *cls, | 8583 | void *cls, |
9095 | struct TALER_EXCHANGEDB_Session *session, | ||
9096 | const struct TALER_CoinPublicInfo *coin, | 8584 | const struct TALER_CoinPublicInfo *coin, |
9097 | const struct TALER_CoinSpendSignatureP *coin_sig, | 8585 | const struct TALER_CoinSpendSignatureP *coin_sig, |
9098 | const struct TALER_DenominationBlindingKeyP *coin_blind, | 8586 | const struct TALER_DenominationBlindingKeyP *coin_blind, |
@@ -9100,6 +8588,7 @@ postgres_insert_recoup_refresh_request ( | |||
9100 | const struct GNUNET_HashCode *h_blind_ev, | 8588 | const struct GNUNET_HashCode *h_blind_ev, |
9101 | struct GNUNET_TIME_Absolute timestamp) | 8589 | struct GNUNET_TIME_Absolute timestamp) |
9102 | { | 8590 | { |
8591 | struct PostgresClosure *pg = cls; | ||
9103 | struct GNUNET_PQ_QueryParam params[] = { | 8592 | struct GNUNET_PQ_QueryParam params[] = { |
9104 | GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub), | 8593 | GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub), |
9105 | GNUNET_PQ_query_param_auto_from_type (coin_sig), | 8594 | GNUNET_PQ_query_param_auto_from_type (coin_sig), |
@@ -9111,12 +8600,11 @@ postgres_insert_recoup_refresh_request ( | |||
9111 | }; | 8600 | }; |
9112 | enum GNUNET_DB_QueryStatus qs; | 8601 | enum GNUNET_DB_QueryStatus qs; |
9113 | 8602 | ||
9114 | (void) cls; | ||
9115 | /* now store actual recoup information */ | 8603 | /* now store actual recoup information */ |
9116 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 8604 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
9117 | "Inserting recoup-refresh for coin %s\n", | 8605 | "Inserting recoup-refresh for coin %s\n", |
9118 | TALER_B2S (&coin->coin_pub)); | 8606 | TALER_B2S (&coin->coin_pub)); |
9119 | qs = GNUNET_PQ_eval_prepared_non_select (session->conn, | 8607 | qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, |
9120 | "recoup_refresh_insert", | 8608 | "recoup_refresh_insert", |
9121 | params); | 8609 | params); |
9122 | if (0 > qs) | 8610 | if (0 > qs) |
@@ -9133,17 +8621,16 @@ postgres_insert_recoup_refresh_request ( | |||
9133 | * from given the hash of the blinded coin. | 8621 | * from given the hash of the blinded coin. |
9134 | * | 8622 | * |
9135 | * @param cls closure | 8623 | * @param cls closure |
9136 | * @param session a session | ||
9137 | * @param h_blind_ev hash of the blinded coin | 8624 | * @param h_blind_ev hash of the blinded coin |
9138 | * @param[out] reserve_pub set to information about the reserve (on success only) | 8625 | * @param[out] reserve_pub set to information about the reserve (on success only) |
9139 | * @return transaction status code | 8626 | * @return transaction status code |
9140 | */ | 8627 | */ |
9141 | static enum GNUNET_DB_QueryStatus | 8628 | static enum GNUNET_DB_QueryStatus |
9142 | postgres_get_reserve_by_h_blind (void *cls, | 8629 | postgres_get_reserve_by_h_blind (void *cls, |
9143 | struct TALER_EXCHANGEDB_Session *session, | ||
9144 | const struct GNUNET_HashCode *h_blind_ev, | 8630 | const struct GNUNET_HashCode *h_blind_ev, |
9145 | struct TALER_ReservePublicKeyP *reserve_pub) | 8631 | struct TALER_ReservePublicKeyP *reserve_pub) |
9146 | { | 8632 | { |
8633 | struct PostgresClosure *pg = cls; | ||
9147 | struct GNUNET_PQ_QueryParam params[] = { | 8634 | struct GNUNET_PQ_QueryParam params[] = { |
9148 | GNUNET_PQ_query_param_auto_from_type (h_blind_ev), | 8635 | GNUNET_PQ_query_param_auto_from_type (h_blind_ev), |
9149 | GNUNET_PQ_query_param_end | 8636 | GNUNET_PQ_query_param_end |
@@ -9154,8 +8641,7 @@ postgres_get_reserve_by_h_blind (void *cls, | |||
9154 | GNUNET_PQ_result_spec_end | 8641 | GNUNET_PQ_result_spec_end |
9155 | }; | 8642 | }; |
9156 | 8643 | ||
9157 | (void) cls; | 8644 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
9158 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
9159 | "reserve_by_h_blind", | 8645 | "reserve_by_h_blind", |
9160 | params, | 8646 | params, |
9161 | rs); | 8647 | rs); |
@@ -9167,17 +8653,16 @@ postgres_get_reserve_by_h_blind (void *cls, | |||
9167 | * given the hash of the blinded (fresh) coin. | 8653 | * given the hash of the blinded (fresh) coin. |
9168 | * | 8654 | * |
9169 | * @param cls closure | 8655 | * @param cls closure |
9170 | * @param session a session | ||
9171 | * @param h_blind_ev hash of the blinded coin | 8656 | * @param h_blind_ev hash of the blinded coin |
9172 | * @param[out] old_coin_pub set to information about the old coin (on success only) | 8657 | * @param[out] old_coin_pub set to information about the old coin (on success only) |
9173 | * @return transaction status code | 8658 | * @return transaction status code |
9174 | */ | 8659 | */ |
9175 | static enum GNUNET_DB_QueryStatus | 8660 | static enum GNUNET_DB_QueryStatus |
9176 | postgres_get_old_coin_by_h_blind (void *cls, | 8661 | postgres_get_old_coin_by_h_blind (void *cls, |
9177 | struct TALER_EXCHANGEDB_Session *session, | ||
9178 | const struct GNUNET_HashCode *h_blind_ev, | 8662 | const struct GNUNET_HashCode *h_blind_ev, |
9179 | struct TALER_CoinSpendPublicKeyP *old_coin_pub) | 8663 | struct TALER_CoinSpendPublicKeyP *old_coin_pub) |
9180 | { | 8664 | { |
8665 | struct PostgresClosure *pg = cls; | ||
9181 | struct GNUNET_PQ_QueryParam params[] = { | 8666 | struct GNUNET_PQ_QueryParam params[] = { |
9182 | GNUNET_PQ_query_param_auto_from_type (h_blind_ev), | 8667 | GNUNET_PQ_query_param_auto_from_type (h_blind_ev), |
9183 | GNUNET_PQ_query_param_end | 8668 | GNUNET_PQ_query_param_end |
@@ -9188,8 +8673,7 @@ postgres_get_old_coin_by_h_blind (void *cls, | |||
9188 | GNUNET_PQ_result_spec_end | 8673 | GNUNET_PQ_result_spec_end |
9189 | }; | 8674 | }; |
9190 | 8675 | ||
9191 | (void) cls; | 8676 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
9192 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
9193 | "old_coin_by_h_blind", | 8677 | "old_coin_by_h_blind", |
9194 | params, | 8678 | params, |
9195 | rs); | 8679 | rs); |
@@ -9201,7 +8685,6 @@ postgres_get_old_coin_by_h_blind (void *cls, | |||
9201 | * in the database. | 8685 | * in the database. |
9202 | * | 8686 | * |
9203 | * @param cls closure | 8687 | * @param cls closure |
9204 | * @param session a session | ||
9205 | * @param denom_pub_hash hash of the revoked denomination key | 8688 | * @param denom_pub_hash hash of the revoked denomination key |
9206 | * @param master_sig signature affirming the revocation | 8689 | * @param master_sig signature affirming the revocation |
9207 | * @return transaction status code | 8690 | * @return transaction status code |
@@ -9209,23 +8692,17 @@ postgres_get_old_coin_by_h_blind (void *cls, | |||
9209 | static enum GNUNET_DB_QueryStatus | 8692 | static enum GNUNET_DB_QueryStatus |
9210 | postgres_insert_denomination_revocation ( | 8693 | postgres_insert_denomination_revocation ( |
9211 | void *cls, | 8694 | void *cls, |
9212 | struct TALER_EXCHANGEDB_Session *session, | ||
9213 | const struct GNUNET_HashCode *denom_pub_hash, | 8695 | const struct GNUNET_HashCode *denom_pub_hash, |
9214 | const struct TALER_MasterSignatureP *master_sig) | 8696 | const struct TALER_MasterSignatureP *master_sig) |
9215 | { | 8697 | { |
9216 | struct PostgresClosure *pc = cls; | 8698 | struct PostgresClosure *pg = cls; |
9217 | struct GNUNET_PQ_QueryParam params[] = { | 8699 | struct GNUNET_PQ_QueryParam params[] = { |
9218 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), | 8700 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), |
9219 | GNUNET_PQ_query_param_auto_from_type (master_sig), | 8701 | GNUNET_PQ_query_param_auto_from_type (master_sig), |
9220 | GNUNET_PQ_query_param_end | 8702 | GNUNET_PQ_query_param_end |
9221 | }; | 8703 | }; |
9222 | 8704 | ||
9223 | if (NULL == session) | 8705 | return GNUNET_PQ_eval_prepared_non_select (pg->conn, |
9224 | session = postgres_get_session (pc); | ||
9225 | if (NULL == session) | ||
9226 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
9227 | |||
9228 | return GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
9229 | "denomination_revocation_insert", | 8706 | "denomination_revocation_insert", |
9230 | params); | 8707 | params); |
9231 | } | 8708 | } |
@@ -9236,7 +8713,6 @@ postgres_insert_denomination_revocation ( | |||
9236 | * the database. | 8713 | * the database. |
9237 | * | 8714 | * |
9238 | * @param cls closure | 8715 | * @param cls closure |
9239 | * @param session a session | ||
9240 | * @param denom_pub_hash hash of the revoked denomination key | 8716 | * @param denom_pub_hash hash of the revoked denomination key |
9241 | * @param[out] master_sig signature affirming the revocation | 8717 | * @param[out] master_sig signature affirming the revocation |
9242 | * @param[out] rowid row where the information is stored | 8718 | * @param[out] rowid row where the information is stored |
@@ -9245,11 +8721,11 @@ postgres_insert_denomination_revocation ( | |||
9245 | static enum GNUNET_DB_QueryStatus | 8721 | static enum GNUNET_DB_QueryStatus |
9246 | postgres_get_denomination_revocation ( | 8722 | postgres_get_denomination_revocation ( |
9247 | void *cls, | 8723 | void *cls, |
9248 | struct TALER_EXCHANGEDB_Session *session, | ||
9249 | const struct GNUNET_HashCode *denom_pub_hash, | 8724 | const struct GNUNET_HashCode *denom_pub_hash, |
9250 | struct TALER_MasterSignatureP *master_sig, | 8725 | struct TALER_MasterSignatureP *master_sig, |
9251 | uint64_t *rowid) | 8726 | uint64_t *rowid) |
9252 | { | 8727 | { |
8728 | struct PostgresClosure *pg = cls; | ||
9253 | struct GNUNET_PQ_QueryParam params[] = { | 8729 | struct GNUNET_PQ_QueryParam params[] = { |
9254 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), | 8730 | GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), |
9255 | GNUNET_PQ_query_param_end | 8731 | GNUNET_PQ_query_param_end |
@@ -9260,8 +8736,7 @@ postgres_get_denomination_revocation ( | |||
9260 | GNUNET_PQ_result_spec_end | 8736 | GNUNET_PQ_result_spec_end |
9261 | }; | 8737 | }; |
9262 | 8738 | ||
9263 | (void) cls; | 8739 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, |
9264 | return GNUNET_PQ_eval_prepared_singleton_select (session->conn, | ||
9265 | "denomination_revocation_get", | 8740 | "denomination_revocation_get", |
9266 | params, | 8741 | params, |
9267 | rs); | 8742 | rs); |
@@ -9365,7 +8840,6 @@ missing_wire_cb (void *cls, | |||
9365 | * been deposited between @a start_date and @a end_date. | 8840 | * been deposited between @a start_date and @a end_date. |
9366 | * | 8841 | * |
9367 | * @param cls closure | 8842 | * @param cls closure |
9368 | * @param session a session | ||
9369 | * @param start_date lower bound on the requested wire execution date | 8843 | * @param start_date lower bound on the requested wire execution date |
9370 | * @param end_date upper bound on the requested wire execution date | 8844 | * @param end_date upper bound on the requested wire execution date |
9371 | * @param cb function to call on all such deposits | 8845 | * @param cb function to call on all such deposits |
@@ -9374,7 +8848,6 @@ missing_wire_cb (void *cls, | |||
9374 | */ | 8848 | */ |
9375 | static enum GNUNET_DB_QueryStatus | 8849 | static enum GNUNET_DB_QueryStatus |
9376 | postgres_select_deposits_missing_wire (void *cls, | 8850 | postgres_select_deposits_missing_wire (void *cls, |
9377 | struct TALER_EXCHANGEDB_Session *session, | ||
9378 | struct GNUNET_TIME_Absolute start_date, | 8851 | struct GNUNET_TIME_Absolute start_date, |
9379 | struct GNUNET_TIME_Absolute end_date, | 8852 | struct GNUNET_TIME_Absolute end_date, |
9380 | TALER_EXCHANGEDB_WireMissingCallback cb, | 8853 | TALER_EXCHANGEDB_WireMissingCallback cb, |
@@ -9394,7 +8867,7 @@ postgres_select_deposits_missing_wire (void *cls, | |||
9394 | }; | 8867 | }; |
9395 | enum GNUNET_DB_QueryStatus qs; | 8868 | enum GNUNET_DB_QueryStatus qs; |
9396 | 8869 | ||
9397 | qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, | 8870 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
9398 | "deposits_get_overdue", | 8871 | "deposits_get_overdue", |
9399 | params, | 8872 | params, |
9400 | &missing_wire_cb, | 8873 | &missing_wire_cb, |
@@ -9409,7 +8882,6 @@ postgres_select_deposits_missing_wire (void *cls, | |||
9409 | * Check the last date an auditor was modified. | 8882 | * Check the last date an auditor was modified. |
9410 | * | 8883 | * |
9411 | * @param cls closure | 8884 | * @param cls closure |
9412 | * @param session a session | ||
9413 | * @param auditor_pub key to look up information for | 8885 | * @param auditor_pub key to look up information for |
9414 | * @param[out] last_date last modification date to auditor status | 8886 | * @param[out] last_date last modification date to auditor status |
9415 | * @return transaction status code | 8887 | * @return transaction status code |
@@ -9417,10 +8889,10 @@ postgres_select_deposits_missing_wire (void *cls, | |||
9417 | static enum GNUNET_DB_QueryStatus | 8889 | static enum GNUNET_DB_QueryStatus |
9418 | postgres_lookup_auditor_timestamp ( | 8890 | postgres_lookup_auditor_timestamp ( |
9419 | void *cls, | 8891 | void *cls, |
9420 | struct TALER_EXCHANGEDB_Session *session, | ||
9421 | const struct TALER_AuditorPublicKeyP *auditor_pub, | 8892 | const struct TALER_AuditorPublicKeyP *auditor_pub, |
9422 | struct GNUNET_TIME_Absolute *last_date) |