{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# 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.Transaction.Run
  ( partitionSomeWitnesses
  , runTransactionCmds
  , runTransactionBuildCmd
  , runTransactionBuildRawCmd
  , runTransactionSignCmd
  , runTransactionSubmitCmd
  , runTransactionCalculateMinFeeCmd
  , runTransactionCalculateMinValueCmd
  , runTransactionPolicyIdCmd
  , runTransactionHashScriptDataCmd
  , runTransactionTxIdCmd
  , runTransactionWitnessCmd
  , runTransactionSignWitnessCmd
  , toTxOutByronEra
  , toTxOutInAnyEra
  )
where

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

import Cardano.Binary qualified as CBOR
import Cardano.CLI.EraBased.Genesis.Internal.Common (readProtocolParameters)
import Cardano.CLI.EraBased.Query.Run
import Cardano.CLI.EraBased.Script.Certificate.Read
import Cardano.CLI.EraBased.Script.Certificate.Type (CertificateScriptWitness (..))
import Cardano.CLI.EraBased.Script.Mint.Read
import Cardano.CLI.EraBased.Script.Mint.Type
import Cardano.CLI.EraBased.Script.Proposal.Type (ProposalScriptWitness (..))
import Cardano.CLI.EraBased.Script.Read.Common
import Cardano.CLI.EraBased.Script.Spend.Read
import Cardano.CLI.EraBased.Script.Spend.Type (SpendScriptWitness (..))
import Cardano.CLI.EraBased.Script.Vote.Type
import Cardano.CLI.EraBased.Script.Withdrawal.Read
import Cardano.CLI.EraBased.Script.Withdrawal.Type (WithdrawalScriptWitness (..))
import Cardano.CLI.EraBased.Transaction.Command
import Cardano.CLI.EraBased.Transaction.Command qualified as Cmd
import Cardano.CLI.EraBased.Transaction.Internal.HashCheck
  ( checkCertificateHashes
  , checkProposalHashes
  , checkVotingProcedureHashes
  )
import Cardano.CLI.Orphan ()
import Cardano.CLI.Read
import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Error.NodeEraMismatchError
import Cardano.CLI.Type.Error.TxCmdError
import Cardano.CLI.Type.Error.TxValidationError
import Cardano.CLI.Type.Output (renderScriptCostsWithScriptHashesMap)
import Cardano.CLI.Type.TxFeature
import Cardano.Ledger.Api (allInputsTxBodyF, bodyTxL)
import Cardano.Prelude (putLByteString)

import Control.Monad
import Data.Aeson ((.=))
import Data.Aeson qualified as Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString qualified as Data.Bytestring
import Data.ByteString.Char8 qualified as BS
import Data.ByteString.Lazy.Char8 qualified as LBS
import Data.Containers.ListUtils (nubOrd)
import Data.Data ((:~:) (..))
import Data.Foldable qualified as Foldable
import Data.Function ((&))
import Data.List qualified as List
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Text qualified as Text
import Data.Text.IO qualified as Text
import Data.Type.Equality (TestEquality (..))
import GHC.Exts (IsList (..))
import Lens.Micro ((^.))
import System.IO qualified 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.TransactionCalculatePlutusScriptCostCmd TransactionCalculatePlutusScriptCostCmdArgs
args -> TransactionCalculatePlutusScriptCostCmdArgs
-> ExceptT TxCmdError IO ()
runTransactionCalculatePlutusScriptCostCmd TransactionCalculatePlutusScriptCostCmdArgs
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
    , nodeConnInfo :: forall era. TransactionBuildCmdArgs era -> LocalNodeConnectInfo
nodeConnInfo =
      nodeConnInfo :: LocalNodeConnectInfo
nodeConnInfo@LocalNodeConnectInfo
        { localNodeNetworkId :: LocalNodeConnectInfo -> NetworkId
localNodeNetworkId = NetworkId
networkId
        , localNodeSocketPath :: LocalNodeConnectInfo -> SocketPath
localNodeSocketPath = SocketPath
nodeSocketPath
        }
    , mScriptValidity :: forall era. TransactionBuildCmdArgs era -> Maybe ScriptValidity
mScriptValidity = Maybe ScriptValidity
mScriptValidity
    , mOverrideWitnesses :: forall era. TransactionBuildCmdArgs era -> Maybe Word
mOverrideWitnesses = Maybe Word
mOverrideWitnesses
    , [(TxIn, Maybe CliSpendScriptRequirements)]
txins :: [(TxIn, Maybe CliSpendScriptRequirements)]
txins :: forall era.
TransactionBuildCmdArgs era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
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 (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: forall era.
TransactionBuildCmdArgs era
-> Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    , 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 CliCertificateScriptRequirements)]
certificates :: [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates :: forall era.
TransactionBuildCmdArgs era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates
    , [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: forall era.
TransactionBuildCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
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 CliVoteScriptRequirements)]
voteFiles :: [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles :: forall era.
TransactionBuildCmdArgs era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles
    , [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: forall era.
TransactionBuildCmdArgs era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
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

    [(TxIn, Maybe (SpendScriptWitness era))]
txinsAndMaybeScriptWits <-
      (FileError CliSpendScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliSpendScriptWitnessError -> TxCmdError
TxCmdCliSpendingScriptWitnessError (ExceptT
   (FileError CliSpendScriptWitnessError)
   IO
   [(TxIn, Maybe (SpendScriptWitness era))]
 -> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))])
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliSpendScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> t m [(TxIn, Maybe (SpendScriptWitness era))]
readSpendScriptWitnesses ShelleyBasedEra era
eon [(TxIn, Maybe CliSpendScriptRequirements)]
txins

    let spendingScriptWitnesses :: [ScriptWitness WitCtxTxIn era]
spendingScriptWitnesses = ((TxIn, Maybe (SpendScriptWitness era))
 -> Maybe (ScriptWitness WitCtxTxIn era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [ScriptWitness WitCtxTxIn era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ((SpendScriptWitness era -> ScriptWitness WitCtxTxIn era)
-> Maybe (SpendScriptWitness era)
-> Maybe (ScriptWitness WitCtxTxIn era)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
forall era. SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
sswScriptWitness (Maybe (SpendScriptWitness era)
 -> Maybe (ScriptWitness WitCtxTxIn era))
-> ((TxIn, Maybe (SpendScriptWitness era))
    -> Maybe (SpendScriptWitness era))
-> (TxIn, Maybe (SpendScriptWitness era))
-> Maybe (ScriptWitness WitCtxTxIn era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, Maybe (SpendScriptWitness era))
-> Maybe (SpendScriptWitness era)
forall a b. (a, b) -> b
snd) [(TxIn, Maybe (SpendScriptWitness era))]
txinsAndMaybeScriptWits

    [(CertificateFile, Maybe (CertificateScriptWitness era))]
certFilesAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(CertificateFile, Maybe (CertificateScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (CertificateScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> t m [(CertificateFile, Maybe (CertificateScriptWitness era))]
readCertificateScriptWitnesses ShelleyBasedEra era
eon [(CertificateFile, Maybe CliCertificateScriptRequirements)]
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
            (,CertificateScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
CertificateScriptWitness era -> ScriptWitness WitCtxStake era
cswScriptWitness (CertificateScriptWitness era -> ScriptWitness WitCtxStake era)
-> Maybe (CertificateScriptWitness era)
-> Maybe (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (CertificateScriptWitness 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 (CertificateScriptWitness era)
mSwit) <- [(CertificateFile, Maybe (CertificateScriptWitness 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 (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ((StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era)))
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness 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
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> t m
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
readWithdrawalScriptWitness ShelleyBasedEra era
eon) [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
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 (MultiAsset
mintedMultiAsset, [CliMintScriptRequirements]
sWitFiles) = (MultiAsset, [CliMintScriptRequirements])
-> Maybe (MultiAsset, [CliMintScriptRequirements])
-> (MultiAsset, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (MultiAsset, [CliMintScriptRequirements])
forall a. Monoid a => a
mempty Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    [MintScriptWitnessWithPolicyId era]
mintingWitnesses <-
      (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 (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> CardanoEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness 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 (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. Monoid a => a
mempty)
        (\ConwayEraOnwards era
w -> (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness 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 (VoteScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a b. (a -> b) -> a -> b
$ IO
  (Either
     VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles))
        CardanoEra era
era'

    [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ((VotingProcedures era, Maybe (VoteScriptWitness 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 (VoteScriptWitness 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 (VoteScriptWitness era))
    -> VotingProcedures era)
-> (VotingProcedures era, Maybe (VoteScriptWitness era))
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VotingProcedures era, Maybe (VoteScriptWitness era))
-> VotingProcedures era
forall a b. (a, b) -> a
fst)

    [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals <-
      IO
  (Either
     TxCmdError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))]
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO
   (Either
      TxCmdError [(Proposal era, Maybe (ProposalScriptWitness era))])
 -> ExceptT
      TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> IO
     (Either
        TxCmdError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        (ProposalError -> TxCmdError)
-> Either
     ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Either
     TxCmdError [(Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness era))]
 -> Either
      TxCmdError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> IO
     (Either
        TxCmdError [(Proposal era, Maybe (ProposalScriptWitness era))])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
readTxGovernanceActions ShelleyBasedEra era
eon [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles

    [(Proposal era, Maybe (ProposalScriptWitness era))]
-> ((Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness 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 (ProposalScriptWitness era))
    -> Proposal era)
-> (Proposal era, Maybe (ProposalScriptWitness era))
-> ExceptT TxCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness era)
_) <- [(Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness era)
_) <- [(Proposal era, Maybe (ProposalScriptWitness 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
_ <- [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
nodeConnInfo
            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 =
          [ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
forall era.
[ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
            [ScriptWitness WitCtxTxIn era]
spendingScriptWitnesses
            ((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]
mintingWitnesses)
            (((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Maybe (ScriptWitness WitCtxStake era))
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [ScriptWitness WitCtxStake era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (ScriptWitness WitCtxStake era)
forall a b. (a, b) -> b
snd [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits)
            (((StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
 -> Maybe (WithdrawalScriptWitness era))
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [WithdrawalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\(StakeAddress
_, Lovelace
_, Maybe (WithdrawalScriptWitness era)
mSwit) -> Maybe (WithdrawalScriptWitness era)
mSwit) [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits)
            (((VotingProcedures era, Maybe (VoteScriptWitness era))
 -> Maybe (VoteScriptWitness era))
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [VoteScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (VotingProcedures era, Maybe (VoteScriptWitness era))
-> Maybe (VoteScriptWitness era)
forall a b. (a, b) -> b
snd [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits)
            (((Proposal era, Maybe (ProposalScriptWitness era))
 -> Maybe (ProposalScriptWitness era))
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> [ProposalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Proposal era, Maybe (ProposalScriptWitness era))
-> Maybe (ProposalScriptWitness era)
forall a b. (a, b) -> b
snd [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals)
            [TxIn]
readOnlyReferenceInputs

    let inputsThatRequireWitnessing :: [TxIn]
inputsThatRequireWitnessing = [TxIn
input | (TxIn
input, Maybe CliSpendScriptRequirements
_) <- [(TxIn, Maybe CliSpendScriptRequirements)]
txins]
        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
nodeConnInfo 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) 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) 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) 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) 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) Lovelace,
            Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr
            LocalNodeConnectInfo
nodeConnInfo
            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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
    -> ExceptT
         TxCmdError
         IO
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole) 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) 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) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole) 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) 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) 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) Lovelace,
      Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError)

    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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
forall era.
ShelleyBasedEra era
-> SocketPath
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild
        ShelleyBasedEra era
eon
        SocketPath
nodeSocketPath
        NetworkId
networkId
        Maybe ScriptValidity
mScriptValidity
        [(TxIn, Maybe (SpendScriptWitness era))]
txinsAndMaybeScriptWits
        [TxIn]
readOnlyReferenceInputs
        [TxIn]
filteredTxinsc
        Maybe (TxOut CtxTx era)
mReturnCollateral
        Maybe Lovelace
mTotalCollateral
        [TxOut CtxTx era]
txOuts
        TxOutChangeAddress
changeAddresses
        (MultiAsset
mintedMultiAsset, [MintScriptWitnessWithPolicyId era]
mintingWitnesses)
        Maybe SlotNo
mValidityLowerBound
        TxValidityUpperBound era
mValidityUpperBound
        [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
        [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits
        [Hash PaymentKey]
requiredSigners
        TxAuxScripts era
txAuxScripts
        TxMetadataInEra era
txMetadata
        TxUpdateProposal era
mProp
        Maybe Word
mOverrideWitnesses
        [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits
        [(Proposal era, Maybe (ProposalScriptWitness 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
        -- Warn that the parameter is deprecated to stderr
        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 -> FilePath -> IO ()
IO.hPutStrLn
            Handle
IO.stderr
            ( FilePath
"Warning: The `--calculate-plutus-script-cost` parameter is deprecated and will be "
                FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
"removed in a future version. Please use the `calculate-script-cost` command instead."
            )

        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

        Map ScriptWitnessIndex ScriptHash
scriptHashes <-
          forall (eon :: * -> *) a era.
(Eon eon, Monoid a) =>
CardanoEra era -> (eon era -> a) -> a
monoidForEraInEon @AlonzoEraOnwards
            CardanoEra era
era'
            (\AlonzoEraOnwards era
aeo -> Map ScriptWitnessIndex ScriptHash
-> Maybe (Map ScriptWitnessIndex ScriptHash)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map ScriptWitnessIndex ScriptHash
 -> Maybe (Map ScriptWitnessIndex ScriptHash))
-> Map ScriptWitnessIndex ScriptHash
-> Maybe (Map ScriptWitnessIndex ScriptHash)
forall a b. (a -> b) -> a -> b
$ AlonzoEraOnwards era
-> Tx era -> UTxO era -> Map ScriptWitnessIndex ScriptHash
forall era.
AlonzoEraOnwards era
-> Tx era -> UTxO era -> Map ScriptWitnessIndex ScriptHash
collectPlutusScriptHashes AlonzoEraOnwards era
aeo ([KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
balancedTxBody) UTxO era
UTxO era
txEraUtxo)
            Maybe (Map ScriptWitnessIndex ScriptHash)
-> (Maybe (Map ScriptWitnessIndex ScriptHash)
    -> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash))
-> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash)
forall a b. a -> (a -> b) -> b
& TxCmdError
-> Maybe (Map ScriptWitnessIndex ScriptHash)
-> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash)
forall (m :: * -> *) x a. Monad m => x -> Maybe a -> ExceptT x m a
hoistMaybe (CardanoEra era -> TxCmdError
forall era. CardanoEra era -> TxCmdError
TxCmdAlonzoEraOnwardsRequired CardanoEra era
era')

        [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
$
              Prices
-> Map ScriptWitnessIndex ScriptHash
-> Map
     ScriptWitnessIndex
     (Either
        ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
-> Either PlutusScriptCostError [ScriptCostOutput]
renderScriptCostsWithScriptHashesMap
                Prices
executionUnitPrices
                Map ScriptWitnessIndex ScriptHash
scriptHashes
                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 CliSpendScriptRequirements)]
txins :: [(TxIn, Maybe CliSpendScriptRequirements)]
txins :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
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 (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: forall era.
TransactionBuildEstimateCmdArgs era
-> Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    , 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 CliCertificateScriptRequirements)]
certificates :: [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates
    , [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
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 CliVoteScriptRequirements)]
voteFiles :: [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles
    , [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: forall era.
TransactionBuildEstimateCmdArgs era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
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 = BabbageEraOnwards era -> MaryEraOnwards era
forall era. BabbageEraOnwards era -> MaryEraOnwards era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert (Era era -> BabbageEraOnwards era
forall era. Era era -> BabbageEraOnwards era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert Era era
currentEra :: BabbageEraOnwards era)

    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 (SpendScriptWitness era))]
txInsAndMaybeScriptWits <-
      (FileError CliSpendScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliSpendScriptWitnessError -> TxCmdError
TxCmdCliSpendingScriptWitnessError (ExceptT
   (FileError CliSpendScriptWitnessError)
   IO
   [(TxIn, Maybe (SpendScriptWitness era))]
 -> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))])
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliSpendScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> t m [(TxIn, Maybe (SpendScriptWitness era))]
readSpendScriptWitnesses ShelleyBasedEra era
sbe [(TxIn, Maybe CliSpendScriptRequirements)]
txins

    [(CertificateFile, Maybe (CertificateScriptWitness era))]
certFilesAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(CertificateFile, Maybe (CertificateScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (CertificateScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> t m [(CertificateFile, Maybe (CertificateScriptWitness era))]
readCertificateScriptWitnesses ShelleyBasedEra era
sbe [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates

    [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ((StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era)))
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness 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
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> t m
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
readWithdrawalScriptWitness ShelleyBasedEra era
sbe) [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
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 (MultiAsset
mas, [CliMintScriptRequirements]
sWitFiles) = (MultiAsset, [CliMintScriptRequirements])
-> Maybe (MultiAsset, [CliMintScriptRequirements])
-> (MultiAsset, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (MultiAsset, [CliMintScriptRequirements])
forall a. Monoid a => a
mempty Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits <-
      (MultiAsset
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (MultiAsset, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (MultiAsset, [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 (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ShelleyBasedEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> ShelleyBasedEra era -> a
inEonForShelleyBasedEra
        ([(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. Monoid a => a
mempty)
        ( \ConwayEraOnwards era
w ->
            (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness 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 (VoteScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> (IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
    -> ExceptT
         VoteError
         IO
         [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO
  (Either
     VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (IO
   (Either
      VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
              ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  IO
    (Either
       VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
 -> IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall a b. (a -> b) -> a -> b
$
                ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles
        )
        ShelleyBasedEra era
sbe

    [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals <-
      IO
  (Either
     ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness 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 CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
readTxGovernanceActions ShelleyBasedEra era
sbe [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles)
        ExceptT
  TxCmdError
  IO
  (Either
     ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> (ExceptT
      TxCmdError
      IO
      (Either
         ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
    -> ExceptT
         TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))]
forall a b. a -> (a -> b) -> b
& (ProposalError
 -> ExceptT
      TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness era))]
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> (ProposalError -> TxCmdError)
-> ProposalError
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness 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
              (,CertificateScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
CertificateScriptWitness era -> ScriptWitness WitCtxStake era
cswScriptWitness (CertificateScriptWitness era -> ScriptWitness WitCtxStake era)
-> Maybe (CertificateScriptWitness era)
-> Maybe (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (CertificateScriptWitness 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 (CertificateScriptWitness era)
mSwit) <- [(CertificateFile, Maybe (CertificateScriptWitness 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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))]
txInsAndMaybeScriptWits
          [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
          (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
          [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
          [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits
          [Hash PaymentKey]
requiredSigners
          Lovelace
0
          TxAuxScripts era
txAuxScripts
          TxMetadataInEra era
txMetadata
          TxUpdateProposal era
txUpdateProposal
          [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits
          [(Proposal era, Maybe (ProposalScriptWitness 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) Lovelace
drepsToDeregisterMap = [Item (Map (Credential 'DRepRole) Lovelace)]
-> Map (Credential 'DRepRole) Lovelace
forall l. IsList l => [Item l] -> l
fromList ([Item (Map (Credential 'DRepRole) Lovelace)]
 -> Map (Credential 'DRepRole) Lovelace)
-> [Item (Map (Credential 'DRepRole) Lovelace)]
-> Map (Credential 'DRepRole) Lovelace
forall a b. (a -> b) -> a -> b
$ [Maybe (Credential 'DRepRole, Lovelace)]
-> [(Credential 'DRepRole, Lovelace)]
forall a. [Maybe a] -> [a]
catMaybes [Certificate era -> Maybe (Credential 'DRepRole, Lovelace)
forall era.
Certificate era -> Maybe (Credential 'DRepRole, 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) Lovelace
-> Map ScriptWitnessIndex ExecutionUnits
-> Lovelace
-> Int
-> Int
-> Int
-> AddressInEra era
-> Value
-> Either (TxFeeEstimationError era) (BalancedTxBody era)
forall era.
HasCallStack =>
MaryEraOnwards era
-> TxBodyContent BuildTx era
-> PParams (ShelleyLedgerEra era)
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole) 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) 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.
(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.
(TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era) -> Maybe PoolId
getConwayDeregistrationPoolId ConwayTxCert (ShelleyLedgerEra era)
cert

getShelleyDeregistrationPoolId
  :: L.ShelleyEraTxCert (ShelleyLedgerEra era)
  => L.TxCert (ShelleyLedgerEra era) ~ L.ShelleyTxCert (ShelleyLedgerEra era)
  => L.ShelleyTxCert (ShelleyLedgerEra era)
  -> Maybe PoolId
getShelleyDeregistrationPoolId :: forall era.
(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
poolId EpochNo
_ -> PoolId -> Maybe PoolId
forall a. a -> Maybe a
Just (KeyHash 'StakePool -> PoolId
StakePoolKeyHash KeyHash 'StakePool
poolId)
    ShelleyTxCert (ShelleyLedgerEra era)
_ -> Maybe PoolId
forall a. Maybe a
Nothing

getConwayDeregistrationPoolId
  :: L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe PoolId
getConwayDeregistrationPoolId :: forall era.
(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
poolId EpochNo
_ -> PoolId -> Maybe PoolId
forall a. a -> Maybe a
Just (KeyHash 'StakePool -> PoolId
StakePoolKeyHash KeyHash 'StakePool
poolId)
    ConwayTxCert (ShelleyLedgerEra era)
_ -> Maybe PoolId
forall a. Maybe a
Nothing

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

getConwayDRepDeregistrationInfo
  :: L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe (L.Credential L.DRepRole, Lovelace)
getConwayDRepDeregistrationInfo :: forall era.
(TxCert (ShelleyLedgerEra era)
 ~ ConwayTxCert (ShelleyLedgerEra era),
 ConwayEraTxCert (ShelleyLedgerEra era)) =>
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole, Lovelace)
getConwayDRepDeregistrationInfo = TxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole, Lovelace)
ConwayTxCert (ShelleyLedgerEra era)
-> Maybe (Credential 'DRepRole, Lovelace)
forall era.
ConwayEraTxCert era =>
TxCert era -> Maybe (Credential 'DRepRole, 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.
(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.
(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.ShelleyEraTxCert (ShelleyLedgerEra era)
  => L.TxCert (ShelleyLedgerEra era) ~ L.ShelleyTxCert (ShelleyLedgerEra era)
  => L.ShelleyTxCert (ShelleyLedgerEra era)
  -> Maybe (StakeCredential, Lovelace)
getShelleyDeregistrationInfo :: forall era.
(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
stakeCred -> (StakeCredential, Lovelace) -> Maybe (StakeCredential, Lovelace)
forall a. a -> Maybe a
Just (StakeCredential -> StakeCredential
fromShelleyStakeCredential StakeCredential
stakeCred, Lovelace
0)
    ShelleyTxCert (ShelleyLedgerEra era)
_ -> Maybe (StakeCredential, Lovelace)
forall a. Maybe a
Nothing

getConwayDeregistrationInfo
  :: L.TxCert (ShelleyLedgerEra era) ~ L.ConwayTxCert (ShelleyLedgerEra era)
  => L.ConwayEraTxCert (ShelleyLedgerEra era)
  => L.ConwayTxCert (ShelleyLedgerEra era)
  -> Maybe (StakeCredential, Lovelace)
getConwayDeregistrationInfo :: forall era.
(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
stakeCred Lovelace
depositRefund -> (StakeCredential, Lovelace) -> Maybe (StakeCredential, Lovelace)
forall a. a -> Maybe a
Just (StakeCredential -> StakeCredential
fromShelleyStakeCredential StakeCredential
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 CliSpendScriptRequirements)]
txIns :: [(TxIn, Maybe CliSpendScriptRequirements)]
txIns :: forall era.
TransactionBuildRawCmdArgs era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
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 (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets :: forall era.
TransactionBuildRawCmdArgs era
-> Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    , 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 CliCertificateScriptRequirements)]
certificates :: [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates :: forall era.
TransactionBuildRawCmdArgs era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates
    , [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
withdrawals :: forall era.
TransactionBuildRawCmdArgs era
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
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 CliVoteScriptRequirements)]
voteFiles :: [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles :: forall era.
TransactionBuildRawCmdArgs era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles
    , [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles :: forall era.
TransactionBuildRawCmdArgs era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
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 (SpendScriptWitness era))]
txInsAndMaybeScriptWits <-
      (FileError CliSpendScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliSpendScriptWitnessError -> TxCmdError
TxCmdCliSpendingScriptWitnessError (ExceptT
   (FileError CliSpendScriptWitnessError)
   IO
   [(TxIn, Maybe (SpendScriptWitness era))]
 -> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))])
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
-> ExceptT TxCmdError IO [(TxIn, Maybe (SpendScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> ExceptT
     (FileError CliSpendScriptWitnessError)
     IO
     [(TxIn, Maybe (SpendScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliSpendScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(TxIn, Maybe CliSpendScriptRequirements)]
-> t m [(TxIn, Maybe (SpendScriptWitness era))]
readSpendScriptWitnesses ShelleyBasedEra era
eon [(TxIn, Maybe CliSpendScriptRequirements)]
txIns

    [(CertificateFile, Maybe (CertificateScriptWitness era))]
certFilesAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(CertificateFile, Maybe (CertificateScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(CertificateFile, Maybe (CertificateScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(CertificateFile, Maybe (CertificateScriptWitness era))]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> [(CertificateFile, Maybe CliCertificateScriptRequirements)]
-> t m [(CertificateFile, Maybe (CertificateScriptWitness era))]
readCertificateScriptWitnesses ShelleyBasedEra era
eon [(CertificateFile, Maybe CliCertificateScriptRequirements)]
certificates

    [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits <-
      (FileError CliScriptWitnessError -> TxCmdError)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError CliScriptWitnessError -> TxCmdError
TxCmdCliScriptWitnessError (ExceptT
   (FileError CliScriptWitnessError)
   IO
   [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))])
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
        ((StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
 -> ExceptT
      (FileError CliScriptWitnessError)
      IO
      (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era)))
-> [(StakeAddress, Lovelace,
     Maybe CliWithdrawalScriptRequirements)]
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness 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
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> ExceptT
     (FileError CliScriptWitnessError)
     IO
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) era.
MonadIOTransError (FileError CliScriptWitnessError) t m =>
ShelleyBasedEra era
-> (StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)
-> t m
     (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
readWithdrawalScriptWitness ShelleyBasedEra era
eon) [(StakeAddress, Lovelace, Maybe CliWithdrawalScriptRequirements)]
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 (MultiAsset
mas, [CliMintScriptRequirements]
sWitFiles) = (MultiAsset, [CliMintScriptRequirements])
-> Maybe (MultiAsset, [CliMintScriptRequirements])
-> (MultiAsset, [CliMintScriptRequirements])
forall a. a -> Maybe a -> a
fromMaybe (MultiAsset, [CliMintScriptRequirements])
forall a. Monoid a => a
mempty Maybe (MultiAsset, [CliMintScriptRequirements])
mMintedAssets
    (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits <-
      (MultiAsset
mas,) ([MintScriptWitnessWithPolicyId era]
 -> (MultiAsset, [MintScriptWitnessWithPolicyId era]))
-> ExceptT TxCmdError IO [MintScriptWitnessWithPolicyId era]
-> ExceptT
     TxCmdError IO (MultiAsset, [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 (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits <-
      ExceptT
  TxCmdError
  IO
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> (ConwayEraOnwards era
    -> ExceptT
         TxCmdError
         IO
         [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ShelleyBasedEra era
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall (eon :: * -> *) a era.
Eon eon =>
a -> (eon era -> a) -> ShelleyBasedEra era -> a
inEonForShelleyBasedEra
        ([(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. a -> ExceptT TxCmdError IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a. Monoid a => a
mempty)
        ( \ConwayEraOnwards era
w ->
            (VoteError -> TxCmdError)
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness 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 (VoteScriptWitness era))]
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> (IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
    -> ExceptT
         VoteError
         IO
         [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO
  (Either
     VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     VoteError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (IO
   (Either
      VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
 -> ExceptT
      TxCmdError
      IO
      [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     [(VotingProcedures era, Maybe (VoteScriptWitness era))]
forall a b. (a -> b) -> a -> b
$
              ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  IO
    (Either
       VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
 -> IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> (ConwayEraOnwardsConstraints era =>
    IO
      (Either
         VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))]))
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall a b. (a -> b) -> a -> b
$
                ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
forall era.
ConwayEraOnwards era
-> [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
-> IO
     (Either
        VoteError [(VotingProcedures era, Maybe (VoteScriptWitness era))])
readVotingProceduresFiles ConwayEraOnwards era
w [(VoteFile 'In, Maybe CliVoteScriptRequirements)]
voteFiles
        )
        ShelleyBasedEra era
eon

    [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals <-
      IO
  (Either
     ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness 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 CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
forall era.
ShelleyBasedEra era
-> [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
-> IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
readTxGovernanceActions ShelleyBasedEra era
eon [(ProposalFile 'In, Maybe CliProposalScriptRequirements)]
proposalFiles)
        ExceptT
  TxCmdError
  IO
  (Either
     ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> (ExceptT
      TxCmdError
      IO
      (Either
         ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
    -> ExceptT
         TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))]
forall a b. a -> (a -> b) -> b
& (ProposalError
 -> ExceptT
      TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError
     IO
     (Either
        ProposalError [(Proposal era, Maybe (ProposalScriptWitness era))])
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness 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 (ProposalScriptWitness era))]
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness era))])
-> (ProposalError -> TxCmdError)
-> ProposalError
-> ExceptT
     TxCmdError IO [(Proposal era, Maybe (ProposalScriptWitness 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
              (,CertificateScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
CertificateScriptWitness era -> ScriptWitness WitCtxStake era
cswScriptWitness (CertificateScriptWitness era -> ScriptWitness WitCtxStake era)
-> Maybe (CertificateScriptWitness era)
-> Maybe (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (CertificateScriptWitness 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 (CertificateScriptWitness era)
mSwit) <- [(CertificateFile, Maybe (CertificateScriptWitness 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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
runTxBuildRaw
          ShelleyBasedEra era
eon
          Maybe ScriptValidity
mScriptValidity
          [(TxIn, Maybe (SpendScriptWitness era))]
txInsAndMaybeScriptWits
          [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
          (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
          [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
          [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawalsAndMaybeScriptWits
          [Hash PaymentKey]
requiredSigners
          TxAuxScripts era
txAuxScripts
          TxMetadataInEra era
txMetadata
          Maybe (LedgerProtocolParameters era)
mLedgerPParams
          TxUpdateProposal era
txUpdateProposal
          [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProceduresAndMaybeScriptWits
          [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness 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
  -> (L.MultiAsset, [MintScriptWitnessWithPolicyId era])
  -- ^ Multi-Asset minted value(s)
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> Maybe (LedgerProtocolParameters era)
  -> TxUpdateProposal era
  -> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
  -> [(Proposal era, Maybe (ProposalScriptWitness era))]
  -> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
  -> Either TxCmdError (TxBody era)
runTxBuildRaw :: forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> Lovelace
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBody era)
runTxBuildRaw
  ShelleyBasedEra era
sbe
  Maybe ScriptValidity
mScriptValidity
  [(TxIn, Maybe (SpendScriptWitness 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
  (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeSriptWits
  [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  Maybe (LedgerProtocolParameters era)
mpparams
  TxUpdateProposal era
txUpdateProposal
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures
  [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals
  Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation = do
    TxBodyContent BuildTx era
txBodyContent <-
      ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))]
inputsAndMaybeScriptWits
        [TxIn]
readOnlyRefIns
        [TxIn]
txinsc
        Maybe (TxOut CtxTx era)
mReturnCollateral
        Maybe Lovelace
mTotCollateral
        [TxOut CtxTx era]
txouts
        Maybe SlotNo
mLowerBound
        TxValidityUpperBound era
mUpperBound
        (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
        [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeSriptWits
        [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals
        [Hash PaymentKey]
reqSigners
        Lovelace
fee
        TxAuxScripts era
txAuxScripts
        TxMetadataInEra era
txMetadata
        TxUpdateProposal era
txUpdateProposal
        [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures
        [(Proposal era, Maybe (ProposalScriptWitness 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.
HasCallStack =>
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 (SpendScriptWitness 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
  -> (L.MultiAsset, [MintScriptWitnessWithPolicyId era])
  -- ^ Multi-Asset value(s)
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
  -- ^ Withdrawals
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> Lovelace
  -- ^ Tx fee
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> TxUpdateProposal era
  -> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
  -> [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
constructTxBodyContent
  ShelleyBasedEra era
sbe
  Maybe ScriptValidity
mScriptValidity
  Maybe (PParams (ShelleyLedgerEra era))
mPparams
  [(TxIn, Maybe (SpendScriptWitness era))]
inputsAndMaybeScriptWits
  [TxIn]
readOnlyRefIns
  [TxIn]
txinsc
  Maybe (TxOut CtxTx era)
mReturnCollateral
  Maybe Lovelace
mTotCollateral
  [TxOut CtxTx era]
txouts
  Maybe SlotNo
mLowerBound
  TxValidityUpperBound era
mUpperBound
  (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
  [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  Lovelace
fee
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  TxUpdateProposal era
txUpdateProposal
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures
  [(Proposal era, Maybe (ProposalScriptWitness era))]
proposals
  Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
mCurrentTreasuryValueAndDonation =
    do
      let allReferenceInputs :: [TxIn]
allReferenceInputs =
            [ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
forall era.
[ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
              ((SpendScriptWitness era -> ScriptWitness WitCtxTxIn era)
-> [SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era]
forall a b. (a -> b) -> [a] -> [b]
map SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
forall era. SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
sswScriptWitness ([SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era])
-> [SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era]
forall a b. (a -> b) -> a -> b
$ ((TxIn, Maybe (SpendScriptWitness era))
 -> Maybe (SpendScriptWitness era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [SpendScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (TxIn, Maybe (SpendScriptWitness era))
-> Maybe (SpendScriptWitness era)
forall a b. (a, b) -> b
snd [(TxIn, Maybe (SpendScriptWitness 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
$ (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [MintScriptWitnessWithPolicyId era]
forall a b. (a, b) -> b
snd (MultiAsset, [MintScriptWitnessWithPolicyId era])
valuesWithScriptWits)
              (((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Maybe (ScriptWitness WitCtxStake era))
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [ScriptWitness WitCtxStake era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (ScriptWitness WitCtxStake era)
forall a b. (a, b) -> b
snd [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits)
              (((StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
 -> Maybe (WithdrawalScriptWitness era))
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [WithdrawalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\(StakeAddress
_, Lovelace
_, Maybe (WithdrawalScriptWitness era)
mSwit) -> Maybe (WithdrawalScriptWitness era)
mSwit) [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals)
              (((VotingProcedures era, Maybe (VoteScriptWitness era))
 -> Maybe (VoteScriptWitness era))
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [VoteScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (VotingProcedures era, Maybe (VoteScriptWitness era))
-> Maybe (VoteScriptWitness era)
forall a b. (a, b) -> b
snd [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures)
              (((Proposal era, Maybe (ProposalScriptWitness era))
 -> Maybe (ProposalScriptWitness era))
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> [ProposalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Proposal era, Maybe (ProposalScriptWitness era))
-> Maybe (ProposalScriptWitness era)
forall a b. (a, b) -> b
snd [(Proposal era, Maybe (ProposalScriptWitness 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
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
forall era.
ShelleyBasedEra era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue ShelleyBasedEra era
sbe (MultiAsset, [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 :: TxVotingProcedures BuildTx era <-
        (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
$
          [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Either
     (VotesMergingConflict era) (TxVotingProcedures BuildTx era)
forall build era.
Applicative (BuildTxWith build) =>
[(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
mkTxVotingProcedures [(VotingProcedures era
v, VoteScriptWitness era -> ScriptWitness WitCtxStake era
forall era. VoteScriptWitness era -> ScriptWitness WitCtxStake era
vswScriptWitness (VoteScriptWitness era -> ScriptWitness WitCtxStake era)
-> Maybe (VoteScriptWitness era)
-> Maybe (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (VoteScriptWitness era)
mSwit) | (VotingProcedures era
v, Maybe (VoteScriptWitness era)
mSwit) <- [(VotingProcedures era, Maybe (VoteScriptWitness 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
$
                      [(ProposalProcedure (ShelleyLedgerEra era)
prop, ProposalScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
ProposalScriptWitness era -> ScriptWitness WitCtxStake era
pswScriptWitness (ProposalScriptWitness era -> ScriptWitness WitCtxStake era)
-> Maybe (ProposalScriptWitness era)
-> Maybe (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ProposalScriptWitness era)
mSwit) | (Proposal ProposalProcedure (ShelleyLedgerEra era)
prop, Maybe (ProposalScriptWitness era)
mSwit) <- [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))] -> TxIns BuildTx era
forall era.
[(TxIn, Maybe (SpendScriptWitness era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns [(TxIn, Maybe (SpendScriptWitness 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 (WithdrawalScriptWitness era))
 -> (StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era)))
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a b. (a -> b) -> [a] -> [b]
map (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
-> (StakeAddress, Lovelace,
    BuildTxWith BuildTx (Witness WitCtxStake era))
convertWithdrawals [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness 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 build era.
Applicative (BuildTxWith build) =>
ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates build era
mkTxCertificates 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 (WithdrawalScriptWitness era))
      -> (StakeAddress, Lovelace, BuildTxWith BuildTx (Witness WitCtxStake era))
    convertWithdrawals :: (StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
-> (StakeAddress, Lovelace,
    BuildTxWith BuildTx (Witness WitCtxStake era))
convertWithdrawals (StakeAddress
sAddr, Lovelace
ll, Maybe (WithdrawalScriptWitness era)
mScriptWitnessFiles) =
      case Maybe (WithdrawalScriptWitness era)
mScriptWitnessFiles of
        Just WithdrawalScriptWitness 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 -> Witness WitCtxStake era)
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall a b. (a -> b) -> a -> b
$ WithdrawalScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
WithdrawalScriptWitness era -> ScriptWitness WitCtxStake era
wswScriptWitness WithdrawalScriptWitness era
sWit)
        Maybe (WithdrawalScriptWitness 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 (SpendScriptWitness 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
  -> (L.MultiAsset, [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 (WithdrawalScriptWitness era))]
  -> [Hash PaymentKey]
  -- ^ Required signers
  -> TxAuxScripts era
  -> TxMetadataInEra era
  -> TxUpdateProposal era
  -> Maybe Word
  -> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
  -> [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> TxOutChangeAddress
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Maybe SlotNo
-> TxValidityUpperBound era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> ExceptT TxCmdError IO (BalancedTxBody era)
runTxBuild
  ShelleyBasedEra era
sbe
  SocketPath
socketPath
  NetworkId
networkId
  Maybe ScriptValidity
mScriptValidity
  [(TxIn, Maybe (SpendScriptWitness era))]
inputsAndMaybeScriptWits
  [TxIn]
readOnlyRefIns
  [TxIn]
txinsc
  Maybe (TxOut CtxTx era)
mReturnCollateral
  Maybe Lovelace
mTotCollateral
  [TxOut CtxTx era]
txouts
  (TxOutChangeAddress AddressAny
changeAddr)
  (MultiAsset, [MintScriptWitnessWithPolicyId era])
mintValueWithScriptWits
  Maybe SlotNo
mLowerBound
  TxValidityUpperBound era
mUpperBound
  [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
  [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals
  [Hash PaymentKey]
reqSigners
  TxAuxScripts era
txAuxScripts
  TxMetadataInEra era
txMetadata
  TxUpdateProposal era
txUpdateProposal
  Maybe Word
mOverrideWits
  [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures
  [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era)
_) <- [(TxIn, Maybe (SpendScriptWitness era))]
inputsAndMaybeScriptWits]

      let allReferenceInputs :: [TxIn]
allReferenceInputs =
            [ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
forall era.
[ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
              ((SpendScriptWitness era -> ScriptWitness WitCtxTxIn era)
-> [SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era]
forall a b. (a -> b) -> [a] -> [b]
map SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
forall era. SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
sswScriptWitness ([SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era])
-> [SpendScriptWitness era] -> [ScriptWitness WitCtxTxIn era]
forall a b. (a -> b) -> a -> b
$ ((TxIn, Maybe (SpendScriptWitness era))
 -> Maybe (SpendScriptWitness era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [SpendScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (TxIn, Maybe (SpendScriptWitness era))
-> Maybe (SpendScriptWitness era)
forall a b. (a, b) -> b
snd [(TxIn, Maybe (SpendScriptWitness 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
$ (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [MintScriptWitnessWithPolicyId era]
forall a b. (a, b) -> b
snd (MultiAsset, [MintScriptWitnessWithPolicyId era])
mintValueWithScriptWits)
              (((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Maybe (ScriptWitness WitCtxStake era))
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [ScriptWitness WitCtxStake era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (ScriptWitness WitCtxStake era)
forall a b. (a, b) -> b
snd [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits)
              (((StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))
 -> Maybe (WithdrawalScriptWitness era))
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [WithdrawalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\(StakeAddress
_, Lovelace
_, Maybe (WithdrawalScriptWitness era)
mSwit) -> Maybe (WithdrawalScriptWitness era)
mSwit) [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals)
              (((VotingProcedures era, Maybe (VoteScriptWitness era))
 -> Maybe (VoteScriptWitness era))
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [VoteScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (VotingProcedures era, Maybe (VoteScriptWitness era))
-> Maybe (VoteScriptWitness era)
forall a b. (a, b) -> b
snd [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures)
              (((Proposal era, Maybe (ProposalScriptWitness era))
 -> Maybe (ProposalScriptWitness era))
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> [ProposalScriptWitness era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Proposal era, Maybe (ProposalScriptWitness era))
-> Maybe (ProposalScriptWitness era)
forall a b. (a, b) -> b
snd [(Proposal era, Maybe (ProposalScriptWitness 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 certsToQuery :: [Certificate era]
certsToQuery = (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Certificate era
forall a b. (a, b) -> a
fst ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> Certificate era)
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [Certificate era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
      (UTxO era
txEraUtxo, LedgerProtocolParameters era
pparams, EraHistory
eraHistory, SystemStart
systemStart, Set PoolId
stakePools, Map StakeCredential Lovelace
stakeDelegDeposits, Map (Credential 'DRepRole) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
queryStateForBalancedTx CardanoEra era
nodeEra [TxIn]
allTxInputs [Certificate era]
[Certificate era]
certsToQuery
          )
          ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
         Set PoolId, Map StakeCredential Lovelace,
         Map (Credential 'DRepRole) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
    -> ExceptT
         TxCmdError
         IO
         (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
          Set PoolId, Map StakeCredential Lovelace,
          Map (Credential 'DRepRole) Lovelace,
          Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole) 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) 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) Lovelace,
         Maybe (Featured ConwayEraOnwards era TxCurrentTreasuryValue)))
-> ExceptT
     TxCmdError
     IO
     (UTxO era, LedgerProtocolParameters era, EraHistory, SystemStart,
      Set PoolId, Map StakeCredential Lovelace,
      Map (Credential 'DRepRole) 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) 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) 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) 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 (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (TxBodyContent BuildTx era)
forall era.
ShelleyBasedEra era
-> Maybe ScriptValidity
-> Maybe (PParams (ShelleyLedgerEra era))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [TxIn]
-> [TxIn]
-> Maybe (TxOut CtxTx era)
-> Maybe Lovelace
-> [TxOut CtxTx era]
-> Maybe SlotNo
-> TxValidityUpperBound era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
-> [Hash PaymentKey]
-> Lovelace
-> TxAuxScripts era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (VoteScriptWitness era))]
-> [(Proposal era, Maybe (ProposalScriptWitness 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 (SpendScriptWitness era))]
inputsAndMaybeScriptWits
            [TxIn]
readOnlyRefIns
            [TxIn]
txinsc
            Maybe (TxOut CtxTx era)
mReturnCollateral
            Maybe Lovelace
mTotCollateral
            [TxOut CtxTx era]
txouts
            Maybe SlotNo
mLowerBound
            TxValidityUpperBound era
mUpperBound
            (MultiAsset, [MintScriptWitnessWithPolicyId era])
mintValueWithScriptWits
            [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certsAndMaybeScriptWits
            [(StakeAddress, Lovelace, Maybe (WithdrawalScriptWitness era))]
withdrawals
            [Hash PaymentKey]
reqSigners
            Lovelace
0
            TxAuxScripts era
txAuxScripts
            TxMetadataInEra era
txMetadata
            TxUpdateProposal era
txUpdateProposal
            [(VotingProcedures era, Maybe (VoteScriptWitness era))]
votingProcedures
            [(Proposal era, Maybe (ProposalScriptWitness 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) Lovelace
-> UTxO era
-> TxBodyContent BuildTx era
-> AddressInEra era
-> Maybe Word
-> Either (TxBodyErrorAutoBalance era) (BalancedTxBody era)
forall era.
HasCallStack =>
ShelleyBasedEra era
-> SystemStart
-> LedgerEpochInfo
-> LedgerProtocolParameters era
-> Set PoolId
-> Map StakeCredential Lovelace
-> Map (Credential 'DRepRole) 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) 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 ann. Lovelace -> Doc ann
forall a ann. Pretty a => a -> 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

-- ----------------------------------------------------------------------------
-- 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 (SpendScriptWitness era))]
  -> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns :: forall era.
[(TxIn, Maybe (SpendScriptWitness era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns = ((TxIn, Maybe (SpendScriptWitness era))
 -> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))
-> [(TxIn, Maybe (SpendScriptWitness era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, Maybe (SpendScriptWitness era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
forall era.
(TxIn, Maybe (SpendScriptWitness era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
convertTxIn
 where
  convertTxIn
    :: (TxIn, Maybe (SpendScriptWitness era))
    -> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  convertTxIn :: forall era.
(TxIn, Maybe (SpendScriptWitness era))
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
convertTxIn (TxIn
txin, Maybe (SpendScriptWitness era)
mScriptWitness) =
    case Maybe (SpendScriptWitness era)
mScriptWitness of
      Just SpendScriptWitness 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 -> Witness WitCtxTxIn era)
-> ScriptWitness WitCtxTxIn era -> Witness WitCtxTxIn era
forall a b. (a -> b) -> a -> b
$ SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
forall era. SpendScriptWitness era -> ScriptWitness WitCtxTxIn era
sswScriptWitness SpendScriptWitness era
sWit)
      Maybe (SpendScriptWitness 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
  :: [ScriptWitness WitCtxTxIn era]
  -> [ScriptWitness WitCtxMint era]
  -> [ScriptWitness WitCtxStake era]
  -> [WithdrawalScriptWitness era]
  -> [VoteScriptWitness era]
  -> [ProposalScriptWitness era]
  -> [TxIn]
  -- ^ Read only reference inputs
  -> [TxIn]
getAllReferenceInputs :: forall era.
[ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [ScriptWitness WitCtxStake era]
-> [WithdrawalScriptWitness era]
-> [VoteScriptWitness era]
-> [ProposalScriptWitness era]
-> [TxIn]
-> [TxIn]
getAllReferenceInputs
  [ScriptWitness WitCtxTxIn era]
spendingWitnesses
  [ScriptWitness WitCtxMint era]
mintWitnesses
  [ScriptWitness WitCtxStake era]
certScriptWitnesses
  [WithdrawalScriptWitness era]
withdrawals
  [VoteScriptWitness era]
votingProceduresAndMaybeScriptWits
  [ProposalScriptWitness era]
propProceduresAnMaybeScriptWits
  [TxIn]
readOnlyRefIns = do
    let txinsWitByRefInputs :: [Maybe TxIn]
txinsWitByRefInputs = (ScriptWitness WitCtxTxIn era -> Maybe TxIn)
-> [ScriptWitness WitCtxTxIn era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map ScriptWitness WitCtxTxIn era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getScriptWitnessReferenceInput [ScriptWitness WitCtxTxIn era]
spendingWitnesses
        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
getScriptWitnessReferenceInput [ScriptWitness WitCtxMint era]
mintWitnesses
        certsWitByRefInputs :: [Maybe TxIn]
certsWitByRefInputs = (ScriptWitness WitCtxStake era -> Maybe TxIn)
-> [ScriptWitness WitCtxStake era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getScriptWitnessReferenceInput [ScriptWitness WitCtxStake era]
certScriptWitnesses
        withdrawalsWitByRefInputs :: [Maybe TxIn]
withdrawalsWitByRefInputs = (WithdrawalScriptWitness era -> Maybe TxIn)
-> [WithdrawalScriptWitness era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getScriptWitnessReferenceInput (ScriptWitness WitCtxStake era -> Maybe TxIn)
-> (WithdrawalScriptWitness era -> ScriptWitness WitCtxStake era)
-> WithdrawalScriptWitness era
-> Maybe TxIn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithdrawalScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
WithdrawalScriptWitness era -> ScriptWitness WitCtxStake era
wswScriptWitness) [WithdrawalScriptWitness era]
withdrawals
        votesWitByRefInputs :: [Maybe TxIn]
votesWitByRefInputs = (VoteScriptWitness era -> Maybe TxIn)
-> [VoteScriptWitness era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getScriptWitnessReferenceInput (ScriptWitness WitCtxStake era -> Maybe TxIn)
-> (VoteScriptWitness era -> ScriptWitness WitCtxStake era)
-> VoteScriptWitness era
-> Maybe TxIn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VoteScriptWitness era -> ScriptWitness WitCtxStake era
forall era. VoteScriptWitness era -> ScriptWitness WitCtxStake era
vswScriptWitness) [VoteScriptWitness era]
votingProceduresAndMaybeScriptWits
        propsWitByRefInputs :: [Maybe TxIn]
propsWitByRefInputs = (ProposalScriptWitness era -> Maybe TxIn)
-> [ProposalScriptWitness era] -> [Maybe TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (ScriptWitness WitCtxStake era -> Maybe TxIn
forall witctx era. ScriptWitness witctx era -> Maybe TxIn
getScriptWitnessReferenceInput (ScriptWitness WitCtxStake era -> Maybe TxIn)
-> (ProposalScriptWitness era -> ScriptWitness WitCtxStake era)
-> ProposalScriptWitness era
-> Maybe TxIn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProposalScriptWitness era -> ScriptWitness WitCtxStake era
forall era.
ProposalScriptWitness era -> ScriptWitness WitCtxStake era
pswScriptWitness) [ProposalScriptWitness 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
      ]

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
  -> (L.MultiAsset, [MintScriptWitnessWithPolicyId era])
  -> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue :: forall era.
ShelleyBasedEra era
-> (MultiAsset, [MintScriptWitnessWithPolicyId era])
-> Either TxCmdError (TxMintValue BuildTx era)
createTxMintValue ShelleyBasedEra era
era (MultiAsset
val, [MintScriptWitnessWithPolicyId era]
scriptWitnesses) =
  if MultiAsset
forall a. Monoid a => a
mempty MultiAsset -> MultiAsset -> Bool
forall a. Eq a => a -> a -> Bool
== MultiAsset
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 :: Map PolicyId PolicyAssets
                policiesWithAssets :: Map PolicyId PolicyAssets
policiesWithAssets = MultiAsset -> Map PolicyId PolicyAssets
multiAssetToPolicyAssets MultiAsset
val
                -- The set of policy ids for which we need witnesses:
                witnessesNeededSet :: Set PolicyId
                witnessesNeededSet :: Set PolicyId
witnessesNeededSet = Map PolicyId PolicyAssets -> Set PolicyId
forall k a. Map k a -> Set k
Map.keysSet Map PolicyId PolicyAssets
policiesWithAssets

                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 :: 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
            -- 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
     (PolicyAssets, BuildTxWith BuildTx (ScriptWitness WitCtxMint era))
-> TxMintValue BuildTx era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
w (Map
   PolicyId
   (PolicyAssets, BuildTxWith BuildTx (ScriptWitness WitCtxMint era))
 -> TxMintValue BuildTx era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith BuildTx (ScriptWitness WitCtxMint era))
-> TxMintValue BuildTx era
forall a b. (a -> b) -> a -> b
$
                (PolicyAssets
 -> ScriptWitness WitCtxMint era
 -> (PolicyAssets,
     BuildTxWith BuildTx (ScriptWitness WitCtxMint era)))
-> Map PolicyId PolicyAssets
-> Map PolicyId (ScriptWitness WitCtxMint era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith BuildTx (ScriptWitness WitCtxMint era))
forall k a b c.
Ord k =>
(a -> b -> c) -> Map k a -> Map k b -> Map k c
Map.intersectionWith
                  (\PolicyAssets
assets ScriptWitness WitCtxMint era
wit -> (PolicyAssets
assets, ScriptWitness WitCtxMint era
-> BuildTxWith BuildTx (ScriptWitness WitCtxMint era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith ScriptWitness WitCtxMint era
wit))
                  Map PolicyId PolicyAssets
policiesWithAssets
                  Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap
        )
        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]
witnessSigningData :: [WitnessSigningData]
witnessSigningData :: TransactionSignCmdArgs -> [WitnessSigningData]
witnessSigningData
    , Maybe NetworkId
mNetworkId :: Maybe NetworkId
mNetworkId :: TransactionSignCmdArgs -> Maybe NetworkId
mNetworkId
    , TxFile 'Out
outTxFile :: TxFile 'Out
outTxFile :: TransactionSignCmdArgs -> 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 :: Tx era
tx@(ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
ledgerTx) <- 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
apiTxBody, [KeyWitness era]
existingTxKeyWits) = Tx era -> (TxBody era, [KeyWitness era])
forall era. Tx era -> (TxBody era, [KeyWitness era])
getTxBodyAndWitnesses Tx era
tx

        [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 e (m :: * -> *) a. MonadError e m => Either e a -> m a
liftEither (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
$
            [ShelleyBootstrapWitnessSigningKeyData]
-> (ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> Either BootstrapWitnessError [KeyWitness era]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [ShelleyBootstrapWitnessSigningKeyData]
sksByron ((ShelleyBootstrapWitnessSigningKeyData
  -> Either BootstrapWitnessError (KeyWitness era))
 -> Either BootstrapWitnessError [KeyWitness era])
-> (ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> Either BootstrapWitnessError [KeyWitness era]
forall a b. (a -> b) -> a -> b
$
              ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era =>
  ShelleyBootstrapWitnessSigningKeyData
  -> Either BootstrapWitnessError (KeyWitness era))
 -> ShelleyBootstrapWitnessSigningKeyData
 -> Either BootstrapWitnessError (KeyWitness era))
-> (ShelleyBasedEraConstraints era =>
    ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall a b. (a -> b) -> a -> b
$
                ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId (Tx (ShelleyLedgerEra era)
ledgerTx Tx (ShelleyLedgerEra era)
-> Getting
     (TxBody (ShelleyLedgerEra era))
     (Tx (ShelleyLedgerEra era))
     (TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall s a. s -> Getting a s a -> a
^. Getting
  (TxBody (ShelleyLedgerEra era))
  (Tx (ShelleyLedgerEra era))
  (TxBody (ShelleyLedgerEra era))
forall era. EraTx era => Lens' (Tx era) (TxBody era)
Lens' (Tx (ShelleyLedgerEra era)) (TxBody (ShelleyLedgerEra era))
L.bodyTxL)

        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
apiTxBody) [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
apiTxBody

        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 :: TxBody era
txbody@(ShelleyTxBody ShelleyBasedEra era
_ TxBody (ShelleyLedgerEra era)
ledgerTxBody [Script (ShelleyLedgerEra era)]
_ TxBodyScriptData era
_ Maybe (TxAuxData (ShelleyLedgerEra era))
_ TxScriptValidity era
_) <- 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 e (m :: * -> *) a. MonadError e m => Either e a -> m a
liftEither (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
$
                [ShelleyBootstrapWitnessSigningKeyData]
-> (ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> Either BootstrapWitnessError [KeyWitness era]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [ShelleyBootstrapWitnessSigningKeyData]
sksByron ((ShelleyBootstrapWitnessSigningKeyData
  -> Either BootstrapWitnessError (KeyWitness era))
 -> Either BootstrapWitnessError [KeyWitness era])
-> (ShelleyBootstrapWitnessSigningKeyData
    -> Either BootstrapWitnessError (KeyWitness era))
-> Either BootstrapWitnessError [KeyWitness era]
forall a b. (a -> b) -> a -> b
$
                  ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId TxBody (ShelleyLedgerEra era)
ledgerTxBody

            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
    { LocalNodeConnectInfo
nodeConnInfo :: LocalNodeConnectInfo
nodeConnInfo :: TransactionSubmitCmdArgs -> LocalNodeConnectInfo
nodeConnInfo
    , 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
    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
nodeConnInfo 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 ann. Lovelace -> Doc ann
forall a ann. Pretty a => a -> 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.
HasCallStack =>
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

runTransactionCalculatePlutusScriptCostCmd
  :: Cmd.TransactionCalculatePlutusScriptCostCmdArgs -> ExceptT TxCmdError IO ()
runTransactionCalculatePlutusScriptCostCmd :: TransactionCalculatePlutusScriptCostCmdArgs
-> ExceptT TxCmdError IO ()
runTransactionCalculatePlutusScriptCostCmd
  Cmd.TransactionCalculatePlutusScriptCostCmdArgs
    { LocalNodeConnectInfo
nodeConnInfo :: LocalNodeConnectInfo
nodeConnInfo :: TransactionCalculatePlutusScriptCostCmdArgs -> LocalNodeConnectInfo
nodeConnInfo
    , FilePath
txFileIn :: FilePath
txFileIn :: TransactionCalculatePlutusScriptCostCmdArgs -> FilePath
txFileIn
    , Maybe (File () 'Out)
outputFile :: Maybe (File () 'Out)
outputFile :: TransactionCalculatePlutusScriptCostCmdArgs -> Maybe (File () 'Out)
outputFile
    } = do
    FileOrPipe
txFileOrPipeIn <- 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
txFileIn
    InAnyShelleyBasedEra ShelleyBasedEra era
txEra tx :: Tx era
tx@(ShelleyTx ShelleyBasedEra era
sbe Tx (ShelleyLedgerEra era)
ledgerTx) <-
      IO
  (Either
     (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
-> ExceptT
     TxCmdError
     IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
forall a. IO a -> ExceptT TxCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FileOrPipe
-> IO
     (Either
        (FileError TextEnvelopeCddlError) (InAnyShelleyBasedEra Tx))
readFileTx FileOrPipe
txFileOrPipeIn) 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 relevantTxIns :: Set TxIn
        relevantTxIns :: Set TxIn
relevantTxIns = (TxIn -> TxIn) -> Set TxIn -> Set TxIn
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map TxIn -> TxIn
fromShelleyTxIn (Set TxIn -> Set TxIn) -> Set TxIn -> Set TxIn
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => Set TxIn) -> Set TxIn
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe (Tx (ShelleyLedgerEra era)
ledgerTx Tx (ShelleyLedgerEra era)
-> Getting (Set TxIn) (Tx (ShelleyLedgerEra era)) (Set TxIn)
-> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const (Set TxIn) (TxBody (ShelleyLedgerEra era)))
-> Tx (ShelleyLedgerEra era)
-> Const (Set TxIn) (Tx (ShelleyLedgerEra era))
forall era. EraTx era => Lens' (Tx era) (TxBody era)
Lens' (Tx (ShelleyLedgerEra era)) (TxBody (ShelleyLedgerEra era))
bodyTxL ((TxBody (ShelleyLedgerEra era)
  -> Const (Set TxIn) (TxBody (ShelleyLedgerEra era)))
 -> Tx (ShelleyLedgerEra era)
 -> Const (Set TxIn) (Tx (ShelleyLedgerEra era)))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody (ShelleyLedgerEra era)
    -> Const (Set TxIn) (TxBody (ShelleyLedgerEra era)))
-> Getting (Set TxIn) (Tx (ShelleyLedgerEra era)) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody (ShelleyLedgerEra era)
-> Const (Set TxIn) (TxBody (ShelleyLedgerEra era))
forall era. EraTxBody era => SimpleGetter (TxBody era) (Set TxIn)
SimpleGetter (TxBody (ShelleyLedgerEra era)) (Set TxIn)
allInputsTxBodyF)

    (AnyCardanoEra CardanoEra era
nodeEra, SystemStart
systemStart, EraHistory
eraHistory, UTxO era
txEraUtxo, LedgerProtocolParameters era
pparams) <-
      IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era)))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
            LedgerProtocolParameters 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
        ( LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
-> IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
            LedgerProtocolParameters era)))
forall a.
LocalNodeConnectInfo
-> Target ChainPoint
-> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
-> IO (Either AcquiringFailure a)
executeLocalStateQueryExpr LocalNodeConnectInfo
nodeConnInfo Target ChainPoint
forall point. Target point
Consensus.VolatileTip (LocalStateQueryExpr
   BlockInMode
   ChainPoint
   QueryInMode
   ()
   IO
   (Either
      QueryConvenienceError
      (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
       LedgerProtocolParameters era))
 -> IO
      (Either
         AcquiringFailure
         (Either
            QueryConvenienceError
            (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
             LedgerProtocolParameters era))))
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
-> IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
            LedgerProtocolParameters era)))
forall a b. (a -> b) -> a -> b
$ do
            Either UnsupportedNtcVersionError AnyCardanoEra
eCurrentEra <- LocalStateQueryExpr
  BlockInMode
  ChainPoint
  QueryInMode
  ()
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
forall block point r.
LocalStateQueryExpr
  block
  point
  QueryInMode
  r
  IO
  (Either UnsupportedNtcVersionError AnyCardanoEra)
queryCurrentEra
            Either UnsupportedNtcVersionError SystemStart
eSystemStart <- LocalStateQueryExpr
  BlockInMode
  ChainPoint
  QueryInMode
  ()
  IO
  (Either UnsupportedNtcVersionError SystemStart)
forall block point r.
LocalStateQueryExpr
  block
  point
  QueryInMode
  r
  IO
  (Either UnsupportedNtcVersionError SystemStart)
querySystemStart
            Either UnsupportedNtcVersionError EraHistory
eEraHistory <- LocalStateQueryExpr
  BlockInMode
  ChainPoint
  QueryInMode
  ()
  IO
  (Either UnsupportedNtcVersionError EraHistory)
forall block point r.
LocalStateQueryExpr
  block
  point
  QueryInMode
  r
  IO
  (Either UnsupportedNtcVersionError EraHistory)
queryEraHistory
            Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era))
eeUtxo <- ShelleyBasedEra era
-> QueryUTxOFilter
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era)))
forall era block point r.
ShelleyBasedEra era
-> QueryUTxOFilter
-> LocalStateQueryExpr
     block
     point
     QueryInMode
     r
     IO
     (Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era)))
queryUtxo ShelleyBasedEra era
txEra (Set TxIn -> QueryUTxOFilter
QueryUTxOByTxIn Set TxIn
relevantTxIns)
            Either
  UnsupportedNtcVersionError
  (Either EraMismatch (PParams (ShelleyLedgerEra era)))
ePp <- QueryInMode (Either EraMismatch (PParams (ShelleyLedgerEra era)))
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        UnsupportedNtcVersionError
        (Either EraMismatch (PParams (ShelleyLedgerEra era))))
forall a block point r.
QueryInMode a
-> LocalStateQueryExpr
     block point QueryInMode r IO (Either UnsupportedNtcVersionError a)
queryExpr (QueryInMode (Either EraMismatch (PParams (ShelleyLedgerEra era)))
 -> LocalStateQueryExpr
      BlockInMode
      ChainPoint
      QueryInMode
      ()
      IO
      (Either
         UnsupportedNtcVersionError
         (Either EraMismatch (PParams (ShelleyLedgerEra era)))))
-> QueryInMode
     (Either EraMismatch (PParams (ShelleyLedgerEra era)))
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        UnsupportedNtcVersionError
        (Either EraMismatch (PParams (ShelleyLedgerEra era))))
forall a b. (a -> b) -> a -> b
$ QueryInEra era (PParams (ShelleyLedgerEra era))
-> QueryInMode
     (Either EraMismatch (PParams (ShelleyLedgerEra era)))
forall era result1.
QueryInEra era result1 -> QueryInMode (Either EraMismatch result1)
QueryInEra (QueryInEra era (PParams (ShelleyLedgerEra era))
 -> QueryInMode
      (Either EraMismatch (PParams (ShelleyLedgerEra era))))
-> QueryInEra era (PParams (ShelleyLedgerEra era))
-> QueryInMode
     (Either EraMismatch (PParams (ShelleyLedgerEra era)))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> QueryInShelleyBasedEra era (PParams (ShelleyLedgerEra era))
-> QueryInEra era (PParams (ShelleyLedgerEra era))
forall era result.
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result -> QueryInEra era result
QueryInShelleyBasedEra ShelleyBasedEra era
sbe QueryInShelleyBasedEra era (PParams (ShelleyLedgerEra era))
forall era.
QueryInShelleyBasedEra era (PParams (ShelleyLedgerEra era))
Api.QueryProtocolParameters
            Either
  QueryConvenienceError
  (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
   LedgerProtocolParameters era)
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
forall a.
a -> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
   QueryConvenienceError
   (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
    LedgerProtocolParameters era)
 -> LocalStateQueryExpr
      BlockInMode
      ChainPoint
      QueryInMode
      ()
      IO
      (Either
         QueryConvenienceError
         (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
          LedgerProtocolParameters era)))
-> Either
     QueryConvenienceError
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era)
-> LocalStateQueryExpr
     BlockInMode
     ChainPoint
     QueryInMode
     ()
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
forall a b. (a -> b) -> a -> b
$ do
              AnyCardanoEra
currentEra <- (UnsupportedNtcVersionError -> QueryConvenienceError)
-> Either UnsupportedNtcVersionError AnyCardanoEra
-> Either QueryConvenienceError AnyCardanoEra
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 UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion Either UnsupportedNtcVersionError AnyCardanoEra
eCurrentEra
              SystemStart
systemStart <- (UnsupportedNtcVersionError -> QueryConvenienceError)
-> Either UnsupportedNtcVersionError SystemStart
-> Either QueryConvenienceError SystemStart
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 UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion Either UnsupportedNtcVersionError SystemStart
eSystemStart
              EraHistory
eraHistory <- (UnsupportedNtcVersionError -> QueryConvenienceError)
-> Either UnsupportedNtcVersionError EraHistory
-> Either QueryConvenienceError EraHistory
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 UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion Either UnsupportedNtcVersionError EraHistory
eEraHistory
              UTxO era
utxo <- (EraMismatch -> QueryConvenienceError)
-> Either EraMismatch (UTxO era)
-> Either QueryConvenienceError (UTxO 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 EraMismatch -> QueryConvenienceError
QueryEraMismatch (Either EraMismatch (UTxO era)
 -> Either QueryConvenienceError (UTxO era))
-> Either QueryConvenienceError (Either EraMismatch (UTxO era))
-> Either QueryConvenienceError (UTxO era)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (UnsupportedNtcVersionError -> QueryConvenienceError)
-> Either
     UnsupportedNtcVersionError (Either EraMismatch (UTxO era))
-> Either QueryConvenienceError (Either EraMismatch (UTxO 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 UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era))
eeUtxo
              PParams (ShelleyLedgerEra era)
pp <- (EraMismatch -> QueryConvenienceError)
-> Either EraMismatch (PParams (ShelleyLedgerEra era))
-> Either QueryConvenienceError (PParams (ShelleyLedgerEra 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 EraMismatch -> QueryConvenienceError
QueryEraMismatch (Either EraMismatch (PParams (ShelleyLedgerEra era))
 -> Either QueryConvenienceError (PParams (ShelleyLedgerEra era)))
-> Either
     QueryConvenienceError
     (Either EraMismatch (PParams (ShelleyLedgerEra era)))
-> Either QueryConvenienceError (PParams (ShelleyLedgerEra era))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (UnsupportedNtcVersionError -> QueryConvenienceError)
-> Either
     UnsupportedNtcVersionError
     (Either EraMismatch (PParams (ShelleyLedgerEra era)))
-> Either
     QueryConvenienceError
     (Either EraMismatch (PParams (ShelleyLedgerEra 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 UnsupportedNtcVersionError -> QueryConvenienceError
QceUnsupportedNtcVersion Either
  UnsupportedNtcVersionError
  (Either EraMismatch (PParams (ShelleyLedgerEra era)))
ePp
              (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
 LedgerProtocolParameters era)
-> Either
     QueryConvenienceError
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era)
forall a. a -> Either QueryConvenienceError a
forall (m :: * -> *) a. Monad m => a -> m a
return (AnyCardanoEra
currentEra, SystemStart
systemStart, EraHistory
eraHistory, UTxO era
utxo, PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
forall era.
PParams (ShelleyLedgerEra era) -> LedgerProtocolParameters era
LedgerProtocolParameters PParams (ShelleyLedgerEra era)
pp)
        )
        ExceptT
  TxCmdError
  IO
  (Either
     AcquiringFailure
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era)))
-> (ExceptT
      TxCmdError
      IO
      (Either
         AcquiringFailure
         (Either
            QueryConvenienceError
            (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
             LedgerProtocolParameters era)))
    -> ExceptT
         TxCmdError
         IO
         (Either
            QueryConvenienceError
            (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
             LedgerProtocolParameters era)))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
forall a b. a -> (a -> b) -> b
& (AcquiringFailure
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
          LedgerProtocolParameters era)))
-> ExceptT
     TxCmdError
     IO
     (Either
        AcquiringFailure
        (Either
           QueryConvenienceError
           (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
            LedgerProtocolParameters era)))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters 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
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
          LedgerProtocolParameters era)))
-> (AcquiringFailure -> TxCmdError)
-> AcquiringFailure
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
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
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era))
-> (ExceptT
      TxCmdError
      IO
      (Either
         QueryConvenienceError
         (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
          LedgerProtocolParameters era))
    -> ExceptT
         TxCmdError
         IO
         (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
          LedgerProtocolParameters era))
-> ExceptT
     TxCmdError
     IO
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era)
forall a b. a -> (a -> b) -> b
& (QueryConvenienceError
 -> ExceptT
      TxCmdError
      IO
      (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
       LedgerProtocolParameters era))
-> ExceptT
     TxCmdError
     IO
     (Either
        QueryConvenienceError
        (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
         LedgerProtocolParameters era))
-> ExceptT
     TxCmdError
     IO
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters 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
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxCmdError
 -> ExceptT
      TxCmdError
      IO
      (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
       LedgerProtocolParameters era))
-> (QueryConvenienceError -> TxCmdError)
-> QueryConvenienceError
-> ExceptT
     TxCmdError
     IO
     (AnyCardanoEra, SystemStart, EraHistory, UTxO era,
      LedgerProtocolParameters era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryConvenienceError -> TxCmdError
TxCmdQueryConvenienceError)

    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
nodeEra (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert ShelleyBasedEra era
txEra)
        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
          ( EraMismatch -> TxCmdError
TxCmdTxSubmitErrorEraMismatch (EraMismatch -> TxCmdError) -> EraMismatch -> TxCmdError
forall a b. (a -> b) -> a -> b
$
              EraMismatch{ledgerEraName :: Text
ledgerEraName = Doc AnsiStyle -> Text
docToText (Doc AnsiStyle -> Text) -> Doc AnsiStyle -> Text
forall a b. (a -> b) -> a -> b
$ CardanoEra era -> Doc AnsiStyle
forall a ann. Pretty a => a -> Doc ann
forall ann. CardanoEra era -> Doc ann
pretty CardanoEra era
nodeEra, otherEraName :: Text
otherEraName = Doc AnsiStyle -> Text
docToText (Doc AnsiStyle -> Text) -> Doc AnsiStyle -> Text
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> Doc AnsiStyle
forall a ann. Pretty a => a -> Doc ann
forall ann. ShelleyBasedEra era -> Doc ann
pretty ShelleyBasedEra era
txEra}
          )

    CardanoEra era
-> SystemStart
-> EraHistory
-> LedgerProtocolParameters era
-> UTxO era
-> Tx era
-> ExceptT TxCmdError IO ()
forall era.
CardanoEra era
-> SystemStart
-> EraHistory
-> LedgerProtocolParameters era
-> UTxO era
-> Tx era
-> ExceptT TxCmdError IO ()
calculatePlutusScriptsCosts
      (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert ShelleyBasedEra era
txEra)
      SystemStart
systemStart
      EraHistory
eraHistory
      LedgerProtocolParameters era
pparams
      UTxO era
txEraUtxo
      Tx era
tx
   where
    calculatePlutusScriptsCosts
      :: CardanoEra era
      -> SystemStart
      -> EraHistory
      -> LedgerProtocolParameters era
      -> UTxO era
      -> Tx era
      -> ExceptT TxCmdError IO ()
    calculatePlutusScriptsCosts :: forall era.
CardanoEra era
-> SystemStart
-> EraHistory
-> LedgerProtocolParameters era
-> UTxO era
-> Tx era
-> ExceptT TxCmdError IO ()
calculatePlutusScriptsCosts CardanoEra era
era' SystemStart
systemStart EraHistory
eraHistory LedgerProtocolParameters era
pparams UTxO era
txEraUtxo Tx era
tx = do
      Map ScriptWitnessIndex ScriptHash
scriptHashes <-
        forall (eon :: * -> *) a era.
(Eon eon, Monoid a) =>
CardanoEra era -> (eon era -> a) -> a
monoidForEraInEon @AlonzoEraOnwards
          CardanoEra era
era'
          (\AlonzoEraOnwards era
aeo -> Map ScriptWitnessIndex ScriptHash
-> Maybe (Map ScriptWitnessIndex ScriptHash)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map ScriptWitnessIndex ScriptHash
 -> Maybe (Map ScriptWitnessIndex ScriptHash))
-> Map ScriptWitnessIndex ScriptHash
-> Maybe (Map ScriptWitnessIndex ScriptHash)
forall a b. (a -> b) -> a -> b
$ AlonzoEraOnwards era
-> Tx era -> UTxO era -> Map ScriptWitnessIndex ScriptHash
forall era.
AlonzoEraOnwards era
-> Tx era -> UTxO era -> Map ScriptWitnessIndex ScriptHash
collectPlutusScriptHashes AlonzoEraOnwards era
aeo Tx era
tx UTxO era
txEraUtxo)
          Maybe (Map ScriptWitnessIndex ScriptHash)
-> (Maybe (Map ScriptWitnessIndex ScriptHash)
    -> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash))
-> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash)
forall a b. a -> (a -> b) -> b
& TxCmdError
-> Maybe (Map ScriptWitnessIndex ScriptHash)
-> ExceptT TxCmdError IO (Map ScriptWitnessIndex ScriptHash)
forall (m :: * -> *) x a. Monad m => x -> Maybe a -> ExceptT x m a
hoistMaybe (CardanoEra era -> TxCmdError
forall era. CardanoEra era -> TxCmdError
TxCmdAlonzoEraOnwardsRequired CardanoEra era
era')

      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)

      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
txEraUtxo
              (Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
tx)

      [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
$
            Prices
-> Map ScriptWitnessIndex ScriptHash
-> Map
     ScriptWitnessIndex
     (Either
        ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
-> Either PlutusScriptCostError [ScriptCostOutput]
renderScriptCostsWithScriptHashesMap
              Prices
executionUnitPrices
              Map ScriptWitnessIndex ScriptHash
scriptHashes
              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
$ ( case Maybe (File () 'Out)
outputFile of
              Just File () 'Out
file -> FilePath -> ByteString -> IO ()
LBS.writeFile (File () 'Out -> FilePath
forall content (direction :: FileDirection).
File content direction -> FilePath
unFile File () 'Out
file)
              Maybe (File () 'Out)
Nothing -> ByteString -> IO ()
forall (m :: * -> *). MonadIO m => ByteString -> m ()
putLByteString
          )
        (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ [ScriptCostOutput] -> ByteString
forall a. ToJSON a => a -> ByteString
encodePretty [ScriptCostOutput]
scriptCostOutput

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)

-- ----------------------------------------------------------------------------
-- 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
    , OutputFormatJsonOrText
outputFormat :: OutputFormatJsonOrText
outputFormat :: TransactionTxIdCmdArgs -> OutputFormatJsonOrText
outputFormat
    } = 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

    let txId :: TxId
txId = TxBody era -> TxId
forall era. TxBody era -> TxId
getTxId TxBody era
txbody

    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
$
      case OutputFormatJsonOrText
outputFormat of
        OutputFormatJsonOrText
OutputFormatJson -> 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
txId
        OutputFormatJsonOrText
OutputFormatText -> ByteString -> IO ()
BS.putStrLn (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytesHex TxId
txId

-- ----------------------------------------------------------------------------
-- 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 :: TxBody era
txbody@(ShelleyTxBody ShelleyBasedEra era
_ TxBody (ShelleyLedgerEra era)
ledgerTxBody [Script (ShelleyLedgerEra era)]
_ TxBodyScriptData era
_ Maybe (TxAuxData (ShelleyLedgerEra era))
_ TxScriptValidity era
_) <- 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 e (m :: * -> *) a. MonadError e m => Either e a -> m a
liftEither (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 (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
forall era.
ShelleyBasedEra era
-> Maybe NetworkId
-> TxBody (ShelleyLedgerEra era)
-> ShelleyBootstrapWitnessSigningKeyData
-> Either BootstrapWitnessError (KeyWitness era)
mkShelleyBootstrapWitness ShelleyBasedEra era
sbe Maybe NetworkId
mNetworkId TxBody (ShelleyLedgerEra era)
ledgerTxBody 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)