Skip to content

Commit

Permalink
Backend(Ether): make sure fee is less than output
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Oct 2, 2023
1 parent 86e96e5 commit 19795ba
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/GWallet.Backend/Ether/EtherAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,24 @@ module internal Account =
return failwith <| SPrintF1 "Assertion failed: currency %A should be Ether or Ether token" account.Currency
}

let private ValidateMinerFee (trans: string) =
let intDecoder = IntTypeDecoder()

let tx = TransactionFactory.CreateTransaction trans

let amountInWei = intDecoder.DecodeBigInteger tx.Value

// TODO: handle validating miner fee in token transfer (where amount is zero)
if amountInWei <> BigInteger.Zero then
let gasLimitInWei = intDecoder.DecodeBigInteger tx.GasLimit
let gasPriceInWei = intDecoder.DecodeBigInteger tx.GasPrice
let minerFeeInWei = gasLimitInWei * gasPriceInWei

if minerFeeInWei > amountInWei then
raise MinerFeeHigherThanOutputs

let private BroadcastRawTransaction (currency: Currency) trans =
ValidateMinerFee trans
Ether.Server.BroadcastTransaction currency ("0x" + trans)

let BroadcastTransaction (trans: SignedTransaction<_>) =
Expand Down

0 comments on commit 19795ba

Please sign in to comment.