Skip to content

Commit

Permalink
Merge pull request #4031 from cardano-foundation/anviking/ADP-3053/rm…
Browse files Browse the repository at this point in the history
…-evaluateMinimumFee

Drop duplicated evaluateMinimumFee
  • Loading branch information
Anviking authored Jul 11, 2023
2 parents e2a0563 + 50899b2 commit 891768a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
29 changes: 0 additions & 29 deletions lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module Cardano.Wallet.Shelley.Transaction

-- * For balancing (To be moved)
, estimateKeyWitnessCount
, evaluateMinimumFee
, estimateSignedTxSize
, KeyWitnessCount (..)
, distributeSurplus
Expand Down Expand Up @@ -165,7 +164,6 @@ import Cardano.Wallet.Read.Primitive.Tx
import Cardano.Wallet.Shelley.Compatibility
( cardanoCertKeysForWitnesses
, fromCardanoAddress
, fromCardanoLovelace
, fromCardanoWdrls
, toCardanoLovelace
, toCardanoPolicyId
Expand Down Expand Up @@ -237,8 +235,6 @@ import Data.Generics.Internal.VL.Lens
( view, (^.) )
import Data.Generics.Labels
()
import Data.IntCast
( intCast )
import Data.Map.Strict
( Map, (!) )
import Data.Maybe
Expand Down Expand Up @@ -719,31 +715,6 @@ mkDelegationCertificates da cred =
]
Quit -> [toStakeKeyDeregCert cred]

-- | Evaluate a minimal fee amount necessary to pay for a given tx
-- using ledger's functionality.
evaluateMinimumFee
:: Cardano.IsShelleyBasedEra era
=> Cardano.BundledProtocolParameters era
-> KeyWitnessCount
-> Cardano.TxBody era
-> Coin
evaluateMinimumFee pp (KeyWitnessCount nWits nBootWits) body =
fromCardanoLovelace (Cardano.evaluateTransactionFee pp body nWits 0)
<> bootWitFees
-- NOTE: Cardano.evaluateTransactionFee will error if passed non-zero
-- nBootWits, so we need to account for it separately.
where
bootWitFees = Coin.fromNatural $ feePerByte * bytes
where
feePerByte :: Natural
feePerByte =
Coin.toNatural . fromCardanoLovelace
$ Cardano.protocolParamTxFeePerByte
$ Cardano.unbundleProtocolParams pp

bytes :: Natural
bytes = unTxSize $ sizeOf_BootstrapWitnesses $ intCast nBootWits

-- | Estimate the size of the transaction (body) when fully signed.
estimateSignedTxSize
:: forall era. Write.IsRecentEra era
Expand Down
16 changes: 6 additions & 10 deletions lib/wallet/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ import Cardano.Wallet.Shelley.Transaction
, estimateKeyWitnessCount
, estimateSignedTxSize
, estimateTxSize
, evaluateMinimumFee
, maximumCostOfIncreasingCoin
, mkByronWitness
, mkDelegationCertificates
Expand Down Expand Up @@ -3275,16 +3274,13 @@ txMinFee
:: Cardano.Tx Cardano.BabbageEra
-> Cardano.UTxO Cardano.BabbageEra
-> Cardano.Lovelace
txMinFee (Cardano.Tx body _) u =
toCardanoLovelace
$ evaluateMinimumFee
( either (error . show) id $
Cardano.bundleProtocolParams
Cardano.BabbageEra
mockCardanoApiPParamsForBalancing
)
txMinFee tx@(Cardano.Tx body _) u =
Write.toCardanoLovelace
$ Write.evaluateMinimumFee
RecentEraBabbage
(Write.pparamsLedger $ mockPParamsForBalancing @Cardano.BabbageEra)
(Write.fromCardanoTx tx)
(estimateKeyWitnessCount u body)
body

-- NOTE: 'balanceTransaction' relies on estimating the number of witnesses that
-- will be needed. The correctness of this estimation is not tested here.
Expand Down

0 comments on commit 891768a

Please sign in to comment.