Skip to content

Commit

Permalink
Delete deprecated functions transactionFee and estimateTransactionFee
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Mar 21, 2024
1 parent e81ccc1 commit 65ccfdb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 102 deletions.
100 changes: 0 additions & 100 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
--
module Cardano.Api.Fees (
-- * Transaction fees
transactionFee,
estimateTransactionFee,
evaluateTransactionFee,
estimateTransactionKeyWitnessCount,

Expand Down Expand Up @@ -53,7 +51,6 @@ import Cardano.Api.Eras.Case
import Cardano.Api.Eras.Core
import Cardano.Api.Error
import qualified Cardano.Api.Ledger.Lens as A
import Cardano.Api.NetworkId
import Cardano.Api.Pretty
import Cardano.Api.ProtocolParameters
import Cardano.Api.Query
Expand All @@ -62,8 +59,6 @@ import Cardano.Api.Tx.Body
import Cardano.Api.Tx.Sign
import Cardano.Api.Value

import qualified Cardano.Binary as CBOR
import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Ledger.Alonzo.Core as Ledger
import qualified Cardano.Ledger.Alonzo.Plutus.Context as Plutus
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
Expand All @@ -78,7 +73,6 @@ import qualified PlutusLedgerApi.V1 as Plutus

import Control.Monad (forM_)
import Data.Bifunctor (bimap, first)
import qualified Data.ByteString as BS
import Data.ByteString.Short (ShortByteString)
import Data.Function ((&))
import Data.Map.Strict (Map)
Expand All @@ -95,100 +89,6 @@ import Lens.Micro ((.~), (^.))
--- Transaction fees
---

-- | For a concrete fully-constructed transaction, determine the minimum fee
-- that it needs to pay.
--
-- This function is simple, but if you are doing input selection then you
-- probably want to consider estimateTransactionFee.
--
transactionFee :: ()
=> ShelleyBasedEra era
-> L.Coin -- ^ The fixed tx fee
-> L.Coin -- ^ The tx fee per byte
-> Tx era
-> L.Coin
transactionFee sbe txFeeFixed txFeePerByte tx =
let a = toInteger txFeePerByte
b = toInteger txFeeFixed
in
case tx of
ShelleyTx _ tx' ->
let x = shelleyBasedEraConstraints sbe $ tx' ^. L.sizeTxF in L.Coin (a * x + b)

{-# DEPRECATED transactionFee "Use 'evaluateTransactionFee' instead" #-}

--TODO: in the Byron case the per-byte is non-integral, would need different
-- parameters. e.g. a new data type for fee params, Byron vs Shelley

-- | This can estimate what the transaction fee will be, based on a starting
-- base transaction, plus the numbers of the additional components of the
-- transaction that may be added.
--
-- So for example with wallet coin selection, the base transaction should
-- contain all the things not subject to coin selection (such as script inputs,
-- metadata, withdrawals, certs etc)
--
estimateTransactionFee :: ()
=> ShelleyBasedEra era
-> NetworkId
-> L.Coin -- ^ The fixed tx fee
-> L.Coin -- ^ The tx fee per byte
-> Tx era
-> Int -- ^ The number of extra UTxO transaction inputs
-> Int -- ^ The number of extra transaction outputs
-> Int -- ^ The number of extra Shelley key witnesses
-> Int -- ^ The number of extra Byron key witnesses
-> L.Coin
estimateTransactionFee sbe nw txFeeFixed txFeePerByte = \case
ShelleyTx era tx ->
let L.Coin baseFee = transactionFee sbe txFeeFixed txFeePerByte (ShelleyTx era tx)
in \nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses ->
--TODO: this is fragile. Move something like this to the ledger and
-- make it robust, based on the txsize calculation.
let extraBytes :: Int
extraBytes =
nInputs * sizeInput
+ nOutputs * sizeOutput
+ nByronKeyWitnesses * sizeByronKeyWitnesses
+ nShelleyKeyWitnesses * sizeShelleyKeyWitnesses

in L.Coin (baseFee + toInteger txFeePerByte * toInteger extraBytes)
where
sizeInput = smallArray + uint + hashObj
sizeOutput = smallArray + uint + address
sizeByronKeyWitnesses = smallArray + keyObj + sigObj + ccodeObj + attrsObj
sizeShelleyKeyWitnesses = smallArray + keyObj + sigObj

smallArray = 1
uint = 5

hashObj = 2 + hashLen
hashLen = 32

keyObj = 2 + keyLen
keyLen = 32

sigObj = 2 + sigLen
sigLen = 64

ccodeObj = 2 + ccodeLen
ccodeLen = 32

address = 2 + addrHeader + 2 * addrHashLen
addrHeader = 1
addrHashLen = 28

attrsObj = 2 + BS.length attributes
attributes = CBOR.serialize' $
Byron.mkAttributes Byron.AddrAttributes {
Byron.aaVKDerivationPath = Nothing,
Byron.aaNetworkMagic = toByronNetworkMagic nw
}

--TODO: also deprecate estimateTransactionFee:
--{-# DEPRECATED estimateTransactionFee "Use 'evaluateTransactionFee' instead" #-}


-- | Compute the transaction fee for a proposed transaction, with the
-- assumption that there will be the given number of key witnesses (i.e.
-- signatures).
Expand Down
2 changes: 0 additions & 2 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ module Cardano.Api (

-- ** Fee calculation
LedgerEpochInfo(..),
transactionFee,
toLedgerEpochInfo,
estimateTransactionFee,
evaluateTransactionFee,
estimateTransactionKeyWitnessCount,

Expand Down

0 comments on commit 65ccfdb

Please sign in to comment.