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/exchange_do_batch_withdraw.sql | |
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/exchange_do_batch_withdraw.sql')
-rw-r--r-- | src/exchangedb/exchange_do_batch_withdraw.sql | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/exchangedb/exchange_do_batch_withdraw.sql b/src/exchangedb/exchange_do_batch_withdraw.sql index be279ab7c..a27f2348e 100644 --- a/src/exchangedb/exchange_do_batch_withdraw.sql +++ b/src/exchangedb/exchange_do_batch_withdraw.sql @@ -24,6 +24,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw( IN do_age_check BOOLEAN, OUT reserve_found BOOLEAN, OUT balance_ok BOOLEAN, + OUT reserve_balance taler_amount, OUT age_ok BOOLEAN, OUT allowed_maximum_age INT2, -- in years OUT ruuid INT8) @@ -40,7 +41,7 @@ BEGIN -- reserves_in by reserve_pub (SELECT) -- wire_targets by wire_target_h_payto - +-- FIXME-Oec: do not use select-*! SELECT * INTO reserve FROM exchange.reserves @@ -51,13 +52,15 @@ THEN -- reserve unknown reserve_found=FALSE; balance_ok=FALSE; + reserve_balance.frac = 0; + reserve_balance.val = 0; age_ok=FALSE; allowed_maximum_age=0; ruuid=2; RETURN; END IF; reserve_found=TRUE; - +reserve_balance = reserve.current_balance; ruuid = reserve.reserve_uuid; -- Check if age requirements are present @@ -79,24 +82,23 @@ ELSE RETURN; END IF; -balance = reserve.current_balance; -- Check reserve balance is sufficient. -IF (balance.val > amount.val) +IF (reserve_balance.val > amount.val) THEN - IF (balance.frac >= amount.frac) + IF (reserve_balance.frac >= amount.frac) THEN - balance.val=balance.val - amount.val; - balance.frac=balance.frac - amount.frac; + balance.val=reserve_balance.val - amount.val; + balance.frac=reserve_balance.frac - amount.frac; ELSE - balance.val=balance.val - amount.val - 1; - balance.frac=balance.frac + 100000000 - amount.frac; + balance.val=reserve_balance.val - amount.val - 1; + balance.frac=reserve_balance.frac + 100000000 - amount.frac; END IF; ELSE - IF (balance.val = amount.val) AND (balance.frac >= amount.frac) + IF (reserve_balance.val = amount.val) AND (reserve_balance.frac >= amount.frac) THEN balance.val=0; - balance.frac=balance.frac - amount.frac; + balance.frac=reserve_balance.frac - amount.frac; ELSE balance_ok=FALSE; RETURN; |