diff options
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index e8ba1b44..2dc17b43 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -5303,6 +5303,11 @@ struct LookupReserveForTipContext * Error status. */ enum TALER_ErrorCode ec; + + /** + * Did we find a good reserve? + */ + bool ok; }; @@ -5368,13 +5373,27 @@ lookup_reserve_for_tip_cb (void *cls, if (0 > TALER_amount_cmp (&remaining, &lac->required_amount)) - continue; /* insufficient balance */ + { + /* insufficient balance */ + if (lac->ok) + continue; /* got another reserve */ + lac->ec = TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_INSUFFICIENT_FUNDS; + continue; + } if ( (lac->expiration.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) && ( (expiration.abs_value_us > lac->expiration.abs_value_us) && (GNUNET_TIME_absolute_get_remaining (lac->expiration).rel_value_us > MIN_EXPIRATION.rel_value_us) ) ) + { + /* reserve expired */ + if (lac->ok) + continue; /* got another reserve */ + lac->ec = TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_EXPIRED; continue; + } + lac->ok = true; + lac->ec = TALER_EC_NONE; lac->expiration = expiration; lac->reserve_pub = reserve_pub; } @@ -5445,11 +5464,8 @@ RETRY: } if (NULL == reserve_pubp) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), - TALER_PQ_query_param_amount (amount), - GNUNET_PQ_query_param_absolute_time (&now), GNUNET_PQ_query_param_end }; @@ -5458,29 +5474,25 @@ RETRY: params, &lookup_reserve_for_tip_cb, &lac); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + switch (qs) { + case GNUNET_DB_STATUS_SOFT_ERROR: postgres_rollback (pg); goto RETRY; - } - if (GNUNET_DB_STATUS_HARD_ERROR == qs) - { + case GNUNET_DB_STATUS_HARD_ERROR: GNUNET_break (0); postgres_rollback (pg); - return - TALER_EC_GENERIC_DB_FETCH_FAILED; - } - if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == - lac.expiration.abs_value_us) - { + return TALER_EC_GENERIC_DB_FETCH_FAILED; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: postgres_rollback (pg); return TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_NOT_FOUND; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + default: + break; } - if (0 == GNUNET_TIME_absolute_get_remaining (lac.expiration).rel_value_us) - { - postgres_rollback (pg); - return TALER_EC_MERCHANT_PRIVATE_POST_TIP_AUTHORIZE_RESERVE_EXPIRED; - } + if (TALER_EC_NONE != lac.ec) + return lac.ec; + GNUNET_assert (lac.ok); reserve_pubp = &lac.reserve_pub; } @@ -8412,16 +8424,11 @@ postgres_connect (void *cls) ",tips_committed_frac" " FROM merchant_tip_reserves" " WHERE" - " exchange_initial_balance_val - tips_committed_val > $2" - " OR" - " (exchange_initial_balance_val - tips_committed_val = $2" - " AND exchange_initial_balance_frac - tips_committed_frac >= $3)" - " AND expiration > $4" - " AND merchant_serial =" + " merchant_serial =" " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)", - 4), + 1), /* For postgres_authorize_tip() */ GNUNET_PQ_make_prepare ("lookup_reserve_status", |