Skip to content

Commit

Permalink
Backend(Ether): fix sweep when high fees
Browse files Browse the repository at this point in the history
This commit fixes crash when balance is less then fees
when sweeping.

Fixes #223

Co-authored-by: Afshin Arani <[email protected]>
  • Loading branch information
2 people authored and knocte committed Oct 6, 2023
1 parent 0c5409e commit 409e29f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/GWallet.Backend/Ether/EtherAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,16 @@ module internal Account =
0.01m

let feeValue = maybeBetterFee.CalculateAbsoluteValue()
if (amount.ValueToSend <> amount.BalanceAtTheMomentOfSending &&
feeValue > (amount.BalanceAtTheMomentOfSending - amount.ValueToSend)) then

let isSweepAndBalanceIsLessThanFee =
amount.ValueToSend = amount.BalanceAtTheMomentOfSending &&
amount.BalanceAtTheMomentOfSending < feeValue

let isNotSweepAndBalanceIsNotSufficient =
amount.ValueToSend <> amount.BalanceAtTheMomentOfSending &&
feeValue > amount.BalanceAtTheMomentOfSending - amount.ValueToSend

if isSweepAndBalanceIsLessThanFee || isNotSweepAndBalanceIsNotSufficient then
raise <| InsufficientBalanceForFee (Some feeValue)

return { Ether.Fee = maybeBetterFee; Ether.TransactionCount = txCount }
Expand Down

0 comments on commit 409e29f

Please sign in to comment.