Skip to content

Commit

Permalink
Add getReferenceInputsSizeForTxIds function
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Apr 4, 2024
1 parent d45171b commit a1e5545
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}

{- HLINT ignore "Avoid lambda using `infix`" -}
{- HLINT ignore "Move brackets to avoid" -}
{- HLINT ignore "Redundant flip" -}
{- HLINT ignore "Use let" -}
{- HLINT ignore "Use section" -}

-- | Transaction bodies
--
module Cardano.Api.Tx.Body (
parseTxId,
-- * Transaction bodies
Expand Down Expand Up @@ -82,6 +75,7 @@ module Cardano.Api.Tx.Body (
TxIns,
TxIx(..),
genesisUTxOPseudoTxIn,
getReferenceInputsSizeForTxIds,

-- * Transaction outputs
CtxTx, CtxUTxO,
Expand Down Expand Up @@ -206,6 +200,7 @@ import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo (hashScriptIntegrity)
import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Babbage.UTxO as L
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
import Cardano.Ledger.Binary (Annotated (..))
import qualified Cardano.Ledger.Binary as CBOR
Expand Down Expand Up @@ -3065,6 +3060,17 @@ genesisUTxOPseudoTxIn nw (GenesisUTxOKeyHash kh) =
(Shelley.KeyHashObj kh)
Shelley.StakeRefNull

-- | Calculate the reference inputs size for provided set of transaction IDs and UTXOs.
getReferenceInputsSizeForTxIds
:: forall era ledgerera. ShelleyLedgerEra era ~ ledgerera
=> BabbageEraOnwards era
-> Ledger.UTxO ledgerera
-> Set TxIn
-> Int
getReferenceInputsSizeForTxIds beo utxo txIds = babbageEraOnwardsConstraints beo $ do
let refScripts = L.getReferenceScriptsNonDistinct utxo (Set.map toShelleyTxIn txIds)
getSum $ foldMap (Sum . SafeHash.originalBytesSize . snd) refScripts

calculateExecutionUnitsLovelace :: Ledger.Prices -> ExecutionUnits -> Maybe L.Coin
calculateExecutionUnitsLovelace prices eUnits =
return $ Alonzo.txscriptfee prices (toAlonzoExUnits eUnits)
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ module Cardano.Api (
TxIns,
TxIx(TxIx),
renderTxIn,
getReferenceInputsSizeForTxIds,

-- ** Transaction outputs
CtxTx, CtxUTxO,
Expand Down

0 comments on commit a1e5545

Please sign in to comment.