Skip to content

Commit 68bba25

Browse files
Handle TODO
1 parent 1fb00c1 commit 68bba25

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ import BotPlutusInterface.Files (DummyPrivKey, unDummyPrivateKey)
1212
import BotPlutusInterface.Files qualified as Files
1313
import BotPlutusInterface.Types (LogLevel (Debug), PABConfig)
1414
import Cardano.Api (ExecutionUnitPrices (ExecutionUnitPrices))
15-
import Cardano.Api.ProtocolParameters (ProtocolParameters)
15+
import Cardano.Api.Shelley (ProtocolParameters (protocolParamPrices))
1616
import Control.Monad (foldM, void, zipWithM)
1717
import Control.Monad.Freer (Eff, Member)
1818
import Control.Monad.Trans.Class (lift)
1919
import Control.Monad.Trans.Either (EitherT, hoistEither, newEitherT, runEitherT)
20-
import Data.Aeson qualified as Aeson
2120
import Data.Coerce (coerce)
2221
import Data.Either.Combinators (rightToMaybe)
23-
import Data.HashMap.Strict qualified as HashMap
2422
import Data.Kind (Type)
2523
import Data.List (partition, (\\))
2624
import Data.Map (Map)
2725
import Data.Map qualified as Map
28-
import Data.Maybe (fromJust, fromMaybe, mapMaybe)
26+
import Data.Maybe (fromMaybe, mapMaybe)
2927
import Data.Set (Set)
3028
import Data.Set qualified as Set
3129
import 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

162152
getBudgetPrice :: ExecutionUnitPrices -> Ledger.ExBudget -> Integer
163153
getBudgetPrice (ExecutionUnitPrices cpuPrice memPrice) (Ledger.ExBudget cpuUsed memUsed) =

0 commit comments

Comments
 (0)