Skip to content

Commit 259d2ce

Browse files
committed
Address review: update haddock example, use failEither and liftMaybe
1 parent 8f19613 commit 259d2ce

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
@@ -107,6 +107,7 @@ import Cardano.Api.Governance.Internal.Action.VotingProcedure
107107
import Cardano.Api.Key.Internal
108108
import Cardano.Api.Ledger.Internal.Reexport (StrictMaybe (..))
109109
import Cardano.Api.Ledger.Internal.Reexport qualified as L
110+
import Cardano.Api.Monad.Error (liftMaybe)
110111
import Cardano.Api.Plutus.Internal.Script
111112
( PlutusScript (..)
112113
, PlutusScriptVersion (..)
@@ -313,7 +314,7 @@ convPParamsToScriptIntegrityHash mTxProtocolParams redeemers datums languages =
313314
&& null languages
314315
if shouldCalculateHash
315316
then do
316-
pp <- maybe (Left MakeUnsignedTxMissingProtocolParams) Right mTxProtocolParams
317+
pp <- liftMaybe MakeUnsignedTxMissingProtocolParams mTxProtocolParams
317318
pure $
318319
SJust $
319320
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)