{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.CLI.EraBased.Script.Guard.Read
  ( readConwayRequiredSigners
  , readDijkstraGuards
  , getTxGuardReferenceInputs
  )
where

import Cardano.Api
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.Plutus qualified as P
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.EraBased.Script.Guard.Type
import Cardano.CLI.EraBased.Script.Read.Common (readScriptDataOrFile)
import Cardano.CLI.EraBased.Transaction.Internal.Common (findDuplicates)
import Cardano.CLI.Read
import Cardano.CLI.Type.Common (RequiredSigner)
import Cardano.CLI.Type.Error.TxCmdError
import Cardano.Ledger.Keys (coerceKeyRole)
import Cardano.Ledger.Plutus.Language qualified as L

import Control.Monad (forM, unless)
import Data.Bifunctor (first)
import Data.Maybe (mapMaybe)
import Data.Set qualified as Set
import GHC.Exts (toList)

-- | Conway retains the separate required-signers field in the transaction body.
readConwayRequiredSigners :: [RequiredSigner] -> CIO e [Hash PaymentKey]
readConwayRequiredSigners :: forall e. [RequiredSigner] -> CIO e [Hash PaymentKey]
readConwayRequiredSigners = (RequiredSigner -> RIO e (Hash PaymentKey))
-> [RequiredSigner] -> RIO e [Hash PaymentKey]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (IO (Either RequiredSignerError (Hash PaymentKey))
-> RIO e (Hash PaymentKey)
forall e (m :: * -> *) a.
(HasCallStack, MonadIO m, Show e, Typeable e, Error e) =>
IO (Either e a) -> m a
fromEitherIOCli (IO (Either RequiredSignerError (Hash PaymentKey))
 -> RIO e (Hash PaymentKey))
-> (RequiredSigner
    -> IO (Either RequiredSignerError (Hash PaymentKey)))
-> RequiredSigner
-> RIO e (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner)

-- | Read both key and script guards into the API's unified collection.
-- The required-signer CLI flags supply key guards in Dijkstra. Their signatures
-- are added during signing; Nothing here means no script witness is attached.
readDijkstraGuards
  :: [Guard]
  -> CIO e (Exp.TxGuards (Exp.LedgerEra Exp.DijkstraEra))
readDijkstraGuards :: forall e. [Guard] -> CIO e (TxGuards (LedgerEra DijkstraEra))
readDijkstraGuards [Guard]
guards = do
  entries <- (Guard
 -> RIO
      e (Credential Guard, Maybe (ScriptGuardWitness DijkstraEra)))
-> [Guard]
-> RIO
     e [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Guard
-> RIO e (Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))
Guard
-> CIO
     e
     (Credential Guard,
      Maybe (ScriptGuardWitness (LedgerEra DijkstraEra)))
forall e.
Guard
-> CIO
     e
     (Credential Guard,
      Maybe (ScriptGuardWitness (LedgerEra DijkstraEra)))
readGuard [Guard]
guards
  -- Preserve the existing order: scripts first, then sorted, distinct key guards.
  -- Changing guard positions would change Plutus redeemer indices.
  let scripts = [(Credential Guard
credential, Maybe (ScriptGuardWitness DijkstraEra)
witness) | (credential :: Credential Guard
credential@L.ScriptHashObj{}, Maybe (ScriptGuardWitness DijkstraEra)
witness) <- [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
entries]
      keys = Set (Credential Guard) -> [Credential Guard]
forall a. Set a -> [a]
Set.toAscList (Set (Credential Guard) -> [Credential Guard])
-> Set (Credential Guard) -> [Credential Guard]
forall a b. (a -> b) -> a -> b
$ [Credential Guard] -> Set (Credential Guard)
forall a. Ord a => [a] -> Set a
Set.fromList [Credential Guard
credential | (credential :: Credential Guard
credential@L.KeyHashObj{}, Maybe (ScriptGuardWitness DijkstraEra)
_) <- [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
entries]
      duplicates = [Credential Guard] -> [Credential Guard]
forall a. Ord a => [a] -> [a]
findDuplicates (((Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))
 -> Credential Guard)
-> [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
-> [Credential Guard]
forall a b. (a -> b) -> [a] -> [b]
map (Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))
-> Credential Guard
forall a b. (a, b) -> a
fst [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
scripts)
  unless (null duplicates) $ throwCliError $ TxCmdDuplicateGuards duplicates
  fromEitherCli $ first TxCmdGuardsError $ Exp.mkTxGuards (scripts ++ [(key, Nothing) | key <- keys])

getTxGuardReferenceInputs :: TxGuardRequirements era -> [TxIn]
getTxGuardReferenceInputs :: forall era. TxGuardRequirements era -> [TxIn]
getTxGuardReferenceInputs (ConwayRequiredSigners [Hash PaymentKey]
_) = []
getTxGuardReferenceInputs (DijkstraGuards TxGuards (LedgerEra DijkstraEra)
guards) =
  ((Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))
 -> Maybe TxIn)
-> [(Credential Guard, Maybe (ScriptGuardWitness DijkstraEra))]
-> [TxIn]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\(Credential Guard
_, Maybe (ScriptGuardWitness DijkstraEra)
witness) -> Maybe (ScriptGuardWitness DijkstraEra)
witness Maybe (ScriptGuardWitness DijkstraEra)
-> (ScriptGuardWitness DijkstraEra -> Maybe TxIn) -> Maybe TxIn
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ScriptGuardWitness DijkstraEra -> Maybe TxIn
forall era. ScriptGuardWitness era -> Maybe TxIn
getGuardScriptReferenceInput) (TxGuards DijkstraEra -> [Item (TxGuards DijkstraEra)]
forall l. IsList l => l -> [Item l]
toList TxGuards (LedgerEra DijkstraEra)
TxGuards DijkstraEra
guards)

getGuardScriptReferenceInput :: Exp.ScriptGuardWitness era -> Maybe TxIn
getGuardScriptReferenceInput :: forall era. ScriptGuardWitness era -> Maybe TxIn
getGuardScriptReferenceInput (Exp.NativeGuardWitness (Exp.SReferenceScript TxIn
input)) = TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
input
getGuardScriptReferenceInput (Exp.NativeGuardWitness (Exp.SScript SimpleScript era
_)) = Maybe TxIn
forall a. Maybe a
Nothing
getGuardScriptReferenceInput (Exp.PlutusGuardWitness (P.PlutusScriptWitness SLanguage 'PlutusV4
_ PlutusScriptOrReferenceInput 'PlutusV4 era
source PlutusScriptDatum 'PlutusV4 'GuardingScript
_ ScriptRedeemer
_ ExecutionUnits
_)) =
  case PlutusScriptOrReferenceInput 'PlutusV4 era
source of
    P.PReferenceScript TxIn
input -> TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
input
    P.PScript PlutusScriptInEra 'PlutusV4 era
_ -> Maybe TxIn
forall a. Maybe a
Nothing

readGuard
  :: Guard
  -> CIO e (L.Credential L.Guard, Maybe (Exp.ScriptGuardWitness (Exp.LedgerEra Exp.DijkstraEra)))
readGuard :: forall e.
Guard
-> CIO
     e
     (Credential Guard,
      Maybe (ScriptGuardWitness (LedgerEra DijkstraEra)))
readGuard (KeyGuard RequiredSigner
signer) = do
  PaymentKeyHash key <- IO (Either RequiredSignerError (Hash PaymentKey))
-> RIO e (Hash PaymentKey)
forall e (m :: * -> *) a.
(HasCallStack, MonadIO m, Show e, Typeable e, Error e) =>
IO (Either e a) -> m a
fromEitherIOCli (IO (Either RequiredSignerError (Hash PaymentKey))
 -> RIO e (Hash PaymentKey))
-> IO (Either RequiredSignerError (Hash PaymentKey))
-> RIO e (Hash PaymentKey)
forall a b. (a -> b) -> a -> b
$ RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner RequiredSigner
signer
  pure (L.KeyHashObj (coerceKeyRole key), Nothing)
readGuard (ScriptGuard GuardScriptSource
source Maybe (ScriptDataOrFile, ExecutionUnits)
mRedeemer) = do
  (credential, witness) <- RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
readScriptGuard
  pure (credential, Just witness)
 where
  readScriptGuard :: RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
readScriptGuard = do
    redeemer <- Maybe (ScriptDataOrFile, ExecutionUnits)
-> ((ScriptDataOrFile, ExecutionUnits)
    -> RIO e (ScriptRedeemer, ExecutionUnits))
-> RIO e (Maybe (ScriptRedeemer, ExecutionUnits))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Maybe (ScriptDataOrFile, ExecutionUnits)
mRedeemer (((ScriptDataOrFile, ExecutionUnits)
  -> RIO e (ScriptRedeemer, ExecutionUnits))
 -> RIO e (Maybe (ScriptRedeemer, ExecutionUnits)))
-> ((ScriptDataOrFile, ExecutionUnits)
    -> RIO e (ScriptRedeemer, ExecutionUnits))
-> RIO e (Maybe (ScriptRedeemer, ExecutionUnits))
forall a b. (a -> b) -> a -> b
$ \(ScriptDataOrFile
datum, ExecutionUnits
units) -> do
      value <- ExceptT ScriptDataError IO ScriptRedeemer -> RIO e ScriptRedeemer
forall e (m :: * -> *) a.
(HasCallStack, MonadIO m, Show e, Typeable e, Error e) =>
ExceptT e IO a -> m a
fromExceptTCli (ExceptT ScriptDataError IO ScriptRedeemer -> RIO e ScriptRedeemer)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> RIO e ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataOrFile -> ExceptT ScriptDataError IO ScriptRedeemer
forall (m :: * -> *).
MonadIO m =>
ScriptDataOrFile -> ExceptT ScriptDataError m ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
datum
      pure (value, units)
    case source of
      GuardScriptOnDisk (File FilePath
path) -> do
        script <- forall (m :: * -> *) era.
(MonadIO m, IsEra era) =>
FilePath -> m (AnyScript (LedgerEra era))
readAnyScript @_ @Exp.DijkstraEra FilePath
path
        case script of
          Exp.AnySimpleScript SimpleScript DijkstraEra
native -> do
            let credential :: Credential Guard
credential = ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
L.ScriptHashObj (SimpleScript (LedgerEra DijkstraEra) -> ScriptHash
forall era. IsEra era => SimpleScript (LedgerEra era) -> ScriptHash
Exp.hashSimpleScript SimpleScript (LedgerEra DijkstraEra)
SimpleScript DijkstraEra
native)
            RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> ((ScriptRedeemer, ExecutionUnits)
    -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> Maybe (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
              ((Credential Guard, ScriptGuardWitness DijkstraEra)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a. a -> RIO e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Credential Guard
credential, SimpleScriptOrReferenceInput DijkstraEra
-> ScriptGuardWitness DijkstraEra
forall era.
SimpleScriptOrReferenceInput era -> ScriptGuardWitness era
Exp.NativeGuardWitness (SimpleScript DijkstraEra
-> SimpleScriptOrReferenceInput DijkstraEra
forall era. SimpleScript era -> SimpleScriptOrReferenceInput era
Exp.SScript SimpleScript DijkstraEra
native)))
              (RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. a -> b -> a
const (RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
 -> (ScriptRedeemer, ExecutionUnits)
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ Credential Guard -> TxCmdError
TxCmdNativeGuardWithRedeemer Credential Guard
credential)
              Maybe (ScriptRedeemer, ExecutionUnits)
redeemer
          Exp.AnyPlutusScript PlutusScriptInEra lang DijkstraEra
scriptInEra ->
            case PlutusScriptInEra lang DijkstraEra -> SLanguage lang
forall (lang :: Language) era.
PlutusLanguage lang =>
PlutusScriptInEra lang era -> SLanguage lang
P.plutusScriptInEraSLanguage PlutusScriptInEra lang DijkstraEra
scriptInEra of
              SLanguage lang
L.SPlutusV1 -> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ FilePath -> Language -> TxCmdError
TxCmdTopLevelGuardUnsupportedPlutusLanguage FilePath
path Language
L.PlutusV1
              SLanguage lang
L.SPlutusV2 -> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ FilePath -> Language -> TxCmdError
TxCmdTopLevelGuardUnsupportedPlutusLanguage FilePath
path Language
L.PlutusV2
              SLanguage lang
L.SPlutusV3 -> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ FilePath -> Language -> TxCmdError
TxCmdTopLevelGuardUnsupportedPlutusLanguage FilePath
path Language
L.PlutusV3
              SLanguage lang
L.SPlutusV4 -> do
                let credential :: Credential Guard
credential = ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
L.ScriptHashObj (PlutusScriptInEra lang (LedgerEra DijkstraEra) -> ScriptHash
forall era (lang :: Language).
IsEra era =>
PlutusScriptInEra lang (LedgerEra era) -> ScriptHash
P.hashPlutusScriptInEra PlutusScriptInEra lang (LedgerEra DijkstraEra)
PlutusScriptInEra lang DijkstraEra
scriptInEra)
                RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> ((ScriptRedeemer, ExecutionUnits)
    -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> Maybe (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                  (TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ Credential Guard -> TxCmdError
TxCmdPlutusGuardMissingRedeemer Credential Guard
credential)
                  (\(ScriptRedeemer
datum, ExecutionUnits
units) -> (Credential Guard, ScriptGuardWitness DijkstraEra)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a. a -> RIO e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Credential Guard
credential, PlutusScriptOrReferenceInput 'PlutusV4 DijkstraEra
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptGuardWitness DijkstraEra
forall era.
PlutusScriptOrReferenceInput 'PlutusV4 era
-> ScriptRedeemer -> ExecutionUnits -> ScriptGuardWitness era
plutusWitness (PlutusScriptInEra 'PlutusV4 DijkstraEra
-> PlutusScriptOrReferenceInput 'PlutusV4 DijkstraEra
forall (lang :: Language) era.
PlutusScriptInEra lang era -> PlutusScriptOrReferenceInput lang era
P.PScript PlutusScriptInEra lang DijkstraEra
PlutusScriptInEra 'PlutusV4 DijkstraEra
scriptInEra) ScriptRedeemer
datum ExecutionUnits
units))
                  Maybe (ScriptRedeemer, ExecutionUnits)
redeemer
      NativeGuardScriptReference TxIn
input (ScriptHash ScriptHash
scriptHash) -> do
        let credential :: Credential Guard
credential = ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
L.ScriptHashObj ScriptHash
scriptHash
        RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> ((ScriptRedeemer, ExecutionUnits)
    -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> Maybe (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
          ((Credential Guard, ScriptGuardWitness DijkstraEra)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a. a -> RIO e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Credential Guard
credential, SimpleScriptOrReferenceInput DijkstraEra
-> ScriptGuardWitness DijkstraEra
forall era.
SimpleScriptOrReferenceInput era -> ScriptGuardWitness era
Exp.NativeGuardWitness (TxIn -> SimpleScriptOrReferenceInput DijkstraEra
forall era. TxIn -> SimpleScriptOrReferenceInput era
Exp.SReferenceScript TxIn
input)))
          (RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. a -> b -> a
const (RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
 -> (ScriptRedeemer, ExecutionUnits)
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ Credential Guard -> TxCmdError
TxCmdNativeGuardWithRedeemer Credential Guard
credential)
          Maybe (ScriptRedeemer, ExecutionUnits)
redeemer
      PlutusGuardScriptReference TxIn
input (ScriptHash ScriptHash
scriptHash) -> do
        let credential :: Credential Guard
credential = ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
L.ScriptHashObj ScriptHash
scriptHash
        RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
-> ((ScriptRedeemer, ExecutionUnits)
    -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> Maybe (ScriptRedeemer, ExecutionUnits)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
          (TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall e (m :: * -> *) a.
(HasCallStack, Show e, Typeable e, Error e, MonadIO m) =>
e -> m a
throwCliError (TxCmdError
 -> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra))
-> TxCmdError
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a b. (a -> b) -> a -> b
$ Credential Guard -> TxCmdError
TxCmdPlutusGuardMissingRedeemer Credential Guard
credential)
          (\(ScriptRedeemer
datum, ExecutionUnits
units) -> (Credential Guard, ScriptGuardWitness DijkstraEra)
-> RIO e (Credential Guard, ScriptGuardWitness DijkstraEra)
forall a. a -> RIO e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Credential Guard
credential, PlutusScriptOrReferenceInput 'PlutusV4 DijkstraEra
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptGuardWitness DijkstraEra
forall era.
PlutusScriptOrReferenceInput 'PlutusV4 era
-> ScriptRedeemer -> ExecutionUnits -> ScriptGuardWitness era
plutusWitness (TxIn -> PlutusScriptOrReferenceInput 'PlutusV4 DijkstraEra
forall (lang :: Language) era.
TxIn -> PlutusScriptOrReferenceInput lang era
P.PReferenceScript TxIn
input) ScriptRedeemer
datum ExecutionUnits
units))
          Maybe (ScriptRedeemer, ExecutionUnits)
redeemer
  plutusWitness
    :: P.PlutusScriptOrReferenceInput L.PlutusV4 era
    -> HashableScriptData
    -> ExecutionUnits
    -> Exp.ScriptGuardWitness era
  plutusWitness :: forall era.
PlutusScriptOrReferenceInput 'PlutusV4 era
-> ScriptRedeemer -> ExecutionUnits -> ScriptGuardWitness era
plutusWitness PlutusScriptOrReferenceInput 'PlutusV4 era
scriptSource ScriptRedeemer
datum ExecutionUnits
units =
    PlutusScriptWitness 'PlutusV4 'GuardingScript era
-> ScriptGuardWitness era
forall era.
PlutusScriptWitness 'PlutusV4 'GuardingScript era
-> ScriptGuardWitness era
Exp.PlutusGuardWitness (PlutusScriptWitness 'PlutusV4 'GuardingScript era
 -> ScriptGuardWitness era)
-> PlutusScriptWitness 'PlutusV4 'GuardingScript era
-> ScriptGuardWitness era
forall a b. (a -> b) -> a -> b
$
      SLanguage 'PlutusV4
-> PlutusScriptOrReferenceInput 'PlutusV4 era
-> PlutusScriptDatum 'PlutusV4 'GuardingScript
-> ScriptRedeemer
-> ExecutionUnits
-> PlutusScriptWitness 'PlutusV4 'GuardingScript era
forall (lang :: Language) era (purpose :: PlutusScriptPurpose).
SLanguage lang
-> PlutusScriptOrReferenceInput lang era
-> PlutusScriptDatum lang purpose
-> ScriptRedeemer
-> ExecutionUnits
-> PlutusScriptWitness lang purpose era
P.PlutusScriptWitness SLanguage 'PlutusV4
L.SPlutusV4 PlutusScriptOrReferenceInput 'PlutusV4 era
scriptSource PlutusScriptDatum 'PlutusV4 'GuardingScript
forall (lang :: Language) (purpose :: PlutusScriptPurpose).
PlutusScriptDatum lang purpose
P.NoScriptDatum ScriptRedeemer
datum ExecutionUnits
units