diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-10-15 23:30:51 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-10-15 23:30:51 +0200 |
commit | 917dd4d70ff2f38d475146b387e649a669996f10 (patch) | |
tree | 2550f23c5d9418bdaae7c5b7b328d9e5c60e226b /src/exchangedb/pg_do_reserve_open.c | |
parent | c72cf2ce10017dccc342c4ea86ac2b006aa54149 (diff) | |
download | exchange-917dd4d70ff2f38d475146b387e649a669996f10.tar.xz |
avoid extra transaction to fetch balance if reserve is out of funds, remove legacy /withdraw endpoint
Diffstat (limited to 'src/exchangedb/pg_do_reserve_open.c')
-rw-r--r-- | src/exchangedb/pg_do_reserve_open.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/exchangedb/pg_do_reserve_open.c b/src/exchangedb/pg_do_reserve_open.c index e82a3e9cf..b15c96dd1 100644 --- a/src/exchangedb/pg_do_reserve_open.c +++ b/src/exchangedb/pg_do_reserve_open.c @@ -38,6 +38,7 @@ TEH_PG_do_reserve_open ( struct GNUNET_TIME_Timestamp now, const struct TALER_Amount *open_fee, bool *no_funds, + struct TALER_Amount *reserve_balance, struct TALER_Amount *open_cost, struct GNUNET_TIME_Timestamp *final_expiration) { @@ -60,16 +61,23 @@ TEH_PG_do_reserve_open ( open_fee), GNUNET_PQ_query_param_end }; + bool no_reserve = true; struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_amount ("out_open_cost", pg->currency, open_cost), + TALER_PQ_result_spec_amount ("out_reserve_balance", + pg->currency, + reserve_balance), GNUNET_PQ_result_spec_timestamp ("out_final_expiration", final_expiration), + GNUNET_PQ_result_spec_bool ("out_no_reserve", + &no_reserve), GNUNET_PQ_result_spec_bool ("out_no_funds", no_funds), GNUNET_PQ_result_spec_end }; + enum GNUNET_DB_QueryStatus qs; PREPARE (pg, "do_reserve_open", @@ -77,10 +85,17 @@ TEH_PG_do_reserve_open ( " out_open_cost" ",out_final_expiration" ",out_no_funds" + ",out_no_reserve" + ",out_reserve_balance" " FROM exchange_do_reserve_open" " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "do_reserve_open", - params, - rs); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "do_reserve_open", + params, + rs); + if (qs <= 0) + return qs; + if (no_reserve) + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + return qs; } |