Skip to content

Commit d67c28f

Browse files
committed
Address review: update haddock example, use failEither and liftMaybe
1 parent fee5f11 commit d67c28f

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

  • cardano-api
    • src/Cardano/Api/Experimental
    • test/cardano-api-test/Test/Cardano/Api/Experimental

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ module Cardano.Api.Experimental.Tx
7878
-- 'TxBodyContent' that we defined earlier:
7979
--
8080
-- @
81-
-- let (Right unsignedTx) = Exp.makeUnsignedTx era txBodyContent
81+
-- case Exp.makeUnsignedTx era txBodyContent of
82+
-- Left err -> error (show err)
83+
-- Right unsignedTx -> ...
8284
-- @
8385
--
8486
-- Next, use the key witness to sign the unsigned transaction with the 'makeKeyWitness' function:

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import Cardano.Api.Governance.Internal.Action.VotingProcedure
105105
import Cardano.Api.Key.Internal
106106
import Cardano.Api.Ledger.Internal.Reexport (StrictMaybe (..))
107107
import Cardano.Api.Ledger.Internal.Reexport qualified as L
108+
import Cardano.Api.Monad.Error (liftMaybe)
108109
import Cardano.Api.Plutus.Internal.ScriptData qualified as Api
109110
import Cardano.Api.Pretty
110111
import Cardano.Api.Tx.Internal.Body
@@ -288,7 +289,7 @@ convPParamsToScriptIntegrityHash mTxProtocolParams redeemers datums languages =
288289
&& null languages
289290
if shouldCalculateHash
290291
then do
291-
pp <- maybe (Left MakeUnsignedTxMissingProtocolParams) Right mTxProtocolParams
292+
pp <- liftMaybe MakeUnsignedTxMissingProtocolParams mTxProtocolParams
292293
pure $
293294
SJust $
294295
L.hashScriptIntegrity $

cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import Cardano.Api.Experimental qualified as Exp
1515
import Cardano.Api.Experimental.Era (convert)
1616
import Cardano.Api.Experimental.Tx qualified as Exp
1717
import Cardano.Api.Ledger qualified as L
18+
import Cardano.Api.Monad.Error (failEither)
1819

1920
import Cardano.Ledger.Api qualified as UnexportedLedger
2021
import Cardano.Ledger.Core qualified as L
2122
import Cardano.Ledger.Mary.Value qualified as Mary
2223
import Cardano.Ledger.Tools qualified as L (calcMinFeeTx)
2324

25+
import Data.Bifunctor (first)
2426
import Data.Foldable (toList)
2527
import Data.Map.Strict qualified as Map
2628
import Data.Sequence.Strict qualified as Seq
@@ -387,9 +389,8 @@ genTinySurplusTx era = Exp.obtainCommonConstraints era $ do
387389
& Exp.setTxIns [(txIn, Exp.AnyKeyWitnessPlaceholder)]
388390
& Exp.setTxOuts [sendTxOut]
389391
& Exp.setTxFee 0
390-
unsignedTx <- case Exp.makeUnsignedTx era txBodyContent of
391-
Left err -> fail $ "makeUnsignedTx: " <> show err
392-
Right tx -> return tx
392+
unsignedTx <-
393+
failEither . first (("makeUnsignedTx: " <>) . show) $ Exp.makeUnsignedTx era txBodyContent
393394
let
394395
-- Compute F1 via case match on UnsignedTx (needed to bring EraTx into scope)
395396
L.Coin f1 = case unsignedTx of

0 commit comments

Comments
 (0)