Skip to content

Commit 1caede2

Browse files
committed
Always query the raw transaction file in writeBalanceTx
Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
1 parent 1b5e68a commit 1caede2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/BotPlutusInterface/Contract.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import BotPlutusInterface.Effects (
2121
import BotPlutusInterface.Files (DummyPrivKey (FromSKey, FromVKey))
2222
import BotPlutusInterface.Files qualified as Files
2323
import BotPlutusInterface.Types (ContractEnvironment (..), LogLevel (Debug, Warn), Tip (block, slot))
24-
import Cardano.Api (AsType (..), EraInMode (..))
24+
import Cardano.Api (AsType (..), EraInMode (..), Tx (Tx))
2525
import Control.Lens (preview, (^.))
2626
import Control.Monad (join, void, when)
2727
import Control.Monad.Freer (Eff, Member, interpret, reinterpret, runM, subsume, type (~>))
@@ -250,6 +250,12 @@ writeBalancedTx contractEnv (Right tx) = do
250250

251251
void $ newEitherT $ CardanoCLI.buildTx @w pabConf privKeys tx
252252

253+
-- TODO: This whole part is hacky and we should remove it.
254+
let path = Text.unpack $ Files.txFilePath pabConf "raw" (Tx.txId tx)
255+
-- We read back the tx from file as tx currently has the wrong id (but the one we create with cardano-cli is correct)
256+
alonzoBody <- firstEitherT (Text.pack . show) $ newEitherT $ readFileTextEnvelope @w (AsTxBody AsAlonzoEra) path
257+
let cardanoTx = Tx.SomeTx (Tx alonzoBody []) AlonzoEraInCardanoMode
258+
253259
if signable
254260
then newEitherT $ CardanoCLI.signTx @w pabConf tx requiredSigners
255261
else
@@ -259,13 +265,6 @@ writeBalancedTx contractEnv (Right tx) = do
259265
, "Signatories (pkh): " <> Text.unwords (map pkhToText requiredSigners)
260266
]
261267

262-
-- TODO: This whole part is hacky and we should remove it.
263-
let ext = if signable then "signed" else "raw"
264-
path = Text.unpack $ Files.txFilePath pabConf ext (Tx.txId tx)
265-
-- We read back the tx from file as tx currently has the wrong id (but the one we create with cardano-cli is correct)
266-
alonxoTx <- firstEitherT (Text.pack . show) $ newEitherT $ readFileTextEnvelope @w (AsTx AsAlonzoEra) path
267-
let cardanoTx = Tx.SomeTx alonxoTx AlonzoEraInCardanoMode
268-
269268
when (not pabConf.pcDryRun && signable) $ do
270269
newEitherT $ CardanoCLI.submitTx @w pabConf tx
271270

test/Spec/MockContract.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ mockCallCommand ShellArgs {cmdName, cmdArgs, cmdOutParser} = do
326326
("cardano-cli", "transaction" : "build-raw" : args) -> do
327327
case drop 1 $ dropWhile (/= "--out-file") args of
328328
filepath : _ ->
329-
modify @(MockContractState w) (files . at (Text.unpack filepath) ?~ TextEnvelopeFile dummyTxSignedFile)
329+
modify @(MockContractState w) (files . at (Text.unpack filepath) ?~ TextEnvelopeFile dummyTxRawFile)
330330
_ -> throwError @Text "Out file argument is missing"
331331

332332
pure $ Right $ cmdOutParser ""

0 commit comments

Comments
 (0)