|
| 1 | +{-# LANGUAGE DataKinds #-} |
| 2 | +{-# LANGUAGE GADTs #-} |
| 3 | +{-# LANGUAGE RankNTypes #-} |
| 4 | + |
| 5 | +module Cardano.Api.Experimental.Tx.Internal.Fee |
| 6 | + ( estimateBalancedTxBody |
| 7 | + ) |
| 8 | +where |
| 9 | + |
| 10 | +import Cardano.Api.Address |
| 11 | +import Cardano.Api.Certificate.Internal |
| 12 | +import Cardano.Api.Era.Internal.Eon.Convert |
| 13 | +import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra |
| 14 | +import Cardano.Api.Experimental.Era |
| 15 | +import Cardano.Api.Ledger.Internal.Reexport qualified as L |
| 16 | +import Cardano.Api.Plutus |
| 17 | +import Cardano.Api.Tx.Internal.Body |
| 18 | +import Cardano.Api.Tx.Internal.Fee qualified as Fee |
| 19 | +import Cardano.Api.Value.Internal |
| 20 | + |
| 21 | +import Cardano.Ledger.Alonzo.Core qualified as Ledger |
| 22 | +import Cardano.Ledger.Credential as Ledger (Credential) |
| 23 | + |
| 24 | +import Data.Map.Strict (Map) |
| 25 | +import Data.Map.Strict qualified as Map |
| 26 | +import Data.Set (Set) |
| 27 | +import GHC.Stack |
| 28 | + |
| 29 | +-- | Use when you do not have access to the UTxOs you intend to spend |
| 30 | +estimateBalancedTxBody |
| 31 | + :: HasCallStack |
| 32 | + => Era era |
| 33 | + -> TxBodyContent BuildTx era |
| 34 | + -> L.PParams (LedgerEra era) |
| 35 | + -> Set PoolId |
| 36 | + -- ^ The set of registered stake pools, being |
| 37 | + -- unregistered in this transaction. |
| 38 | + -> Map StakeCredential L.Coin |
| 39 | + -- ^ A map of all deposits for stake credentials that are being |
| 40 | + -- unregistered in this transaction. |
| 41 | + -> Map (Ledger.Credential Ledger.DRepRole) L.Coin |
| 42 | + -- ^ A map of all deposits for DRep credentials that are being |
| 43 | + -- unregistered in this transaction. |
| 44 | + -> Map (Ledger.PlutusPurpose Ledger.AsIx (LedgerEra era)) ExecutionUnits |
| 45 | + -- ^ Plutus script execution units. |
| 46 | + -> Coin |
| 47 | + -- ^ Total potential collateral amount. |
| 48 | + -> Int |
| 49 | + -- ^ The number of key witnesses to be added to the transaction. |
| 50 | + -> Int |
| 51 | + -- ^ The number of Byron key witnesses to be added to the transaction. |
| 52 | + -> Int |
| 53 | + -- ^ The size of all reference scripts in bytes. |
| 54 | + -> AddressInEra era |
| 55 | + -- ^ Change address. |
| 56 | + -> Value |
| 57 | + -- ^ Total value of UTXOs being spent. |
| 58 | + -> Either (Fee.TxFeeEstimationError era) (Fee.BalancedTxBody era) |
| 59 | +estimateBalancedTxBody |
| 60 | + w |
| 61 | + txbodycontent |
| 62 | + pparams |
| 63 | + poolids |
| 64 | + stakeDelegDeposits |
| 65 | + drepDelegDeposits |
| 66 | + exUnitsMap = |
| 67 | + obtainCommonConstraints w $ |
| 68 | + Fee.estimateBalancedTxBody |
| 69 | + (convert w) |
| 70 | + txbodycontent |
| 71 | + (ledgerPParamsShim w pparams) |
| 72 | + poolids |
| 73 | + stakeDelegDeposits |
| 74 | + drepDelegDeposits |
| 75 | + (Map.mapKeys (toScriptIndex (convert w)) exUnitsMap) |
| 76 | + |
| 77 | +ledgerPParamsShim |
| 78 | + :: Era era -> L.PParams (LedgerEra era) -> L.PParams (ShelleyLedgerEra era) |
| 79 | +ledgerPParamsShim ConwayEra pp = pp |
0 commit comments