@@ -12,20 +12,18 @@ import BotPlutusInterface.Files (DummyPrivKey, unDummyPrivateKey)
1212import BotPlutusInterface.Files qualified as Files
1313import BotPlutusInterface.Types (LogLevel (Debug ), PABConfig )
1414import Cardano.Api (ExecutionUnitPrices (ExecutionUnitPrices ))
15- import Cardano.Api.ProtocolParameters (ProtocolParameters )
15+ import Cardano.Api.Shelley (ProtocolParameters ( protocolParamPrices ) )
1616import Control.Monad (foldM , void , zipWithM )
1717import Control.Monad.Freer (Eff , Member )
1818import Control.Monad.Trans.Class (lift )
1919import Control.Monad.Trans.Either (EitherT , hoistEither , newEitherT , runEitherT )
20- import Data.Aeson qualified as Aeson
2120import Data.Coerce (coerce )
2221import Data.Either.Combinators (rightToMaybe )
23- import Data.HashMap.Strict qualified as HashMap
2422import Data.Kind (Type )
2523import Data.List (partition , (\\) )
2624import Data.Map (Map )
2725import Data.Map qualified as Map
28- import Data.Maybe (fromJust , fromMaybe , mapMaybe )
26+ import Data.Maybe (fromMaybe , mapMaybe )
2927import Data.Set (Set )
3028import Data.Set qualified as Set
3129import Data.Text (Text )
@@ -137,7 +135,7 @@ balanceTxIO pabConf ownPkh unbalancedTx =
137135 exBudget <- newEitherT $ CardanoCLI. buildTx @ w pabConf privKeys txWithoutFees
138136 nonBudgettedFees <- newEitherT $ CardanoCLI. calculateMinFee @ w pabConf txWithoutFees
139137 -- TODO: not fromJust here
140- let fees = nonBudgettedFees + getBudgetPrice (fromJust $ getProtocolParamsPrices pabConf. pcProtocolParams ) exBudget
138+ let fees = nonBudgettedFees + getBudgetPrice (getExecutionUnitPrices pabConf) exBudget
141139
142140 lift $ printLog @ w Debug $ " Fees: " ++ show fees
143141
@@ -148,16 +146,8 @@ balanceTxIO pabConf ownPkh unbalancedTx =
148146 then pure (balancedTx, minUtxos)
149147 else loop utxoIndex privKeys minUtxos balancedTx
150148
151- -- I can't seem to import the accessor for this?
152- -- As such, heres a disgusting hack to read the data
153- -- Another possibility is converting the Protocol params to Alonzo params, and reading the `Prices` field
154- -- (This is probably safer, I should do that)
155- getProtocolParamsPrices :: ProtocolParameters -> Maybe ExecutionUnitPrices
156- getProtocolParamsPrices params = do
157- (Aeson. Object o) <- pure $ Aeson. toJSON params
158- unitsValue <- HashMap. lookup " executionUnitPrices" o
159- (Aeson. Success units) <- pure $ Aeson. fromJSON unitsValue
160- pure units
149+ getExecutionUnitPrices :: PABConfig -> ExecutionUnitPrices
150+ getExecutionUnitPrices pabConf = fromMaybe (ExecutionUnitPrices 0 0 ) $ protocolParamPrices pabConf. pcProtocolParams
161151
162152getBudgetPrice :: ExecutionUnitPrices -> Ledger. ExBudget -> Integer
163153getBudgetPrice (ExecutionUnitPrices cpuPrice memPrice) (Ledger. ExBudget cpuUsed memUsed) =
0 commit comments