diff options
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 886d26ed4..9032d0da1 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c | |||
@@ -436,7 +436,8 @@ postgres_get_session (void *cls) | |||
436 | ",gc_date" | 436 | ",gc_date" |
437 | ") VALUES " | 437 | ") VALUES " |
438 | "($1, $2, $3, $4, $5, $6)" | 438 | "($1, $2, $3, $4, $5, $6)" |
439 | " ON CONFLICT DO NOTHING;", | 439 | " ON CONFLICT DO NOTHING" |
440 | " RETURNING reserve_uuid;", | ||
440 | 6), | 441 | 6), |
441 | /* Used in #postgres_insert_reserve_closed() */ | 442 | /* Used in #postgres_insert_reserve_closed() */ |
442 | GNUNET_PQ_make_prepare ("reserves_close_insert", | 443 | GNUNET_PQ_make_prepare ("reserves_close_insert", |
@@ -478,6 +479,19 @@ postgres_get_session (void *cls) | |||
478 | " WHERE reserve_pub=$1" | 479 | " WHERE reserve_pub=$1" |
479 | " ON CONFLICT DO NOTHING;", | 480 | " ON CONFLICT DO NOTHING;", |
480 | 7), | 481 | 7), |
482 | /* Used in #postgres_reserves_in_insert() to store transaction details */ | ||
483 | GNUNET_PQ_make_prepare ("reserves_in_add_by_uuid", | ||
484 | "INSERT INTO reserves_in " | ||
485 | "(reserve_uuid" | ||
486 | ",wire_reference" | ||
487 | ",credit_val" | ||
488 | ",credit_frac" | ||
489 | ",exchange_account_section" | ||
490 | ",sender_account_details" | ||
491 | ",execution_date" | ||
492 | ") VALUES ($1, $2, $3, $4, $5, $6, $7)" | ||
493 | " ON CONFLICT DO NOTHING;", | ||
494 | 7), | ||
481 | /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound | 495 | /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound |
482 | transactions for reserves with serial id '\geq' the given parameter */ | 496 | transactions for reserves with serial id '\geq' the given parameter */ |
483 | GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference", | 497 | GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference", |
@@ -3488,6 +3502,7 @@ postgres_reserves_in_insert (void *cls, | |||
3488 | struct GNUNET_TIME_Absolute expiry; | 3502 | struct GNUNET_TIME_Absolute expiry; |
3489 | struct GNUNET_TIME_Absolute gc; | 3503 | struct GNUNET_TIME_Absolute gc; |
3490 | struct GNUNET_TIME_Absolute now; | 3504 | struct GNUNET_TIME_Absolute now; |
3505 | uint64_t reserve_uuid; | ||
3491 | 3506 | ||
3492 | now = GNUNET_TIME_absolute_get (); | 3507 | now = GNUNET_TIME_absolute_get (); |
3493 | (void) GNUNET_TIME_round_abs (&now); | 3508 | (void) GNUNET_TIME_round_abs (&now); |
@@ -3517,34 +3532,61 @@ postgres_reserves_in_insert (void *cls, | |||
3517 | TALER_PQ_query_param_absolute_time (&gc), | 3532 | TALER_PQ_query_param_absolute_time (&gc), |
3518 | GNUNET_PQ_query_param_end | 3533 | GNUNET_PQ_query_param_end |
3519 | }; | 3534 | }; |
3535 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
3536 | GNUNET_PQ_result_spec_uint64 ("reserve_uuid", | ||
3537 | &reserve_uuid), | ||
3538 | GNUNET_PQ_result_spec_end | ||
3539 | }; | ||
3520 | 3540 | ||
3521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3522 | "Reserve does not exist; creating a new one\n"); | 3542 | "Reserve does not exist; creating a new one\n"); |
3523 | /* Note: query uses 'on conflict do nothing' */ | 3543 | /* Note: query uses 'on conflict do nothing' */ |
3524 | qs1 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3544 | qs1 = GNUNET_PQ_eval_prepared_singleton_select (session->conn, |
3525 | "reserve_create", | 3545 | "reserve_create", |
3526 | params); | 3546 | params, |
3547 | rs); | ||
3527 | if (qs1 < 0) | 3548 | if (qs1 < 0) |
3528 | return qs1; | 3549 | return qs1; |
3529 | } | 3550 | } |
3530 | 3551 | ||
3531 | /* Create new incoming transaction, "ON CONFLICT DO NOTHING" | 3552 | /* Create new incoming transaction, "ON CONFLICT DO NOTHING" |
3532 | is again used to guard against duplicates. */ | 3553 | is again used to guard against duplicates. */ |
3554 | |||
3533 | { | 3555 | { |
3534 | struct GNUNET_PQ_QueryParam params[] = { | ||
3535 | GNUNET_PQ_query_param_auto_from_type (&reserve.pub), | ||
3536 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3537 | TALER_PQ_query_param_amount (balance), | ||
3538 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3539 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3540 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3541 | GNUNET_PQ_query_param_end | ||
3542 | }; | ||
3543 | enum GNUNET_DB_QueryStatus qs2; | 3556 | enum GNUNET_DB_QueryStatus qs2; |
3544 | 3557 | ||
3545 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3558 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs1) |
3546 | "reserves_in_add_transaction", | 3559 | { |
3547 | params); | 3560 | struct GNUNET_PQ_QueryParam params[] = { |
3561 | GNUNET_PQ_query_param_auto_from_type (&reserve.pub), | ||
3562 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3563 | TALER_PQ_query_param_amount (balance), | ||
3564 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3565 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3566 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3567 | GNUNET_PQ_query_param_end | ||
3568 | }; | ||
3569 | |||
3570 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
3571 | "reserves_in_add_transaction", | ||
3572 | params); | ||
3573 | } | ||
3574 | else | ||
3575 | { | ||
3576 | struct GNUNET_PQ_QueryParam params[] = { | ||
3577 | GNUNET_PQ_query_param_uint64 (&reserve_uuid), | ||
3578 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3579 | TALER_PQ_query_param_amount (balance), | ||
3580 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3581 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3582 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3583 | GNUNET_PQ_query_param_end | ||
3584 | }; | ||
3585 | |||
3586 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
3587 | "reserves_in_add_by_uuid", | ||
3588 | params); | ||
3589 | } | ||
3548 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs2) | 3590 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs2) |
3549 | { | 3591 | { |
3550 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs2); | 3592 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs2); |