Skip to content

Commit 9681566

Browse files
committed
Fix buildRaw throwing away build errors
1 parent 4f1342b commit 9681566

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

src/BotPlutusInterface/BodyBuilder.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import BotPlutusInterface.Effects (PABEffect, estimateBudget)
1010

1111
import BotPlutusInterface.Files (
1212
DummyPrivKey,
13+
txFilePath,
1314
)
1415
import BotPlutusInterface.Types (PABConfig, TxFile (Raw))
1516
import Control.Monad.Freer (Eff, Member)
@@ -18,7 +19,7 @@ import Data.Kind (Type)
1819
import Data.Map (Map)
1920
import Data.Text (Text)
2021
import Data.Text qualified as Text
21-
import Ledger (ExBudget, Tx)
22+
import Ledger (ExBudget, Tx, txId)
2223
import Ledger.Crypto (PubKeyHash)
2324
import Prelude
2425

@@ -36,10 +37,10 @@ buildRaw ::
3637
Eff effs (Either Text ExBudget)
3738
buildRaw pabConf privKeys tx = runEitherT $ do
3839
buildDraftTxBody
39-
>>= estimateBudgetByDraftBody
40+
>> estimateBudgetByDraftBody (Text.unpack $ txFilePath pabConf "raw" (txId tx))
4041
>>= buildBodyUsingEstimatedBudget
4142
where
42-
buildDraftTxBody = newEitherT $ CardanoCLI.buildDraftTx @w pabConf privKeys tx
43+
buildDraftTxBody = newEitherT $ CardanoCLI.buildTx @w pabConf privKeys mempty tx
4344

4445
estimateBudgetByDraftBody path =
4546
firstEitherT toText . newEitherT $ estimateBudget @w (Raw path)

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module BotPlutusInterface.CardanoCLI (
1212
policyScriptFilePath,
1313
utxosAt,
1414
queryTip,
15-
buildDraftTx,
1615
) where
1716

1817
import BotPlutusInterface.Effects (PABEffect, ShellArgs (..), callCommand)
@@ -25,7 +24,7 @@ import BotPlutusInterface.Files (
2524
txFilePath,
2625
validatorScriptFilePath,
2726
)
28-
import BotPlutusInterface.Types (MintBudgets, PABConfig, SpendBudgets, Tip, TxBudget, emptyBudget, mintBudgets, spendBudgets)
27+
import BotPlutusInterface.Types (MintBudgets, PABConfig, SpendBudgets, Tip, TxBudget, mintBudgets, spendBudgets)
2928
import BotPlutusInterface.UtxoParser qualified as UtxoParser
3029
import Cardano.Api.Shelley (NetworkId (Mainnet, Testnet), NetworkMagic (..), serialiseAddress)
3130
import Control.Monad (join)
@@ -173,20 +172,6 @@ calculateMinFee pabConf tx =
173172
, cmdOutParser = mapLeft Text.pack . parseOnly UtxoParser.feeParser . Text.pack
174173
}
175174

176-
{- | Build draft tx body w/o setting ExBudget for inputs.
177-
This body will be used to estimate `ExBudget` with `Cardano.Api` by `BodyBuilder`
178-
-}
179-
buildDraftTx ::
180-
forall (w :: Type) (effs :: [Type -> Type]).
181-
Member (PABEffect w) effs =>
182-
PABConfig ->
183-
Map PubKeyHash DummyPrivKey ->
184-
Tx ->
185-
Eff effs (Either Text FilePath)
186-
buildDraftTx pabConf privKeys tx = do
187-
_ <- buildTx @w pabConf privKeys emptyBudget tx
188-
return $ Right (Text.unpack $ txFilePath pabConf "raw" (txId tx))
189-
190175
-- | Build a tx body and write it to disk
191176
buildTx ::
192177
forall (w :: Type) (effs :: [Type -> Type]).

src/BotPlutusInterface/Types.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module BotPlutusInterface.Types (
2020
BudgetEstimationError (..),
2121
SpendBudgets,
2222
MintBudgets,
23-
emptyBudget,
2423
) where
2524

2625
import Cardano.Api (NetworkId (Testnet), NetworkMagic (..), ScriptExecutionError, ScriptWitnessIndex)
@@ -185,9 +184,11 @@ data TxBudget = TxBudget
185184
}
186185
deriving stock (Show)
187186

188-
-- | Budget with no estimations for `CardanoCLI.buildDraftTx`
189-
emptyBudget :: TxBudget
190-
emptyBudget = TxBudget mempty mempty
187+
instance Semigroup TxBudget where
188+
TxBudget s m <> TxBudget s' m' = TxBudget (s <> s') (m <> m')
189+
190+
instance Monoid TxBudget where
191+
mempty = TxBudget mempty mempty
191192

192193
type SpendBudgets = Map TxOutRef ExBudget
193194

0 commit comments

Comments
 (0)