{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{- HLINT ignore "Unused LANGUAGE pragma" -}
{- HLINT ignore "Avoid lambda using `infix`" -}

module Cardano.CLI.EraBased.Run.Transaction
  ( mkShelleyBootstrapWitnesses
  , partitionSomeWitnesses
  , runTransactionCmds
  , runTransactionBuildCmd
  , runTransactionBuildRawCmd
  , runTransactionSignCmd
  , runTransactionSubmitCmd
  , runTransactionCalculateMinFeeCmd
  , runTransactionCalculateMinValueCmd
  , runTransactionPolicyIdCmd
  , runTransactionHashScriptDataCmd
  , runTransactionTxIdCmd
  , runTransactionWitnessCmd
  , runTransactionSignWitnessCmd
  , toTxOutByronEra
  , toTxOutInAnyEra
  )
where

import           Cardano.Api
import qualified Cardano.Api.Byron as Byron
import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Network as Consensus
import qualified Cardano.Api.Network as Net.Tx
import           Cardano.Api.Shelley

import qualified Cardano.Binary as CBOR
import           Cardano.CLI.EraBased.Commands.Transaction
                   (TransactionCalculateMinFeeCmdArgs (txBodyFile))
import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd
import           Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters)
import           Cardano.CLI.EraBased.Run.Query
import           Cardano.CLI.EraBased.Script.Mint.Read
import           Cardano.CLI.EraBased.Script.Mint.Types
import           Cardano.CLI.EraBased.Transaction.HashCheck (checkCertificateHashes,
                   checkProposalHashes, checkVotingProcedureHashes)
import           Cardano.CLI.Orphans ()
import           Cardano.CLI.Read
import           Cardano.CLI.Types.Common
import           Cardano.CLI.Types.Errors.BootstrapWitnessError
import           Cardano.CLI.Types.Errors.NodeEraMismatchError
import           Cardano.CLI.Types.Errors.TxCmdError
import           Cardano.CLI.Types.Errors.TxValidationError
import           Cardano.CLI.Types.Output (renderScriptCosts)
import           Cardano.CLI.Types.TxFeature

import           Control.Monad (forM, unless)
import           Data.Aeson ((.=))
import qualified Data.Aeson as Aeson
import           Data.Aeson.Encode.Pretty (encodePretty)
import           Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString as Data.Bytestring
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as LBS
import           Data.Containers.ListUtils (nubOrd)
import           Data.Data ((:~:) (..))
import           Data.Foldable (forM_)
import qualified Data.Foldable as Foldable
import           Data.Function ((&))
import qualified Data.List as List
import           Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import           Data.Maybe (catMaybes, fromMaybe, mapMaybe, maybeToList)
import           Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import           Data.Type.Equality (TestEquality (..))
import           GHC.Exts (IsList (..))
import           Lens.Micro ((^.))
import qualified System.IO as IO

runTransactionCmds :: Cmd.TransactionCmds era -> ExceptT TxCmdError IO ()
runTransactionCmds :: forall era. TransactionCmds era -> ExceptT TxCmdError IO ()
runTransactionCmds = \case
  Cmd.TransactionBuildCmd TransactionBuildCmdArgs era
args -> TransactionBuildCmdArgs era -> ExceptT TxCmdError IO ()
forall era. TransactionBuildCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildCmd TransactionBuildCmdArgs era
args
  Cmd.TransactionBuildEstimateCmd TransactionBuildEstimateCmdArgs era
args -> TransactionBuildEstimateCmdArgs era -> ExceptT TxCmdError IO ()
forall era.
TransactionBuildEstimateCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildEstimateCmd TransactionBuildEstimateCmdArgs era
args
  Cmd.TransactionBuildRawCmd TransactionBuildRawCmdArgs era
args -> TransactionBuildRawCmdArgs era -> ExceptT TxCmdError IO ()
forall era.
TransactionBuildRawCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildRawCmd TransactionBuildRawCmdArgs era
args
  Cmd.TransactionSignCmd TransactionSignCmdArgs
args -> TransactionSignCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSignCmd TransactionSignCmdArgs
args
  Cmd.TransactionSubmitCmd TransactionSubmitCmdArgs
args -> TransactionSubmitCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSubmitCmd TransactionSubmitCmdArgs
args
  Cmd.TransactionCalculateMinFeeCmd TransactionCalculateMinFeeCmdArgs
args -> TransactionCalculateMinFeeCmdArgs -> ExceptT TxCmdError IO ()
runTransactionCalculateMinFeeCmd TransactionCalculateMinFeeCmdArgs
args
  Cmd.TransactionCalculateMinValueCmd TransactionCalculateMinValueCmdArgs era
args -> TransactionCalculateMinValueCmdArgs era -> ExceptT TxCmdError IO ()
forall era.
TransactionCalculateMinValueCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionCalculateMinValueCmd TransactionCalculateMinValueCmdArgs era
args
  Cmd.TransactionHashScriptDataCmd TransactionHashScriptDataCmdArgs
args -> TransactionHashScriptDataCmdArgs -> ExceptT TxCmdError IO ()
runTransactionHashScriptDataCmd TransactionHashScriptDataCmdArgs
args
  Cmd.TransactionTxIdCmd TransactionTxIdCmdArgs
args -> TransactionTxIdCmdArgs -> ExceptT TxCmdError IO ()
runTransactionTxIdCmd TransactionTxIdCmdArgs
args
  Cmd.TransactionPolicyIdCmd TransactionPolicyIdCmdArgs
args -> TransactionPolicyIdCmdArgs -> ExceptT TxCmdError IO ()
runTransactionPolicyIdCmd TransactionPolicyIdCmdArgs
args
  Cmd.TransactionWitnessCmd TransactionWitnessCmdArgs
args -> TransactionWitnessCmdArgs -> ExceptT TxCmdError IO ()
runTransactionWitnessCmd TransactionWitnessCmdArgs
args
  Cmd.TransactionSignWitnessCmd TransactionSignWitnessCmdArgs
args -> TransactionSignWitnessCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSignWitnessCmd TransactionSignWitnessCmdArgs
args

-- ----------------------------------------------------------------------------
-- Building transactions
--

runTransactionBuildCmd
  :: Cmd.TransactionBuildCmdArgs era
  -> ExceptT TxCmdError IO ()
runTransactionBuildCmd :: forall era. TransactionBuildCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildCmd
  Cmd.TransactionBuildCmdArgs
    { Era era
currentEra :: Era era
currentEra :: forall era. TransactionBuildCmdArgs era -> Era era
currentEra
    , SocketPath
nodeSocketPath :: SocketPath
nodeSocketPath :: forall era. TransactionBuildCmdArgs era -> SocketPath
nodeSocketPath
    , ConsensusModeParams
consensusModeParams :: ConsensusModeParams
consensusModeParams :: forall era. TransactionBuildCmdArgs era -> ConsensusModeParams
consensusModeParams
    , networkId :: forall era. TransactionBuildCmdArgs era -> NetworkId
networkId = NetworkId
networkId
    , mScriptValidity :: forall era. TransactionBuildCmdArgs era -> Maybe ScriptValidity
mScriptValidity = Maybe ScriptValidity
mScriptValidity
    , mOverrideWitnesses :: forall era. TransactionBuildCmdArgs era -> Maybe Word
mOverrideWitnesses = Maybe Word
mOverrideWitnesses
    , [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins :: [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins :: forall era.
TransactionBuildCmdArgs era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins
    , [TxIn]
readOnlyReferenceInputs :: [TxIn]
readOnlyReferenceInputs :: forall era. TransactionBuildCmdArgs era -> [TxIn]
readOnlyReferenceInputs
    , requiredSigners :: forall era. TransactionBuildCmdArgs era -> [RequiredSigner]
requiredSigners = [RequiredSigner]
reqSigners
    , [TxIn]
txinsc :: [TxIn]
txinsc :: forall era. TransactionBuildCmdArgs era -> [TxIn]
txinsc
    , mReturnCollateral :: forall era.
TransactionBuildCmdArgs era -> Maybe TxOutShelleyBasedEra
mReturnCollateral = Maybe TxOutShelleyBasedEra
mReturnColl
    , Maybe Lovelace
mTotalCollateral :: Maybe Lovelace
mTotalCollateral :: forall era. TransactionBuildCmdArgs era -> Maybe Lovelace
mTotalCollateral
    , [TxOutAnyEra]
txouts :: [TxOutAnyEra]
txouts :: forall era. TransactionBuildCmdArgs era -> [TxOutAnyEra]
txouts
    , TxOutChangeAddress
changeAddresses :: TxOutChangeAddress
changeAddresses :: forall era. TransactionBuildCmdArgs era -> TxOutChangeAddress
changeAddresses
    , Maybe (Value, [CliMintScriptRequirements])
mValue :: Maybe (Value, [CliMintScriptRequirements])
mValue :: forall era.
TransactionBuildCmdArgs era
-> Maybe (Value, [CliMintScriptRequirements])
mValue
    , Maybe SlotNo
mValidityLowerBound :: Maybe SlotNo
mValidityLowerBound :: forall era. TransactionBuildCmdArgs era -> Maybe SlotNo
mValidityLowerBound
    , TxValidityUpperBound era
mValidityUpperBound :: TxValidityUpperBound era
mValidityUpperBound :: forall era. TransactionBuildCmdArgs era -> TxValidityUpperBound era
mValidityUpperBound
    , [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: forall era.
TransactionBuildCmdArgs era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates
    , [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: forall era.
TransactionBuildCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    , TxMetadataJsonSchema
metadataSchema :: TxMetadataJsonSchema
metadataSchema :: forall era. TransactionBuildCmdArgs era -> TxMetadataJsonSchema
metadataSchema
    , [ScriptFile]
scriptFiles :: [ScriptFile]
scriptFiles :: forall era. TransactionBuildCmdArgs era -> [ScriptFile]
scriptFiles
    , [MetadataFile]
metadataFiles :: [MetadataFile]
metadataFiles :: forall era. TransactionBuildCmdArgs era -> [MetadataFile]
metadataFiles
    , Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile :: Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile :: forall era.
TransactionBuildCmdArgs era
-> Maybe
     (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile
    , [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: forall era.
TransactionBuildCmdArgs era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles
    , [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: forall era.
TransactionBuildCmdArgs era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles
    , Maybe TxTreasuryDonation
treasuryDonation :: Maybe TxTreasuryDonation
treasuryDonation :: forall era. TransactionBuildCmdArgs era -> Maybe TxTreasuryDonation
treasuryDonation -- Maybe TxTreasuryDonation
    , TxBuildOutputOptions
buildOutputOptions :: TxBuildOutputOptions
buildOutputOptions :: forall era. TransactionBuildCmdArgs era -> TxBuildOutputOptions
buildOutputOptions
    } = do
    let eon :: ShelleyBasedEra era
eon = Era era -> ShelleyBasedEra era
forall era. Era era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert Era era
currentEra
        era' :: CardanoEra era
era' = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
eon

    -- The user can specify an era prior to the era that the node is currently in.
    -- We cannot use the user specified era to construct a query against a node because it may differ
    -- from the node's era and this will result in the 'QueryEraMismatch' failure.

    let localNodeConnInfo :: LocalNodeConnectInfo
localNodeConnInfo =
          LocalNodeConnectInfo
            { localConsensusModeParams :: ConsensusModeParams
localConsensusModeParams = ConsensusModeParams
consensusModeParams
            , localNodeNetworkId :: NetworkId
localNodeNetworkId = NetworkId
networkId
            , localNodeSocketPath :: SocketPath
localNodeSocketPath = SocketPath
nodeSocketPath
            }

    [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits <- (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
 -> ExceptT
      TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
eon [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins
    [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
eon [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates

    -- TODO: Conway Era - How can we make this more composable?
    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits <-
      [ExceptT
   TxCmdError
   IO
   (Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence
        [ (Certificate era
 -> (Certificate era, Maybe (ScriptWitness WitCtxStake era)))
-> ExceptT TxCmdError IO (Certificate era)
-> ExceptT
     TxCmdError
     IO
     (Certificate era, Maybe (ScriptWitness WitCtxStake era))
forall a b.
(a -> b) -> ExceptT TxCmdError IO a -> ExceptT TxCmdError IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
            (,Maybe (ScriptWitness WitCtxStake era)
mSwit)
            ( (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
-> ExceptT TxCmdError IO (Certificate era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO (Certificate era)
 -> ExceptT TxCmdError IO (Certificate era))
-> (IO (Either (FileError TextEnvelopeError) (Certificate era))
    -> ExceptT (FileError TextEnvelopeError) IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (Certificate era))
 -> ExceptT TxCmdError IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall a b. (a -> b) -> a -> b
$
                ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    IO (Either (FileError TextEnvelopeError) (Certificate era)))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
eon ((ShelleyBasedEraConstraints era =>
  IO (Either (FileError TextEnvelopeError) (Certificate era)))
 -> IO (Either (FileError TextEnvelopeError) (Certificate era)))
-> (ShelleyBasedEraConstraints era =>
    IO (Either (FileError TextEnvelopeError) (Certificate era)))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
forall a b. (a -> b) -> a -> b
$
                  AsType (Certificate era)
-> File Any 'In
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
forall a content.
HasTextEnvelope a =>
AsType a
-> File content 'In -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType (Certificate era)
forall era. AsType (Certificate era)
AsCertificate (FilePath -> File Any 'In
forall content (direction :: FileDirection).
FilePath -> File content direction
File FilePath
certFile)
            )
        | (CertificateFile FilePath
certFile, Maybe (ScriptWitness WitCtxStake era)
mSwit) <- [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits
        ]

    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits (Certificate era -> ExceptT TxCmdError IO ()
forall era. Certificate era -> ExceptT TxCmdError IO ()
checkCertificateHashes (Certificate era -> ExceptT TxCmdError IO ())
-> ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
    -> Certificate era)
-> (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Certificate era
forall a b. (a, b) -> a
fst)

    [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall era a b ctx.
ShelleyBasedEra era
-> [(a, b, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, b, Maybe (ScriptWitness ctx era))]
readScriptWitnessFilesTuple ShelleyBasedEra era
eon [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    TxMetadataInEra era
txMetadata <-
      (MetadataError -> TxCmdError)
-> ExceptT MetadataError IO (TxMetadataInEra era)
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT MetadataError -> TxCmdError
TxCmdMetadataError (ExceptT MetadataError IO (TxMetadataInEra era)
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> (IO (Either MetadataError (TxMetadataInEra era))
    -> ExceptT MetadataError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT MetadataError IO (TxMetadataInEra era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either MetadataError (TxMetadataInEra era))
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
readTxMetadata ShelleyBasedEra era
eon TxMetadataJsonSchema
metadataSchema [MetadataFile]
metadataFiles
    let (Value
mas, [CliMintScriptRequirements]
sWitFiles) = (Value, [CliMintScriptRequirements])
-> Maybe (Value, [CliMintScriptRequirements])
-> (Value, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (Value
forall a. Monoid a => a
mempty, [CliMintScriptRequirements]
forall a. Monoid a => a
mempty) Maybe (Value, [CliMintScriptRequirements])
mValue
    (Value, [MintScriptWitnessWithPolicyId era])
usedToGetReferenceInputs <-
      (Value
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (Value, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (Value, [MintScriptWitnessWithPolicyId era])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError ((CliMintScriptRequirements
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (MintScriptWitnessWithPolicyId era))
-> [CliMintScriptRequirements]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
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 (ShelleyBasedEra era
-> CliMintScriptRequirements
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (MintScriptWitnessWithPolicyId era)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> CliMintScriptRequirements
-> t m (MintScriptWitnessWithPolicyId era)
readMintScriptWitness ShelleyBasedEra era
eon) [CliMintScriptRequirements]
sWitFiles)
    [ScriptInAnyLang]
scripts <-
      (FileError ScriptDecodeError -> TxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> TxCmdError
TxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
 -> ExceptT TxCmdError IO [ScriptInAnyLang])
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall a b. (a -> b) -> a -> b
$
        (ScriptFile
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> [ScriptFile]
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
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 (FilePath
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
MonadIOTransError (FileError ScriptDecodeError) t m =>
FilePath -> t m ScriptInAnyLang
readFileScriptInAnyLang (FilePath
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> (ScriptFile -> FilePath)
-> ScriptFile
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptFile -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile) [ScriptFile]
scriptFiles
    TxAuxScripts era
txAuxScripts <-
      Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxAuxScripts era)
 -> ExceptT TxCmdError IO (TxAuxScripts era))
-> Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ (TxAuxScriptsValidationError -> TxCmdError)
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxAuxScriptsValidationError -> TxCmdError
TxCmdAuxScriptsValidationError (Either TxAuxScriptsValidationError (TxAuxScripts era)
 -> Either TxCmdError (TxAuxScripts era))
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
forall era.
ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
validateTxAuxScripts ShelleyBasedEra era
eon [ScriptInAnyLang]
scripts

    TxUpdateProposal era
mProp <- case Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile of
      Just (Featured ShelleyToBabbageEra era
w (Just UpdateProposalFile
updateProposalFile)) ->
        ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
forall era.
ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
readTxUpdateProposal ShelleyToBabbageEra era
w UpdateProposalFile
updateProposalFile ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> (ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
    -> ExceptT TxCmdError IO (TxUpdateProposal era))
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError
      Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
_ -> TxUpdateProposal era
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone

    [Hash PaymentKey]
requiredSigners <-
      (RequiredSigner -> ExceptT TxCmdError IO (Hash PaymentKey))
-> [RequiredSigner] -> ExceptT TxCmdError IO [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 ((RequiredSignerError -> TxCmdError)
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT RequiredSignerError -> TxCmdError
TxCmdRequiredSignerError (ExceptT RequiredSignerError IO (Hash PaymentKey)
 -> ExceptT TxCmdError IO (Hash PaymentKey))
-> (RequiredSigner
    -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> RequiredSigner
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either RequiredSignerError (Hash PaymentKey))
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either RequiredSignerError (Hash PaymentKey))
 -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> (RequiredSigner
    -> IO (Either RequiredSignerError (Hash PaymentKey)))
-> RequiredSigner
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner) [RequiredSigner]
reqSigners
    Maybe (TxOut CtxTx era)
mReturnCollateral <- Maybe TxOutShelleyBasedEra
-> (TxOutShelleyBasedEra
    -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> ExceptT TxCmdError IO (Maybe (TxOut CtxTx era))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Maybe TxOutShelleyBasedEra
mReturnColl ((TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
 -> ExceptT TxCmdError IO (Maybe (TxOut CtxTx era)))
-> (TxOutShelleyBasedEra
    -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> ExceptT TxCmdError IO (Maybe (TxOut CtxTx era))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra ShelleyBasedEra era
eon

    [TxOut CtxTx era]
txOuts <- (TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> [TxOutAnyEra] -> ExceptT TxCmdError IO [TxOut CtxTx era]
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 (ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra ShelleyBasedEra era
eon) [TxOutAnyEra]
txouts

    -- Conway related
    [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> CardanoEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a era.
a -> (ConwayEraOnwards era -> a) -> CardanoEra era -> a
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> CardanoEra era -> a
inEonForEra
        ([(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. Monoid a => a
mempty)
        (\ConwayEraOnwards era
w -> (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT VoteError -> TxCmdError
TxCmdVoteError (ExceptT
   VoteError
   IO
   [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$ IO
  (Either
     VoteError
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles))
        CardanoEra era
era'

    [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ((VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits (ShelleyBasedEra era
-> VotingProcedures era -> ExceptT TxCmdError IO ()
forall era.
ShelleyBasedEra era
-> VotingProcedures era -> ExceptT TxCmdError IO ()
checkVotingProcedureHashes ShelleyBasedEra era
eon (VotingProcedures era -> ExceptT TxCmdError IO ())
-> ((VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
    -> VotingProcedures era)
-> (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
-> VotingProcedures era
forall a b. (a, b) -> a
fst)

    [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals <-
      IO
  (Either
     TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO
   (Either
      TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
 -> ExceptT
      TxCmdError
      IO
      [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        (ProposalError -> TxCmdError)
-> Either
     ProposalError
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Either
     TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ProposalError -> TxCmdError
TxCmdProposalError
          (Either
   ProposalError
   [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
 -> Either
      TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        TxCmdError [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
readTxGovernanceActions ShelleyBasedEra era
eon [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles

    [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> ((Proposal era, Maybe (ScriptWitness WitCtxStake era))
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals (ShelleyBasedEra era -> Proposal era -> ExceptT TxCmdError IO ()
forall era.
ShelleyBasedEra era -> Proposal era -> ExceptT TxCmdError IO ()
checkProposalHashes ShelleyBasedEra era
eon (Proposal era -> ExceptT TxCmdError IO ())
-> ((Proposal era, Maybe (ScriptWitness WitCtxStake era))
    -> Proposal era)
-> (Proposal era, Maybe (ScriptWitness WitCtxStake era))
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Proposal era, Maybe (ScriptWitness WitCtxStake era))
-> Proposal era
forall a b. (a, b) -> a
fst)

    -- Extract return addresses from proposals and check that the return address in each proposal is registered

    let returnAddrHashes :: Set StakeCredential
returnAddrHashes =
          [Item (Set StakeCredential)] -> Set StakeCredential
forall l. IsList l => [Item l] -> l
fromList
            [ Item (Set StakeCredential)
StakeCredential
stakeCred
            | (Proposal era
proposal, Maybe (ScriptWitness WitCtxStake era)
_) <- [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
            , let (Lovelace
_, StakeCredential
stakeCred, GovernanceAction era
_) = ShelleyBasedEra era
-> Proposal era
-> (Lovelace, StakeCredential, GovernanceAction era)
forall era.
ShelleyBasedEra era
-> Proposal era
-> (Lovelace, StakeCredential, GovernanceAction era)
fromProposalProcedure ShelleyBasedEra era
eon Proposal era
proposal
            ]
        treasuryWithdrawalAddresses :: Set StakeCredential
treasuryWithdrawalAddresses =
          [Item (Set StakeCredential)] -> Set StakeCredential
forall l. IsList l => [Item l] -> l
fromList
            [ Item (Set StakeCredential)
StakeCredential
stakeCred
            | (Proposal era
proposal, Maybe (ScriptWitness WitCtxStake era)
_) <- [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
            , let (Lovelace
_, StakeCredential
_, GovernanceAction era
govAction) = ShelleyBasedEra era
-> Proposal era
-> (Lovelace, StakeCredential, GovernanceAction era)
forall era.
ShelleyBasedEra era
-> Proposal era
-> (Lovelace, StakeCredential, GovernanceAction era)
fromProposalProcedure ShelleyBasedEra era
eon Proposal era
proposal
            , TreasuryWithdrawal [(Network, StakeCredential, Lovelace)]
withdrawalsList StrictMaybe (ScriptHash StandardCrypto)
_ <- [GovernanceAction era
govAction] -- Match on TreasuryWithdrawal action
            , (Network
_, StakeCredential
stakeCred, Lovelace
_) <- [(Network, StakeCredential, Lovelace)]
withdrawalsList -- Extract fund-receiving stake credentials
            ]
        allAddrHashes :: Set StakeCredential
allAddrHashes = Set StakeCredential -> Set StakeCredential -> Set StakeCredential
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set StakeCredential
returnAddrHashes Set StakeCredential
treasuryWithdrawalAddresses

    (Map StakeAddress Lovelace
balances, Map StakeAddress PoolId
_) <-
      IO
  (Either
     AcquiringFailure
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           UnsupportedNtcVersionError
           (Either
              EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
        ( LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> IO
     (Either
        AcquiringFailure
        (Either
           UnsupportedNtcVersionError
           (Either
              EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr
            LocalNodeConnectInfo
localNodeConnInfo
            Target ChainPoint
forall point. Target point
Consensus.VolatileTip
            (ShelleyBasedEra era
-> Set StakeCredential
-> NetworkId
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
forall era block point r.
ShelleyBasedEra era
-> Set StakeCredential
-> NetworkId
-> LocalStateQueryExpr
     block
     point
     QueryInMode
     r
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
queryStakeAddresses ShelleyBasedEra era
eon Set StakeCredential
allAddrHashes NetworkId
networkId)
        )
        ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure
         (Either
            UnsupportedNtcVersionError
            (Either
               EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
    -> ExceptT
         TxCmdError
         IO
         (Either
            UnsupportedNtcVersionError
            (Either
               EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> ExceptT
     TxCmdError
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError
      IO
      (Either
         UnsupportedNtcVersionError
         (Either
            EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           UnsupportedNtcVersionError
           (Either
              EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> ExceptT
     TxCmdError
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (Either
         UnsupportedNtcVersionError
         (Either
            EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
        ExceptT
  TxCmdError
  IO
  (Either
     UnsupportedNtcVersionError
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> (ExceptT
      TxCmdError
      IO
      (Either
         UnsupportedNtcVersionError
         (Either
            EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
    -> ExceptT
         TxCmdError
         IO
         (Either
            EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> ExceptT
     TxCmdError
     IO
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
forall a b. a -> (a -> b) -> b
& (UnsupportedNtcVersionError
 -> ExceptT
      TxCmdError
      IO
      (Either
         EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> ExceptT
     TxCmdError
     IO
     (Either
        UnsupportedNtcVersionError
        (Either
           EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> ExceptT
     TxCmdError
     IO
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (Either
         EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId)))
-> (UnsupportedNtcVersionError -> TxCmdError)
-> UnsupportedNtcVersionError
-> ExceptT
     TxCmdError
     IO
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (UnsupportedNtcVersionError -> QueryConvenienceError)
-> UnsupportedNtcVersionError
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion)
        ExceptT
  TxCmdError
  IO
  (Either
     EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
-> (ExceptT
      TxCmdError
      IO
      (Either
         EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
    -> ExceptT
         TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId))
-> ExceptT
     TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId)
forall a b. a -> (a -> b) -> b
& (EraMismatch
 -> ExceptT
      TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId))
-> ExceptT
     TxCmdError
     IO
     (Either
        EraMismatch (Map StakeAddress Lovelace, Map StakeAddress PoolId))
-> ExceptT
     TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId))
-> (EraMismatch -> TxCmdError)
-> EraMismatch
-> ExceptT
     TxCmdError IO (Map StakeAddress Lovelace, Map StakeAddress PoolId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EraMismatch -> TxCmdError
TxCmdTxSubmitErrorEraMismatch)

    let unregisteredAddresses :: Set StakeCredential
unregisteredAddresses =
          (StakeCredential -> Bool)
-> Set StakeCredential -> Set StakeCredential
forall a. (a -> Bool) -> Set a -> Set a
Set.filter
            (\StakeCredential
stakeCred -> StakeAddress -> Map StakeAddress Lovelace -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.notMember (NetworkId -> StakeCredential -> StakeAddress
makeStakeAddress NetworkId
networkId StakeCredential
stakeCred) Map StakeAddress Lovelace
balances)
            Set StakeCredential
allAddrHashes

    Bool -> ExceptT TxCmdError IO () -> ExceptT TxCmdError IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set StakeCredential -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set StakeCredential
unregisteredAddresses) (ExceptT TxCmdError IO () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
      TxCmdError -> ExceptT TxCmdError IO ()
forall a. TxCmdError -> ExceptT TxCmdError IO a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (TxCmdError -> ExceptT TxCmdError IO ())
-> TxCmdError -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
        Set StakeCredential -> TxCmdError
TxCmdUnregisteredStakeAddress Set StakeCredential
unregisteredAddresses

    -- the same collateral input can be used for several plutus scripts
    let filteredTxinsc :: [TxIn]
filteredTxinsc = [TxIn] -> [TxIn]
forall a. Ord a => [a] -> [a]
nubOrd [TxIn]
txinsc

    let allReferenceInputs :: [TxIn]
allReferenceInputs =
          [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
            [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
            ((MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era)
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> [a] -> [b]
map MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
forall era.
MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
mswScriptWitness ([MintScriptWitnessWithPolicyId era]
 -> [ScriptWitness WitCtxMint era])
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> a -> b
$ (Value, [MintScriptWitnessWithPolicyId era])
-> [MintScriptWitnessWithPolicyId era]
forall a b. (a, b) -> b
snd (Value, [MintScriptWitnessWithPolicyId era])
usedToGetReferenceInputs)
            [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
            [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits
            [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits
            [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
            [TxIn]
readOnlyReferenceInputs

    let inputsThatRequireWitnessing :: [TxIn]
inputsThatRequireWitnessing = [TxIn
input | (TxIn
input, Maybe (ScriptWitness WitCtxTxIn era)
_) <- [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits]
        allTxInputs :: [TxIn]
allTxInputs = [TxIn]
inputsThatRequireWitnessing [TxIn] -> [TxIn] -> [TxIn]
forall a. [a] -> [a] -> [a]
++ [TxIn]
allReferenceInputs [TxIn] -> [TxIn] -> [TxIn]
forall a. [a] -> [a] -> [a]
++ [TxIn]
filteredTxinsc

    AnyCardanoEra CardanoEra era
nodeEra <-
      IO
  (Either
     AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either UnsupportedNtcVersionError AnyCardanoEra)
-> IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr LocalNodeConnectInfo
localNodeConnInfo Target ChainPoint
forall point. Target point
Consensus.VolatileTip LocalStateQueryExpr
  BlockInMode
  ChainPoint
  QueryInMode
  ()
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
forall block point r.
LocalStateQueryExpr
  block
  point
  QueryInMode
  r
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
queryCurrentEra)
        ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
    -> ExceptT
         TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
        ExceptT
  TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
-> (ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
    -> ExceptT TxCmdError IO AnyCardanoEra)
-> ExceptT TxCmdError IO AnyCardanoEra
forall a b. a -> (a -> b) -> b
& (UnsupportedNtcVersionError -> ExceptT TxCmdError IO AnyCardanoEra)
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
-> ExceptT TxCmdError IO AnyCardanoEra
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO AnyCardanoEra
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO AnyCardanoEra)
-> (UnsupportedNtcVersionError -> TxCmdError)
-> UnsupportedNtcVersionError
-> ExceptT TxCmdError IO AnyCardanoEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (UnsupportedNtcVersionError -> QueryConvenienceError)
-> UnsupportedNtcVersionError
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion)

    (UTxO era
txEraUtxo, LedgerProtocolParameters era
_, EraHistory
eraHistory, SystemStart
systemStart, Set PoolId
_, Map StakeCredential Lovelace
_, Map (Credential 'DRepRole StandardCrypto) Lovelace
_, Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)
featuredCurrentTreasuryValueM) <-
      IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
        ( LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr
            LocalNodeConnectInfo
localNodeConnInfo
            Target ChainPoint
forall point. Target point
Consensus.VolatileTip
            (CardanoEra era
-> [TxIn]
-> [Certificate era]
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall era block point r.
CardanoEra era
-> [TxIn]
-> [Certificate era]
-> LocalStateQueryExpr
     block
     point
     QueryInMode
     r
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
queryStateForBalancedTx CardanoEra era
nodeEra [TxIn]
allTxInputs [])
        )
        ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure
         (Either
            QueryConvenienceError
            (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
             Set PoolId, Map StakeCredential Lovelace,
             Map (Credential 'DRepRole StandardCrypto) Lovelace,
             Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
    -> ExceptT
         TxCmdError
         IO
         (Either
            QueryConvenienceError
            (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
             Set PoolId, Map StakeCredential Lovelace,
             Map (Credential 'DRepRole StandardCrypto) Lovelace,
             Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
        ExceptT
  TxCmdError
  IO
  (Either
     QueryConvenienceError
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> (ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
    -> ExceptT
         TxCmdError
         IO
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall a b. a -> (a -> b) -> b
& (QueryConvenienceError
 -> ExceptT
      TxCmdError
      IO
      (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
       Set PoolId, Map StakeCredential Lovelace,
       Map (Credential 'DRepRole StandardCrypto) Lovelace,
       Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
       Set PoolId, Map StakeCredential Lovelace,
       Map (Credential 'DRepRole StandardCrypto) Lovelace,
       Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> (QueryConvenienceError -> TxCmdError)
-> QueryConvenienceError
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError)

    (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits <-
      (Value
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (Value, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (Value, [MintScriptWitnessWithPolicyId era])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError ((CliMintScriptRequirements
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (MintScriptWitnessWithPolicyId era))
-> [CliMintScriptRequirements]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
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 (ShelleyBasedEra era
-> CliMintScriptRequirements
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (MintScriptWitnessWithPolicyId era)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> CliMintScriptRequirements
-> t m (MintScriptWitnessWithPolicyId era)
readMintScriptWitness ShelleyBasedEra era
eon) [CliMintScriptRequirements]
sWitFiles)
    let currentTreasuryValueAndDonation :: Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation =
          case (Maybe TxTreasuryDonation
treasuryDonation, Featured ConwayEraOnwards era TxCurrentTreasuryValue
-> TxCurrentTreasuryValue
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (Featured ConwayEraOnwards era TxCurrentTreasuryValue
 -> TxCurrentTreasuryValue)
-> Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)
-> Maybe TxCurrentTreasuryValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)
featuredCurrentTreasuryValueM) of
            (Maybe TxTreasuryDonation
Nothing, Maybe TxCurrentTreasuryValue
_) -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
forall a. Maybe a
Nothing -- We shouldn't specify the treasury value when no donation is being done
            (Just TxTreasuryDonation
_td, Maybe TxCurrentTreasuryValue
Nothing) -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
forall a. Maybe a
Nothing -- TODO: Current treasury value couldn't be obtained but is required: we should fail suggesting that the node's version is too old
            (Just TxTreasuryDonation
td, Just TxCurrentTreasuryValue
ctv) -> (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
forall a. a -> Maybe a
Just (TxCurrentTreasuryValue
ctv, TxTreasuryDonation
td)

    -- We need to construct the txBodycontent outside of runTxBuild
    BalancedTxBody TxBodyContent BuildTx era
txBodyContent TxBody era
balancedTxBody TxOut CtxTx era
_ Lovelace
_ <-
      ShelleyBasedEra era
-> SocketPath
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall era.
ShelleyBasedEra era
-> SocketPath
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild
        ShelleyBasedEra era
eon
        SocketPath
nodeSocketPath
        NetworkId
networkId
        Maybe ScriptValidity
mScriptValidity
        [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
        [TxIn]
readOnlyReferenceInputs
        [TxIn]
filteredTxinsc
        Maybe (TxOut CtxTx era)
mReturnCollateral
        Maybe Lovelace
mTotalCollateral
        [TxOut CtxTx era]
txOuts
        TxOutChangeAddress
changeAddresses
        (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
        Maybe SlotNo
mValidityLowerBound
        TxValidityUpperBound era
mValidityUpperBound
        [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
        [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits
        [Hash PaymentKey]
requiredSigners
        TxAuxScripts era
txAuxScripts
        TxMetadataInEra era
txMetadata
        TxUpdateProposal era
mProp
        Maybe Word
mOverrideWitnesses
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
        Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation

    -- TODO: Calculating the script cost should live as a different command.
    -- Why? Because then we can simply read a txbody and figure out
    -- the script cost vs having to build the tx body each time
    case TxBuildOutputOptions
buildOutputOptions of
      OutputScriptCostOnly File () 'Out
fp -> do
        let BuildTxWith Maybe (LedgerProtocolParameters era)
mTxProtocolParams = TxBodyContent BuildTx era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams TxBodyContent BuildTx era
txBodyContent

        LedgerProtocolParameters era
pparams <- Maybe (LedgerProtocolParameters era)
-> ExceptT TxCmdError IO (Maybe (LedgerProtocolParameters era))
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (LedgerProtocolParameters era)
mTxProtocolParams ExceptT TxCmdError IO (Maybe (LedgerProtocolParameters era))
-> (ExceptT TxCmdError IO (Maybe (LedgerProtocolParameters era))
    -> ExceptT TxCmdError IO (LedgerProtocolParameters era))
-> ExceptT TxCmdError IO (LedgerProtocolParameters era)
forall a b. a -> (a -> b) -> b
& ExceptT TxCmdError IO (LedgerProtocolParameters era)
-> ExceptT TxCmdError IO (Maybe (LedgerProtocolParameters era))
-> ExceptT TxCmdError IO (LedgerProtocolParameters era)
forall x (m :: * -> *) a.
Monad m =>
ExceptT x m a -> ExceptT x m (Maybe a) -> ExceptT x m a
onNothing (TxCmdError -> ExceptT TxCmdError IO (LedgerProtocolParameters era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left TxCmdError
TxCmdProtocolParametersNotPresentInTxBody)
        Prices
executionUnitPrices <-
          Maybe Prices -> ExceptT TxCmdError IO (Maybe Prices)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CardanoEra era -> LedgerProtocolParameters era -> Maybe Prices
forall era.
CardanoEra era -> LedgerProtocolParameters era -> Maybe Prices
getExecutionUnitPrices CardanoEra era
era' LedgerProtocolParameters era
pparams) ExceptT TxCmdError IO (Maybe Prices)
-> (ExceptT TxCmdError IO (Maybe Prices)
    -> ExceptT TxCmdError IO Prices)
-> ExceptT TxCmdError IO Prices
forall a b. a -> (a -> b) -> b
& ExceptT TxCmdError IO Prices
-> ExceptT TxCmdError IO (Maybe Prices)
-> ExceptT TxCmdError IO Prices
forall x (m :: * -> *) a.
Monad m =>
ExceptT x m a -> ExceptT x m (Maybe a) -> ExceptT x m a
onNothing (TxCmdError -> ExceptT TxCmdError IO Prices
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left TxCmdError
TxCmdPParamExecutionUnitsNotAvailable)

        era :~: era
Refl <-
          CardanoEra era -> CardanoEra era -> Maybe (era :~: era)
forall a b. CardanoEra a -> CardanoEra b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality CardanoEra era
era' CardanoEra era
nodeEra
            Maybe (era :~: era)
-> (Maybe (era :~: era) -> ExceptT TxCmdError IO (era :~: era))
-> ExceptT TxCmdError IO (era :~: era)
forall a b. a -> (a -> b) -> b
& TxCmdError
-> Maybe (era :~: era) -> ExceptT TxCmdError IO (era :~: era)
forall (m :: * -> *) x a. Monad m => x -> Maybe a -> ExceptT x m a
hoistMaybe (NodeEraMismatchError -> TxCmdError
TxCmdTxNodeEraMismatchError (NodeEraMismatchError -> TxCmdError)
-> NodeEraMismatchError -> TxCmdError
forall a b. (a -> b) -> a -> b
$ CardanoEra era -> CardanoEra era -> NodeEraMismatchError
forall era nodeEra.
CardanoEra era -> CardanoEra nodeEra -> NodeEraMismatchError
NodeEraMismatchError CardanoEra era
era' CardanoEra era
nodeEra)

        Map
  ScriptWitnessIndex
  (Either
     ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
scriptExecUnitsMap <-
          (TransactionValidityError era -> TxCmdError)
-> ExceptT
     (TransactionValidityError era)
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
-> ExceptT
     TxCmdError
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (AnyTxCmdTxExecUnitsErr -> TxCmdError
TxCmdTxExecUnitsErr (AnyTxCmdTxExecUnitsErr -> TxCmdError)
-> (TransactionValidityError era -> AnyTxCmdTxExecUnitsErr)
-> TransactionValidityError era
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TransactionValidityError era -> AnyTxCmdTxExecUnitsErr
forall era. TransactionValidityError era -> AnyTxCmdTxExecUnitsErr
AnyTxCmdTxExecUnitsErr) (ExceptT
   (TransactionValidityError era)
   IO
   (Map
      ScriptWitnessIndex
      (Either
         ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
 -> ExceptT
      TxCmdError
      IO
      (Map
         ScriptWitnessIndex
         (Either
            ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))))
-> ExceptT
     (TransactionValidityError era)
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
-> ExceptT
     TxCmdError
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
forall a b. (a -> b) -> a -> b
$
            Either
  (TransactionValidityError era)
  (Map
     ScriptWitnessIndex
     (Either
        ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
-> ExceptT
     (TransactionValidityError era)
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either
   (TransactionValidityError era)
   (Map
      ScriptWitnessIndex
      (Either
         ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
 -> ExceptT
      (TransactionValidityError era)
      IO
      (Map
         ScriptWitnessIndex
         (Either
            ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))))
-> Either
     (TransactionValidityError era)
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
-> ExceptT
     (TransactionValidityError era)
     IO
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
forall a b. (a -> b) -> a -> b
$
              CardanoEra era
-> SystemStart
-> LedgerEpochInfo
-> LedgerProtocolParameters era
-> UTxO era
-> TxBody era
-> Either
     (TransactionValidityError era)
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
forall era.
CardanoEra era
-> SystemStart
-> LedgerEpochInfo
-> LedgerProtocolParameters era
-> UTxO era
-> TxBody era
-> Either
     (TransactionValidityError era)
     (Map
        ScriptWitnessIndex
        (Either
           ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)))
evaluateTransactionExecutionUnits
                CardanoEra era
era'
                SystemStart
systemStart
                (EraHistory -> LedgerEpochInfo
toLedgerEpochInfo EraHistory
eraHistory)
                LedgerProtocolParameters era
pparams
                UTxO era
UTxO era
txEraUtxo
                TxBody era
balancedTxBody

        let mScriptWits :: [(ScriptWitnessIndex, AnyScriptWitness era)]
mScriptWits = CardanoEra era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> (ShelleyBasedEra era
    -> [(ScriptWitnessIndex, AnyScriptWitness era)])
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall (eon :: * -> *) era a.
Eon eon =>
CardanoEra era -> a -> (eon era -> a) -> a
forEraInEon CardanoEra era
era' [] ((ShelleyBasedEra era
  -> [(ScriptWitnessIndex, AnyScriptWitness era)])
 -> [(ScriptWitnessIndex, AnyScriptWitness era)])
-> (ShelleyBasedEra era
    -> [(ScriptWitnessIndex, AnyScriptWitness era)])
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a b. (a -> b) -> a -> b
$ \ShelleyBasedEra era
sbe -> ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txBodyContent

        [ScriptCostOutput]
scriptCostOutput <-
          (PlutusScriptCostError -> TxCmdError)
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
-> ExceptT TxCmdError IO [ScriptCostOutput]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT PlutusScriptCostError -> TxCmdError
TxCmdPlutusScriptCostErr (ExceptT PlutusScriptCostError IO [ScriptCostOutput]
 -> ExceptT TxCmdError IO [ScriptCostOutput])
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
-> ExceptT TxCmdError IO [ScriptCostOutput]
forall a b. (a -> b) -> a -> b
$
            Either PlutusScriptCostError [ScriptCostOutput]
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either PlutusScriptCostError [ScriptCostOutput]
 -> ExceptT PlutusScriptCostError IO [ScriptCostOutput])
-> Either PlutusScriptCostError [ScriptCostOutput]
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
forall a b. (a -> b) -> a -> b
$
              UTxO era
-> Prices
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> Map
     ScriptWitnessIndex
     (Either
        ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
-> Either PlutusScriptCostError [ScriptCostOutput]
forall era.
UTxO era
-> Prices
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> Map
     ScriptWitnessIndex
     (Either
        ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
-> Either PlutusScriptCostError [ScriptCostOutput]
renderScriptCosts
                UTxO era
txEraUtxo
                Prices
executionUnitPrices
                [(ScriptWitnessIndex, AnyScriptWitness era)]
[(ScriptWitnessIndex, AnyScriptWitness era)]
mScriptWits
                Map
  ScriptWitnessIndex
  (Either
     ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
scriptExecUnitsMap
        IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> ByteString -> IO ()
LBS.writeFile (File () 'Out -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile File () 'Out
fp) (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ [ScriptCostOutput] -> ByteString
forall a. ToJSON a => a -> ByteString
encodePretty [ScriptCostOutput]
scriptCostOutput
      OutputTxBodyOnly TxBodyFile 'Out
fpath -> do
        let noWitTx :: Tx era
noWitTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
balancedTxBody
        IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (CardanoEra era
-> (CardanoEraConstraints era => IO (Either (FileError ()) ()))
-> IO (Either (FileError ()) ())
forall era a.
CardanoEra era -> (CardanoEraConstraints era => a) -> a
cardanoEraConstraints CardanoEra era
era' ((CardanoEraConstraints era => IO (Either (FileError ()) ()))
 -> IO (Either (FileError ()) ()))
-> (CardanoEraConstraints era => IO (Either (FileError ()) ()))
-> IO (Either (FileError ()) ())
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxBodyFile 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
eon TxBodyFile 'Out
fpath Tx era
noWitTx)
          ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)

runTransactionBuildEstimateCmd
  :: forall era
   . Cmd.TransactionBuildEstimateCmdArgs era
  -> ExceptT TxCmdError IO ()
runTransactionBuildEstimateCmd :: forall era.
TransactionBuildEstimateCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildEstimateCmd -- TODO change type
  Cmd.TransactionBuildEstimateCmdArgs
    { Era era
currentEra :: Era era
currentEra :: forall era. TransactionBuildEstimateCmdArgs era -> Era era
currentEra
    , Maybe ScriptValidity
mScriptValidity :: Maybe ScriptValidity
mScriptValidity :: forall era.
TransactionBuildEstimateCmdArgs era -> Maybe ScriptValidity
mScriptValidity
    , Int
shelleyWitnesses :: Int
shelleyWitnesses :: forall era. TransactionBuildEstimateCmdArgs era -> Int
shelleyWitnesses
    , Maybe Int
mByronWitnesses :: Maybe Int
mByronWitnesses :: forall era. TransactionBuildEstimateCmdArgs era -> Maybe Int
mByronWitnesses
    , ProtocolParamsFile
protocolParamsFile :: ProtocolParamsFile
protocolParamsFile :: forall era.
TransactionBuildEstimateCmdArgs era -> ProtocolParamsFile
protocolParamsFile
    , Value
totalUTxOValue :: Value
totalUTxOValue :: forall era. TransactionBuildEstimateCmdArgs era -> Value
totalUTxOValue
    , [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins :: [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins
    , readOnlyReferenceInputs :: forall era. TransactionBuildEstimateCmdArgs era -> [TxIn]
readOnlyReferenceInputs = [TxIn]
readOnlyRefIns
    , requiredSigners :: forall era. TransactionBuildEstimateCmdArgs era -> [RequiredSigner]
requiredSigners = [RequiredSigner]
reqSigners
    , txinsc :: forall era. TransactionBuildEstimateCmdArgs era -> [TxIn]
txinsc = [TxIn]
txInsCollateral
    , mReturnCollateral :: forall era.
TransactionBuildEstimateCmdArgs era -> Maybe TxOutShelleyBasedEra
mReturnCollateral = Maybe TxOutShelleyBasedEra
mReturnColl
    , [TxOutAnyEra]
txouts :: [TxOutAnyEra]
txouts :: forall era. TransactionBuildEstimateCmdArgs era -> [TxOutAnyEra]
txouts
    , changeAddress :: forall era.
TransactionBuildEstimateCmdArgs era -> TxOutChangeAddress
changeAddress = TxOutChangeAddress AddressAny
changeAddr
    , Maybe (Value, [CliMintScriptRequirements])
mValue :: Maybe (Value, [CliMintScriptRequirements])
mValue :: forall era.
TransactionBuildEstimateCmdArgs era
-> Maybe (Value, [CliMintScriptRequirements])
mValue
    , Maybe SlotNo
mValidityLowerBound :: Maybe SlotNo
mValidityLowerBound :: forall era. TransactionBuildEstimateCmdArgs era -> Maybe SlotNo
mValidityLowerBound
    , TxValidityUpperBound era
mValidityUpperBound :: TxValidityUpperBound era
mValidityUpperBound :: forall era.
TransactionBuildEstimateCmdArgs era -> TxValidityUpperBound era
mValidityUpperBound
    , [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates
    , [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    , TxMetadataJsonSchema
metadataSchema :: TxMetadataJsonSchema
metadataSchema :: forall era.
TransactionBuildEstimateCmdArgs era -> TxMetadataJsonSchema
metadataSchema
    , [ScriptFile]
scriptFiles :: [ScriptFile]
scriptFiles :: forall era. TransactionBuildEstimateCmdArgs era -> [ScriptFile]
scriptFiles
    , [MetadataFile]
metadataFiles :: [MetadataFile]
metadataFiles :: forall era. TransactionBuildEstimateCmdArgs era -> [MetadataFile]
metadataFiles
    , Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile :: Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile :: forall era.
TransactionBuildEstimateCmdArgs era
-> Maybe
     (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile
    , [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles
    , [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles
    , Maybe Lovelace
plutusCollateral :: Maybe Lovelace
plutusCollateral :: forall era. TransactionBuildEstimateCmdArgs era -> Maybe Lovelace
plutusCollateral
    , Maybe ReferenceScriptSize
totalReferenceScriptSize :: Maybe ReferenceScriptSize
totalReferenceScriptSize :: forall era.
TransactionBuildEstimateCmdArgs era -> Maybe ReferenceScriptSize
totalReferenceScriptSize
    , Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation :: Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation :: forall era.
TransactionBuildEstimateCmdArgs era
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation
    , TxBodyFile 'Out
txBodyOutFile :: TxBodyFile 'Out
txBodyOutFile :: forall era. TransactionBuildEstimateCmdArgs era -> TxBodyFile 'Out
txBodyOutFile
    } = do
    let sbe :: ShelleyBasedEra era
sbe = Era era -> ShelleyBasedEra era
forall era. Era era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert Era era
currentEra
        meo :: MaryEraOnwards era
meo = Era era -> MaryEraOnwards era
forall era. Era era -> MaryEraOnwards era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert Era era
currentEra

    PParams (ShelleyLedgerEra era)
ledgerPParams <-
      (ProtocolParamsError -> TxCmdError)
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ProtocolParamsError -> TxCmdError
TxCmdProtocolParamsError (ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
 -> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era)))
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
readProtocolParameters ShelleyBasedEra era
sbe ProtocolParamsFile
protocolParamsFile
    [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
 -> ExceptT
      TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
sbe [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins
    [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
sbe [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates

    [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall era a b ctx.
ShelleyBasedEra era
-> [(a, b, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, b, Maybe (ScriptWitness ctx era))]
readScriptWitnessFilesTuple ShelleyBasedEra era
sbe [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    TxMetadataInEra era
txMetadata <-
      (MetadataError -> TxCmdError)
-> ExceptT MetadataError IO (TxMetadataInEra era)
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT MetadataError -> TxCmdError
TxCmdMetadataError
        (ExceptT MetadataError IO (TxMetadataInEra era)
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> (IO (Either MetadataError (TxMetadataInEra era))
    -> ExceptT MetadataError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT MetadataError IO (TxMetadataInEra era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
        (IO (Either MetadataError (TxMetadataInEra era))
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
readTxMetadata ShelleyBasedEra era
sbe TxMetadataJsonSchema
metadataSchema [MetadataFile]
metadataFiles

    let (Value
mas, [CliMintScriptRequirements]
sWitFiles) = (Value, [CliMintScriptRequirements])
-> Maybe (Value, [CliMintScriptRequirements])
-> (Value, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (Value
forall a. Monoid a => a
mempty, [CliMintScriptRequirements]
forall a. Monoid a => a
mempty) Maybe (Value, [CliMintScriptRequirements])
mValue
    (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits <-
      (Value
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (Value, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (Value, [MintScriptWitnessWithPolicyId era])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError ((CliMintScriptRequirements
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (MintScriptWitnessWithPolicyId era))
-> [CliMintScriptRequirements]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
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 (ShelleyBasedEra era
-> CliMintScriptRequirements
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (MintScriptWitnessWithPolicyId era)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> CliMintScriptRequirements
-> t m (MintScriptWitnessWithPolicyId era)
readMintScriptWitness ShelleyBasedEra era
sbe) [CliMintScriptRequirements]
sWitFiles)

    [ScriptInAnyLang]
scripts <-
      (FileError ScriptDecodeError -> TxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> TxCmdError
TxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
 -> ExceptT TxCmdError IO [ScriptInAnyLang])
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall a b. (a -> b) -> a -> b
$
        (ScriptFile
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> [ScriptFile]
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
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 (FilePath
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
MonadIOTransError (FileError ScriptDecodeError) t m =>
FilePath -> t m ScriptInAnyLang
readFileScriptInAnyLang (FilePath
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> (ScriptFile -> FilePath)
-> ScriptFile
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptFile -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile) [ScriptFile]
scriptFiles
    TxAuxScripts era
txAuxScripts <-
      Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxAuxScripts era)
 -> ExceptT TxCmdError IO (TxAuxScripts era))
-> Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ (TxAuxScriptsValidationError -> TxCmdError)
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxAuxScriptsValidationError -> TxCmdError
TxCmdAuxScriptsValidationError (Either TxAuxScriptsValidationError (TxAuxScripts era)
 -> Either TxCmdError (TxAuxScripts era))
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
forall era.
ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
validateTxAuxScripts ShelleyBasedEra era
sbe [ScriptInAnyLang]
scripts

    TxUpdateProposal era
txUpdateProposal <- case Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProposalFile of
      Just (Featured ShelleyToBabbageEra era
w (Just UpdateProposalFile
updateProposalFile)) ->
        ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
forall era.
ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
readTxUpdateProposal ShelleyToBabbageEra era
w UpdateProposalFile
updateProposalFile ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> (ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
    -> ExceptT TxCmdError IO (TxUpdateProposal era))
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError
      Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
_ -> TxUpdateProposal era
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone

    [Hash PaymentKey]
requiredSigners <-
      (RequiredSigner -> ExceptT TxCmdError IO (Hash PaymentKey))
-> [RequiredSigner] -> ExceptT TxCmdError IO [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 ((RequiredSignerError -> TxCmdError)
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT RequiredSignerError -> TxCmdError
TxCmdRequiredSignerError (ExceptT RequiredSignerError IO (Hash PaymentKey)
 -> ExceptT TxCmdError IO (Hash PaymentKey))
-> (RequiredSigner
    -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> RequiredSigner
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either RequiredSignerError (Hash PaymentKey))
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either RequiredSignerError (Hash PaymentKey))
 -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> (RequiredSigner
    -> IO (Either RequiredSignerError (Hash PaymentKey)))
-> RequiredSigner
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner) [RequiredSigner]
reqSigners

    Maybe (TxOut CtxTx era)
mReturnCollateral <- (TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> Maybe TxOutShelleyBasedEra
-> ExceptT TxCmdError IO (Maybe (TxOut CtxTx era))
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) -> Maybe a -> m (Maybe b)
mapM (ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra ShelleyBasedEra era
sbe) Maybe TxOutShelleyBasedEra
mReturnColl

    [TxOut CtxTx era]
txOuts <- (TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> [TxOutAnyEra] -> ExceptT TxCmdError IO [TxOut CtxTx era]
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 (ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra ShelleyBasedEra era
sbe) [TxOutAnyEra]
txouts

    -- the same collateral input can be used for several plutus scripts
    let filteredTxinsc :: [TxIn]
filteredTxinsc = [TxIn] -> [TxIn]
forall a. Ord a => [a] -> [a]
nubOrd [TxIn]
txInsCollateral

    -- Conway related
    [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ShelleyBasedEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> ShelleyBasedEra era -> a
inEonForShelleyBasedEra
        ([(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. Monoid a => a
mempty)
        ( \ConwayEraOnwards era
w ->
            (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT VoteError -> TxCmdError
TxCmdVoteError (ExceptT
   VoteError
   IO
   [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> (IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
    -> ExceptT
         VoteError
         IO
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO
  (Either
     VoteError
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (IO
   (Either
      VoteError
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
              ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  IO
    (Either
       VoteError
       [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
 -> IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall a b. (a -> b) -> a -> b
$
                ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles
        )
        ShelleyBasedEra era
sbe

    [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals <-
      IO
  (Either
     ProposalError
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
readTxGovernanceActions ShelleyBasedEra era
sbe [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles)
        ExceptT
  TxCmdError
  IO
  (Either
     ProposalError
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> (ExceptT
      TxCmdError
      IO
      (Either
         ProposalError
         [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
    -> ExceptT
         TxCmdError
         IO
         [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. a -> (a -> b) -> b
& (ProposalError
 -> ExceptT
      TxCmdError
      IO
      [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> (ProposalError -> TxCmdError)
-> ProposalError
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProposalError -> TxCmdError
TxCmdProposalError)

    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits <-
      ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era =>
  ExceptT
    TxCmdError
    IO
    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
 -> ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> (ShelleyBasedEraConstraints era =>
    ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        [ExceptT
   TxCmdError
   IO
   (Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence
          [ (Certificate era
 -> (Certificate era, Maybe (ScriptWitness WitCtxStake era)))
-> ExceptT TxCmdError IO (Certificate era)
-> ExceptT
     TxCmdError
     IO
     (Certificate era, Maybe (ScriptWitness WitCtxStake era))
forall a b.
(a -> b) -> ExceptT TxCmdError IO a -> ExceptT TxCmdError IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
              (,Maybe (ScriptWitness WitCtxStake era)
mSwit)
              ( (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
-> ExceptT TxCmdError IO (Certificate era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO (Certificate era)
 -> ExceptT TxCmdError IO (Certificate era))
-> (IO (Either (FileError TextEnvelopeError) (Certificate era))
    -> ExceptT (FileError TextEnvelopeError) IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (Certificate era))
 -> ExceptT TxCmdError IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall a b. (a -> b) -> a -> b
$
                  AsType (Certificate era)
-> File Any 'In
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
forall a content.
HasTextEnvelope a =>
AsType a
-> File content 'In -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType (Certificate era)
forall era. AsType (Certificate era)
AsCertificate (FilePath -> File Any 'In
forall content (direction :: FileDirection).
FilePath -> File content direction
File FilePath
certFile)
              )
          | (CertificateFile FilePath
certFile, Maybe (ScriptWitness WitCtxStake era)
mSwit) <- [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits
          ]

    TxBodyContent BuildTx era
txBodyContent <-
      Either TxCmdError (TxBodyContent BuildTx era)
-> ExceptT TxCmdError IO (TxBodyContent BuildTx era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxBodyContent BuildTx era)
 -> ExceptT TxCmdError IO (TxBodyContent BuildTx era))
-> Either TxCmdError (TxBodyContent BuildTx era)
-> ExceptT TxCmdError IO (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent
          ShelleyBasedEra era
sbe
          Maybe ScriptValidity
mScriptValidity
          (PParams (ShelleyLedgerEra era)
-> Maybe (PParams (ShelleyLedgerEra era))
forall a. a -> Maybe a
Just PParams (ShelleyLedgerEra era)
ledgerPParams)
          [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
          [TxIn]
readOnlyRefIns
          [TxIn]
filteredTxinsc
          Maybe (TxOut CtxTx era)
mReturnCollateral
          Maybe Lovelace
forall a. Maybe a
Nothing -- TODO: Remove total collateral parameter from estimateBalancedTxBody
          [TxOut CtxTx era]
txOuts
          Maybe SlotNo
mValidityLowerBound
          TxValidityUpperBound era
mValidityUpperBound
          (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
          [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
          [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits
          [Hash PaymentKey]
requiredSigners
          Lovelace
0
          TxAuxScripts era
txAuxScripts
          TxMetadataInEra era
txMetadata
          TxUpdateProposal era
txUpdateProposal
          [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits
          [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
          Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation
    let stakeCredentialsToDeregisterMap :: Map StakeCredential Lovelace
stakeCredentialsToDeregisterMap = [Item (Map StakeCredential Lovelace)]
-> Map StakeCredential Lovelace
forall l. IsList l => [Item l] -> l
fromList ([Item (Map StakeCredential Lovelace)]
 -> Map StakeCredential Lovelace)
-> [Item (Map StakeCredential Lovelace)]
-> Map StakeCredential Lovelace
forall a b. (a -> b) -> a -> b
$ [Maybe (StakeCredential, Lovelace)]
-> [(StakeCredential, Lovelace)]
forall a. [Maybe a] -> [a]
catMaybes [Certificate era -> Maybe (StakeCredential, Lovelace)
forall era. Certificate era -> Maybe (StakeCredential, Lovelace)
getStakeDeregistrationInfo Certificate era
cert | (Certificate era
cert, Maybe (ScriptWitness WitCtxStake era)
_) <- [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits]
        drepsToDeregisterMap :: Map (Credential 'DRepRole StandardCrypto) Lovelace
drepsToDeregisterMap = [Item (Map (Credential 'DRepRole StandardCrypto) Lovelace)]
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
forall l. IsList l => [Item l] -> l
fromList ([Item (Map (Credential 'DRepRole StandardCrypto) Lovelace)]
 -> Map (Credential 'DRepRole StandardCrypto) Lovelace)
-> [Item (Map (Credential 'DRepRole StandardCrypto) Lovelace)]
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
forall a b. (a -> b) -> a -> b
$ [Maybe (Credential 'DRepRole StandardCrypto, Lovelace)]
-> [(Credential 'DRepRole StandardCrypto, Lovelace)]
forall a. [Maybe a] -> [a]
catMaybes [Certificate era
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall era.
Certificate era
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
getDRepDeregistrationInfo Certificate era
cert | (Certificate era
cert, Maybe (ScriptWitness WitCtxStake era)
_) <- [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits]
        poolsToDeregister :: Set PoolId
poolsToDeregister = [Item (Set PoolId)] -> Set PoolId
forall l. IsList l => [Item l] -> l
fromList ([Item (Set PoolId)] -> Set PoolId)
-> [Item (Set PoolId)] -> Set PoolId
forall a b. (a -> b) -> a -> b
$ [Maybe PoolId] -> [PoolId]
forall a. [Maybe a] -> [a]
catMaybes [Certificate era -> Maybe PoolId
forall era. Certificate era -> Maybe PoolId
getPoolDeregistrationInfo Certificate era
cert | (Certificate era
cert, Maybe (ScriptWitness WitCtxStake era)
_) <- [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits]
        totCol :: Lovelace
totCol = Lovelace -> Maybe Lovelace -> Lovelace
forall a. a -> Maybe a -> a
fromMaybe Lovelace
0 Maybe Lovelace
plutusCollateral
        pScriptExecUnits :: Map ScriptWitnessIndex ExecutionUnits
pScriptExecUnits =
          [Item (Map ScriptWitnessIndex ExecutionUnits)]
-> Map ScriptWitnessIndex ExecutionUnits
forall l. IsList l => [Item l] -> l
fromList
            [ (ScriptWitnessIndex
sWitIndex, ExecutionUnits
execUnits)
            | (ScriptWitnessIndex
sWitIndex, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
execUnits)) <-
                ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txBodyContent
            ]

    BalancedTxBody TxBodyContent BuildTx era
_ TxBody era
balancedTxBody TxOut CtxTx era
_ Lovelace
_ <-
      Either TxCmdError (BalancedTxBody era)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (BalancedTxBody era)
 -> ExceptT TxCmdError IO (BalancedTxBody era))
-> Either TxCmdError (BalancedTxBody era)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall a b. (a -> b) -> a -> b
$
        (TxFeeEstimationError era -> TxCmdError)
-> Either (TxFeeEstimationError era) (BalancedTxBody era)
-> Either TxCmdError (BalancedTxBody era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxFeeEstimationError era -> TxCmdError
forall era. TxFeeEstimationError era -> TxCmdError
TxCmdFeeEstimationError (Either (TxFeeEstimationError era) (BalancedTxBody era)
 -> Either TxCmdError (BalancedTxBody era))
-> Either (TxFeeEstimationError era) (BalancedTxBody era)
-> Either TxCmdError (BalancedTxBody era)
forall a b. (a -> b) -> a -> b
$
          MaryEraOnwards era
-> TxBodyContent BuildTx era
-> PParams (ShelleyLedgerEra era)
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
-> Map ScriptWitnessIndex ExecutionUnits
-> Lovelace
-> Int
-> Int
-> Int
-> AddressInEra era
-> Value
-> Either (TxFeeEstimationError era) (BalancedTxBody era)
forall era.
MaryEraOnwards era
-> TxBodyContent BuildTx era
-> PParams (ShelleyLedgerEra era)
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
-> Map ScriptWitnessIndex ExecutionUnits
-> Lovelace
-> Int
-> Int
-> Int
-> AddressInEra era
-> Value
-> Either (TxFeeEstimationError era) (BalancedTxBody era)
estimateBalancedTxBody
            MaryEraOnwards era
meo
            TxBodyContent BuildTx era
txBodyContent
            PParams (ShelleyLedgerEra era)
ledgerPParams
            Set PoolId
poolsToDeregister
            Map StakeCredential Lovelace
stakeCredentialsToDeregisterMap
            Map (Credential 'DRepRole StandardCrypto) Lovelace
drepsToDeregisterMap
            Map ScriptWitnessIndex ExecutionUnits
pScriptExecUnits
            Lovelace
totCol
            Int
shelleyWitnesses
            (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
0 Maybe Int
mByronWitnesses)
            (Int
-> (ReferenceScriptSize -> Int) -> Maybe ReferenceScriptSize -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 ReferenceScriptSize -> Int
unReferenceScriptSize Maybe ReferenceScriptSize
totalReferenceScriptSize)
            (ShelleyBasedEra era -> AddressAny -> AddressInEra era
forall era. ShelleyBasedEra era -> AddressAny -> AddressInEra era
anyAddressInShelleyBasedEra ShelleyBasedEra era
sbe AddressAny
changeAddr)
            Value
totalUTxOValue

    let noWitTx :: Tx era
noWitTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
balancedTxBody
    IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
      ( CardanoEra era
-> (CardanoEraConstraints era => IO (Either (FileError ()) ()))
-> IO (Either (FileError ()) ())
forall era a.
CardanoEra era -> (CardanoEraConstraints era => a) -> a
cardanoEraConstraints (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe) ((CardanoEraConstraints era => IO (Either (FileError ()) ()))
 -> IO (Either (FileError ()) ()))
-> (CardanoEraConstraints era => IO (Either (FileError ()) ()))
-> IO (Either (FileError ()) ())
forall a b. (a -> b) -> a -> b
$
          ShelleyBasedEra era
-> TxBodyFile 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
sbe TxBodyFile 'Out
txBodyOutFile Tx era
noWitTx
      )
      ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)

getPoolDeregistrationInfo
  :: Certificate era
  -> Maybe PoolId
getPoolDeregistrationInfo :: forall era. Certificate era -> Maybe PoolId
getPoolDeregistrationInfo (ShelleyRelatedCertificate ShelleyToBabbageEra era
w ShelleyTxCert (ShelleyLedgerEra era)
cert) =
  ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era => Maybe PoolId)
-> Maybe PoolId
forall era a.
ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era => a) -> a
shelleyToBabbageEraConstraints ShelleyToBabbageEra era
w ((ShelleyToBabbageEraConstraints era => Maybe PoolId)
 -> Maybe PoolId)
-> (ShelleyToBabbageEraConstraints era => Maybe PoolId)
-> Maybe PoolId
forall a b. (a -> b) -> a -> b
$ ShelleyTxCert (ShelleyLedgerEra era) -> Maybe PoolId
forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 ShelleyEraTxCert (ShelleyLedgerEra era),
 TxCert (ShelleyLedgerEra era)
 ~ ShelleyTxCert (ShelleyLedgerEra era)) =>
ShelleyTxCert (ShelleyLedgerEra era) -> Maybe PoolId
getShelleyDeregistrationPoolId ShelleyTxCert (ShelleyLedgerEra era)
cert
getPoolDeregistrationInfo (ConwayCertificate ConwayEraOnwards era
w ConwayTxCert (ShelleyLedgerEra era)
cert) =
  ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era => Maybe PoolId)
-> Maybe PoolId
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era => Maybe PoolId) -> Maybe PoolId)
-> (ConwayEraOnwardsConstraints era => Maybe PoolId)
-> Maybe PoolId
forall a b. (a -> b) -> a -> b
$ ConwayTxCert (ShelleyLedgerEra era) -> Maybe PoolId
forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era) -> Maybe PoolId
getConwayDeregistrationPoolId ConwayTxCert (ShelleyLedgerEra era)
cert

getShelleyDeregistrationPoolId
  :: L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  => L.ShelleyEraTxCert (ShelleyLedgerEra era)
  => L.TxCert (ShelleyLedgerEra era) ~ L.ShelleyTxCert (ShelleyLedgerEra era)
  => L.ShelleyTxCert (ShelleyLedgerEra era)
  -> Maybe PoolId
getShelleyDeregistrationPoolId :: forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 ShelleyEraTxCert (ShelleyLedgerEra era),
 TxCert (ShelleyLedgerEra era)
 ~ ShelleyTxCert (ShelleyLedgerEra era)) =>
ShelleyTxCert (ShelleyLedgerEra era) -> Maybe PoolId
getShelleyDeregistrationPoolId ShelleyTxCert (ShelleyLedgerEra era)
cert = do
  case ShelleyTxCert (ShelleyLedgerEra era)
cert of
    L.RetirePoolTxCert KeyHash 'StakePool (EraCrypto (ShelleyLedgerEra era))
poolId EpochNo
_ -> PoolId -> Maybe PoolId
forall a. a -> Maybe a
Just (KeyHash 'StakePool StandardCrypto -> PoolId
StakePoolKeyHash KeyHash 'StakePool (EraCrypto (ShelleyLedgerEra era))
KeyHash 'StakePool StandardCrypto
poolId)
    ShelleyTxCert (ShelleyLedgerEra era)
_ -> Maybe PoolId
forall a. Maybe a
Nothing

getConwayDeregistrationPoolId
  :: L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  => L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe PoolId
getConwayDeregistrationPoolId :: forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era) -> Maybe PoolId
getConwayDeregistrationPoolId ConwayTxCert (ShelleyLedgerEra era)
cert = do
  case ConwayTxCert (ShelleyLedgerEra era)
cert of
    L.RetirePoolTxCert KeyHash 'StakePool (EraCrypto (ShelleyLedgerEra era))
poolId EpochNo
_ -> PoolId -> Maybe PoolId
forall a. a -> Maybe a
Just (KeyHash 'StakePool StandardCrypto -> PoolId
StakePoolKeyHash KeyHash 'StakePool (EraCrypto (ShelleyLedgerEra era))
KeyHash 'StakePool StandardCrypto
poolId)
    ConwayTxCert (ShelleyLedgerEra era)
_ -> Maybe PoolId
forall a. Maybe a
Nothing

getDRepDeregistrationInfo
  :: Certificate era
  -> Maybe (L.Credential L.DRepRole L.StandardCrypto, Lovelace)
getDRepDeregistrationInfo :: forall era.
Certificate era
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
getDRepDeregistrationInfo ShelleyRelatedCertificate{} = Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall a. Maybe a
Nothing
getDRepDeregistrationInfo (ConwayCertificate ConwayEraOnwards era
w ConwayTxCert (ShelleyLedgerEra era)
cert) =
  ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Maybe (Credential 'DRepRole StandardCrypto, Lovelace))
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  Maybe (Credential 'DRepRole StandardCrypto, Lovelace))
 -> Maybe (Credential 'DRepRole StandardCrypto, Lovelace))
-> (ConwayEraOnwardsConstraints era =>
    Maybe (Credential 'DRepRole StandardCrypto, Lovelace))
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall a b. (a -> b) -> a -> b
$ ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
getConwayDRepDeregistrationInfo ConwayTxCert (ShelleyLedgerEra era)
cert

getConwayDRepDeregistrationInfo
  :: L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  => L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe (L.Credential L.DRepRole L.StandardCrypto, Lovelace)
getConwayDRepDeregistrationInfo :: forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
getConwayDRepDeregistrationInfo = TxCert (ShelleyLedgerEra era)
-> Maybe
     (Credential 'DRepRole (EraCrypto (ShelleyLedgerEra era)), Lovelace)
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole StandardCrypto, Lovelace)
forall era.
ConwayEraTxCert era =>
TxCert era
-> Maybe (Credential 'DRepRole (EraCrypto era), Lovelace)
L.getUnRegDRepTxCert

getStakeDeregistrationInfo
  :: Certificate era
  -> Maybe (StakeCredential, Lovelace)
getStakeDeregistrationInfo :: forall era. Certificate era -> Maybe (StakeCredential, Lovelace)
getStakeDeregistrationInfo (ShelleyRelatedCertificate ShelleyToBabbageEra era
w ShelleyTxCert (ShelleyLedgerEra era)
cert) =
  ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era =>
    Maybe (StakeCredential, Lovelace))
-> Maybe (StakeCredential, Lovelace)
forall era a.
ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era => a) -> a
shelleyToBabbageEraConstraints ShelleyToBabbageEra era
w ((ShelleyToBabbageEraConstraints era =>
  Maybe (StakeCredential, Lovelace))
 -> Maybe (StakeCredential, Lovelace))
-> (ShelleyToBabbageEraConstraints era =>
    Maybe (StakeCredential, Lovelace))
-> Maybe (StakeCredential, Lovelace)
forall a b. (a -> b) -> a -> b
$ ShelleyTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 ShelleyEraTxCert (ShelleyLedgerEra era),
 TxCert (ShelleyLedgerEra era)
 ~ ShelleyTxCert (ShelleyLedgerEra era)) =>
ShelleyTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
getShelleyDeregistrationInfo ShelleyTxCert (ShelleyLedgerEra era)
cert
getStakeDeregistrationInfo (ConwayCertificate ConwayEraOnwards era
w ConwayTxCert (ShelleyLedgerEra era)
cert) =
  ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Maybe (StakeCredential, Lovelace))
-> Maybe (StakeCredential, Lovelace)
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  Maybe (StakeCredential, Lovelace))
 -> Maybe (StakeCredential, Lovelace))
-> (ConwayEraOnwardsConstraints era =>
    Maybe (StakeCredential, Lovelace))
-> Maybe (StakeCredential, Lovelace)
forall a b. (a -> b) -> a -> b
$ ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
getConwayDeregistrationInfo ConwayTxCert (ShelleyLedgerEra era)
cert

-- There for no deposits required pre-conway for registering stake
-- credentials.
getShelleyDeregistrationInfo
  :: L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  => L.ShelleyEraTxCert (ShelleyLedgerEra era)
  => L.TxCert (ShelleyLedgerEra era) ~ L.ShelleyTxCert (ShelleyLedgerEra era)
  => L.ShelleyTxCert (ShelleyLedgerEra era)
  -> Maybe (StakeCredential, Lovelace)
getShelleyDeregistrationInfo :: forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 ShelleyEraTxCert (ShelleyLedgerEra era),
 TxCert (ShelleyLedgerEra era)
 ~ ShelleyTxCert (ShelleyLedgerEra era)) =>
ShelleyTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
getShelleyDeregistrationInfo ShelleyTxCert (ShelleyLedgerEra era)
cert = do
  case ShelleyTxCert (ShelleyLedgerEra era)
cert of
    L.UnRegTxCert StakeCredential (EraCrypto (ShelleyLedgerEra era))
stakeCred -> (StakeCredential, Lovelace) -> Maybe (StakeCredential, Lovelace)
forall a. a -> Maybe a
Just (StakeCredential StandardCrypto -> StakeCredential
fromShelleyStakeCredential StakeCredential (EraCrypto (ShelleyLedgerEra era))
StakeCredential StandardCrypto
stakeCred, Lovelace
0)
    ShelleyTxCert (ShelleyLedgerEra era)
_ -> Maybe (StakeCredential, Lovelace)
forall a. Maybe a
Nothing

getConwayDeregistrationInfo
  :: L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  => L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe (StakeCredential, Lovelace)
getConwayDeregistrationInfo :: forall era.
(EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto,
 TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (StakeCredential, Lovelace)
getConwayDeregistrationInfo ConwayTxCert (ShelleyLedgerEra era)
cert = do
  case ConwayTxCert (ShelleyLedgerEra era)
cert of
    L.UnRegDepositTxCert StakeCredential (EraCrypto (ShelleyLedgerEra era))
stakeCred Lovelace
depositRefund -> (StakeCredential, Lovelace) -> Maybe (StakeCredential, Lovelace)
forall a. a -> Maybe a
Just (StakeCredential StandardCrypto -> StakeCredential
fromShelleyStakeCredential StakeCredential (EraCrypto (ShelleyLedgerEra era))
StakeCredential StandardCrypto
stakeCred, Lovelace
depositRefund)
    ConwayTxCert (ShelleyLedgerEra era)
_ -> Maybe (StakeCredential, Lovelace)
forall a. Maybe a
Nothing

getExecutionUnitPrices :: CardanoEra era -> LedgerProtocolParameters era -> Maybe L.Prices
getExecutionUnitPrices :: forall era.
CardanoEra era -> LedgerProtocolParameters era -> Maybe Prices
getExecutionUnitPrices CardanoEra era
cEra (LedgerProtocolParameters PParams (ShelleyLedgerEra era)
pp) =
  CardanoEra era -> (AlonzoEraOnwards era -> Prices) -> Maybe Prices
forall (eon :: * -> *) era a.
Eon eon =>
CardanoEra era -> (eon era -> a) -> Maybe a
forEraInEonMaybe CardanoEra era
cEra ((AlonzoEraOnwards era -> Prices) -> Maybe Prices)
-> (AlonzoEraOnwards era -> Prices) -> Maybe Prices
forall a b. (a -> b) -> a -> b
$ \AlonzoEraOnwards era
aeo ->
    AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era => Prices) -> Prices
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
aeo ((AlonzoEraOnwardsConstraints era => Prices) -> Prices)
-> (AlonzoEraOnwardsConstraints era => Prices) -> Prices
forall a b. (a -> b) -> a -> b
$
      PParams (ShelleyLedgerEra era)
pp PParams (ShelleyLedgerEra era)
-> Getting Prices (PParams (ShelleyLedgerEra era)) Prices -> Prices
forall s a. s -> Getting a s a -> a
^. Getting Prices (PParams (ShelleyLedgerEra era)) Prices
forall era. AlonzoEraPParams era => Lens' (PParams era) Prices
Lens' (PParams (ShelleyLedgerEra era)) Prices
L.ppPricesL

runTransactionBuildRawCmd
  :: ()
  => Cmd.TransactionBuildRawCmdArgs era
  -> ExceptT TxCmdError IO ()
runTransactionBuildRawCmd :: forall era.
TransactionBuildRawCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionBuildRawCmd
  Cmd.TransactionBuildRawCmdArgs
    { ShelleyBasedEra era
eon :: ShelleyBasedEra era
eon :: forall era. TransactionBuildRawCmdArgs era -> ShelleyBasedEra era
eon
    , Maybe ScriptValidity
mScriptValidity :: Maybe ScriptValidity
mScriptValidity :: forall era. TransactionBuildRawCmdArgs era -> Maybe ScriptValidity
mScriptValidity
    , [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txIns :: [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txIns :: forall era.
TransactionBuildRawCmdArgs era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txIns
    , [TxIn]
readOnlyRefIns :: [TxIn]
readOnlyRefIns :: forall era. TransactionBuildRawCmdArgs era -> [TxIn]
readOnlyRefIns
    , [TxIn]
txInsCollateral :: [TxIn]
txInsCollateral :: forall era. TransactionBuildRawCmdArgs era -> [TxIn]
txInsCollateral
    , mReturnCollateral :: forall era.
TransactionBuildRawCmdArgs era -> Maybe TxOutShelleyBasedEra
mReturnCollateral = Maybe TxOutShelleyBasedEra
mReturnColl
    , Maybe Lovelace
mTotalCollateral :: Maybe Lovelace
mTotalCollateral :: forall era. TransactionBuildRawCmdArgs era -> Maybe Lovelace
mTotalCollateral
    , requiredSigners :: forall era. TransactionBuildRawCmdArgs era -> [RequiredSigner]
requiredSigners = [RequiredSigner]
reqSigners
    , [TxOutAnyEra]
txouts :: [TxOutAnyEra]
txouts :: forall era. TransactionBuildRawCmdArgs era -> [TxOutAnyEra]
txouts
    , Maybe (Value, [CliMintScriptRequirements])
mValue :: Maybe (Value, [CliMintScriptRequirements])
mValue :: forall era.
TransactionBuildRawCmdArgs era
-> Maybe (Value, [CliMintScriptRequirements])
mValue
    , Maybe SlotNo
mValidityLowerBound :: Maybe SlotNo
mValidityLowerBound :: forall era. TransactionBuildRawCmdArgs era -> Maybe SlotNo
mValidityLowerBound
    , TxValidityUpperBound era
mValidityUpperBound :: TxValidityUpperBound era
mValidityUpperBound :: forall era.
TransactionBuildRawCmdArgs era -> TxValidityUpperBound era
mValidityUpperBound
    , Lovelace
fee :: Lovelace
fee :: forall era. TransactionBuildRawCmdArgs era -> Lovelace
fee
    , [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates :: forall era.
TransactionBuildRawCmdArgs era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates
    , [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals :: forall era.
TransactionBuildRawCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    , TxMetadataJsonSchema
metadataSchema :: TxMetadataJsonSchema
metadataSchema :: forall era. TransactionBuildRawCmdArgs era -> TxMetadataJsonSchema
metadataSchema
    , [ScriptFile]
scriptFiles :: [ScriptFile]
scriptFiles :: forall era. TransactionBuildRawCmdArgs era -> [ScriptFile]
scriptFiles
    , [MetadataFile]
metadataFiles :: [MetadataFile]
metadataFiles :: forall era. TransactionBuildRawCmdArgs era -> [MetadataFile]
metadataFiles
    , Maybe ProtocolParamsFile
mProtocolParamsFile :: Maybe ProtocolParamsFile
mProtocolParamsFile :: forall era.
TransactionBuildRawCmdArgs era -> Maybe ProtocolParamsFile
mProtocolParamsFile
    , Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProprosalFile :: Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProprosalFile :: forall era.
TransactionBuildRawCmdArgs era
-> Maybe
     (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProprosalFile
    , [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles :: forall era.
TransactionBuildRawCmdArgs era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles
    , [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles :: forall era.
TransactionBuildRawCmdArgs era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles
    , Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation :: Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation :: forall era.
TransactionBuildRawCmdArgs era
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation
    , TxBodyFile 'Out
txBodyOutFile :: TxBodyFile 'Out
txBodyOutFile :: forall era. TransactionBuildRawCmdArgs era -> TxBodyFile 'Out
txBodyOutFile
    } = do
    [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
 -> ExceptT
      TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> ExceptT
     TxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ScriptWitnessError
     IO
     [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
eon [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txIns
    [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
forall era a ctx.
ShelleyBasedEra era
-> [(a, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, Maybe (ScriptWitness ctx era))]
readScriptWitnessFiles ShelleyBasedEra era
eon [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certificates

    [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits <-
      (ScriptWitnessError -> TxCmdError)
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptWitnessError -> TxCmdError
TxCmdScriptWitnessError (ExceptT
   ScriptWitnessError
   IO
   [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ScriptWitnessError
     IO
     [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
forall era a b ctx.
ShelleyBasedEra era
-> [(a, b, Maybe (ScriptWitnessFiles ctx))]
-> ExceptT
     ScriptWitnessError IO [(a, b, Maybe (ScriptWitness ctx era))]
readScriptWitnessFilesTuple ShelleyBasedEra era
eon [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    TxMetadataInEra era
txMetadata <-
      (MetadataError -> TxCmdError)
-> ExceptT MetadataError IO (TxMetadataInEra era)
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT MetadataError -> TxCmdError
TxCmdMetadataError
        (ExceptT MetadataError IO (TxMetadataInEra era)
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> (IO (Either MetadataError (TxMetadataInEra era))
    -> ExceptT MetadataError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT MetadataError IO (TxMetadataInEra era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
        (IO (Either MetadataError (TxMetadataInEra era))
 -> ExceptT TxCmdError IO (TxMetadataInEra era))
-> IO (Either MetadataError (TxMetadataInEra era))
-> ExceptT TxCmdError IO (TxMetadataInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
readTxMetadata ShelleyBasedEra era
eon TxMetadataJsonSchema
metadataSchema [MetadataFile]
metadataFiles

    let (Value
mas, [CliMintScriptRequirements]
sWitFiles) = (Value, [CliMintScriptRequirements])
-> Maybe (Value, [CliMintScriptRequirements])
-> (Value, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (Value
forall a. Monoid a => a
mempty, [CliMintScriptRequirements]
forall a. Monoid a => a
mempty) Maybe (Value, [CliMintScriptRequirements])
mValue
    (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits <-
      (Value
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (Value, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (Value, [MintScriptWitnessWithPolicyId era])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError ((CliMintScriptRequirements
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (MintScriptWitnessWithPolicyId era))
-> [CliMintScriptRequirements]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [MintScriptWitnessWithPolicyId era]
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 (ShelleyBasedEra era
-> CliMintScriptRequirements
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (MintScriptWitnessWithPolicyId era)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> CliMintScriptRequirements
-> t m (MintScriptWitnessWithPolicyId era)
readMintScriptWitness ShelleyBasedEra era
eon) [CliMintScriptRequirements]
sWitFiles)

    [ScriptInAnyLang]
scripts <-
      (FileError ScriptDecodeError -> TxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> TxCmdError
TxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
 -> ExceptT TxCmdError IO [ScriptInAnyLang])
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
-> ExceptT TxCmdError IO [ScriptInAnyLang]
forall a b. (a -> b) -> a -> b
$
        (ScriptFile
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> [ScriptFile]
-> ExceptT (FileError ScriptDecodeError) IO [ScriptInAnyLang]
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 (FilePath
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
MonadIOTransError (FileError ScriptDecodeError) t m =>
FilePath -> t m ScriptInAnyLang
readFileScriptInAnyLang (FilePath
 -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang)
-> (ScriptFile -> FilePath)
-> ScriptFile
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptFile -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile) [ScriptFile]
scriptFiles
    TxAuxScripts era
txAuxScripts <-
      Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxAuxScripts era)
 -> ExceptT TxCmdError IO (TxAuxScripts era))
-> Either TxCmdError (TxAuxScripts era)
-> ExceptT TxCmdError IO (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ (TxAuxScriptsValidationError -> TxCmdError)
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxAuxScriptsValidationError -> TxCmdError
TxCmdAuxScriptsValidationError (Either TxAuxScriptsValidationError (TxAuxScripts era)
 -> Either TxCmdError (TxAuxScripts era))
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
-> Either TxCmdError (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
forall era.
ShelleyBasedEra era
-> [ScriptInAnyLang]
-> Either TxAuxScriptsValidationError (TxAuxScripts era)
validateTxAuxScripts ShelleyBasedEra era
eon [ScriptInAnyLang]
scripts

    Maybe (PParams (ShelleyLedgerEra era))
pparams <- Maybe ProtocolParamsFile
-> (ProtocolParamsFile
    -> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era)))
-> ExceptT TxCmdError IO (Maybe (PParams (ShelleyLedgerEra era)))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Maybe ProtocolParamsFile
mProtocolParamsFile ((ProtocolParamsFile
  -> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era)))
 -> ExceptT TxCmdError IO (Maybe (PParams (ShelleyLedgerEra era))))
-> (ProtocolParamsFile
    -> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era)))
-> ExceptT TxCmdError IO (Maybe (PParams (ShelleyLedgerEra era)))
forall a b. (a -> b) -> a -> b
$ \ProtocolParamsFile
ppf ->
      (ProtocolParamsError -> TxCmdError)
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ProtocolParamsError -> TxCmdError
TxCmdProtocolParamsError (ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
readProtocolParameters ShelleyBasedEra era
eon ProtocolParamsFile
ppf)

    let mLedgerPParams :: Maybe (LedgerProtocolParameters era)
mLedgerPParams = PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
forall era.
PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
LedgerProtocolParameters (PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era)
-> Maybe (PParams (ShelleyLedgerEra era))
-> Maybe (LedgerProtocolParameters era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (PParams (ShelleyLedgerEra era))
pparams

    TxUpdateProposal era
txUpdateProposal <- case Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
mUpdateProprosalFile of
      Just (Featured ShelleyToBabbageEra era
w (Just UpdateProposalFile
updateProposalFile)) ->
        ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
forall era.
ShelleyToBabbageEra era
-> UpdateProposalFile
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
readTxUpdateProposal ShelleyToBabbageEra era
w UpdateProposalFile
updateProposalFile ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> (ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
    -> ExceptT TxCmdError IO (TxUpdateProposal era))
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxUpdateProposal era)
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError
      Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile))
_ -> TxUpdateProposal era
-> ExceptT TxCmdError IO (TxUpdateProposal era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone

    [Hash PaymentKey]
requiredSigners <-
      (RequiredSigner -> ExceptT TxCmdError IO (Hash PaymentKey))
-> [RequiredSigner] -> ExceptT TxCmdError IO [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 ((RequiredSignerError -> TxCmdError)
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT RequiredSignerError -> TxCmdError
TxCmdRequiredSignerError (ExceptT RequiredSignerError IO (Hash PaymentKey)
 -> ExceptT TxCmdError IO (Hash PaymentKey))
-> (RequiredSigner
    -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> RequiredSigner
-> ExceptT TxCmdError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either RequiredSignerError (Hash PaymentKey))
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either RequiredSignerError (Hash PaymentKey))
 -> ExceptT RequiredSignerError IO (Hash PaymentKey))
-> (RequiredSigner
    -> IO (Either RequiredSignerError (Hash PaymentKey)))
-> RequiredSigner
-> ExceptT RequiredSignerError IO (Hash PaymentKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner) [RequiredSigner]
reqSigners

    Maybe (TxOut CtxTx era)
mReturnCollateral <- (TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> Maybe TxOutShelleyBasedEra
-> ExceptT TxCmdError IO (Maybe (TxOut CtxTx era))
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) -> Maybe a -> m (Maybe b)
mapM (ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra ShelleyBasedEra era
eon) Maybe TxOutShelleyBasedEra
mReturnColl

    [TxOut CtxTx era]
txOuts <- (TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> [TxOutAnyEra] -> ExceptT TxCmdError IO [TxOut CtxTx era]
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 (ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra ShelleyBasedEra era
eon) [TxOutAnyEra]
txouts

    -- the same collateral input can be used for several plutus scripts
    let filteredTxinsc :: [Item (Set TxIn)]
filteredTxinsc = forall l. IsList l => l -> [Item l]
toList @(Set _) (Set TxIn -> [Item (Set TxIn)]) -> Set TxIn -> [Item (Set TxIn)]
forall a b. (a -> b) -> a -> b
$ [Item (Set TxIn)] -> Set TxIn
forall l. IsList l => [Item l] -> l
fromList [Item (Set TxIn)]
[TxIn]
txInsCollateral

    -- Conway related
    [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ShelleyBasedEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> ShelleyBasedEra era -> a
inEonForShelleyBasedEra
        ([(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a. Monoid a => a
mempty)
        ( \ConwayEraOnwards era
w ->
            (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT VoteError -> TxCmdError
TxCmdVoteError (ExceptT
   VoteError
   IO
   [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> (IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
    -> ExceptT
         VoteError
         IO
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO
  (Either
     VoteError
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (IO
   (Either
      VoteError
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
              ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  IO
    (Either
       VoteError
       [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
 -> IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError
         [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]))
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall a b. (a -> b) -> a -> b
$
                ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        VoteError
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
voteFiles
        )
        ShelleyBasedEra era
eon

    [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals <-
      IO
  (Either
     ProposalError
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
-> IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
readTxGovernanceActions ShelleyBasedEra era
eon [(ProposalFile 'In, Maybe (ScriptWitnessFiles WitCtxStake))]
proposalFiles)
        ExceptT
  TxCmdError
  IO
  (Either
     ProposalError
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> (ExceptT
      TxCmdError
      IO
      (Either
         ProposalError
         [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
    -> ExceptT
         TxCmdError
         IO
         [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. a -> (a -> b) -> b
& (ProposalError
 -> ExceptT
      TxCmdError
      IO
      [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      [(Proposal era, Maybe (ScriptWitness WitCtxStake era))])
-> (ProposalError -> TxCmdError)
-> ProposalError
-> ExceptT
     TxCmdError
     IO
     [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProposalError -> TxCmdError
TxCmdProposalError)

    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits <-
      ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
eon ((ShelleyBasedEraConstraints era =>
  ExceptT
    TxCmdError
    IO
    [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
 -> ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> (ShelleyBasedEraConstraints era =>
    ExceptT
      TxCmdError
      IO
      [(Certificate era, Maybe (ScriptWitness WitCtxStake era))])
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
        [ExceptT
   TxCmdError
   IO
   (Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> ExceptT
     TxCmdError
     IO
     [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence
          [ (Certificate era
 -> (Certificate era, Maybe (ScriptWitness WitCtxStake era)))
-> ExceptT TxCmdError IO (Certificate era)
-> ExceptT
     TxCmdError
     IO
     (Certificate era, Maybe (ScriptWitness WitCtxStake era))
forall a b.
(a -> b) -> ExceptT TxCmdError IO a -> ExceptT TxCmdError IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
              (,Maybe (ScriptWitness WitCtxStake era)
mSwit)
              ( (FileError TextEnvelopeError -> TxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
-> ExceptT TxCmdError IO (Certificate era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> TxCmdError
TxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO (Certificate era)
 -> ExceptT TxCmdError IO (Certificate era))
-> (IO (Either (FileError TextEnvelopeError) (Certificate era))
    -> ExceptT (FileError TextEnvelopeError) IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT (FileError TextEnvelopeError) IO (Certificate era)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (Certificate era))
 -> ExceptT TxCmdError IO (Certificate era))
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
-> ExceptT TxCmdError IO (Certificate era)
forall a b. (a -> b) -> a -> b
$
                  AsType (Certificate era)
-> File Any 'In
-> IO (Either (FileError TextEnvelopeError) (Certificate era))
forall a content.
HasTextEnvelope a =>
AsType a
-> File content 'In -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType (Certificate era)
forall era. AsType (Certificate era)
AsCertificate (FilePath -> File Any 'In
forall content (direction :: FileDirection).
FilePath -> File content direction
File FilePath
certFile)
              )
          | (CertificateFile FilePath
certFile, Maybe (ScriptWitness WitCtxStake era)
mSwit) <- [(CertificateFile, Maybe (ScriptWitness WitCtxStake era))]
certFilesAndMaybeScriptWits
          ]
    TxBody era
txBody <-
      Either TxCmdError (TxBody era)
-> ExceptT TxCmdError IO (TxBody era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxBody era)
 -> ExceptT TxCmdError IO (TxBody era))
-> Either TxCmdError (TxBody era)
-> ExceptT TxCmdError IO (TxBody era)
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
runTxBuildRaw
          ShelleyBasedEra era
eon
          Maybe ScriptValidity
mScriptValidity
          [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
          [TxIn]
readOnlyRefIns
          [Item (Set TxIn)]
[TxIn]
filteredTxinsc
          Maybe (TxOut CtxTx era)
mReturnCollateral
          Maybe Lovelace
mTotalCollateral
          [TxOut CtxTx era]
txOuts
          Maybe SlotNo
mValidityLowerBound
          TxValidityUpperBound era
mValidityUpperBound
          Lovelace
fee
          (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
          [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
          [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawalsAndMaybeScriptWits
          [Hash PaymentKey]
requiredSigners
          TxAuxScripts era
txAuxScripts
          TxMetadataInEra era
txMetadata
          Maybe (LedgerProtocolParameters era)
mLedgerPParams
          TxUpdateProposal era
txUpdateProposal
          [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits
          [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
          Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
currentTreasuryValueAndDonation

    let noWitTx :: Tx era
noWitTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
txBody
    IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> TxBodyFile 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
eon TxBodyFile 'Out
txBodyOutFile Tx era
noWitTx)
      ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)

runTxBuildRaw
  :: ()
  => ShelleyBasedEra era
  -> Maybe ScriptValidity
  -- ^ Mark script as expected to pass or fail validation
  -> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
  -- ^ TxIn with potential script witness
  -> [TxIn]
  -- ^ Read only reference inputs
  -> [TxIn]
  -- ^ TxIn for collateral
  -> Maybe (TxOut CtxTx era)
  -- ^ Return collateral
  -> Maybe Lovelace
  -- ^ Total collateral
  -> [TxOut CtxTx era]
  -> Maybe SlotNo
  -- ^ Tx lower bound
  -> TxValidityUpperBound era
  -- ^ Tx upper bound
  -> Lovelace
  -- ^ Tx fee
  -> (Value, [MintScriptWitnessWithPolicyId era])
  -- ^ Multi-Asset value(s)
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> Maybe (LedgerProtocolParameters era)
  -> TxUpdateProposal era
  -> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
  -> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
  -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
  -> Either TxCmdError (TxBody era)
runTxBuildRaw :: forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
runTxBuildRaw
  ShelleyBasedEra era
sbe
  Maybe ScriptValidity
mScriptValidity
  [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
  [TxIn]
readOnlyRefIns
  [TxIn]
txinsc
  Maybe (TxOut CtxTx era)
mReturnCollateral
  Maybe Lovelace
mTotCollateral
  [TxOut CtxTx era]
txouts
  Maybe SlotNo
mLowerBound
  TxValidityUpperBound era
mUpperBound
  Lovelace
fee
  (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeSriptWits
  [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  Maybe (LedgerProtocolParameters era)
mpparams
  TxUpdateProposal era
txUpdateProposal
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
  [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
  Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation = do
    TxBodyContent BuildTx era
txBodyContent <-
      ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent
        ShelleyBasedEra era
sbe
        Maybe ScriptValidity
mScriptValidity
        (LedgerProtocolParameters era -> PParams (ShelleyLedgerEra era)
forall era.
LedgerProtocolParameters era -> PParams (ShelleyLedgerEra era)
unLedgerProtocolParameters (LedgerProtocolParameters era -> PParams (ShelleyLedgerEra era))
-> Maybe (LedgerProtocolParameters era)
-> Maybe (PParams (ShelleyLedgerEra era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LedgerProtocolParameters era)
mpparams)
        [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
        [TxIn]
readOnlyRefIns
        [TxIn]
txinsc
        Maybe (TxOut CtxTx era)
mReturnCollateral
        Maybe Lovelace
mTotCollateral
        [TxOut CtxTx era]
txouts
        Maybe SlotNo
mLowerBound
        TxValidityUpperBound era
mUpperBound
        (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
        [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeSriptWits
        [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
        [Hash PaymentKey]
reqSigners
        Lovelace
fee
        TxAuxScripts era
txAuxScripts
        TxMetadataInEra era
txMetadata
        TxUpdateProposal era
txUpdateProposal
        [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
        [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
        Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation

    (TxBodyError -> TxCmdError)
-> Either TxBodyError (TxBody era)
-> Either TxCmdError (TxBody era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxBodyError -> TxCmdError
TxCmdTxBodyError (Either TxBodyError (TxBody era) -> Either TxCmdError (TxBody era))
-> Either TxBodyError (TxBody era)
-> Either TxCmdError (TxBody era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
createTransactionBody ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txBodyContent

constructTxBodyContent
  :: forall era
   . ShelleyBasedEra era
  -> Maybe ScriptValidity
  -> Maybe (L.PParams (ShelleyLedgerEra era))
  -> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
  -- ^ TxIn with potential script witness
  -> [TxIn]
  -- ^ Read only reference inputs
  -> [TxIn]
  -- ^ TxIn for collateral
  -> Maybe (TxOut CtxTx era)
  -- ^ Return collateral
  -> Maybe Lovelace
  -- ^ Total collateral
  -> [TxOut CtxTx era]
  -- ^ Normal outputs
  -> Maybe SlotNo
  -- ^ Tx lower bound
  -> TxValidityUpperBound era
  -- ^ Tx upper bound
  -> (Value, [MintScriptWitnessWithPolicyId era])
  -- ^ Multi-Asset value(s)
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Withdrawals
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> Lovelace
  -- ^ Tx fee
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> TxUpdateProposal era
  -> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
  -> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
  -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
  -- ^ The current treasury value and the donation. This is a stop gap as the
  -- semantics of the donation and treasury value depend on the script languages
  -- being used.
  -> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent :: forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent
  ShelleyBasedEra era
sbe
  Maybe ScriptValidity
mScriptValidity
  Maybe (PParams (ShelleyLedgerEra era))
mPparams
  [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
  [TxIn]
readOnlyRefIns
  [TxIn]
txinsc
  Maybe (TxOut CtxTx era)
mReturnCollateral
  Maybe Lovelace
mTotCollateral
  [TxOut CtxTx era]
txouts
  Maybe SlotNo
mLowerBound
  TxValidityUpperBound era
mUpperBound
  (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
  [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  Lovelace
fee
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  TxUpdateProposal era
txUpdateProposal
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
  [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
  Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation =
    do
      let allReferenceInputs :: [TxIn]
allReferenceInputs =
            [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
              [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
              ((MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era)
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> [a] -> [b]
map MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
forall era.
MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
mswScriptWitness ([MintScriptWitnessWithPolicyId era]
 -> [ScriptWitness WitCtxMint era])
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> a -> b
$ (Value, [MintScriptWitnessWithPolicyId era])
-> [MintScriptWitnessWithPolicyId era]
forall a b. (a, b) -> b
snd (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits)
              [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
              [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
              [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
              [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
              [TxIn]
readOnlyRefIns

      TxInsCollateral era
validatedCollateralTxIns <- ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsCollateral era)
forall era.
ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsCollateral era)
validateTxInsCollateral ShelleyBasedEra era
sbe [TxIn]
txinsc
      TxInsReference era
validatedRefInputs <- ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsReference era)
forall era.
ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsReference era)
validateTxInsReference ShelleyBasedEra era
sbe [TxIn]
allReferenceInputs
      TxTotalCollateral era
validatedTotCollateral <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era) (TxTotalCollateral era)
-> Either TxCmdError (TxTotalCollateral era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError (Either
   (TxNotSupportedInEraValidationError era) (TxTotalCollateral era)
 -> Either TxCmdError (TxTotalCollateral era))
-> Either
     (TxNotSupportedInEraValidationError era) (TxTotalCollateral era)
-> Either TxCmdError (TxTotalCollateral era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe Lovelace
-> Either
     (TxNotSupportedInEraValidationError era) (TxTotalCollateral era)
forall era.
ShelleyBasedEra era
-> Maybe Lovelace
-> Either
     (TxNotSupportedInEraValidationError era) (TxTotalCollateral era)
validateTxTotalCollateral ShelleyBasedEra era
sbe Maybe Lovelace
mTotCollateral
      TxReturnCollateral CtxTx era
validatedRetCol <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era)
     (TxReturnCollateral CtxTx era)
-> Either TxCmdError (TxReturnCollateral CtxTx era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError (Either
   (TxNotSupportedInEraValidationError era)
   (TxReturnCollateral CtxTx era)
 -> Either TxCmdError (TxReturnCollateral CtxTx era))
-> Either
     (TxNotSupportedInEraValidationError era)
     (TxReturnCollateral CtxTx era)
-> Either TxCmdError (TxReturnCollateral CtxTx era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe (TxOut CtxTx era)
-> Either
     (TxNotSupportedInEraValidationError era)
     (TxReturnCollateral CtxTx era)
forall era.
ShelleyBasedEra era
-> Maybe (TxOut CtxTx era)
-> Either
     (TxNotSupportedInEraValidationError era)
     (TxReturnCollateral CtxTx era)
validateTxReturnCollateral ShelleyBasedEra era
sbe Maybe (TxOut CtxTx era)
mReturnCollateral
      let txFee :: TxFee era
txFee = ShelleyBasedEra era -> Lovelace -> TxFee era
forall era. ShelleyBasedEra era -> Lovelace -> TxFee era
TxFeeExplicit ShelleyBasedEra era
sbe Lovelace
fee
      TxValidityLowerBound era
validatedLowerBound <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era) (TxValidityLowerBound era)
-> Either TxCmdError (TxValidityLowerBound era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError (Either
   (TxNotSupportedInEraValidationError era) (TxValidityLowerBound era)
 -> Either TxCmdError (TxValidityLowerBound era))
-> Either
     (TxNotSupportedInEraValidationError era) (TxValidityLowerBound era)
-> Either TxCmdError (TxValidityLowerBound era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe SlotNo
-> Either
     (TxNotSupportedInEraValidationError era) (TxValidityLowerBound era)
forall era.
ShelleyBasedEra era
-> Maybe SlotNo
-> Either
     (TxNotSupportedInEraValidationError era) (TxValidityLowerBound era)
validateTxValidityLowerBound ShelleyBasedEra era
sbe Maybe SlotNo
mLowerBound
      TxExtraKeyWitnesses era
validatedReqSigners <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era) (TxExtraKeyWitnesses era)
-> Either TxCmdError (TxExtraKeyWitnesses era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError (Either
   (TxNotSupportedInEraValidationError era) (TxExtraKeyWitnesses era)
 -> Either TxCmdError (TxExtraKeyWitnesses era))
-> Either
     (TxNotSupportedInEraValidationError era) (TxExtraKeyWitnesses era)
-> Either TxCmdError (TxExtraKeyWitnesses era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [Hash PaymentKey]
-> Either
     (TxNotSupportedInEraValidationError era) (TxExtraKeyWitnesses era)
forall era.
ShelleyBasedEra era
-> [Hash PaymentKey]
-> Either
     (TxNotSupportedInEraValidationError era) (TxExtraKeyWitnesses era)
validateRequiredSigners ShelleyBasedEra era
sbe [Hash PaymentKey]
reqSigners
      TxMintValue BuildTx era
validatedMintValue <- ShelleyBasedEra era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
forall era.
ShelleyBasedEra era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue ShelleyBasedEra era
sbe (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
      TxScriptValidity era
validatedTxScriptValidity <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era) (TxScriptValidity era)
-> Either TxCmdError (TxScriptValidity era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError (Either
   (TxNotSupportedInEraValidationError era) (TxScriptValidity era)
 -> Either TxCmdError (TxScriptValidity era))
-> Either
     (TxNotSupportedInEraValidationError era) (TxScriptValidity era)
-> Either TxCmdError (TxScriptValidity era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe ScriptValidity
-> Either
     (TxNotSupportedInEraValidationError era) (TxScriptValidity era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Either
     (TxNotSupportedInEraValidationError era) (TxScriptValidity era)
validateTxScriptValidity ShelleyBasedEra era
sbe Maybe ScriptValidity
mScriptValidity
      TxVotingProcedures BuildTx era
validatedVotingProcedures <-
        (VotesMergingConflict era -> TxCmdError)
-> Either
     (VotesMergingConflict era) (TxVotingProcedures BuildTx era)
-> Either TxCmdError (TxVotingProcedures BuildTx era)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (TxGovDuplicateVotes era -> TxCmdError
forall era. TxGovDuplicateVotes era -> TxCmdError
TxCmdTxGovDuplicateVotes (TxGovDuplicateVotes era -> TxCmdError)
-> (VotesMergingConflict era -> TxGovDuplicateVotes era)
-> VotesMergingConflict era
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VotesMergingConflict era -> TxGovDuplicateVotes era
forall era. VotesMergingConflict era -> TxGovDuplicateVotes era
TxGovDuplicateVotes) (Either (VotesMergingConflict era) (TxVotingProcedures BuildTx era)
 -> Either TxCmdError (TxVotingProcedures BuildTx era))
-> Either
     (VotesMergingConflict era) (TxVotingProcedures BuildTx era)
-> Either TxCmdError (TxVotingProcedures BuildTx era)
forall a b. (a -> b) -> a -> b
$
          forall build era.
Applicative (BuildTxWith build) =>
[(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
mkTxVotingProcedures @BuildTx ([Item
   [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
forall l. IsList l => [Item l] -> l
fromList [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
[Item
   [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]]
votingProcedures)
      let txProposals :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposals = ShelleyBasedEra era
-> (ConwayEraOnwards era
    -> Featured
         ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
sbe ((ConwayEraOnwards era
  -> Featured
       ConwayEraOnwards era (TxProposalProcedures BuildTx era))
 -> Maybe
      (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)))
-> (ConwayEraOnwards era
    -> Featured
         ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w -> do
            let txp :: TxProposalProcedures BuildTx era
                txp :: TxProposalProcedures BuildTx era
txp = ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  TxProposalProcedures BuildTx era)
 -> TxProposalProcedures BuildTx era)
-> (ConwayEraOnwardsConstraints era =>
    TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall a b. (a -> b) -> a -> b
$ [(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures BuildTx era
forall era build.
(Applicative (BuildTxWith build), IsShelleyBasedEra era) =>
[(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures build era
mkTxProposalProcedures ([(ProposalProcedure (ShelleyLedgerEra era),
   Maybe (ScriptWitness WitCtxStake era))]
 -> TxProposalProcedures BuildTx era)
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures BuildTx era
forall a b. (a -> b) -> a -> b
$ ((Proposal era, Maybe (ScriptWitness WitCtxStake era))
 -> (ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era)))
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> [a] -> [b]
map ((Proposal era -> ProposalProcedure (ShelleyLedgerEra era))
-> (Proposal era, Maybe (ScriptWitness WitCtxStake era))
-> (ProposalProcedure (ShelleyLedgerEra era),
    Maybe (ScriptWitness WitCtxStake era))
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Proposal era -> ProposalProcedure (ShelleyLedgerEra era)
forall era.
Proposal era -> ProposalProcedure (ShelleyLedgerEra era)
unProposal) [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
            ConwayEraOnwards era
-> TxProposalProcedures BuildTx era
-> Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)
forall (eon :: * -> *) era a. eon era -> a -> Featured eon era a
Featured ConwayEraOnwards era
w TxProposalProcedures BuildTx era
txp
      Maybe (Featured ConwayEraOnwards era (Maybe Lovelace))
validatedCurrentTreasuryValue <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era (Maybe Lovelace)))
-> Either
     TxCmdError (Maybe (Featured ConwayEraOnwards era (Maybe Lovelace)))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first
          TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError
          (ShelleyBasedEra era
-> Maybe TxCurrentTreasuryValue
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era (Maybe Lovelace)))
forall era.
ShelleyBasedEra era
-> Maybe TxCurrentTreasuryValue
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era (Maybe Lovelace)))
validateTxCurrentTreasuryValue ShelleyBasedEra era
sbe ((TxCurrentTreasuryValue, TxTreasuryDonation)
-> TxCurrentTreasuryValue
forall a b. (a, b) -> a
fst ((TxCurrentTreasuryValue, TxTreasuryDonation)
 -> TxCurrentTreasuryValue)
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe TxCurrentTreasuryValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation))
      Maybe (Featured ConwayEraOnwards era Lovelace)
validatedTreasuryDonation <-
        (TxNotSupportedInEraValidationError era -> TxCmdError)
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era Lovelace))
-> Either
     TxCmdError (Maybe (Featured ConwayEraOnwards era Lovelace))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first
          TxNotSupportedInEraValidationError era -> TxCmdError
forall era. TxNotSupportedInEraValidationError era -> TxCmdError
TxCmdNotSupportedInEraValidationError
          (ShelleyBasedEra era
-> Maybe TxTreasuryDonation
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era Lovelace))
forall era.
ShelleyBasedEra era
-> Maybe TxTreasuryDonation
-> Either
     (TxNotSupportedInEraValidationError era)
     (Maybe (Featured ConwayEraOnwards era Lovelace))
validateTxTreasuryDonation ShelleyBasedEra era
sbe ((TxCurrentTreasuryValue, TxTreasuryDonation) -> TxTreasuryDonation
forall a b. (a, b) -> b
snd ((TxCurrentTreasuryValue, TxTreasuryDonation)
 -> TxTreasuryDonation)
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Maybe TxTreasuryDonation
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation))
      TxBodyContent BuildTx era
-> Either TxCmdError (TxBodyContent BuildTx era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBodyContent BuildTx era
 -> Either TxCmdError (TxBodyContent BuildTx era))
-> TxBodyContent BuildTx era
-> Either TxCmdError (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints
          ShelleyBasedEra era
sbe
          ( ShelleyBasedEra era -> TxBodyContent BuildTx era
forall era. ShelleyBasedEra era -> TxBodyContent BuildTx era
defaultTxBodyContent ShelleyBasedEra era
sbe
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxIns BuildTx era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall build era.
TxIns build era
-> TxBodyContent build era -> TxBodyContent build era
setTxIns ([(TxIn, Maybe (ScriptWitness WitCtxTxIn era))] -> TxIns BuildTx era
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits)
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxInsCollateral era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxInsCollateral era
-> TxBodyContent build era -> TxBodyContent build era
setTxInsCollateral TxInsCollateral era
validatedCollateralTxIns
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxInsReference era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxInsReference era
-> TxBodyContent build era -> TxBodyContent build era
setTxInsReference TxInsReference era
validatedRefInputs
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& [TxOut CtxTx era]
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
[TxOut CtxTx era]
-> TxBodyContent build era -> TxBodyContent build era
setTxOuts [TxOut CtxTx era]
txouts
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxTotalCollateral era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxTotalCollateral era
-> TxBodyContent build era -> TxBodyContent build era
setTxTotalCollateral TxTotalCollateral era
validatedTotCollateral
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxReturnCollateral CtxTx era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxReturnCollateral CtxTx era
-> TxBodyContent build era -> TxBodyContent build era
setTxReturnCollateral TxReturnCollateral CtxTx era
validatedRetCol
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxFee era -> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxFee era -> TxBodyContent build era -> TxBodyContent build era
setTxFee TxFee era
txFee
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxValidityLowerBound era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxValidityLowerBound era
-> TxBodyContent build era -> TxBodyContent build era
setTxValidityLowerBound TxValidityLowerBound era
validatedLowerBound
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxValidityUpperBound era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxValidityUpperBound era
-> TxBodyContent build era -> TxBodyContent build era
setTxValidityUpperBound TxValidityUpperBound era
mUpperBound
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxMetadataInEra era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxMetadataInEra era
-> TxBodyContent build era -> TxBodyContent build era
setTxMetadata TxMetadataInEra era
txMetadata
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxAuxScripts era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxAuxScripts era
-> TxBodyContent build era -> TxBodyContent build era
setTxAuxScripts TxAuxScripts era
txAuxScripts
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxExtraKeyWitnesses era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxExtraKeyWitnesses era
-> TxBodyContent build era -> TxBodyContent build era
setTxExtraKeyWits TxExtraKeyWitnesses era
validatedReqSigners
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall build era.
BuildTxWith build (Maybe (LedgerProtocolParameters era))
-> TxBodyContent build era -> TxBodyContent build era
setTxProtocolParams (Maybe (LedgerProtocolParameters era)
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Maybe (LedgerProtocolParameters era)
 -> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era)))
-> Maybe (LedgerProtocolParameters era)
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
forall a b. (a -> b) -> a -> b
$ PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
forall era.
PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
LedgerProtocolParameters (PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era)
-> Maybe (PParams (ShelleyLedgerEra era))
-> Maybe (LedgerProtocolParameters era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (PParams (ShelleyLedgerEra era))
mPparams)
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxWithdrawals BuildTx era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall build era.
TxWithdrawals build era
-> TxBodyContent build era -> TxBodyContent build era
setTxWithdrawals (ShelleyBasedEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> TxWithdrawals BuildTx era
forall era build.
ShelleyBasedEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals ShelleyBasedEra era
sbe ([(StakeAddress, Lovelace,
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> TxWithdrawals BuildTx era)
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> TxWithdrawals BuildTx era
forall a b. (a -> b) -> a -> b
$ ((StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))
 -> (StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era)))
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a b. (a -> b) -> [a] -> [b]
map (StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))
-> (StakeAddress, Lovelace,
    BuildTxWith BuildTx (Witness WitCtxStake era))
convertWithdrawals [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals)
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxCertificates BuildTx era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall build era.
TxCertificates build era
-> TxBodyContent build era -> TxBodyContent build era
setTxCertificates (ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates BuildTx era
forall era.
ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates BuildTx era
convertCertificates ShelleyBasedEra era
sbe [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits)
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxUpdateProposal era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxUpdateProposal era
-> TxBodyContent build era -> TxBodyContent build era
setTxUpdateProposal TxUpdateProposal era
txUpdateProposal
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxMintValue BuildTx era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall build era.
TxMintValue build era
-> TxBodyContent build era -> TxBodyContent build era
setTxMintValue TxMintValue BuildTx era
validatedMintValue
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& TxScriptValidity era
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
TxScriptValidity era
-> TxBodyContent build era -> TxBodyContent build era
setTxScriptValidity TxScriptValidity era
validatedTxScriptValidity
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures build era))
-> TxBodyContent build era -> TxBodyContent build era
setTxVotingProcedures (TxVotingProcedures BuildTx era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
forall (eon :: * -> *) era a.
(IsCardanoEra era, Eon eon) =>
a -> Maybe (Featured eon era a)
mkFeatured TxVotingProcedures BuildTx era
validatedVotingProcedures)
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures build era))
-> TxBodyContent build era -> TxBodyContent build era
setTxProposalProcedures Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposals
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& Maybe (Featured ConwayEraOnwards era (Maybe Lovelace))
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
Maybe (Featured ConwayEraOnwards era (Maybe Lovelace))
-> TxBodyContent build era -> TxBodyContent build era
setTxCurrentTreasuryValue Maybe (Featured ConwayEraOnwards era (Maybe Lovelace))
validatedCurrentTreasuryValue
              TxBodyContent BuildTx era
-> (TxBodyContent BuildTx era -> TxBodyContent BuildTx era)
-> TxBodyContent BuildTx era
forall a b. a -> (a -> b) -> b
& Maybe (Featured ConwayEraOnwards era Lovelace)
-> TxBodyContent BuildTx era -> TxBodyContent BuildTx era
forall era build.
Maybe (Featured ConwayEraOnwards era Lovelace)
-> TxBodyContent build era -> TxBodyContent build era
setTxTreasuryDonation Maybe (Featured ConwayEraOnwards era Lovelace)
validatedTreasuryDonation
          )
   where
    convertWithdrawals
      :: (StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))
      -> (StakeAddress, Lovelace, BuildTxWith BuildTx (Witness WitCtxStake era))
    convertWithdrawals :: (StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))
-> (StakeAddress, Lovelace,
    BuildTxWith BuildTx (Witness WitCtxStake era))
convertWithdrawals (StakeAddress
sAddr, Lovelace
ll, Maybe (ScriptWitness WitCtxStake era)
mScriptWitnessFiles) =
      case Maybe (ScriptWitness WitCtxStake era)
mScriptWitnessFiles of
        Just ScriptWitness WitCtxStake era
sWit -> (StakeAddress
sAddr, Lovelace
ll, Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxStake era
 -> BuildTxWith BuildTx (Witness WitCtxStake era))
-> Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$ ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit)
        Maybe (ScriptWitness WitCtxStake era)
Nothing -> (StakeAddress
sAddr, Lovelace
ll, Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxStake era
 -> BuildTxWith BuildTx (Witness WitCtxStake era))
-> Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$ KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr)

runTxBuild
  :: ()
  => ShelleyBasedEra era
  -> SocketPath
  -> NetworkId
  -> Maybe ScriptValidity
  -- ^ Mark script as expected to pass or fail validation
  -> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
  -- ^ Read only reference inputs
  -> [TxIn]
  -- ^ TxIn with potential script witness
  -> [TxIn]
  -- ^ TxIn for collateral
  -> Maybe (TxOut CtxTx era)
  -- ^ Return collateral
  -> Maybe Lovelace
  -- ^ Total collateral
  -> [TxOut CtxTx era]
  -- ^ Normal outputs
  -> TxOutChangeAddress
  -- ^ A change output
  -> (Value, [MintScriptWitnessWithPolicyId era])
  -- ^ Multi-Asset value(s)
  -> Maybe SlotNo
  -- ^ Tx lower bound
  -> TxValidityUpperBound era
  -- ^ Tx upper bound
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> TxUpdateProposal era
  -> Maybe Word
  -> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
  -> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
  -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
  -- ^ The current treasury value and the donation.
  -> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild :: forall era.
ShelleyBasedEra era
-> SocketPath
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild
  ShelleyBasedEra era
sbe
  SocketPath
socketPath
  NetworkId
networkId
  Maybe ScriptValidity
mScriptValidity
  [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
  [TxIn]
readOnlyRefIns
  [TxIn]
txinsc
  Maybe (TxOut CtxTx era)
mReturnCollateral
  Maybe Lovelace
mTotCollateral
  [TxOut CtxTx era]
txouts
  (TxOutChangeAddress AddressAny
changeAddr)
  (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
  Maybe SlotNo
mLowerBound
  TxValidityUpperBound era
mUpperBound
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
  [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  TxUpdateProposal era
txUpdateProposal
  Maybe Word
mOverrideWits
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
  [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
  Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation =
    ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    ExceptT TxCmdError IO (BalancedTxBody era))
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era =>
  ExceptT TxCmdError IO (BalancedTxBody era))
 -> ExceptT TxCmdError IO (BalancedTxBody era))
-> (ShelleyBasedEraConstraints era =>
    ExceptT TxCmdError IO (BalancedTxBody era))
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall a b. (a -> b) -> a -> b
$ do
      -- TODO: All functions should be parameterized by ShelleyBasedEra
      -- as it's not possible to call this function with ByronEra
      let era :: CardanoEra era
era = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe
          inputsThatRequireWitnessing :: [TxIn]
inputsThatRequireWitnessing = [TxIn
input | (TxIn
input, Maybe (ScriptWitness WitCtxTxIn era)
_) <- [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits]

      let allReferenceInputs :: [TxIn]
allReferenceInputs =
            [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
              [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
              ((MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era)
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> [a] -> [b]
map MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
forall era.
MintScriptWitnessWithPolicyId era -> ScriptWitness WitCtxMint era
mswScriptWitness ([MintScriptWitnessWithPolicyId era]
 -> [ScriptWitness WitCtxMint era])
-> [MintScriptWitnessWithPolicyId era]
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> a -> b
$ (Value, [MintScriptWitnessWithPolicyId era])
-> [MintScriptWitnessWithPolicyId era]
forall a b. (a, b) -> b
snd (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits)
              [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
              [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
              [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
              [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
              [TxIn]
readOnlyRefIns

      let allTxInputs :: [TxIn]
allTxInputs = [TxIn]
inputsThatRequireWitnessing [TxIn] -> [TxIn] -> [TxIn]
forall a. [a] -> [a] -> [a]
++ [TxIn]
allReferenceInputs [TxIn] -> [TxIn] -> [TxIn]
forall a. [a] -> [a] -> [a]
++ [TxIn]
txinsc
          localNodeConnInfo :: LocalNodeConnectInfo
localNodeConnInfo =
            LocalNodeConnectInfo
              { localConsensusModeParams :: ConsensusModeParams
localConsensusModeParams = EpochSlots -> ConsensusModeParams
CardanoModeParams (EpochSlots -> ConsensusModeParams)
-> EpochSlots -> ConsensusModeParams
forall a b. (a -> b) -> a -> b
$ Word64 -> EpochSlots
EpochSlots Word64
21600
              , localNodeNetworkId :: NetworkId
localNodeNetworkId = NetworkId
networkId
              , localNodeSocketPath :: SocketPath
localNodeSocketPath = SocketPath
socketPath
              }

      AnyCardanoEra CardanoEra era
nodeEra <-
        IO
  (Either
     AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either UnsupportedNtcVersionError AnyCardanoEra)
-> IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr LocalNodeConnectInfo
localNodeConnInfo Target ChainPoint
forall point. Target point
Consensus.VolatileTip LocalStateQueryExpr
  BlockInMode
  ChainPoint
  QueryInMode
  ()
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
forall block point r.
LocalStateQueryExpr
  block
  point
  QueryInMode
  r
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
queryCurrentEra)
          ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
    -> ExceptT
         TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure (Either UnsupportedNtcVersionError AnyCardanoEra))
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
          ExceptT
  TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
-> (ExceptT
      TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
    -> ExceptT TxCmdError IO AnyCardanoEra)
-> ExceptT TxCmdError IO AnyCardanoEra
forall a b. a -> (a -> b) -> b
& (UnsupportedNtcVersionError -> ExceptT TxCmdError IO AnyCardanoEra)
-> ExceptT
     TxCmdError IO (Either UnsupportedNtcVersionError AnyCardanoEra)
-> ExceptT TxCmdError IO AnyCardanoEra
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO AnyCardanoEra
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO AnyCardanoEra)
-> (UnsupportedNtcVersionError -> TxCmdError)
-> UnsupportedNtcVersionError
-> ExceptT TxCmdError IO AnyCardanoEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (UnsupportedNtcVersionError -> QueryConvenienceError)
-> UnsupportedNtcVersionError
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion)

      era :~: era
Refl <-
        CardanoEra era -> CardanoEra era -> Maybe (era :~: era)
forall a b. CardanoEra a -> CardanoEra b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality CardanoEra era
era CardanoEra era
nodeEra
          Maybe (era :~: era)
-> (Maybe (era :~: era) -> ExceptT TxCmdError IO (era :~: era))
-> ExceptT TxCmdError IO (era :~: era)
forall a b. a -> (a -> b) -> b
& TxCmdError
-> Maybe (era :~: era) -> ExceptT TxCmdError IO (era :~: era)
forall (m :: * -> *) x a. Monad m => x -> Maybe a -> ExceptT x m a
hoistMaybe (NodeEraMismatchError -> TxCmdError
TxCmdTxNodeEraMismatchError (NodeEraMismatchError -> TxCmdError)
-> NodeEraMismatchError -> TxCmdError
forall a b. (a -> b) -> a -> b
$ CardanoEra era -> CardanoEra era -> NodeEraMismatchError
forall era nodeEra.
CardanoEra era -> CardanoEra nodeEra -> NodeEraMismatchError
NodeEraMismatchError CardanoEra era
era CardanoEra era
nodeEra)

      let certs :: [Certificate era]
certs =
            case ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates BuildTx era
forall era.
ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates BuildTx era
convertCertificates ShelleyBasedEra era
sbe [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits of
              TxCertificates ShelleyBasedEra era
_ [Certificate era]
cs BuildTxWith BuildTx [(StakeCredential, Witness WitCtxStake era)]
_ -> [Certificate era]
cs
              TxCertificates BuildTx era
_ -> []

      (UTxO era
txEraUtxo, LedgerProtocolParameters era
pparams, EraHistory
eraHistory, SystemStart
systemStart, Set PoolId
stakePools, Map StakeCredential Lovelace
stakeDelegDeposits, Map (Credential 'DRepRole StandardCrypto) Lovelace
drepDelegDeposits, Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)
_) <-
        IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
          ( LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr LocalNodeConnectInfo
localNodeConnInfo Target ChainPoint
forall point. Target point
Consensus.VolatileTip (LocalStateQueryExpr
   BlockInMode
   ChainPoint
   QueryInMode
   ()
   IO
   (Either
      QueryConvenienceError
      (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
       Set PoolId, Map StakeCredential Lovelace,
       Map (Credential 'DRepRole StandardCrypto) Lovelace,
       Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
 -> IO
      (Either
         AcquiringFailure
         (Either
            QueryConvenienceError
            (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
             Set PoolId, Map StakeCredential Lovelace,
             Map (Credential 'DRepRole StandardCrypto) Lovelace,
             Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))))
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall a b. (a -> b) -> a -> b
$
              CardanoEra era
-> [TxIn]
-> [Certificate era]
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall era block point r.
CardanoEra era
-> [TxIn]
-> [Certificate era]
-> LocalStateQueryExpr
     block
     point
     QueryInMode
     r
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
queryStateForBalancedTx CardanoEra era
nodeEra [TxIn]
allTxInputs [Certificate era]
[Certificate era]
certs
          )
          ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure
         (Either
            QueryConvenienceError
            (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
             Set PoolId, Map StakeCredential Lovelace,
             Map (Credential 'DRepRole StandardCrypto) Lovelace,
             Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
    -> ExceptT
         TxCmdError
         IO
         (Either
            QueryConvenienceError
            (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
             Set PoolId, Map StakeCredential Lovelace,
             Map (Credential 'DRepRole StandardCrypto) Lovelace,
             Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
            Set PoolId, Map StakeCredential Lovelace,
            Map (Credential 'DRepRole StandardCrypto) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError (QueryConvenienceError -> TxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
          ExceptT
  TxCmdError
  IO
  (Either
     QueryConvenienceError
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> (ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
    -> ExceptT
         TxCmdError
         IO
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole StandardCrypto) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall a b. a -> (a -> b) -> b
& (QueryConvenienceError
 -> ExceptT
      TxCmdError
      IO
      (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
       Set PoolId, Map StakeCredential Lovelace,
       Map (Credential 'DRepRole StandardCrypto) Lovelace,
       Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole StandardCrypto) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
       Set PoolId, Map StakeCredential Lovelace,
       Map (Credential 'DRepRole StandardCrypto) Lovelace,
       Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> (QueryConvenienceError -> TxCmdError)
-> QueryConvenienceError
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole StandardCrypto) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError)

      TxBodyContent BuildTx era
txBodyContent <-
        Either TxCmdError (TxBodyContent BuildTx era)
-> ExceptT TxCmdError IO (TxBodyContent BuildTx era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxBodyContent BuildTx era)
 -> ExceptT TxCmdError IO (TxBodyContent BuildTx era))
-> Either TxCmdError (TxBodyContent BuildTx era)
-> ExceptT TxCmdError IO (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$
          ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent
            ShelleyBasedEra era
sbe
            Maybe ScriptValidity
mScriptValidity
            (PParams (ShelleyLedgerEra era)
-> Maybe (PParams (ShelleyLedgerEra era))
forall a. a -> Maybe a
Just (PParams (ShelleyLedgerEra era)
 -> Maybe (PParams (ShelleyLedgerEra era)))
-> PParams (ShelleyLedgerEra era)
-> Maybe (PParams (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ LedgerProtocolParameters era -> PParams (ShelleyLedgerEra era)
forall era.
LedgerProtocolParameters era -> PParams (ShelleyLedgerEra era)
unLedgerProtocolParameters LedgerProtocolParameters era
pparams)
            [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits
            [TxIn]
readOnlyRefIns
            [TxIn]
txinsc
            Maybe (TxOut CtxTx era)
mReturnCollateral
            Maybe Lovelace
mTotCollateral
            [TxOut CtxTx era]
txouts
            Maybe SlotNo
mLowerBound
            TxValidityUpperBound era
mUpperBound
            (Value, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
            [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
            [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
            [Hash PaymentKey]
reqSigners
            Lovelace
0
            TxAuxScripts era
txAuxScripts
            TxMetadataInEra era
txMetadata
            TxUpdateProposal era
txUpdateProposal
            [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
            [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
proposals
            Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation

      (TxInsExistError -> TxCmdError)
-> ExceptT TxInsExistError IO () -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT TxInsExistError -> TxCmdError
TxCmdTxInsDoNotExist
        (ExceptT TxInsExistError IO () -> ExceptT TxCmdError IO ())
-> (Either TxInsExistError () -> ExceptT TxInsExistError IO ())
-> Either TxInsExistError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either TxInsExistError () -> ExceptT TxInsExistError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
        (Either TxInsExistError () -> ExceptT TxCmdError IO ())
-> Either TxInsExistError () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ [TxIn] -> UTxO era -> Either TxInsExistError ()
forall era. [TxIn] -> UTxO era -> Either TxInsExistError ()
txInsExistInUTxO [TxIn]
allTxInputs UTxO era
txEraUtxo
      (ScriptLockedTxInsError -> TxCmdError)
-> ExceptT ScriptLockedTxInsError IO () -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptLockedTxInsError -> TxCmdError
TxCmdQueryNotScriptLocked
        (ExceptT ScriptLockedTxInsError IO () -> ExceptT TxCmdError IO ())
-> (Either ScriptLockedTxInsError ()
    -> ExceptT ScriptLockedTxInsError IO ())
-> Either ScriptLockedTxInsError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either ScriptLockedTxInsError ()
-> ExceptT ScriptLockedTxInsError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
        (Either ScriptLockedTxInsError () -> ExceptT TxCmdError IO ())
-> Either ScriptLockedTxInsError () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ [TxIn] -> UTxO era -> Either ScriptLockedTxInsError ()
forall era. [TxIn] -> UTxO era -> Either ScriptLockedTxInsError ()
notScriptLockedTxIns [TxIn]
txinsc UTxO era
txEraUtxo

      AddressInEra era
cAddr <-
        Either FilePath (AddressInEra era)
-> ExceptT TxCmdError IO (Either FilePath (AddressInEra era))
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CardanoEra era -> AddressAny -> Either FilePath (AddressInEra era)
forall era.
CardanoEra era -> AddressAny -> Either FilePath (AddressInEra era)
anyAddressInEra CardanoEra era
era AddressAny
changeAddr)
          ExceptT TxCmdError IO (Either FilePath (AddressInEra era))
-> (ExceptT TxCmdError IO (Either FilePath (AddressInEra era))
    -> ExceptT TxCmdError IO (AddressInEra era))
-> ExceptT TxCmdError IO (AddressInEra era)
forall a b. a -> (a -> b) -> b
& (FilePath -> ExceptT TxCmdError IO (AddressInEra era))
-> ExceptT TxCmdError IO (Either FilePath (AddressInEra era))
-> ExceptT TxCmdError IO (AddressInEra era)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (FilePath -> FilePath -> ExceptT TxCmdError IO (AddressInEra era)
forall a. HasCallStack => FilePath -> a
error (FilePath -> FilePath -> ExceptT TxCmdError IO (AddressInEra era))
-> FilePath -> FilePath -> ExceptT TxCmdError IO (AddressInEra era)
forall a b. (a -> b) -> a -> b
$ FilePath
"runTxBuild: Byron address used: " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> AddressAny -> FilePath
forall a. Show a => a -> FilePath
show AddressAny
changeAddr) -- should this throw instead?
      balancedTxBody :: BalancedTxBody era
balancedTxBody@(BalancedTxBody TxBodyContent BuildTx era
_ TxBody era
_ TxOut CtxTx era
_ Lovelace
fee) <-
        (TxBodyErrorAutoBalance era -> TxCmdError)
-> ExceptT (TxBodyErrorAutoBalance era) IO (BalancedTxBody era)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (AnyTxBodyErrorAutoBalance -> TxCmdError
TxCmdBalanceTxBody (AnyTxBodyErrorAutoBalance -> TxCmdError)
-> (TxBodyErrorAutoBalance era -> AnyTxBodyErrorAutoBalance)
-> TxBodyErrorAutoBalance era
-> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxBodyErrorAutoBalance era -> AnyTxBodyErrorAutoBalance
forall era. TxBodyErrorAutoBalance era -> AnyTxBodyErrorAutoBalance
AnyTxBodyErrorAutoBalance)
          (ExceptT (TxBodyErrorAutoBalance era) IO (BalancedTxBody era)
 -> ExceptT TxCmdError IO (BalancedTxBody era))
-> (Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
    -> ExceptT (TxBodyErrorAutoBalance era) IO (BalancedTxBody era))
-> Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
-> ExceptT (TxBodyErrorAutoBalance era) IO (BalancedTxBody era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
          (Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
 -> ExceptT TxCmdError IO (BalancedTxBody era))
-> Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> SystemStart
-> LedgerEpochInfo
-> LedgerProtocolParameters era
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
-> UTxO era
-> TxBodyContent BuildTx era
-> AddressInEra era
-> Maybe Word
-> Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
forall era.
ShelleyBasedEra era
-> SystemStart
-> LedgerEpochInfo
-> LedgerProtocolParameters era
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole StandardCrypto) Lovelace
-> UTxO era
-> TxBodyContent BuildTx era
-> AddressInEra era
-> Maybe Word
-> Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
makeTransactionBodyAutoBalance
            ShelleyBasedEra era
sbe
            SystemStart
systemStart
            (EraHistory -> LedgerEpochInfo
toLedgerEpochInfo EraHistory
eraHistory)
            LedgerProtocolParameters era
LedgerProtocolParameters era
pparams
            Set PoolId
stakePools
            Map StakeCredential Lovelace
stakeDelegDeposits
            Map (Credential 'DRepRole StandardCrypto) Lovelace
drepDelegDeposits
            UTxO era
UTxO era
txEraUtxo
            TxBodyContent BuildTx era
txBodyContent
            AddressInEra era
cAddr
            Maybe Word
mOverrideWits

      IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> (Doc AnsiStyle -> IO ())
-> Doc AnsiStyle
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO ()
putStrLn (FilePath -> IO ())
-> (Doc AnsiStyle -> FilePath) -> Doc AnsiStyle -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc AnsiStyle -> FilePath
docToString (Doc AnsiStyle -> ExceptT TxCmdError IO ())
-> Doc AnsiStyle -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Doc AnsiStyle
"Estimated transaction fee:" Doc AnsiStyle -> Doc AnsiStyle -> Doc AnsiStyle
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Lovelace -> Doc AnsiStyle
forall a ann. Pretty a => a -> Doc ann
forall ann. Lovelace -> Doc ann
pretty Lovelace
fee

      BalancedTxBody era -> ExceptT TxCmdError IO (BalancedTxBody era)
forall a. a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return BalancedTxBody era
balancedTxBody

convertCertificates
  :: ()
  => ShelleyBasedEra era
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -> TxCertificates BuildTx era
convertCertificates :: forall era.
ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates BuildTx era
convertCertificates ShelleyBasedEra era
sbe [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndScriptWitnesses =
  ShelleyBasedEra era
-> [Certificate era]
-> BuildTxWith BuildTx [(StakeCredential, Witness WitCtxStake era)]
-> TxCertificates BuildTx era
forall era build.
ShelleyBasedEra era
-> [Certificate era]
-> BuildTxWith build [(StakeCredential, Witness WitCtxStake era)]
-> TxCertificates build era
TxCertificates ShelleyBasedEra era
sbe [Certificate era]
certs (BuildTxWith BuildTx [(StakeCredential, Witness WitCtxStake era)]
 -> TxCertificates BuildTx era)
-> BuildTxWith BuildTx [(StakeCredential, Witness WitCtxStake era)]
-> TxCertificates BuildTx era
forall a b. (a -> b) -> a -> b
$ [(StakeCredential, Witness WitCtxStake era)]
-> BuildTxWith BuildTx [(StakeCredential, Witness WitCtxStake era)]
forall a. a -> BuildTxWith BuildTx a
BuildTxWith [(StakeCredential, Witness WitCtxStake era)]
reqWits
 where
  certs :: [Certificate era]
certs = ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Certificate era)
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [Certificate era]
forall a b. (a -> b) -> [a] -> [b]
map (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Certificate era
forall a b. (a, b) -> a
fst [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndScriptWitnesses
  reqWits :: [(StakeCredential, Witness WitCtxStake era)]
reqWits = [Item [(StakeCredential, Witness WitCtxStake era)]]
-> [(StakeCredential, Witness WitCtxStake era)]
forall l. IsList l => [Item l] -> l
fromList ([Item [(StakeCredential, Witness WitCtxStake era)]]
 -> [(StakeCredential, Witness WitCtxStake era)])
-> [Item [(StakeCredential, Witness WitCtxStake era)]]
-> [(StakeCredential, Witness WitCtxStake era)]
forall a b. (a -> b) -> a -> b
$ ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Maybe (StakeCredential, Witness WitCtxStake era))
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeCredential, Witness WitCtxStake era)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall era.
(Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (StakeCredential, Witness WitCtxStake era)
convertCert [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndScriptWitnesses
  convertCert
    :: (Certificate era, Maybe (ScriptWitness WitCtxStake era))
    -> Maybe (StakeCredential, Witness WitCtxStake era)
  convertCert :: forall era.
(Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (StakeCredential, Witness WitCtxStake era)
convertCert (Certificate era
cert, Maybe (ScriptWitness WitCtxStake era)
mScriptWitnessFiles) = do
    StakeCredential
sCred <- Certificate era -> Maybe StakeCredential
forall era. Certificate era -> Maybe StakeCredential
selectStakeCredentialWitness Certificate era
cert
    (StakeCredential, Witness WitCtxStake era)
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall a. a -> Maybe a
Just ((StakeCredential, Witness WitCtxStake era)
 -> Maybe (StakeCredential, Witness WitCtxStake era))
-> (StakeCredential, Witness WitCtxStake era)
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$ case Maybe (ScriptWitness WitCtxStake era)
mScriptWitnessFiles of
      Just ScriptWitness WitCtxStake era
sWit -> (StakeCredential
sCred, ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit)
      Maybe (ScriptWitness WitCtxStake era)
Nothing -> (StakeCredential
sCred, KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr)

-- ----------------------------------------------------------------------------
-- Transaction body validation and conversion
--

txFeatureMismatch
  :: ()
  => Monad m
  => CardanoEra era
  -> TxFeature
  -> ExceptT TxCmdError m a
txFeatureMismatch :: forall (m :: * -> *) era a.
Monad m =>
CardanoEra era -> TxFeature -> ExceptT TxCmdError m a
txFeatureMismatch CardanoEra era
era TxFeature
feature =
  Either TxCmdError a -> ExceptT TxCmdError m a
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError a -> ExceptT TxCmdError m a)
-> (TxCmdError -> Either TxCmdError a)
-> TxCmdError
-> ExceptT TxCmdError m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxCmdError -> Either TxCmdError a
forall a b. a -> Either a b
Left (TxCmdError -> ExceptT TxCmdError m a)
-> TxCmdError -> ExceptT TxCmdError m a
forall a b. (a -> b) -> a -> b
$ AnyCardanoEra -> TxFeature -> TxCmdError
TxCmdTxFeatureMismatch (CardanoEra era -> AnyCardanoEra
forall era. CardanoEra era -> AnyCardanoEra
anyCardanoEra CardanoEra era
era) TxFeature
feature

txFeatureMismatchPure
  :: CardanoEra era
  -> TxFeature
  -> Either TxCmdError a
txFeatureMismatchPure :: forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure CardanoEra era
era TxFeature
feature =
  TxCmdError -> Either TxCmdError a
forall a b. a -> Either a b
Left (AnyCardanoEra -> TxFeature -> TxCmdError
TxCmdTxFeatureMismatch (CardanoEra era -> AnyCardanoEra
forall era. CardanoEra era -> AnyCardanoEra
anyCardanoEra CardanoEra era
era) TxFeature
feature)

validateTxIns
  :: [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
  -> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns :: forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns = ((TxIn, Maybe (ScriptWitness WitCtxTxIn era))
 -> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))
-> [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
forall era.
(TxIn, Maybe (ScriptWitness WitCtxTxIn era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
convertTxIn
 where
  convertTxIn
    :: (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
    -> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  convertTxIn :: forall era.
(TxIn, Maybe (ScriptWitness WitCtxTxIn era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
convertTxIn (TxIn
txin, Maybe (ScriptWitness WitCtxTxIn era)
mScriptWitness) =
    case Maybe (ScriptWitness WitCtxTxIn era)
mScriptWitness of
      Just ScriptWitness WitCtxTxIn era
sWit ->
        (TxIn
txin, Witness WitCtxTxIn era
-> BuildTxWith BuildTx (Witness WitCtxTxIn era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxTxIn era
 -> BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> Witness WitCtxTxIn era
-> BuildTxWith BuildTx (Witness WitCtxTxIn era)
forall a b. (a -> b) -> a -> b
$ ScriptWitnessInCtx WitCtxTxIn
-> ScriptWitness WitCtxTxIn era -> Witness WitCtxTxIn era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxTxIn
ScriptWitnessForSpending ScriptWitness WitCtxTxIn era
sWit)
      Maybe (ScriptWitness WitCtxTxIn era)
Nothing ->
        (TxIn
txin, Witness WitCtxTxIn era
-> BuildTxWith BuildTx (Witness WitCtxTxIn era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxTxIn era
 -> BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> Witness WitCtxTxIn era
-> BuildTxWith BuildTx (Witness WitCtxTxIn era)
forall a b. (a -> b) -> a -> b
$ KeyWitnessInCtx WitCtxTxIn -> Witness WitCtxTxIn era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxTxIn
KeyWitnessForSpending)

validateTxInsCollateral
  :: ShelleyBasedEra era
  -> [TxIn]
  -> Either TxCmdError (TxInsCollateral era)
validateTxInsCollateral :: forall era.
ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsCollateral era)
validateTxInsCollateral ShelleyBasedEra era
_ [] = TxInsCollateral era -> Either TxCmdError (TxInsCollateral era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
validateTxInsCollateral ShelleyBasedEra era
era [TxIn]
txins = do
  ShelleyBasedEra era
-> (AlonzoEraOnwards era -> TxInsCollateral era)
-> Maybe (TxInsCollateral era)
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
era (\AlonzoEraOnwards era
supported -> AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
forall era. AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
TxInsCollateral AlonzoEraOnwards era
supported [TxIn]
txins)
    Maybe (TxInsCollateral era)
-> (Maybe (TxInsCollateral era)
    -> Either TxCmdError (TxInsCollateral era))
-> Either TxCmdError (TxInsCollateral era)
forall a b. a -> (a -> b) -> b
& Either TxCmdError (TxInsCollateral era)
-> (TxInsCollateral era -> Either TxCmdError (TxInsCollateral era))
-> Maybe (TxInsCollateral era)
-> Either TxCmdError (TxInsCollateral era)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (CardanoEra era
-> TxFeature -> Either TxCmdError (TxInsCollateral era)
forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era) TxFeature
TxFeatureCollateral) TxInsCollateral era -> Either TxCmdError (TxInsCollateral era)
forall a b. b -> Either a b
Right

validateTxInsReference
  :: ShelleyBasedEra era
  -> [TxIn]
  -> Either TxCmdError (TxInsReference era)
validateTxInsReference :: forall era.
ShelleyBasedEra era
-> [TxIn] -> Either TxCmdError (TxInsReference era)
validateTxInsReference ShelleyBasedEra era
_ [] = TxInsReference era -> Either TxCmdError (TxInsReference era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return TxInsReference era
forall era. TxInsReference era
TxInsReferenceNone
validateTxInsReference ShelleyBasedEra era
sbe [TxIn]
allRefIns = do
  ShelleyBasedEra era
-> (BabbageEraOnwards era -> TxInsReference era)
-> Maybe (TxInsReference era)
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
sbe (\BabbageEraOnwards era
supported -> BabbageEraOnwards era -> [TxIn] -> TxInsReference era
forall era. BabbageEraOnwards era -> [TxIn] -> TxInsReference era
TxInsReference BabbageEraOnwards era
supported [TxIn]
allRefIns)
    Maybe (TxInsReference era)
-> (Maybe (TxInsReference era)
    -> Either TxCmdError (TxInsReference era))
-> Either TxCmdError (TxInsReference era)
forall a b. a -> (a -> b) -> b
& Either TxCmdError (TxInsReference era)
-> (TxInsReference era -> Either TxCmdError (TxInsReference era))
-> Maybe (TxInsReference era)
-> Either TxCmdError (TxInsReference era)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (CardanoEra era
-> TxFeature -> Either TxCmdError (TxInsReference era)
forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe) TxFeature
TxFeatureReferenceInputs) TxInsReference era -> Either TxCmdError (TxInsReference era)
forall a b. b -> Either a b
Right

getAllReferenceInputs
  :: [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
  -> [ScriptWitness WitCtxMint era]
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
  -> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
  -> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
  -> [TxIn]
  -- ^ Read only reference inputs
  -> [TxIn]
getAllReferenceInputs :: forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
  [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
txins
  [ScriptWitness WitCtxMint era]
mintWitnesses
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certFiles
  [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals
  [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits
  [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
propProceduresAnMaybeScriptWits
  [TxIn]
readOnlyRefIns = do
    let txinsWitByRefInputs :: [Maybe TxIn]
txinsWitByRefInputs = [ScriptWitness WitCtxTxIn era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness WitCtxTxIn era
sWit | (TxIn
_, Just ScriptWitness WitCtxTxIn era
sWit) <- [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
txins]
        mintingRefInputs :: [Maybe TxIn]
mintingRefInputs = (ScriptWitness WitCtxMint era -> Maybe TxIn)
-> [ScriptWitness WitCtxMint era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map ScriptWitness WitCtxMint era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput [ScriptWitness WitCtxMint era]
mintWitnesses
        certsWitByRefInputs :: [Maybe TxIn]
certsWitByRefInputs = [ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness WitCtxStake era
sWit | (Certificate era
_, Just ScriptWitness WitCtxStake era
sWit) <- [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certFiles]
        withdrawalsWitByRefInputs :: [Maybe TxIn]
withdrawalsWitByRefInputs = [ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness WitCtxStake era
sWit | (StakeAddress
_, Lovelace
_, Just ScriptWitness WitCtxStake era
sWit) <- [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
withdrawals]
        votesWitByRefInputs :: [Maybe TxIn]
votesWitByRefInputs = [ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness WitCtxStake era
sWit | (VotingProcedures era
_, Just ScriptWitness WitCtxStake era
sWit) <- [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProceduresAndMaybeScriptWits]
        propsWitByRefInputs :: [Maybe TxIn]
propsWitByRefInputs = [ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness WitCtxStake era
sWit | (Proposal era
_, Just ScriptWitness WitCtxStake era
sWit) <- [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
propProceduresAnMaybeScriptWits]

    ([Maybe TxIn] -> [TxIn]) -> [[Maybe TxIn]] -> [TxIn]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap
      [Maybe TxIn] -> [TxIn]
forall a. [Maybe a] -> [a]
catMaybes
      [ [Maybe TxIn]
txinsWitByRefInputs
      , [Maybe TxIn]
mintingRefInputs
      , [Maybe TxIn]
certsWitByRefInputs
      , [Maybe TxIn]
withdrawalsWitByRefInputs
      , [Maybe TxIn]
votesWitByRefInputs
      , [Maybe TxIn]
propsWitByRefInputs
      , (TxIn -> Maybe TxIn) -> [TxIn] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just [TxIn]
readOnlyRefIns
      ]
   where
    getReferenceInput
      :: ScriptWitness witctx era -> Maybe TxIn
    getReferenceInput :: forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getReferenceInput ScriptWitness witctx era
sWit =
      case ScriptWitness witctx era
sWit of
        PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ (PReferenceScript TxIn
refIn) ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_ -> TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
refIn
        PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ PScript{} ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_ -> Maybe TxIn
forall a. Maybe a
Nothing
        SimpleScriptWitness ScriptLanguageInEra SimpleScript' era
_ (SReferenceScript TxIn
refIn) -> TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
refIn
        SimpleScriptWitness ScriptLanguageInEra SimpleScript' era
_ SScript{} -> Maybe TxIn
forall a. Maybe a
Nothing

toAddressInAnyEra
  :: CardanoEra era
  -> AddressAny
  -> Either TxCmdError (AddressInEra era)
toAddressInAnyEra :: forall era.
CardanoEra era
-> AddressAny -> Either TxCmdError (AddressInEra era)
toAddressInAnyEra CardanoEra era
era AddressAny
addrAny = Except TxCmdError (AddressInEra era)
-> Either TxCmdError (AddressInEra era)
forall e a. Except e a -> Either e a
runExcept (Except TxCmdError (AddressInEra era)
 -> Either TxCmdError (AddressInEra era))
-> Except TxCmdError (AddressInEra era)
-> Either TxCmdError (AddressInEra era)
forall a b. (a -> b) -> a -> b
$ do
  case AddressAny
addrAny of
    AddressByron Address ByronAddr
bAddr -> AddressInEra era -> Except TxCmdError (AddressInEra era)
forall a. a -> ExceptT TxCmdError Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AddressTypeInEra ByronAddr era
-> Address ByronAddr -> AddressInEra era
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra AddressTypeInEra ByronAddr era
forall era. AddressTypeInEra ByronAddr era
ByronAddressInAnyEra Address ByronAddr
bAddr)
    AddressShelley Address ShelleyAddr
sAddr -> do
      ShelleyBasedEra era
sbe <-
        CardanoEra era
-> ExceptT TxCmdError Identity (Maybe (ShelleyBasedEra era))
forall (m :: * -> *) era.
Applicative m =>
CardanoEra era -> m (Maybe (ShelleyBasedEra era))
requireShelleyBasedEra CardanoEra era
era
          ExceptT TxCmdError Identity (Maybe (ShelleyBasedEra era))
-> (ExceptT TxCmdError Identity (Maybe (ShelleyBasedEra era))
    -> ExceptT TxCmdError Identity (ShelleyBasedEra era))
-> ExceptT TxCmdError Identity (ShelleyBasedEra era)
forall a b. a -> (a -> b) -> b
& ExceptT TxCmdError Identity (ShelleyBasedEra era)
-> ExceptT TxCmdError Identity (Maybe (ShelleyBasedEra era))
-> ExceptT TxCmdError Identity (ShelleyBasedEra era)
forall x (m :: * -> *) a.
Monad m =>
ExceptT x m a -> ExceptT x m (Maybe a) -> ExceptT x m a
onNothing (CardanoEra era
-> TxFeature -> ExceptT TxCmdError Identity (ShelleyBasedEra era)
forall (m :: * -> *) era a.
Monad m =>
CardanoEra era -> TxFeature -> ExceptT TxCmdError m a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureShelleyAddresses)

      AddressInEra era -> Except TxCmdError (AddressInEra era)
forall a. a -> ExceptT TxCmdError Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AddressTypeInEra ShelleyAddr era
-> Address ShelleyAddr -> AddressInEra era
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra (ShelleyBasedEra era -> AddressTypeInEra ShelleyAddr era
forall era. ShelleyBasedEra era -> AddressTypeInEra ShelleyAddr era
ShelleyAddressInEra ShelleyBasedEra era
sbe) Address ShelleyAddr
sAddr)

toAddressInShelleyBasedEra
  :: ShelleyBasedEra era
  -> Address ShelleyAddr
  -> Either TxCmdError (AddressInEra era)
toAddressInShelleyBasedEra :: forall era.
ShelleyBasedEra era
-> Address ShelleyAddr -> Either TxCmdError (AddressInEra era)
toAddressInShelleyBasedEra ShelleyBasedEra era
sbe Address ShelleyAddr
sAddr =
  Except TxCmdError (AddressInEra era)
-> Either TxCmdError (AddressInEra era)
forall e a. Except e a -> Either e a
runExcept (Except TxCmdError (AddressInEra era)
 -> Either TxCmdError (AddressInEra era))
-> Except TxCmdError (AddressInEra era)
-> Either TxCmdError (AddressInEra era)
forall a b. (a -> b) -> a -> b
$
    AddressInEra era -> Except TxCmdError (AddressInEra era)
forall a. a -> ExceptT TxCmdError Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AddressTypeInEra ShelleyAddr era
-> Address ShelleyAddr -> AddressInEra era
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra (ShelleyBasedEra era -> AddressTypeInEra ShelleyAddr era
forall era. ShelleyBasedEra era -> AddressTypeInEra ShelleyAddr era
ShelleyAddressInEra ShelleyBasedEra era
sbe) Address ShelleyAddr
sAddr)

toTxOutValueInAnyEra
  :: ShelleyBasedEra era
  -> Value
  -> Either TxCmdError (TxOutValue era)
toTxOutValueInAnyEra :: forall era.
ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
toTxOutValueInAnyEra ShelleyBasedEra era
era Value
val =
  (ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> Either TxCmdError (TxOutValue era))
-> (MaryEraOnwardsConstraints era =>
    MaryEraOnwards era -> Either TxCmdError (TxOutValue era))
-> ShelleyBasedEra era
-> Either TxCmdError (TxOutValue era)
forall era a.
(ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> a)
-> (MaryEraOnwardsConstraints era => MaryEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAllegraOrMaryEraOnwards
    ( \ShelleyToAllegraEra era
_ -> case Value -> Maybe Lovelace
valueToLovelace Value
val of
        Just Lovelace
l -> TxOutValue era -> Either TxCmdError (TxOutValue era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
era Value (ShelleyLedgerEra era)
Lovelace
l)
        Maybe Lovelace
Nothing -> CardanoEra era -> TxFeature -> Either TxCmdError (TxOutValue era)
forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era) TxFeature
TxFeatureMultiAssetOutputs
    )
    (\MaryEraOnwards era
w -> TxOutValue era -> Either TxCmdError (TxOutValue era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
era (MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
forall era.
MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
toLedgerValue MaryEraOnwards era
w Value
val)))
    ShelleyBasedEra era
era

toTxOutValueInShelleyBasedEra
  :: ShelleyBasedEra era
  -> Value
  -> Either TxCmdError (TxOutValue era)
toTxOutValueInShelleyBasedEra :: forall era.
ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
toTxOutValueInShelleyBasedEra ShelleyBasedEra era
sbe Value
val =
  (ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> Either TxCmdError (TxOutValue era))
-> (MaryEraOnwardsConstraints era =>
    MaryEraOnwards era -> Either TxCmdError (TxOutValue era))
-> ShelleyBasedEra era
-> Either TxCmdError (TxOutValue era)
forall era a.
(ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> a)
-> (MaryEraOnwardsConstraints era => MaryEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAllegraOrMaryEraOnwards
    ( \ShelleyToAllegraEra era
_ -> case Value -> Maybe Lovelace
valueToLovelace Value
val of
        Just Lovelace
l -> TxOutValue era -> Either TxCmdError (TxOutValue era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
Lovelace
l)
        Maybe Lovelace
Nothing -> CardanoEra era -> TxFeature -> Either TxCmdError (TxOutValue era)
forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe) TxFeature
TxFeatureMultiAssetOutputs
    )
    (\MaryEraOnwards era
w -> TxOutValue era -> Either TxCmdError (TxOutValue era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
forall era.
MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
toLedgerValue MaryEraOnwards era
w Value
val)))
    ShelleyBasedEra era
sbe

toTxOutInShelleyBasedEra
  :: ShelleyBasedEra era
  -> TxOutShelleyBasedEra
  -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra :: forall era.
ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra ShelleyBasedEra era
era (TxOutShelleyBasedEra Address ShelleyAddr
addr' Value
val' TxOutDatumAnyEra
mDatumHash ReferenceScriptAnyEra
refScriptFp) = do
  AddressInEra era
addr <- Either TxCmdError (AddressInEra era)
-> ExceptT TxCmdError IO (AddressInEra era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (AddressInEra era)
 -> ExceptT TxCmdError IO (AddressInEra era))
-> Either TxCmdError (AddressInEra era)
-> ExceptT TxCmdError IO (AddressInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Address ShelleyAddr -> Either TxCmdError (AddressInEra era)
forall era.
ShelleyBasedEra era
-> Address ShelleyAddr -> Either TxCmdError (AddressInEra era)
toAddressInShelleyBasedEra ShelleyBasedEra era
era Address ShelleyAddr
addr'
  TxOutValue era
val <- Either TxCmdError (TxOutValue era)
-> ExceptT TxCmdError IO (TxOutValue era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxOutValue era)
 -> ExceptT TxCmdError IO (TxOutValue era))
-> Either TxCmdError (TxOutValue era)
-> ExceptT TxCmdError IO (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
forall era.
ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
toTxOutValueInShelleyBasedEra ShelleyBasedEra era
era Value
val'

  TxOutDatum CtxTx era
datum <-
    (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era
 -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era
    -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> ShelleyBasedEra era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
      (ExceptT TxCmdError IO (TxOutDatum CtxTx era)
-> ShelleyToMaryEra era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a b. a -> b -> a
const (TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone))
      (\AlonzoEraOnwards era
wa -> AlonzoEraOnwards era
-> TxOutDatumAnyEra -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall era.
AlonzoEraOnwards era
-> TxOutDatumAnyEra -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum AlonzoEraOnwards era
wa TxOutDatumAnyEra
mDatumHash)
      ShelleyBasedEra era
era

  ReferenceScript era
refScript <-
    ExceptT TxCmdError IO (ReferenceScript era)
-> (BabbageEraOnwards era
    -> ExceptT TxCmdError IO (ReferenceScript era))
-> CardanoEra era
-> ExceptT TxCmdError IO (ReferenceScript era)
forall a era.
a -> (BabbageEraOnwards era -> a) -> CardanoEra era -> a
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> CardanoEra era -> a
inEonForEra
      (ReferenceScript era -> ExceptT TxCmdError IO (ReferenceScript era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone)
      (\BabbageEraOnwards era
wb -> BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> ExceptT TxCmdError IO (ReferenceScript era)
forall era.
BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> ExceptT TxCmdError IO (ReferenceScript era)
getReferenceScript BabbageEraOnwards era
wb ReferenceScriptAnyEra
refScriptFp)
      (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era)

  TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall a b. (a -> b) -> a -> b
$ AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxTx era
datum ReferenceScript era
refScript

toTxOutByronEra
  :: TxOutAnyEra
  -> ExceptT TxCmdError IO (TxOut CtxTx ByronEra)
toTxOutByronEra :: TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx ByronEra)
toTxOutByronEra (TxOutAnyEra AddressAny
addr' Value
val' TxOutDatumAnyEra
_ ReferenceScriptAnyEra
_) = do
  AddressInEra ByronEra
addr <- Either TxCmdError (AddressInEra ByronEra)
-> ExceptT TxCmdError IO (AddressInEra ByronEra)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (AddressInEra ByronEra)
 -> ExceptT TxCmdError IO (AddressInEra ByronEra))
-> Either TxCmdError (AddressInEra ByronEra)
-> ExceptT TxCmdError IO (AddressInEra ByronEra)
forall a b. (a -> b) -> a -> b
$ CardanoEra ByronEra
-> AddressAny -> Either TxCmdError (AddressInEra ByronEra)
forall era.
CardanoEra era
-> AddressAny -> Either TxCmdError (AddressInEra era)
toAddressInAnyEra CardanoEra ByronEra
ByronEra AddressAny
addr'
  let ada :: TxOutValue ByronEra
ada = Lovelace -> TxOutValue ByronEra
forall era. Lovelace -> TxOutValue era
TxOutValueByron (Lovelace -> TxOutValue ByronEra)
-> Lovelace -> TxOutValue ByronEra
forall a b. (a -> b) -> a -> b
$ Value -> Lovelace
selectLovelace Value
val'
  TxOut CtxTx ByronEra
-> ExceptT TxCmdError IO (TxOut CtxTx ByronEra)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOut CtxTx ByronEra
 -> ExceptT TxCmdError IO (TxOut CtxTx ByronEra))
-> TxOut CtxTx ByronEra
-> ExceptT TxCmdError IO (TxOut CtxTx ByronEra)
forall a b. (a -> b) -> a -> b
$ AddressInEra ByronEra
-> TxOutValue ByronEra
-> TxOutDatum CtxTx ByronEra
-> ReferenceScript ByronEra
-> TxOut CtxTx ByronEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra ByronEra
addr TxOutValue ByronEra
ada TxOutDatum CtxTx ByronEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript ByronEra
forall era. ReferenceScript era
ReferenceScriptNone

-- TODO: toTxOutInAnyEra eventually will not be needed because
-- byron related functionality will be treated
-- separately
toTxOutInAnyEra
  :: ShelleyBasedEra era
  -> TxOutAnyEra
  -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra :: forall era.
ShelleyBasedEra era
-> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra ShelleyBasedEra era
era (TxOutAnyEra AddressAny
addr' Value
val' TxOutDatumAnyEra
mDatumHash ReferenceScriptAnyEra
refScriptFp) = do
  let cEra :: CardanoEra era
cEra = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era
  AddressInEra era
addr <- Either TxCmdError (AddressInEra era)
-> ExceptT TxCmdError IO (AddressInEra era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (AddressInEra era)
 -> ExceptT TxCmdError IO (AddressInEra era))
-> Either TxCmdError (AddressInEra era)
-> ExceptT TxCmdError IO (AddressInEra era)
forall a b. (a -> b) -> a -> b
$ CardanoEra era
-> AddressAny -> Either TxCmdError (AddressInEra era)
forall era.
CardanoEra era
-> AddressAny -> Either TxCmdError (AddressInEra era)
toAddressInAnyEra CardanoEra era
cEra AddressAny
addr'
  TxOutValue era
val <- Either TxCmdError (TxOutValue era)
-> ExceptT TxCmdError IO (TxOutValue era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxCmdError (TxOutValue era)
 -> ExceptT TxCmdError IO (TxOutValue era))
-> Either TxCmdError (TxOutValue era)
-> ExceptT TxCmdError IO (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
forall era.
ShelleyBasedEra era -> Value -> Either TxCmdError (TxOutValue era)
toTxOutValueInAnyEra ShelleyBasedEra era
era Value
val'

  TxOutDatum CtxTx era
datum <-
    (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era
 -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era
    -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> ShelleyBasedEra era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
      (ExceptT TxCmdError IO (TxOutDatum CtxTx era)
-> ShelleyToMaryEra era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a b. a -> b -> a
const (TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone))
      (\AlonzoEraOnwards era
wa -> AlonzoEraOnwards era
-> TxOutDatumAnyEra -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall era.
AlonzoEraOnwards era
-> TxOutDatumAnyEra -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum AlonzoEraOnwards era
wa TxOutDatumAnyEra
mDatumHash)
      ShelleyBasedEra era
era

  ReferenceScript era
refScript <-
    (ShelleyToAlonzoEraConstraints era =>
 ShelleyToAlonzoEra era
 -> ExceptT TxCmdError IO (ReferenceScript era))
-> (BabbageEraOnwardsConstraints era =>
    BabbageEraOnwards era
    -> ExceptT TxCmdError IO (ReferenceScript era))
-> ShelleyBasedEra era
-> ExceptT TxCmdError IO (ReferenceScript era)
forall era a.
(ShelleyToAlonzoEraConstraints era => ShelleyToAlonzoEra era -> a)
-> (BabbageEraOnwardsConstraints era => BabbageEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAlonzoOrBabbageEraOnwards
      (ExceptT TxCmdError IO (ReferenceScript era)
-> ShelleyToAlonzoEra era
-> ExceptT TxCmdError IO (ReferenceScript era)
forall a b. a -> b -> a
const (ReferenceScript era -> ExceptT TxCmdError IO (ReferenceScript era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone))
      (\BabbageEraOnwards era
wb -> BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> ExceptT TxCmdError IO (ReferenceScript era)
forall era.
BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> ExceptT TxCmdError IO (ReferenceScript era)
getReferenceScript BabbageEraOnwards era
wb ReferenceScriptAnyEra
refScriptFp)
      ShelleyBasedEra era
era
  TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era))
-> TxOut CtxTx era -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall a b. (a -> b) -> a -> b
$ AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxTx era
datum ReferenceScript era
refScript

getReferenceScript
  :: ()
  => BabbageEraOnwards era
  -> ReferenceScriptAnyEra
  -> ExceptT TxCmdError IO (ReferenceScript era)
getReferenceScript :: forall era.
BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> ExceptT TxCmdError IO (ReferenceScript era)
getReferenceScript BabbageEraOnwards era
w = \case
  ReferenceScriptAnyEra
ReferenceScriptAnyEraNone -> ReferenceScript era -> ExceptT TxCmdError IO (ReferenceScript era)
forall a. a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
  ReferenceScriptAnyEra FilePath
fp -> BabbageEraOnwards era -> ScriptInAnyLang -> ReferenceScript era
forall era.
BabbageEraOnwards era -> ScriptInAnyLang -> ReferenceScript era
ReferenceScript BabbageEraOnwards era
w (ScriptInAnyLang -> ReferenceScript era)
-> ExceptT TxCmdError IO ScriptInAnyLang
-> ExceptT TxCmdError IO (ReferenceScript era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError ScriptDecodeError -> TxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT TxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> TxCmdError
TxCmdScriptFileError (FilePath
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
MonadIOTransError (FileError ScriptDecodeError) t m =>
FilePath -> t m ScriptInAnyLang
readFileScriptInAnyLang FilePath
fp)

toTxAlonzoDatum
  :: ()
  => AlonzoEraOnwards era
  -> TxOutDatumAnyEra
  -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum :: forall era.
AlonzoEraOnwards era
-> TxOutDatumAnyEra -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum AlonzoEraOnwards era
supp TxOutDatumAnyEra
cliDatum =
  case TxOutDatumAnyEra
cliDatum of
    TxOutDatumAnyEra
TxOutDatumByNone -> TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
    TxOutDatumByHashOnly Hash ScriptData
h -> TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
supp Hash ScriptData
h)
    TxOutDatumByHashOf ScriptDataOrFile
sDataOrFile -> do
      ScriptRedeemer
sData <- (ScriptDataError -> TxCmdError)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptDataError -> TxCmdError
TxCmdScriptDataError (ExceptT ScriptDataError IO ScriptRedeemer
 -> ExceptT TxCmdError IO ScriptRedeemer)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataOrFile -> ExceptT ScriptDataError IO ScriptRedeemer
forall (m :: * -> *).
MonadIO m =>
ScriptDataOrFile -> ExceptT ScriptDataError m ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
sDataOrFile
      TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
supp (Hash ScriptData -> TxOutDatum CtxTx era)
-> Hash ScriptData -> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$ ScriptRedeemer -> Hash ScriptData
hashScriptDataBytes ScriptRedeemer
sData)
    TxOutDatumByValue ScriptDataOrFile
sDataOrFile -> do
      ScriptRedeemer
sData <- (ScriptDataError -> TxCmdError)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptDataError -> TxCmdError
TxCmdScriptDataError (ExceptT ScriptDataError IO ScriptRedeemer
 -> ExceptT TxCmdError IO ScriptRedeemer)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataOrFile -> ExceptT ScriptDataError IO ScriptRedeemer
forall (m :: * -> *).
MonadIO m =>
ScriptDataOrFile -> ExceptT ScriptDataError m ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
sDataOrFile
      TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AlonzoEraOnwards era -> ScriptRedeemer -> TxOutDatum CtxTx era
forall era.
AlonzoEraOnwards era -> ScriptRedeemer -> TxOutDatum CtxTx era
TxOutSupplementalDatum AlonzoEraOnwards era
supp ScriptRedeemer
sData)
    TxOutInlineDatumByValue ScriptDataOrFile
sDataOrFile -> do
      let cEra :: CardanoEra era
cEra = AlonzoEraOnwards era -> CardanoEra era
forall era. AlonzoEraOnwards era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra AlonzoEraOnwards era
supp
      CardanoEra era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
-> (BabbageEraOnwards era
    -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall (eon :: * -> *) era a.
Eon eon =>
CardanoEra era -> a -> (eon era -> a) -> a
forEraInEon CardanoEra era
cEra (CardanoEra era
-> TxFeature -> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall (m :: * -> *) era a.
Monad m =>
CardanoEra era -> TxFeature -> ExceptT TxCmdError m a
txFeatureMismatch CardanoEra era
cEra TxFeature
TxFeatureInlineDatums) ((BabbageEraOnwards era
  -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
 -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> (BabbageEraOnwards era
    -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a b. (a -> b) -> a -> b
$ \BabbageEraOnwards era
babbageOnwards -> do
        ScriptRedeemer
sData <- (ScriptDataError -> TxCmdError)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptDataError -> TxCmdError
TxCmdScriptDataError (ExceptT ScriptDataError IO ScriptRedeemer
 -> ExceptT TxCmdError IO ScriptRedeemer)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataOrFile -> ExceptT ScriptDataError IO ScriptRedeemer
forall (m :: * -> *).
MonadIO m =>
ScriptDataOrFile -> ExceptT ScriptDataError m ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
sDataOrFile
        TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutDatum CtxTx era
 -> ExceptT TxCmdError IO (TxOutDatum CtxTx era))
-> TxOutDatum CtxTx era
-> ExceptT TxCmdError IO (TxOutDatum CtxTx era)
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era -> ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
BabbageEraOnwards era -> ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
babbageOnwards ScriptRedeemer
sData

-- TODO: Currently we specify the policyId with the '--mint' option on the cli
-- and we added a separate '--policy-id' parser that parses the policy id for the
-- given reference input (since we don't have the script in this case). To avoid asking
-- for the policy id twice (in the build command) we can potentially query the UTxO and
-- access the script (and therefore the policy id).
createTxMintValue
  :: forall era
   . ShelleyBasedEra era
  -> (Value, [MintScriptWitnessWithPolicyId era])
  -> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue :: forall era.
ShelleyBasedEra era
-> (Value, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue ShelleyBasedEra era
era (Value
val, [MintScriptWitnessWithPolicyId era]
scriptWitnesses) =
  if [(AssetId, Quantity)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
List.null (Value -> [Item Value]
forall l. IsList l => l -> [Item l]
toList Value
val) Bool -> Bool -> Bool
&& [MintScriptWitnessWithPolicyId era] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
List.null [MintScriptWitnessWithPolicyId era]
scriptWitnesses
    then TxMintValue BuildTx era
-> Either TxCmdError (TxMintValue BuildTx era)
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return TxMintValue BuildTx era
forall build era. TxMintValue build era
TxMintNone
    else do
      (ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era
 -> Either TxCmdError (TxMintValue BuildTx era))
-> (MaryEraOnwardsConstraints era =>
    MaryEraOnwards era -> Either TxCmdError (TxMintValue BuildTx era))
-> ShelleyBasedEra era
-> Either TxCmdError (TxMintValue BuildTx era)
forall era a.
(ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> a)
-> (MaryEraOnwardsConstraints era => MaryEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAllegraOrMaryEraOnwards
        (Either TxCmdError (TxMintValue BuildTx era)
-> ShelleyToAllegraEra era
-> Either TxCmdError (TxMintValue BuildTx era)
forall a b. a -> b -> a
const (CardanoEra era
-> TxFeature -> Either TxCmdError (TxMintValue BuildTx era)
forall era a. CardanoEra era -> TxFeature -> Either TxCmdError a
txFeatureMismatchPure (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era) TxFeature
TxFeatureMintValue))
        ( \MaryEraOnwards era
w -> do
            let policiesWithAssets :: [(PolicyId, AssetName, Quantity)]
                policiesWithAssets :: [(PolicyId, AssetName, Quantity)]
policiesWithAssets = [(PolicyId
pid, AssetName
assetName, Quantity
quantity) | (AssetId PolicyId
pid AssetName
assetName, Quantity
quantity) <- Value -> [Item Value]
forall l. IsList l => l -> [Item l]
toList Value
val]
                -- The set of policy ids for which we need witnesses:
                witnessesNeededSet :: Set PolicyId
                witnessesNeededSet :: Set PolicyId
witnessesNeededSet = [Item (Set PolicyId)] -> Set PolicyId
forall l. IsList l => [Item l] -> l
fromList [Item (Set PolicyId)
PolicyId
pid | (PolicyId
pid, AssetName
_, Quantity
_) <- [(PolicyId, AssetName, Quantity)]
policiesWithAssets]

            let witnessesProvidedMap :: Map PolicyId (ScriptWitness WitCtxMint era)
                witnessesProvidedMap :: Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap = [Item (Map PolicyId (ScriptWitness WitCtxMint era))]
-> Map PolicyId (ScriptWitness WitCtxMint era)
forall l. IsList l => [Item l] -> l
fromList ([Item (Map PolicyId (ScriptWitness WitCtxMint era))]
 -> Map PolicyId (ScriptWitness WitCtxMint era))
-> [Item (Map PolicyId (ScriptWitness WitCtxMint era))]
-> Map PolicyId (ScriptWitness WitCtxMint era)
forall a b. (a -> b) -> a -> b
$ [(PolicyId
polid, ScriptWitness WitCtxMint era
sWit) | MintScriptWitnessWithPolicyId PolicyId
polid ScriptWitness WitCtxMint era
sWit <- [MintScriptWitnessWithPolicyId era]
scriptWitnesses]
                witnessesProvidedSet :: Set PolicyId
witnessesProvidedSet = Map PolicyId (ScriptWitness WitCtxMint era) -> Set PolicyId
forall k a. Map k a -> Set k
Map.keysSet Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap
                policiesWithWitnesses :: Map
  PolicyId
  [(AssetName, Quantity,
    BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
policiesWithWitnesses =
                  ([(AssetName, Quantity,
   BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
 -> [(AssetName, Quantity,
      BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
 -> [(AssetName, Quantity,
      BuildTxWith BuildTx (ScriptWitness WitCtxMint era))])
-> [(PolicyId,
     [(AssetName, Quantity,
       BuildTxWith BuildTx (ScriptWitness WitCtxMint era))])]
-> Map
     PolicyId
     [(AssetName, Quantity,
       BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith
                    [(AssetName, Quantity,
  BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
-> [(AssetName, Quantity,
     BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
-> [(AssetName, Quantity,
     BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
forall a. Semigroup a => a -> a -> a
(<>)
                    [ (PolicyId
pid, [(AssetName
assetName, Quantity
quantity, ScriptWitness WitCtxMint era
-> BuildTxWith BuildTx (ScriptWitness WitCtxMint era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith ScriptWitness WitCtxMint era
witness)])
                    | (PolicyId
pid, AssetName
assetName, Quantity
quantity) <- [(PolicyId, AssetName, Quantity)]
policiesWithAssets
                    , ScriptWitness WitCtxMint era
witness <- Maybe (ScriptWitness WitCtxMint era)
-> [ScriptWitness WitCtxMint era]
forall a. Maybe a -> [a]
maybeToList (Maybe (ScriptWitness WitCtxMint era)
 -> [ScriptWitness WitCtxMint era])
-> Maybe (ScriptWitness WitCtxMint era)
-> [ScriptWitness WitCtxMint era]
forall a b. (a -> b) -> a -> b
$ PolicyId
-> Map PolicyId (ScriptWitness WitCtxMint era)
-> Maybe (ScriptWitness WitCtxMint era)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PolicyId
pid Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap
                    ]
            -- Check not too many, nor too few:
            Set PolicyId -> Set PolicyId -> Either TxCmdError ()
validateAllWitnessesProvided Set PolicyId
witnessesNeededSet Set PolicyId
witnessesProvidedSet
            Set PolicyId -> Set PolicyId -> Either TxCmdError ()
validateNoUnnecessaryWitnesses Set PolicyId
witnessesNeededSet Set PolicyId
witnessesProvidedSet
            TxMintValue BuildTx era
-> Either TxCmdError (TxMintValue BuildTx era)
forall a. a -> Either TxCmdError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxMintValue BuildTx era
 -> Either TxCmdError (TxMintValue BuildTx era))
-> TxMintValue BuildTx era
-> Either TxCmdError (TxMintValue BuildTx era)
forall a b. (a -> b) -> a -> b
$ MaryEraOnwards era
-> Map
     PolicyId
     [(AssetName, Quantity,
       BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
-> TxMintValue BuildTx era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     [(AssetName, Quantity,
       BuildTxWith build (ScriptWitness WitCtxMint era))]
-> TxMintValue build era
TxMintValue MaryEraOnwards era
w Map
  PolicyId
  [(AssetName, Quantity,
    BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
policiesWithWitnesses
        )
        ShelleyBasedEra era
era
 where
  validateAllWitnessesProvided :: Set PolicyId -> Set PolicyId -> Either TxCmdError ()
validateAllWitnessesProvided Set PolicyId
witnessesNeeded Set PolicyId
witnessesProvided
    | [PolicyId] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PolicyId]
witnessesMissing = () -> Either TxCmdError ()
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    | Bool
otherwise = TxCmdError -> Either TxCmdError ()
forall a b. a -> Either a b
Left ([PolicyId] -> [PolicyId] -> TxCmdError
TxCmdPolicyIdsMissing [PolicyId]
witnessesMissing (Set PolicyId -> [Item (Set PolicyId)]
forall l. IsList l => l -> [Item l]
toList Set PolicyId
witnessesProvided))
   where
    witnessesMissing :: [PolicyId]
witnessesMissing = Set PolicyId -> [PolicyId]
forall a. Set a -> [a]
Set.elems (Set PolicyId
witnessesNeeded Set PolicyId -> Set PolicyId -> Set PolicyId
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PolicyId
witnessesProvided)

  validateNoUnnecessaryWitnesses :: Set PolicyId -> Set PolicyId -> Either TxCmdError ()
validateNoUnnecessaryWitnesses Set PolicyId
witnessesNeeded Set PolicyId
witnessesProvided
    | [PolicyId] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PolicyId]
witnessesExtra = () -> Either TxCmdError ()
forall a. a -> Either TxCmdError a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    | Bool
otherwise = TxCmdError -> Either TxCmdError ()
forall a b. a -> Either a b
Left ([PolicyId] -> TxCmdError
TxCmdPolicyIdsExcess [PolicyId]
witnessesExtra)
   where
    witnessesExtra :: [PolicyId]
witnessesExtra = Set PolicyId -> [PolicyId]
forall a. Set a -> [a]
Set.elems (Set PolicyId
witnessesProvided Set PolicyId -> Set PolicyId -> Set PolicyId
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set PolicyId
witnessesNeeded)

-- ----------------------------------------------------------------------------
-- Transaction signing
--

runTransactionSignCmd
  :: ()
  => Cmd.TransactionSignCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionSignCmd :: TransactionSignCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSignCmd
  Cmd.TransactionSignCmdArgs
    { txOrTxBodyFile :: TransactionSignCmdArgs -> InputTxBodyOrTxFile
txOrTxBodyFile = InputTxBodyOrTxFile
txOrTxBody
    , witnessSigningData :: TransactionSignCmdArgs -> [WitnessSigningData]
witnessSigningData = [WitnessSigningData]
witnessSigningData
    , mNetworkId :: TransactionSignCmdArgs -> Maybe NetworkId
mNetworkId = Maybe NetworkId
mNetworkId
    , outTxFile :: TransactionSignCmdArgs -> TxFile 'Out
outTxFile = TxFile 'Out
outTxFile
    } = do
    [SomeSigningWitness]
sks <- [WitnessSigningData]
-> (WitnessSigningData -> ExceptT TxCmdError IO SomeSigningWitness)
-> ExceptT TxCmdError IO [SomeSigningWitness]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [WitnessSigningData]
witnessSigningData ((WitnessSigningData -> ExceptT TxCmdError IO SomeSigningWitness)
 -> ExceptT TxCmdError IO [SomeSigningWitness])
-> (WitnessSigningData -> ExceptT TxCmdError IO SomeSigningWitness)
-> ExceptT TxCmdError IO [SomeSigningWitness]
forall a b. (a -> b) -> a -> b
$ \WitnessSigningData
d ->
      IO (Either ReadWitnessSigningDataError SomeSigningWitness)
-> ExceptT
     TxCmdError
     IO
     (Either ReadWitnessSigningDataError SomeSigningWitness)
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (WitnessSigningData
-> IO (Either ReadWitnessSigningDataError SomeSigningWitness)
readWitnessSigningData WitnessSigningData
d)
        ExceptT
  TxCmdError
  IO
  (Either ReadWitnessSigningDataError SomeSigningWitness)
-> (ExceptT
      TxCmdError
      IO
      (Either ReadWitnessSigningDataError SomeSigningWitness)
    -> ExceptT TxCmdError IO SomeSigningWitness)
-> ExceptT TxCmdError IO SomeSigningWitness
forall a b. a -> (a -> b) -> b
& (ReadWitnessSigningDataError
 -> ExceptT TxCmdError IO SomeSigningWitness)
-> ExceptT
     TxCmdError
     IO
     (Either ReadWitnessSigningDataError SomeSigningWitness)
-> ExceptT TxCmdError IO SomeSigningWitness
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO SomeSigningWitness
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO SomeSigningWitness)
-> (ReadWitnessSigningDataError -> TxCmdError)
-> ReadWitnessSigningDataError
-> ExceptT TxCmdError IO SomeSigningWitness
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReadWitnessSigningDataError -> TxCmdError
TxCmdReadWitnessSigningDataError)

    let ([ShelleyBootstrapWitnessSigningKeyData]
sksByron, [ShelleyWitnessSigningKey]
sksShelley) = [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
partitionSomeWitnesses ([ByronOrShelleyWitness]
 -> ([ShelleyBootstrapWitnessSigningKeyData],
     [ShelleyWitnessSigningKey]))
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
forall a b. (a -> b) -> a -> b
$ (SomeSigningWitness -> ByronOrShelleyWitness)
-> [SomeSigningWitness] -> [ByronOrShelleyWitness]
forall a b. (a -> b) -> [a] -> [b]
map SomeSigningWitness -> ByronOrShelleyWitness
categoriseSomeSigningWitness [SomeSigningWitness]
sks

    case InputTxBodyOrTxFile
txOrTxBody of
      InputTxFile (File FilePath
inputTxFilePath) -> do
        FileOrPipe
inputTxFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
inputTxFilePath
        InAnyShelleyBasedEra Tx
anyTx <- IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (FileOrPipe
-> IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
readFileTx FileOrPipe
inputTxFile) ExceptT
  TxCmdError
  IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> (ExceptT
      TxCmdError
      IO
      (Either
         (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
    -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeCddlError
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> (FileError TextEnvelopeCddlError -> TxCmdError)
-> FileError TextEnvelopeCddlError
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError)

        InAnyShelleyBasedEra ShelleyBasedEra era
sbe Tx era
tx <- InAnyShelleyBasedEra Tx
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InAnyShelleyBasedEra Tx
anyTx

        let (TxBody era
txbody, [KeyWitness era]
existingTxKeyWits) = Tx era -> (TxBody era, [KeyWitness era])
forall era. Tx era -> (TxBody era, [KeyWitness era])
getTxBodyAndWitnesses Tx era
tx

        [KeyWitness era]
byronWitnesses <-
          Either BootstrapWitnessError [KeyWitness era]
-> ExceptT
     TxCmdError IO (Either BootstrapWitnessError [KeyWitness era])
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId TxBody era
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron)
            ExceptT
  TxCmdError IO (Either BootstrapWitnessError [KeyWitness era])
-> (ExceptT
      TxCmdError IO (Either BootstrapWitnessError [KeyWitness era])
    -> ExceptT TxCmdError IO [KeyWitness era])
-> ExceptT TxCmdError IO [KeyWitness era]
forall a b. a -> (a -> b) -> b
& (BootstrapWitnessError -> ExceptT TxCmdError IO [KeyWitness era])
-> ExceptT
     TxCmdError IO (Either BootstrapWitnessError [KeyWitness era])
-> ExceptT TxCmdError IO [KeyWitness era]
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO [KeyWitness era]
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO [KeyWitness era])
-> (BootstrapWitnessError -> TxCmdError)
-> BootstrapWitnessError
-> ExceptT TxCmdError IO [KeyWitness era]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BootstrapWitnessError -> TxCmdError
TxCmdBootstrapWitnessError)

        let newShelleyKeyWits :: [KeyWitness era]
newShelleyKeyWits = (ShelleyWitnessSigningKey -> KeyWitness era)
-> [ShelleyWitnessSigningKey] -> [KeyWitness era]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness ShelleyBasedEra era
sbe TxBody era
txbody) [ShelleyWitnessSigningKey]
sksShelley
            allKeyWits :: [KeyWitness era]
allKeyWits = [KeyWitness era]
existingTxKeyWits [KeyWitness era] -> [KeyWitness era] -> [KeyWitness era]
forall a. [a] -> [a] -> [a]
++ [KeyWitness era]
newShelleyKeyWits [KeyWitness era] -> [KeyWitness era] -> [KeyWitness era]
forall a. [a] -> [a] -> [a]
++ [KeyWitness era]
byronWitnesses
            signedTx :: Tx era
signedTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [KeyWitness era]
allKeyWits TxBody era
txbody

        IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> TxFile 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
sbe TxFile 'Out
outTxFile Tx era
signedTx)
          ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)
      InputTxBodyFile (File FilePath
txbodyFilePath) -> do
        FileOrPipe
txbodyFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
        IncompleteCddlTxBody
unwitnessed <-
          (FileError TextEnvelopeCddlError -> TxCmdError)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError (ExceptT (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> (IO
      (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
    -> ExceptT
         (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall a b. (a -> b) -> a -> b
$
            FileOrPipe
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
readFileTxBody FileOrPipe
txbodyFile

        case IncompleteCddlTxBody
unwitnessed of
          IncompleteCddlTxBody InAnyShelleyBasedEra TxBody
anyTxBody -> do
            InAnyShelleyBasedEra ShelleyBasedEra era
sbe TxBody era
txbody <- InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InAnyShelleyBasedEra TxBody
anyTxBody

            -- Byron witnesses require the network ID. This can either be provided
            -- directly or derived from a provided Byron address.
            [KeyWitness era]
byronWitnesses <-
              (BootstrapWitnessError -> TxCmdError)
-> ExceptT BootstrapWitnessError IO [KeyWitness era]
-> ExceptT TxCmdError IO [KeyWitness era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT BootstrapWitnessError -> TxCmdError
TxCmdBootstrapWitnessError
                (ExceptT BootstrapWitnessError IO [KeyWitness era]
 -> ExceptT TxCmdError IO [KeyWitness era])
-> (Either BootstrapWitnessError [KeyWitness era]
    -> ExceptT BootstrapWitnessError IO [KeyWitness era])
-> Either BootstrapWitnessError [KeyWitness era]
-> ExceptT TxCmdError IO [KeyWitness era]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either BootstrapWitnessError [KeyWitness era]
-> ExceptT BootstrapWitnessError IO [KeyWitness era]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
                (Either BootstrapWitnessError [KeyWitness era]
 -> ExceptT TxCmdError IO [KeyWitness era])
-> Either BootstrapWitnessError [KeyWitness era]
-> ExceptT TxCmdError IO [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId TxBody era
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron

            let shelleyKeyWitnesses :: [KeyWitness era]
shelleyKeyWitnesses = (ShelleyWitnessSigningKey -> KeyWitness era)
-> [ShelleyWitnessSigningKey] -> [KeyWitness era]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness ShelleyBasedEra era
sbe TxBody era
txbody) [ShelleyWitnessSigningKey]
sksShelley
                tx :: Tx era
tx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction ([KeyWitness era]
byronWitnesses [KeyWitness era] -> [KeyWitness era] -> [KeyWitness era]
forall a. [a] -> [a] -> [a]
++ [KeyWitness era]
shelleyKeyWitnesses) TxBody era
txbody

            IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> TxFile 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
sbe TxFile 'Out
outTxFile Tx era
tx)
              ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)

-- ----------------------------------------------------------------------------
-- Transaction submission
--

runTransactionSubmitCmd
  :: ()
  => Cmd.TransactionSubmitCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionSubmitCmd :: TransactionSubmitCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSubmitCmd
  Cmd.TransactionSubmitCmdArgs
    { SocketPath
nodeSocketPath :: SocketPath
nodeSocketPath :: TransactionSubmitCmdArgs -> SocketPath
nodeSocketPath
    , ConsensusModeParams
consensusModeParams :: ConsensusModeParams
consensusModeParams :: TransactionSubmitCmdArgs -> ConsensusModeParams
consensusModeParams
    , NetworkId
networkId :: NetworkId
networkId :: TransactionSubmitCmdArgs -> NetworkId
networkId
    , FilePath
txFile :: FilePath
txFile :: TransactionSubmitCmdArgs -> FilePath
txFile
    } = do
    FileOrPipe
txFileOrPipe <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txFile
    InAnyShelleyBasedEra ShelleyBasedEra era
era Tx era
tx <-
      IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (FileOrPipe
-> IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
readFileTx FileOrPipe
txFileOrPipe) ExceptT
  TxCmdError
  IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> (ExceptT
      TxCmdError
      IO
      (Either
         (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
    -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeCddlError
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> (FileError TextEnvelopeCddlError -> TxCmdError)
-> FileError TextEnvelopeCddlError
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError)
    let txInMode :: TxInMode
txInMode = ShelleyBasedEra era -> Tx era -> TxInMode
forall era. ShelleyBasedEra era -> Tx era -> TxInMode
TxInMode ShelleyBasedEra era
era Tx era
tx
        localNodeConnInfo :: LocalNodeConnectInfo
localNodeConnInfo =
          LocalNodeConnectInfo
            { localConsensusModeParams :: ConsensusModeParams
localConsensusModeParams = ConsensusModeParams
consensusModeParams
            , localNodeNetworkId :: NetworkId
localNodeNetworkId = NetworkId
networkId
            , localNodeSocketPath :: SocketPath
localNodeSocketPath = SocketPath
nodeSocketPath
            }

    SubmitResult TxValidationErrorInCardanoMode
res <- IO (SubmitResult TxValidationErrorInCardanoMode)
-> ExceptT
     TxCmdError IO (SubmitResult TxValidationErrorInCardanoMode)
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (SubmitResult TxValidationErrorInCardanoMode)
 -> ExceptT
      TxCmdError IO (SubmitResult TxValidationErrorInCardanoMode))
-> IO (SubmitResult TxValidationErrorInCardanoMode)
-> ExceptT
     TxCmdError IO (SubmitResult TxValidationErrorInCardanoMode)
forall a b. (a -> b) -> a -> b
$ LocalNodeConnectInfo
-> TxInMode -> IO (SubmitResult TxValidationErrorInCardanoMode)
forall (m :: * -> *).
MonadIO m =>
LocalNodeConnectInfo
-> TxInMode -> m (SubmitResult TxValidationErrorInCardanoMode)
submitTxToNodeLocal LocalNodeConnectInfo
localNodeConnInfo TxInMode
txInMode
    case SubmitResult TxValidationErrorInCardanoMode
res of
      SubmitResult TxValidationErrorInCardanoMode
Net.Tx.SubmitSuccess -> do
        IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Handle -> Text -> IO ()
Text.hPutStrLn Handle
IO.stderr Text
"Transaction successfully submitted. Transaction hash is:"
        IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
LBS.putStrLn (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ TxSubmissionResult -> ByteString
forall a. ToJSON a => a -> ByteString
Aeson.encode (TxSubmissionResult -> ByteString)
-> TxSubmissionResult -> ByteString
forall a b. (a -> b) -> a -> b
$ TxId -> TxSubmissionResult
TxSubmissionResult (TxId -> TxSubmissionResult) -> TxId -> TxSubmissionResult
forall a b. (a -> b) -> a -> b
$ TxBody era -> TxId
forall era. TxBody era -> TxId
getTxId (TxBody era -> TxId) -> TxBody era -> TxId
forall a b. (a -> b) -> a -> b
$ Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
tx
      Net.Tx.SubmitFail TxValidationErrorInCardanoMode
reason ->
        case TxValidationErrorInCardanoMode
reason of
          TxValidationErrorInCardanoMode TxValidationError era
err -> TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FilePath -> TxCmdError) -> FilePath -> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TxCmdError
TxCmdTxSubmitError (Text -> TxCmdError)
-> (FilePath -> Text) -> FilePath -> TxCmdError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
Text.pack (FilePath -> ExceptT TxCmdError IO ())
-> FilePath -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ TxValidationError era -> FilePath
forall a. Show a => a -> FilePath
show TxValidationError era
err
          TxValidationEraMismatch EraMismatch
mismatchErr -> TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> TxCmdError -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ EraMismatch -> TxCmdError
TxCmdTxSubmitErrorEraMismatch EraMismatch
mismatchErr

-- ----------------------------------------------------------------------------
-- Transaction fee calculation
--

runTransactionCalculateMinFeeCmd
  :: ()
  => Cmd.TransactionCalculateMinFeeCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionCalculateMinFeeCmd :: TransactionCalculateMinFeeCmdArgs -> ExceptT TxCmdError IO ()
runTransactionCalculateMinFeeCmd
  Cmd.TransactionCalculateMinFeeCmdArgs
    { txBodyFile :: TransactionCalculateMinFeeCmdArgs -> File (TxBody ()) 'In
txBodyFile = File FilePath
txbodyFilePath
    , protocolParamsFile :: TransactionCalculateMinFeeCmdArgs -> ProtocolParamsFile
protocolParamsFile = ProtocolParamsFile
protocolParamsFile
    , txShelleyWitnessCount :: TransactionCalculateMinFeeCmdArgs -> TxShelleyWitnessCount
txShelleyWitnessCount = TxShelleyWitnessCount Int
nShelleyKeyWitnesses
    , txByronWitnessCount :: TransactionCalculateMinFeeCmdArgs -> TxByronWitnessCount
txByronWitnessCount = TxByronWitnessCount Int
nByronKeyWitnesses
    , referenceScriptSize :: TransactionCalculateMinFeeCmdArgs -> ReferenceScriptSize
referenceScriptSize = ReferenceScriptSize Int
sReferenceScript
    , Maybe OutputFormatJsonOrText
outputFormat :: Maybe OutputFormatJsonOrText
outputFormat :: TransactionCalculateMinFeeCmdArgs -> Maybe OutputFormatJsonOrText
outputFormat
    , Maybe (File () 'Out)
outFile :: Maybe (File () 'Out)
outFile :: TransactionCalculateMinFeeCmdArgs -> Maybe (File () 'Out)
outFile
    } = do
    FileOrPipe
txbodyFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
    IncompleteCddlTxBody
unwitnessed <-
      (FileError TextEnvelopeCddlError -> TxCmdError)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError (ExceptT (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> (IO
      (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
    -> ExceptT
         (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall a b. (a -> b) -> a -> b
$
        FileOrPipe
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
readFileTxBody FileOrPipe
txbodyFile

    let nShelleyKeyWitW32 :: Word
nShelleyKeyWitW32 = Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nShelleyKeyWitnesses

    InAnyShelleyBasedEra ShelleyBasedEra era
sbe TxBody era
txbody <- InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InAnyShelleyBasedEra TxBody
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody))
-> InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a b. (a -> b) -> a -> b
$ IncompleteCddlTxBody -> InAnyShelleyBasedEra TxBody
unIncompleteCddlTxBody IncompleteCddlTxBody
unwitnessed

    PParams (ShelleyLedgerEra era)
lpparams <-
      (ProtocolParamsError -> TxCmdError)
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ProtocolParamsError -> TxCmdError
TxCmdProtocolParamsError (ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
 -> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era)))
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
readProtocolParameters ShelleyBasedEra era
sbe ProtocolParamsFile
protocolParamsFile

    let shelleyfee :: Lovelace
shelleyfee = ShelleyBasedEra era
-> PParams (ShelleyLedgerEra era)
-> TxBody era
-> Word
-> Word
-> Int
-> Lovelace
forall era.
ShelleyBasedEra era
-> PParams (ShelleyLedgerEra era)
-> TxBody era
-> Word
-> Word
-> Int
-> Lovelace
evaluateTransactionFee ShelleyBasedEra era
sbe PParams (ShelleyLedgerEra era)
lpparams TxBody era
txbody Word
nShelleyKeyWitW32 Word
0 Int
sReferenceScript

    let byronfee :: Lovelace
byronfee =
          ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => Lovelace) -> Lovelace
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => Lovelace) -> Lovelace)
-> (ShelleyBasedEraConstraints era => Lovelace) -> Lovelace
forall a b. (a -> b) -> a -> b
$
            Lovelace -> Int -> Lovelace
calculateByronWitnessFees (PParams (ShelleyLedgerEra era)
lpparams PParams (ShelleyLedgerEra era)
-> Getting Lovelace (PParams (ShelleyLedgerEra era)) Lovelace
-> Lovelace
forall s a. s -> Getting a s a -> a
^. Getting Lovelace (PParams (ShelleyLedgerEra era)) Lovelace
forall era. EraPParams era => Lens' (PParams era) Lovelace
Lens' (PParams (ShelleyLedgerEra era)) Lovelace
L.ppMinFeeAL) Int
nByronKeyWitnesses

    let fee :: Lovelace
fee = Lovelace
shelleyfee Lovelace -> Lovelace -> Lovelace
forall a. Num a => a -> a -> a
+ Lovelace
byronfee
        textToWrite :: Text
textToWrite = Doc AnsiStyle -> Text
docToText (Doc AnsiStyle -> Text) -> Doc AnsiStyle -> Text
forall a b. (a -> b) -> a -> b
$ Lovelace -> Doc AnsiStyle
forall a ann. Pretty a => a -> Doc ann
forall ann. Lovelace -> Doc ann
pretty Lovelace
fee
        jsonToWrite :: ByteString
jsonToWrite = Value -> ByteString
forall a. ToJSON a => a -> ByteString
encodePretty (Value -> ByteString) -> Value -> ByteString
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
Aeson.object [Key
"fee" Key -> Lovelace -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Lovelace
fee]

    case (Maybe OutputFormatJsonOrText
-> Maybe (File () 'Out) -> OutputFormatJsonOrText
forall a.
Maybe OutputFormatJsonOrText -> Maybe a -> OutputFormatJsonOrText
newOutputFormat Maybe OutputFormatJsonOrText
outputFormat Maybe (File () 'Out)
outFile, Maybe (File () 'Out)
outFile) of
      (OutputFormatJsonOrText
OutputFormatText, Maybe (File () 'Out)
Nothing) ->
        IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Text -> IO ()
Text.putStrLn Text
textToWrite
      (OutputFormatJsonOrText
OutputFormatText, Just File () 'Out
file) ->
        (FileError () -> TxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> TxCmdError
TxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ()
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ File () 'Out -> Text -> IO (Either (FileError ()) ())
forall (m :: * -> *) content e.
MonadIO m =>
File content 'Out -> Text -> m (Either (FileError e) ())
writeTextFile File () 'Out
file Text
textToWrite
      (OutputFormatJsonOrText
OutputFormatJson, Maybe (File () 'Out)
Nothing) ->
        IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
LBS.putStrLn ByteString
jsonToWrite
      (OutputFormatJsonOrText
OutputFormatJson, Just File () 'Out
file) ->
        (FileError () -> TxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> TxCmdError
TxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ()
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ File () 'Out -> ByteString -> IO (Either (FileError ()) ())
forall (m :: * -> *) content e.
MonadIO m =>
File content 'Out -> ByteString -> m (Either (FileError e) ())
writeLazyByteStringFile File () 'Out
file ByteString
jsonToWrite

-- Extra logic to handle byron witnesses.
-- TODO: move this to Cardano.API.Fee.evaluateTransactionFee.
calculateByronWitnessFees
  :: ()
  => Lovelace
  -- ^ The tx fee per byte (from protocol parameters)
  -> Int
  -- ^ The number of Byron key witnesses
  -> Lovelace
calculateByronWitnessFees :: Lovelace -> Int -> Lovelace
calculateByronWitnessFees Lovelace
txFeePerByte Int
byronwitcount =
  Integer -> Lovelace
L.Coin (Integer -> Lovelace) -> Integer -> Lovelace
forall a b. (a -> b) -> a -> b
$
    Lovelace -> Integer
forall a. Integral a => a -> Integer
toInteger Lovelace
txFeePerByte
      Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
byronwitcount
      Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
sizeByronKeyWitnesses
 where
  sizeByronKeyWitnesses :: Int
sizeByronKeyWitnesses = Int
smallArray Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
keyObj Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
sigObj Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ccodeObj Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
attrsObj

  smallArray :: Int
smallArray = Int
1

  keyObj :: Int
keyObj = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
keyLen
  keyLen :: Int
keyLen = Int
32

  sigObj :: Int
sigObj = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
sigLen
  sigLen :: Int
sigLen = Int
64

  ccodeObj :: Int
ccodeObj = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ccodeLen
  ccodeLen :: Int
ccodeLen = Int
32

  attrsObj :: Int
attrsObj = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ ByteString -> Int
Data.Bytestring.length ByteString
attributes

  -- We assume testnet network magic here to avoid having
  -- to thread the actual network ID into this function
  -- merely to calculate the fees of byron witnesses more accurately.
  -- This may slightly over-estimate min fees for byron witnesses
  -- in mainnet transaction by one Word32 per witness.
  attributes :: ByteString
attributes =
    Attributes AddrAttributes -> ByteString
forall a. ToCBOR a => a -> ByteString
CBOR.serialize' (Attributes AddrAttributes -> ByteString)
-> Attributes AddrAttributes -> ByteString
forall a b. (a -> b) -> a -> b
$
      AddrAttributes -> Attributes AddrAttributes
forall h. h -> Attributes h
Byron.mkAttributes
        Byron.AddrAttributes
          { aaVKDerivationPath :: Maybe HDAddressPayload
Byron.aaVKDerivationPath = Maybe HDAddressPayload
forall a. Maybe a
Nothing
          , aaNetworkMagic :: NetworkMagic
Byron.aaNetworkMagic = Word32 -> NetworkMagic
Byron.NetworkTestnet Word32
forall a. Bounded a => a
maxBound
          }

-- ----------------------------------------------------------------------------
-- Transaction fee calculation
--

runTransactionCalculateMinValueCmd
  :: ()
  => Cmd.TransactionCalculateMinValueCmdArgs era
  -> ExceptT TxCmdError IO ()
runTransactionCalculateMinValueCmd :: forall era.
TransactionCalculateMinValueCmdArgs era -> ExceptT TxCmdError IO ()
runTransactionCalculateMinValueCmd
  Cmd.TransactionCalculateMinValueCmdArgs
    { ShelleyBasedEra era
eon :: ShelleyBasedEra era
eon :: forall era.
TransactionCalculateMinValueCmdArgs era -> ShelleyBasedEra era
eon
    , ProtocolParamsFile
protocolParamsFile :: ProtocolParamsFile
protocolParamsFile :: forall era.
TransactionCalculateMinValueCmdArgs era -> ProtocolParamsFile
protocolParamsFile
    , TxOutShelleyBasedEra
txOut :: TxOutShelleyBasedEra
txOut :: forall era.
TransactionCalculateMinValueCmdArgs era -> TxOutShelleyBasedEra
txOut
    } = do
    PParams (ShelleyLedgerEra era)
pp <- (ProtocolParamsError -> TxCmdError)
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
-> ExceptT TxCmdError IO (PParams (ShelleyLedgerEra era))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ProtocolParamsError -> TxCmdError
TxCmdProtocolParamsError (ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (PParams (ShelleyLedgerEra era))
readProtocolParameters ShelleyBasedEra era
eon ProtocolParamsFile
protocolParamsFile)
    TxOut CtxTx era
out <- ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
forall era.
ShelleyBasedEra era
-> TxOutShelleyBasedEra -> ExceptT TxCmdError IO (TxOut CtxTx era)
toTxOutInShelleyBasedEra ShelleyBasedEra era
eon TxOutShelleyBasedEra
txOut

    let minValue :: Lovelace
minValue = ShelleyBasedEra era
-> TxOut CtxTx era -> PParams (ShelleyLedgerEra era) -> Lovelace
forall era.
ShelleyBasedEra era
-> TxOut CtxTx era -> PParams (ShelleyLedgerEra era) -> Lovelace
calculateMinimumUTxO ShelleyBasedEra era
eon TxOut CtxTx era
out PParams (ShelleyLedgerEra era)
pp
    IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> (Lovelace -> IO ()) -> Lovelace -> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lovelace -> IO ()
forall a. Show a => a -> IO ()
IO.print (Lovelace -> ExceptT TxCmdError IO ())
-> Lovelace -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Lovelace
minValue

runTransactionPolicyIdCmd
  :: ()
  => Cmd.TransactionPolicyIdCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionPolicyIdCmd :: TransactionPolicyIdCmdArgs -> ExceptT TxCmdError IO ()
runTransactionPolicyIdCmd
  Cmd.TransactionPolicyIdCmdArgs
    { scriptFile :: TransactionPolicyIdCmdArgs -> ScriptFile
scriptFile = File FilePath
sFile
    } = do
    ScriptInAnyLang ScriptLanguage lang
_ Script lang
script <-
      (FileError ScriptDecodeError -> TxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT TxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> TxCmdError
TxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
 -> ExceptT TxCmdError IO ScriptInAnyLang)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT TxCmdError IO ScriptInAnyLang
forall a b. (a -> b) -> a -> b
$
        FilePath
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
MonadIOTransError (FileError ScriptDecodeError) t m =>
FilePath -> t m ScriptInAnyLang
readFileScriptInAnyLang FilePath
sFile
    IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> (ScriptHash -> IO ()) -> ScriptHash -> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> IO ()
Text.putStrLn (Text -> IO ()) -> (ScriptHash -> Text) -> ScriptHash -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptHash -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText (ScriptHash -> ExceptT TxCmdError IO ())
-> ScriptHash -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Script lang -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript Script lang
script

partitionSomeWitnesses
  :: [ByronOrShelleyWitness]
  -> ( [ShelleyBootstrapWitnessSigningKeyData]
     , [ShelleyWitnessSigningKey]
     )
partitionSomeWitnesses :: [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
partitionSomeWitnesses = ([ShelleyBootstrapWitnessSigningKeyData],
 [ShelleyWitnessSigningKey])
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
forall {a} {a}. ([a], [a]) -> ([a], [a])
reversePartitionedWits (([ShelleyBootstrapWitnessSigningKeyData],
  [ShelleyWitnessSigningKey])
 -> ([ShelleyBootstrapWitnessSigningKeyData],
     [ShelleyWitnessSigningKey]))
-> ([ByronOrShelleyWitness]
    -> ([ShelleyBootstrapWitnessSigningKeyData],
        [ShelleyWitnessSigningKey]))
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([ShelleyBootstrapWitnessSigningKeyData],
  [ShelleyWitnessSigningKey])
 -> ByronOrShelleyWitness
 -> ([ShelleyBootstrapWitnessSigningKeyData],
     [ShelleyWitnessSigningKey]))
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' ([ShelleyBootstrapWitnessSigningKeyData],
 [ShelleyWitnessSigningKey])
-> ByronOrShelleyWitness
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
go ([ShelleyBootstrapWitnessSigningKeyData],
 [ShelleyWitnessSigningKey])
forall a. Monoid a => a
mempty
 where
  reversePartitionedWits :: ([a], [a]) -> ([a], [a])
reversePartitionedWits ([a]
bw, [a]
skw) =
    ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
bw, [a] -> [a]
forall a. [a] -> [a]
reverse [a]
skw)

  go :: ([ShelleyBootstrapWitnessSigningKeyData],
 [ShelleyWitnessSigningKey])
-> ByronOrShelleyWitness
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
go ([ShelleyBootstrapWitnessSigningKeyData]
byronAcc, [ShelleyWitnessSigningKey]
shelleyKeyAcc) ByronOrShelleyWitness
byronOrShelleyWit =
    case ByronOrShelleyWitness
byronOrShelleyWit of
      AByronWitness ShelleyBootstrapWitnessSigningKeyData
byronWit ->
        (ShelleyBootstrapWitnessSigningKeyData
byronWit ShelleyBootstrapWitnessSigningKeyData
-> [ShelleyBootstrapWitnessSigningKeyData]
-> [ShelleyBootstrapWitnessSigningKeyData]
forall a. a -> [a] -> [a]
: [ShelleyBootstrapWitnessSigningKeyData]
byronAcc, [ShelleyWitnessSigningKey]
shelleyKeyAcc)
      AShelleyKeyWitness ShelleyWitnessSigningKey
shelleyKeyWit ->
        ([ShelleyBootstrapWitnessSigningKeyData]
byronAcc, ShelleyWitnessSigningKey
shelleyKeyWit ShelleyWitnessSigningKey
-> [ShelleyWitnessSigningKey] -> [ShelleyWitnessSigningKey]
forall a. a -> [a] -> [a]
: [ShelleyWitnessSigningKey]
shelleyKeyAcc)

-- | Construct a Shelley bootstrap witness (i.e. a Byron key witness in the
-- Shelley era).
mkShelleyBootstrapWitness
  :: ()
  => ShelleyBasedEra era
  -> Maybe NetworkId
  -> TxBody era
  -> ShelleyBootstrapWitnessSigningKeyData
  -> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness :: forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
_ Maybe NetworkId
Nothing TxBody era
_ (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
_ Maybe (Address ByronAddr)
Nothing) =
  BootstrapWitnessError
-> Either BootstrapWitnessError (KeyWitness era)
forall a b. a -> Either a b
Left BootstrapWitnessError
MissingNetworkIdOrByronAddressError
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe (Just NetworkId
nw) TxBody era
txBody (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
skey Maybe (Address ByronAddr)
Nothing) =
  KeyWitness era -> Either BootstrapWitnessError (KeyWitness era)
forall a b. b -> Either a b
Right (KeyWitness era -> Either BootstrapWitnessError (KeyWitness era))
-> KeyWitness era -> Either BootstrapWitnessError (KeyWitness era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> WitnessNetworkIdOrByronAddress
-> TxBody era
-> SigningKey ByronKey
-> KeyWitness era
forall era.
ShelleyBasedEra era
-> WitnessNetworkIdOrByronAddress
-> TxBody era
-> SigningKey ByronKey
-> KeyWitness era
makeShelleyBootstrapWitness ShelleyBasedEra era
sbe (NetworkId -> WitnessNetworkIdOrByronAddress
Byron.WitnessNetworkId NetworkId
nw) TxBody era
txBody SigningKey ByronKey
skey
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
_ TxBody era
txBody (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
skey (Just Address ByronAddr
addr)) =
  KeyWitness era -> Either BootstrapWitnessError (KeyWitness era)
forall a b. b -> Either a b
Right (KeyWitness era -> Either BootstrapWitnessError (KeyWitness era))
-> KeyWitness era -> Either BootstrapWitnessError (KeyWitness era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> WitnessNetworkIdOrByronAddress
-> TxBody era
-> SigningKey ByronKey
-> KeyWitness era
forall era.
ShelleyBasedEra era
-> WitnessNetworkIdOrByronAddress
-> TxBody era
-> SigningKey ByronKey
-> KeyWitness era
makeShelleyBootstrapWitness ShelleyBasedEra era
sbe (Address ByronAddr -> WitnessNetworkIdOrByronAddress
Byron.WitnessByronAddress Address ByronAddr
addr) TxBody era
txBody SigningKey ByronKey
skey

-- | Attempt to construct Shelley bootstrap witnesses until an error is
-- encountered.
mkShelleyBootstrapWitnesses
  :: ()
  => ShelleyBasedEra era
  -> Maybe NetworkId
  -> TxBody era
  -> [ShelleyBootstrapWitnessSigningKeyData]
  -> Either BootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses :: forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses ShelleyBasedEra era
sbe Maybe NetworkId
mnw TxBody era
txBody =
  (ShelleyBootstrapWitnessSigningKeyData
 -> Either BootstrapWitnessError (KeyWitness era))
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either BootstrapWitnessError [KeyWitness era]
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 (ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
mnw TxBody era
txBody)

-- ----------------------------------------------------------------------------
-- Other misc small commands
--

runTransactionHashScriptDataCmd
  :: ()
  => Cmd.TransactionHashScriptDataCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionHashScriptDataCmd :: TransactionHashScriptDataCmdArgs -> ExceptT TxCmdError IO ()
runTransactionHashScriptDataCmd
  Cmd.TransactionHashScriptDataCmdArgs
    { ScriptDataOrFile
scriptDataOrFile :: ScriptDataOrFile
scriptDataOrFile :: TransactionHashScriptDataCmdArgs -> ScriptDataOrFile
scriptDataOrFile
    } = do
    ScriptRedeemer
d <- (ScriptDataError -> TxCmdError)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptDataError -> TxCmdError
TxCmdScriptDataError (ExceptT ScriptDataError IO ScriptRedeemer
 -> ExceptT TxCmdError IO ScriptRedeemer)
-> ExceptT ScriptDataError IO ScriptRedeemer
-> ExceptT TxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataOrFile -> ExceptT ScriptDataError IO ScriptRedeemer
forall (m :: * -> *).
MonadIO m =>
ScriptDataOrFile -> ExceptT ScriptDataError m ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
scriptDataOrFile
    IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BS.putStrLn (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Hash ScriptData -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytesHex (ScriptRedeemer -> Hash ScriptData
hashScriptDataBytes ScriptRedeemer
d)

runTransactionTxIdCmd
  :: ()
  => Cmd.TransactionTxIdCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionTxIdCmd :: TransactionTxIdCmdArgs -> ExceptT TxCmdError IO ()
runTransactionTxIdCmd
  Cmd.TransactionTxIdCmdArgs
    { InputTxBodyOrTxFile
inputTxBodyOrTxFile :: InputTxBodyOrTxFile
inputTxBodyOrTxFile :: TransactionTxIdCmdArgs -> InputTxBodyOrTxFile
inputTxBodyOrTxFile
    } = do
    InAnyShelleyBasedEra ShelleyBasedEra era
_era TxBody era
txbody <-
      case InputTxBodyOrTxFile
inputTxBodyOrTxFile of
        InputTxBodyFile (File FilePath
txbodyFilePath) -> do
          FileOrPipe
txbodyFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
          IncompleteCddlTxBody
unwitnessed <-
            (FileError TextEnvelopeCddlError -> TxCmdError)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError (ExceptT (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> (IO
      (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
    -> ExceptT
         (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall a b. (a -> b) -> a -> b
$
              FileOrPipe
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
readFileTxBody FileOrPipe
txbodyFile
          InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a. a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (InAnyShelleyBasedEra TxBody
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody))
-> InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a b. (a -> b) -> a -> b
$ IncompleteCddlTxBody -> InAnyShelleyBasedEra TxBody
unIncompleteCddlTxBody IncompleteCddlTxBody
unwitnessed
        InputTxFile (File FilePath
txFilePath) -> do
          FileOrPipe
txFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txFilePath
          InAnyShelleyBasedEra ShelleyBasedEra era
era Tx era
tx <- IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (FileOrPipe
-> IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
readFileTx FileOrPipe
txFile) ExceptT
  TxCmdError
  IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> (ExceptT
      TxCmdError
      IO
      (Either
         (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
    -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeCddlError
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx))
-> (FileError TextEnvelopeCddlError -> TxCmdError)
-> FileError TextEnvelopeCddlError
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra Tx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError)
          InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a. a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (InAnyShelleyBasedEra TxBody
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody))
-> (TxBody era -> InAnyShelleyBasedEra TxBody)
-> TxBody era
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyBasedEra era -> TxBody era -> InAnyShelleyBasedEra TxBody
forall era (thing :: * -> *).
Typeable era =>
ShelleyBasedEra era -> thing era -> InAnyShelleyBasedEra thing
InAnyShelleyBasedEra ShelleyBasedEra era
era (TxBody era -> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody))
-> TxBody era
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a b. (a -> b) -> a -> b
$ Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
tx

    IO () -> ExceptT TxCmdError IO ()
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT TxCmdError IO ())
-> IO () -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BS.putStrLn (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytesHex (TxBody era -> TxId
forall era. TxBody era -> TxId
getTxId TxBody era
txbody)

-- ----------------------------------------------------------------------------
-- Witness commands
--

runTransactionWitnessCmd
  :: ()
  => Cmd.TransactionWitnessCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionWitnessCmd :: TransactionWitnessCmdArgs -> ExceptT TxCmdError IO ()
runTransactionWitnessCmd
  Cmd.TransactionWitnessCmdArgs
    { txBodyFile :: TransactionWitnessCmdArgs -> File (TxBody ()) 'In
txBodyFile = File FilePath
txbodyFilePath
    , WitnessSigningData
witnessSigningData :: WitnessSigningData
witnessSigningData :: TransactionWitnessCmdArgs -> WitnessSigningData
witnessSigningData
    , Maybe NetworkId
mNetworkId :: Maybe NetworkId
mNetworkId :: TransactionWitnessCmdArgs -> Maybe NetworkId
mNetworkId
    , File () 'Out
outFile :: File () 'Out
outFile :: TransactionWitnessCmdArgs -> File () 'Out
outFile
    } = do
    FileOrPipe
txbodyFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
    IncompleteCddlTxBody
unwitnessed <-
      (FileError TextEnvelopeCddlError -> TxCmdError)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError (ExceptT (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> (IO
      (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
    -> ExceptT
         (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT
     (FileError TextEnvelopeCddlError) IO IncompleteCddlTxBody
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall a b. (a -> b) -> a -> b
$
        FileOrPipe
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
readFileTxBody FileOrPipe
txbodyFile
    case IncompleteCddlTxBody
unwitnessed of
      IncompleteCddlTxBody InAnyShelleyBasedEra TxBody
anyTxBody -> do
        InAnyShelleyBasedEra ShelleyBasedEra era
sbe TxBody era
txbody <- InAnyShelleyBasedEra TxBody
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra TxBody)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InAnyShelleyBasedEra TxBody
anyTxBody
        SomeSigningWitness
someWit <-
          (ReadWitnessSigningDataError -> TxCmdError)
-> ExceptT ReadWitnessSigningDataError IO SomeSigningWitness
-> ExceptT TxCmdError IO SomeSigningWitness
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ReadWitnessSigningDataError -> TxCmdError
TxCmdReadWitnessSigningDataError
            (ExceptT ReadWitnessSigningDataError IO SomeSigningWitness
 -> ExceptT TxCmdError IO SomeSigningWitness)
-> (IO (Either ReadWitnessSigningDataError SomeSigningWitness)
    -> ExceptT ReadWitnessSigningDataError IO SomeSigningWitness)
-> IO (Either ReadWitnessSigningDataError SomeSigningWitness)
-> ExceptT TxCmdError IO SomeSigningWitness
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either ReadWitnessSigningDataError SomeSigningWitness)
-> ExceptT ReadWitnessSigningDataError IO SomeSigningWitness
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
            (IO (Either ReadWitnessSigningDataError SomeSigningWitness)
 -> ExceptT TxCmdError IO SomeSigningWitness)
-> IO (Either ReadWitnessSigningDataError SomeSigningWitness)
-> ExceptT TxCmdError IO SomeSigningWitness
forall a b. (a -> b) -> a -> b
$ WitnessSigningData
-> IO (Either ReadWitnessSigningDataError SomeSigningWitness)
readWitnessSigningData WitnessSigningData
witnessSigningData
        KeyWitness era
witness <-
          case SomeSigningWitness -> ByronOrShelleyWitness
categoriseSomeSigningWitness SomeSigningWitness
someWit of
            -- Byron witnesses require the network ID. This can either be provided
            -- directly or derived from a provided Byron address.
            AByronWitness ShelleyBootstrapWitnessSigningKeyData
bootstrapWitData ->
              (BootstrapWitnessError -> TxCmdError)
-> ExceptT BootstrapWitnessError IO (KeyWitness era)
-> ExceptT TxCmdError IO (KeyWitness era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT BootstrapWitnessError -> TxCmdError
TxCmdBootstrapWitnessError
                (ExceptT BootstrapWitnessError IO (KeyWitness era)
 -> ExceptT TxCmdError IO (KeyWitness era))
-> (Either BootstrapWitnessError (KeyWitness era)
    -> ExceptT BootstrapWitnessError IO (KeyWitness era))
-> Either BootstrapWitnessError (KeyWitness era)
-> ExceptT TxCmdError IO (KeyWitness era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either BootstrapWitnessError (KeyWitness era)
-> ExceptT BootstrapWitnessError IO (KeyWitness era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
                (Either BootstrapWitnessError (KeyWitness era)
 -> ExceptT TxCmdError IO (KeyWitness era))
-> Either BootstrapWitnessError (KeyWitness era)
-> ExceptT TxCmdError IO (KeyWitness era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody era
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId TxBody era
txbody ShelleyBootstrapWitnessSigningKeyData
bootstrapWitData
            AShelleyKeyWitness ShelleyWitnessSigningKey
skShelley ->
              KeyWitness era -> ExceptT TxCmdError IO (KeyWitness era)
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (KeyWitness era -> ExceptT TxCmdError IO (KeyWitness era))
-> KeyWitness era -> ExceptT TxCmdError IO (KeyWitness era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
ShelleyBasedEra era
-> TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness ShelleyBasedEra era
sbe TxBody era
txbody ShelleyWitnessSigningKey
skShelley

        (FileError () -> TxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> TxCmdError
TxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT TxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ()
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT TxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
          ShelleyBasedEra era
-> File () 'Out -> KeyWitness era -> IO (Either (FileError ()) ())
forall era.
ShelleyBasedEra era
-> File () 'Out -> KeyWitness era -> IO (Either (FileError ()) ())
writeTxWitnessFileTextEnvelopeCddl ShelleyBasedEra era
sbe File () 'Out
outFile KeyWitness era
witness

runTransactionSignWitnessCmd
  :: ()
  => Cmd.TransactionSignWitnessCmdArgs
  -> ExceptT TxCmdError IO ()
runTransactionSignWitnessCmd :: TransactionSignWitnessCmdArgs -> ExceptT TxCmdError IO ()
runTransactionSignWitnessCmd
  Cmd.TransactionSignWitnessCmdArgs
    { txBodyFile :: TransactionSignWitnessCmdArgs -> File (TxBody ()) 'In
txBodyFile = File FilePath
txbodyFilePath
    , witnessFiles :: TransactionSignWitnessCmdArgs -> [WitnessFile]
witnessFiles = [WitnessFile]
witnessFiles
    , outFile :: TransactionSignWitnessCmdArgs -> File () 'Out
outFile = File () 'Out
outFile
    } = do
    FileOrPipe
txbodyFile <- IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe)
-> IO FileOrPipe -> ExceptT TxCmdError IO FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
    IncompleteCddlTxBody
unwitnessed <- IO (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT
     TxCmdError
     IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (FileOrPipe
-> IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
readFileTxBody FileOrPipe
txbodyFile) ExceptT
  TxCmdError
  IO
  (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> (ExceptT
      TxCmdError
      IO
      (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
    -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall a b. a -> (a -> b) -> b
& (FileError TextEnvelopeCddlError
 -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> ExceptT
     TxCmdError
     IO
     (Either (FileError TextEnvelopeCddlError) IncompleteCddlTxBody)
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO IncompleteCddlTxBody
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO IncompleteCddlTxBody)
-> (FileError TextEnvelopeCddlError -> TxCmdError)
-> FileError TextEnvelopeCddlError
-> ExceptT TxCmdError IO IncompleteCddlTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError TextEnvelopeCddlError -> TxCmdError
TxCmdTextEnvCddlError)
    case IncompleteCddlTxBody
unwitnessed of
      IncompleteCddlTxBody (InAnyShelleyBasedEra ShelleyBasedEra era
era TxBody era
txbody) -> do
        -- TODO: Left off here. Remember we were never reading byron key witnesses anyways!
        [KeyWitness era]
witnesses <-
          [ExceptT TxCmdError IO (KeyWitness era)]
-> ExceptT TxCmdError IO [KeyWitness era]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence
            [ do
                InAnyShelleyBasedEra ShelleyBasedEra era
era' KeyWitness era
witness <-
                  IO (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
-> ExceptT
     TxCmdError
     IO
     (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (FilePath
-> IO (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
readFileTxKeyWitness FilePath
file) ExceptT
  TxCmdError
  IO
  (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
-> (ExceptT
      TxCmdError
      IO
      (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
    -> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness)
forall a b. a -> (a -> b) -> b
& (CddlWitnessError
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness))
-> ExceptT
     TxCmdError
     IO
     (Either CddlWitnessError (InAnyShelleyBasedEra KeyWitness))
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness)
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness))
-> (CddlWitnessError -> TxCmdError)
-> CddlWitnessError
-> ExceptT TxCmdError IO (InAnyShelleyBasedEra KeyWitness)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CddlWitnessError -> TxCmdError
TxCmdCddlWitnessError)

                case ShelleyBasedEra era -> ShelleyBasedEra era -> Maybe (era :~: era)
forall a b.
ShelleyBasedEra a -> ShelleyBasedEra b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality ShelleyBasedEra era
era ShelleyBasedEra era
era' of
                  Maybe (era :~: era)
Nothing ->
                    TxCmdError -> ExceptT TxCmdError IO (KeyWitness era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO (KeyWitness era))
-> TxCmdError -> ExceptT TxCmdError IO (KeyWitness era)
forall a b. (a -> b) -> a -> b
$
                      AnyCardanoEra -> AnyCardanoEra -> WitnessFile -> TxCmdError
TxCmdWitnessEraMismatch
                        (CardanoEra era -> AnyCardanoEra
forall era. Typeable era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra (CardanoEra era -> AnyCardanoEra)
-> CardanoEra era -> AnyCardanoEra
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era)
                        (CardanoEra era -> AnyCardanoEra
forall era. Typeable era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra (CardanoEra era -> AnyCardanoEra)
-> CardanoEra era -> AnyCardanoEra
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
era')
                        WitnessFile
witnessFile
                  Just era :~: era
Refl -> KeyWitness era -> ExceptT TxCmdError IO (KeyWitness era)
forall a. a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return KeyWitness era
KeyWitness era
witness
            | witnessFile :: WitnessFile
witnessFile@(WitnessFile FilePath
file) <- [WitnessFile]
witnessFiles
            ]

        let tx :: Tx era
tx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [KeyWitness era]
witnesses TxBody era
txbody

        IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT TxCmdError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ShelleyBasedEra era
-> File () 'Out -> Tx era -> IO (Either (FileError ()) ())
forall era content.
ShelleyBasedEra era
-> File content 'Out -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl ShelleyBasedEra era
era File () 'Out
outFile Tx era
tx) ExceptT TxCmdError IO (Either (FileError ()) ())
-> (ExceptT TxCmdError IO (Either (FileError ()) ())
    -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO ()
forall a b. a -> (a -> b) -> b
& (FileError () -> ExceptT TxCmdError IO ())
-> ExceptT TxCmdError IO (Either (FileError ()) ())
-> ExceptT TxCmdError IO ()
forall e x (m :: * -> *) a.
Monad m =>
(e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft (TxCmdError -> ExceptT TxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError -> ExceptT TxCmdError IO ())
-> (FileError () -> TxCmdError)
-> FileError ()
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileError () -> TxCmdError
TxCmdWriteFileError)