Skip to content

Commit eec5722

Browse files
committed
Implement experimental estimateBalancedTxBody
1 parent d9fe76b commit eec5722

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

cardano-api/cardano-api.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ library
226226
Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
227227
Cardano.Api.Experimental.Tx.Internal.AnyWitness
228228
Cardano.Api.Experimental.Tx.Internal.Certificate
229+
Cardano.Api.Experimental.Tx.Internal.Fee
229230
Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
230231
Cardano.Api.Genesis.Internal
231232
Cardano.Api.Genesis.Internal.Parameters

cardano-api/src/Cardano/Api/Experimental.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ module Cardano.Api.Experimental
2626
, convertToOldApiCertificate
2727
, mkTxCertificates
2828

29+
-- ** Transaction fee related
30+
, estimateBalancedTxBody
31+
2932
-- ** Era-related
3033
, BabbageEra
3134
, ConwayEra
@@ -75,4 +78,5 @@ import Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
7578
import Cardano.Api.Experimental.Simple.Script
7679
import Cardano.Api.Experimental.Tx
7780
import Cardano.Api.Experimental.Tx.Internal.Certificate
81+
import Cardano.Api.Experimental.Tx.Internal.Fee
7882
import Cardano.Api.Tx.Internal.Fee (evaluateTransactionExecutionUnitsShelley)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)