{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Cardano.CLI.Shelley.Run.Transaction
  ( ShelleyTxCmdError(..)
  , renderShelleyTxCmdError
  , runTransactionCmd
  , readCddlTx
  , readFileTx
  , readProtocolParametersSourceSpec
  , toTxOutInAnyEra
  ) where

import           Cardano.Prelude hiding (All, Any)
import           Prelude (String, error)

import           Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, handleLeftT,
                   hoistEither, hoistMaybe, left, newExceptT)
import qualified Data.Aeson as Aeson
import           Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as LBS
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as Text
import           Data.Type.Equality (TestEquality (..))
import qualified System.IO as IO


import           Cardano.Api
import           Cardano.Api.Byron hiding (SomeByronSigningKey (..))
import           Cardano.Api.Shelley

--TODO: do this nicely via the API too:
import qualified Cardano.Binary as CBOR
--TODO: following import needed for orphan Eq Script instance
import           Cardano.Ledger.Shelley.Scripts ()

import           Cardano.CLI.Run.Friendly (friendlyTxBS, friendlyTxBodyBS)
import           Cardano.CLI.Shelley.Key (InputDecodeError, readSigningKeyFileAnyOf)
import           Cardano.CLI.Shelley.Output
import           Cardano.CLI.Shelley.Parsers
import           Cardano.CLI.Shelley.Run.Genesis (ShelleyGenesisCmdError (..),
                   readShelleyGenesisWithDefault)
import           Cardano.CLI.Shelley.Script
import           Cardano.CLI.Types

import           Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx

{- HLINT ignore "Use let" -}

data ShelleyTxCmdError
  = ShelleyTxCmdAesonDecodeProtocolParamsError !FilePath !Text
  | ShelleyTxCmdReadFileError !(FileError ())
  | ShelleyTxCmdScriptFileError (FileError ScriptDecodeError)
  | ShelleyTxCmdReadTextViewFileError !(FileError TextEnvelopeError)
  | ShelleyTxCmdReadWitnessSigningDataError !ReadWitnessSigningDataError
  | ShelleyTxCmdReadRequiredSignerError !(FileError InputDecodeError)
  | ShelleyTxCmdRequiredSignerByronKeyError !SigningKeyFile
  | ShelleyTxCmdWriteFileError !(FileError ())
  | ShelleyTxCmdEraConsensusModeMismatch
      !(Maybe FilePath)
      !AnyConsensusMode
      !AnyCardanoEra
      -- ^ Era
  | ShelleyTxCmdMetadataJsonParseError !FilePath !String
  | ShelleyTxCmdMetadataConversionError !FilePath !TxMetadataJsonError
  | ShelleyTxCmdMetaValidationError !FilePath ![(Word64, TxMetadataRangeError)]
  | ShelleyTxCmdScriptDataJsonParseError  !FilePath !String
  | ShelleyTxCmdScriptDataConversionError !FilePath !ScriptDataJsonError
  | ShelleyTxCmdScriptDataValidationError !FilePath !ScriptDataRangeError
  | ShelleyTxCmdMetaDecodeError !FilePath !CBOR.DecoderError
  | ShelleyTxCmdBootstrapWitnessError !ShelleyBootstrapWitnessError
  | ShelleyTxCmdSocketEnvError !EnvSocketError
  | ShelleyTxCmdTxSubmitError !Text
  | ShelleyTxCmdTxSubmitErrorEraMismatch !EraMismatch
  | ShelleyTxCmdTxFeatureMismatch !AnyCardanoEra !TxFeature
  | ShelleyTxCmdTxBodyError !TxBodyError
  | ShelleyTxCmdNotImplemented !Text
  | ShelleyTxCmdWitnessEraMismatch !AnyCardanoEra !AnyCardanoEra !WitnessFile
  | ShelleyTxCmdScriptLanguageNotSupportedInEra !AnyScriptLanguage !AnyCardanoEra
  | ShelleyTxCmdReferenceScriptsNotSupportedInEra !AnyCardanoEra
  | ShelleyTxCmdScriptExpectedSimple !FilePath !AnyScriptLanguage
  | ShelleyTxCmdScriptExpectedPlutus !FilePath !AnyScriptLanguage
  | ShelleyTxCmdGenesisCmdError !ShelleyGenesisCmdError
  | ShelleyTxCmdPolicyIdsMissing ![PolicyId]
  | ShelleyTxCmdPolicyIdsExcess  ![PolicyId]
  | ShelleyTxCmdUnsupportedMode !AnyConsensusMode
  | ShelleyTxCmdByronEra
  | ShelleyTxCmdEraConsensusModeMismatchTxBalance
      !TxBuildOutputOptions
      !AnyConsensusMode
      !AnyCardanoEra
  | ShelleyTxCmdBalanceTxBody !TxBodyErrorAutoBalance
  | ShelleyTxCmdTxInsDoNotExist !TxInsExistError
  | ShelleyTxCmdMinimumUTxOErr !MinimumUTxOError
  | ShelleyTxCmdPParamsErr !ProtocolParametersError
  | ShelleyTxCmdTextEnvCddlError
      !(FileError TextEnvelopeError)
      !(FileError TextEnvelopeCddlError)
  | ShelleyTxCmdTxExecUnitsErr !TransactionValidityError
  | ShelleyTxCmdPlutusScriptCostErr !PlutusScriptCostError
  | ShelleyTxCmdPParamExecutionUnitsNotAvailable
  | ShelleyTxCmdTxEraCastErr EraCastError
  | ShelleyTxCmdQueryConvenienceError !QueryConvenienceError
  | ShelleyTxCmdQueryNotScriptLocked !ScriptLockedTxInsError

renderShelleyTxCmdError :: ShelleyTxCmdError -> Text
renderShelleyTxCmdError :: ShelleyTxCmdError -> Text
renderShelleyTxCmdError ShelleyTxCmdError
err =
  case ShelleyTxCmdError
err of
    ShelleyTxCmdReadFileError FileError ()
fileErr -> String -> Text
Text.pack (FileError () -> String
forall e. Error e => e -> String
displayError FileError ()
fileErr)
    ShelleyTxCmdReadTextViewFileError FileError TextEnvelopeError
fileErr -> String -> Text
Text.pack (FileError TextEnvelopeError -> String
forall e. Error e => e -> String
displayError FileError TextEnvelopeError
fileErr)
    ShelleyTxCmdScriptFileError FileError ScriptDecodeError
fileErr -> String -> Text
Text.pack (FileError ScriptDecodeError -> String
forall e. Error e => e -> String
displayError FileError ScriptDecodeError
fileErr)
    ShelleyTxCmdReadWitnessSigningDataError ReadWitnessSigningDataError
witSignDataErr ->
      ReadWitnessSigningDataError -> Text
renderReadWitnessSigningDataError ReadWitnessSigningDataError
witSignDataErr
    ShelleyTxCmdReadRequiredSignerError FileError InputDecodeError
fileErr ->
      Text
"Error reading required signer: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (FileError InputDecodeError -> String
forall e. Error e => e -> String
displayError FileError InputDecodeError
fileErr)
    ShelleyTxCmdRequiredSignerByronKeyError (SigningKeyFile String
fp) ->
      Text
"Byron key witness was used as a required signer: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
    ShelleyTxCmdWriteFileError FileError ()
fileErr -> String -> Text
Text.pack (FileError () -> String
forall e. Error e => e -> String
displayError FileError ()
fileErr)
    ShelleyTxCmdMetadataJsonParseError String
fp String
jsonErr ->
       Text
"Invalid JSON format in file: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
                Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nJSON parse error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
jsonErr
    ShelleyTxCmdMetadataConversionError String
fp TxMetadataJsonError
metadataErr ->
       Text
"Error reading metadata at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
                             Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (TxMetadataJsonError -> String
forall e. Error e => e -> String
displayError TxMetadataJsonError
metadataErr)
    ShelleyTxCmdMetaDecodeError String
fp DecoderError
metadataErr ->
       Text
"Error decoding CBOR metadata at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
                             Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" Error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DecoderError -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show DecoderError
metadataErr
    ShelleyTxCmdMetaValidationError String
fp [(Word64, TxMetadataRangeError)]
errs ->
      Text
"Error validating transaction metadata at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text -> [Text] -> Text
Text.intercalate Text
"\n"
        [ Text
"key " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Word64 -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show Word64
k Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (TxMetadataRangeError -> String
forall e. Error e => e -> String
displayError TxMetadataRangeError
valErr)
        | (Word64
k, TxMetadataRangeError
valErr) <- [(Word64, TxMetadataRangeError)]
errs ]

    ShelleyTxCmdScriptDataJsonParseError  String
fp String
jsonErr ->
       Text
"Invalid JSON format in file: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
       Text
"\nJSON parse error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
jsonErr
    ShelleyTxCmdScriptDataConversionError String
fp ScriptDataJsonError
cerr ->
       Text
"Error reading metadata at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
                             Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (ScriptDataJsonError -> String
forall e. Error e => e -> String
displayError ScriptDataJsonError
cerr)
    ShelleyTxCmdScriptDataValidationError String
fp ScriptDataRangeError
verr ->
      Text
"Error validating script data at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      String -> Text
Text.pack (ScriptDataRangeError -> String
forall e. Error e => e -> String
displayError ScriptDataRangeError
verr)

    ShelleyTxCmdSocketEnvError EnvSocketError
envSockErr -> EnvSocketError -> Text
renderEnvSocketError EnvSocketError
envSockErr
    ShelleyTxCmdAesonDecodeProtocolParamsError String
fp Text
decErr ->
      Text
"Error while decoding the protocol parameters at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
fp
                                            Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" Error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show Text
decErr
    ShelleyTxCmdTxSubmitError Text
res -> Text
"Error while submitting tx: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
res
    ShelleyTxCmdTxSubmitErrorEraMismatch EraMismatch{Text
ledgerEraName :: EraMismatch -> Text
ledgerEraName :: Text
ledgerEraName, Text
otherEraName :: EraMismatch -> Text
otherEraName :: Text
otherEraName} ->
      Text
"The era of the node and the tx do not match. " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"The node is running in the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ledgerEraName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
" era, but the transaction is for the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
otherEraName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era."
    ShelleyTxCmdBootstrapWitnessError ShelleyBootstrapWitnessError
sbwErr ->
      ShelleyBootstrapWitnessError -> Text
renderShelleyBootstrapWitnessError ShelleyBootstrapWitnessError
sbwErr

    ShelleyTxCmdTxFeatureMismatch AnyCardanoEra
era TxFeature
TxFeatureImplicitFees ->
      Text
"An explicit transaction fee must be specified for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era transactions."

    ShelleyTxCmdTxFeatureMismatch (AnyCardanoEra CardanoEra era
ShelleyEra)
                                  TxFeature
TxFeatureValidityNoUpperBound ->
      Text
"A TTL must be specified for Shelley era transactions."

    ShelleyTxCmdTxFeatureMismatch AnyCardanoEra
era TxFeature
feature ->
      TxFeature -> Text
renderFeature TxFeature
feature Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" cannot be used for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
" era transactions."

    ShelleyTxCmdTxBodyError TxBodyError
err' ->
      Text
"Transaction validaton error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (TxBodyError -> String
forall e. Error e => e -> String
displayError TxBodyError
err')

    ShelleyTxCmdNotImplemented Text
msg ->
      Text
"Feature not yet implemented: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
msg

    ShelleyTxCmdWitnessEraMismatch AnyCardanoEra
era AnyCardanoEra
era' (WitnessFile String
file) ->
      Text
"The era of a witness does not match the era of the transaction. " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"The transaction is for the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era, but the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"witness in " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show String
file Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" is for the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyCardanoEra -> Text
renderEra AnyCardanoEra
era' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era."

    ShelleyTxCmdScriptLanguageNotSupportedInEra (AnyScriptLanguage ScriptLanguage lang
lang) AnyCardanoEra
era ->
      Text
"The script language " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ScriptLanguage lang -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show ScriptLanguage lang
lang Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" is not supported in the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era."

    ShelleyTxCmdScriptExpectedSimple String
file (AnyScriptLanguage ScriptLanguage lang
lang) ->
      String -> Text
Text.pack String
file Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
": expected a script in the simple script language, " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"but it is actually using " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ScriptLanguage lang -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show ScriptLanguage lang
lang Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Alternatively, to use " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"a Plutus script, you must also specify the redeemer " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"(datum if appropriate) and script execution units."

    ShelleyTxCmdScriptExpectedPlutus String
file (AnyScriptLanguage ScriptLanguage lang
lang) ->
      String -> Text
Text.pack String
file Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
": expected a script in the Plutus script language, " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"but it is actually using " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ScriptLanguage lang -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show ScriptLanguage lang
lang Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."

    ShelleyTxCmdEraConsensusModeMismatch Maybe String
fp AnyConsensusMode
mode AnyCardanoEra
era ->
       Text
"Submitting " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era transaction (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Maybe String -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show Maybe String
fp Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
       Text
") is not supported in the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyConsensusMode -> Text
renderMode AnyConsensusMode
mode Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" consensus mode."
    ShelleyTxCmdGenesisCmdError ShelleyGenesisCmdError
e -> String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ ShelleyGenesisCmdError -> String
forall e. Error e => e -> String
displayError ShelleyGenesisCmdError
e
    ShelleyTxCmdPolicyIdsMissing [PolicyId]
policyids ->
      Text
"The \"--mint\" flag specifies an asset with a policy Id, but no \
      \corresponding monetary policy script has been provided as a witness \
      \(via the \"--mint-script-file\" flag). The policy Id in question is: "
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate Text
", " ((PolicyId -> Text) -> [PolicyId] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map PolicyId -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText [PolicyId]
policyids)

    ShelleyTxCmdPolicyIdsExcess [PolicyId]
policyids ->
      Text
"A script provided to witness minting does not correspond to the policy \
      \id of any asset specified in the \"--mint\" field. The script hash is: "
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate Text
", " ((PolicyId -> Text) -> [PolicyId] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map PolicyId -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText [PolicyId]
policyids)
    ShelleyTxCmdUnsupportedMode AnyConsensusMode
mode -> Text
"Unsupported mode: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyConsensusMode -> Text
renderMode AnyConsensusMode
mode
    ShelleyTxCmdError
ShelleyTxCmdByronEra -> Text
"This query cannot be used for the Byron era"
    ShelleyTxCmdEraConsensusModeMismatchTxBalance TxBuildOutputOptions
fp AnyConsensusMode
mode AnyCardanoEra
era ->
       Text
"Cannot balance " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyCardanoEra -> Text
renderEra AnyCardanoEra
era Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" era transaction body (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TxBuildOutputOptions -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show TxBuildOutputOptions
fp Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
       Text
") because is not supported in the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AnyConsensusMode -> Text
renderMode AnyConsensusMode
mode Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" consensus mode."
    ShelleyTxCmdBalanceTxBody TxBodyErrorAutoBalance
err' -> String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ TxBodyErrorAutoBalance -> String
forall e. Error e => e -> String
displayError TxBodyErrorAutoBalance
err'
    ShelleyTxCmdTxInsDoNotExist TxInsExistError
e ->
      TxInsExistError -> Text
renderTxInsExistError TxInsExistError
e
    ShelleyTxCmdMinimumUTxOErr MinimumUTxOError
err' -> String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ MinimumUTxOError -> String
forall e. Error e => e -> String
displayError MinimumUTxOError
err'
    ShelleyTxCmdPParamsErr ProtocolParametersError
err' -> String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ ProtocolParametersError -> String
forall e. Error e => e -> String
displayError ProtocolParametersError
err'
    ShelleyTxCmdTextEnvCddlError FileError TextEnvelopeError
textEnvErr FileError TextEnvelopeCddlError
cddlErr ->
      Text
"Failed to decode neither the cli's serialisation format nor the ledger's \
      \CDDL serialisation format. TextEnvelope error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (FileError TextEnvelopeError -> String
forall e. Error e => e -> String
displayError FileError TextEnvelopeError
textEnvErr) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
      Text
"TextEnvelopeCddl error: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (FileError TextEnvelopeCddlError -> String
forall e. Error e => e -> String
displayError FileError TextEnvelopeCddlError
cddlErr)
    ShelleyTxCmdTxExecUnitsErr TransactionValidityError
err' ->  String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ TransactionValidityError -> String
forall e. Error e => e -> String
displayError TransactionValidityError
err'
    ShelleyTxCmdPlutusScriptCostErr PlutusScriptCostError
err'-> String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ PlutusScriptCostError -> String
forall e. Error e => e -> String
displayError PlutusScriptCostError
err'
    ShelleyTxCmdError
ShelleyTxCmdPParamExecutionUnitsNotAvailable ->
      Text
"Execution units not available in the protocol parameters. This is \
      \likely due to not being in the Alonzo era"
    ShelleyTxCmdReferenceScriptsNotSupportedInEra (AnyCardanoEra CardanoEra era
era) ->
      Text
"TxCmd: Reference scripts not supported in era: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CardanoEra era -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show CardanoEra era
era
    ShelleyTxCmdTxEraCastErr (EraCastError value
value CardanoEra fromEra
fromEra CardanoEra toEra
toEra) ->
      Text
"Unable to cast era from " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CardanoEra fromEra -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show CardanoEra fromEra
fromEra Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" to " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CardanoEra toEra -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show CardanoEra toEra
toEra Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" the value " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> value -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show value
value
    ShelleyTxCmdQueryConvenienceError QueryConvenienceError
e ->
      QueryConvenienceError -> Text
renderQueryConvenienceError QueryConvenienceError
e
    ShelleyTxCmdQueryNotScriptLocked ScriptLockedTxInsError
e ->
      ScriptLockedTxInsError -> Text
renderNotScriptLockedTxInsError ScriptLockedTxInsError
e

renderEra :: AnyCardanoEra -> Text
renderEra :: AnyCardanoEra -> Text
renderEra (AnyCardanoEra CardanoEra era
ByronEra)   = Text
"Byron"
renderEra (AnyCardanoEra CardanoEra era
ShelleyEra) = Text
"Shelley"
renderEra (AnyCardanoEra CardanoEra era
AllegraEra) = Text
"Allegra"
renderEra (AnyCardanoEra CardanoEra era
MaryEra)    = Text
"Mary"
renderEra (AnyCardanoEra CardanoEra era
AlonzoEra)  = Text
"Alonzo"
renderEra (AnyCardanoEra CardanoEra era
BabbageEra) = Text
"Babbage"

renderFeature :: TxFeature -> Text
renderFeature :: TxFeature -> Text
renderFeature TxFeature
TxFeatureShelleyAddresses     = Text
"Shelley addresses"
renderFeature TxFeature
TxFeatureExplicitFees         = Text
"Explicit fees"
renderFeature TxFeature
TxFeatureImplicitFees         = Text
"Implicit fees"
renderFeature TxFeature
TxFeatureValidityLowerBound   = Text
"A validity lower bound"
renderFeature TxFeature
TxFeatureValidityUpperBound   = Text
"A validity upper bound"
renderFeature TxFeature
TxFeatureValidityNoUpperBound = Text
"An absent validity upper bound"
renderFeature TxFeature
TxFeatureTxMetadata           = Text
"Transaction metadata"
renderFeature TxFeature
TxFeatureAuxScripts           = Text
"Auxiliary scripts"
renderFeature TxFeature
TxFeatureWithdrawals          = Text
"Reward account withdrawals"
renderFeature TxFeature
TxFeatureCertificates         = Text
"Certificates"
renderFeature TxFeature
TxFeatureMintValue            = Text
"Asset minting"
renderFeature TxFeature
TxFeatureMultiAssetOutputs    = Text
"Multi-Asset outputs"
renderFeature TxFeature
TxFeatureScriptWitnesses      = Text
"Script witnesses"
renderFeature TxFeature
TxFeatureShelleyKeys          = Text
"Shelley keys"
renderFeature TxFeature
TxFeatureCollateral           = Text
"Collateral inputs"
renderFeature TxFeature
TxFeatureProtocolParameters   = Text
"Protocol parameters"
renderFeature TxFeature
TxFeatureTxOutDatum           = Text
"Transaction output datums"
renderFeature TxFeature
TxFeatureScriptValidity       = Text
"Script validity"
renderFeature TxFeature
TxFeatureExtraKeyWits         = Text
"Required signers"
renderFeature TxFeature
TxFeatureInlineDatums         = Text
"Inline datums"
renderFeature TxFeature
TxFeatureTotalCollateral      = Text
"Total collateral"
renderFeature TxFeature
TxFeatureReferenceInputs      = Text
"Reference inputs"
renderFeature TxFeature
TxFeatureReturnCollateral     = Text
"Return collateral"

runTransactionCmd :: TransactionCmd -> ExceptT ShelleyTxCmdError IO ()
runTransactionCmd :: TransactionCmd -> ExceptT ShelleyTxCmdError IO ()
runTransactionCmd TransactionCmd
cmd =
  case TransactionCmd
cmd of
    TxBuild AnyCardanoEra
era AnyConsensusModeParams
consensusModeParams NetworkId
nid Maybe ScriptValidity
mScriptValidity Maybe Word
mOverrideWits [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins [TxIn]
readOnlyRefIns
            [RequiredSigner]
reqSigners [TxIn]
txinsc Maybe TxOutAnyEra
mReturnColl Maybe Lovelace
mTotCollateral [TxOutAnyEra]
txouts TxOutChangeAddress
changeAddr Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue Maybe SlotNo
mLowBound
            Maybe SlotNo
mUpperBound [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certs [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
wdrls TxMetadataJsonSchema
metadataSchema [ScriptFile]
scriptFiles [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams
            Maybe UpdateProposalFile
mUpProp TxBuildOutputOptions
output ->
      AnyCardanoEra
-> AnyConsensusModeParams
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> [TxIn]
-> [TxIn]
-> Maybe TxOutAnyEra
-> Maybe Lovelace
-> [TxOutAnyEra]
-> TxOutChangeAddress
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> Maybe SlotNo
-> Maybe SlotNo
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [RequiredSigner]
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> Maybe Word
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO ()
runTxBuild AnyCardanoEra
era AnyConsensusModeParams
consensusModeParams NetworkId
nid Maybe ScriptValidity
mScriptValidity [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins [TxIn]
readOnlyRefIns [TxIn]
txinsc
                 Maybe TxOutAnyEra
mReturnColl Maybe Lovelace
mTotCollateral [TxOutAnyEra]
txouts TxOutChangeAddress
changeAddr Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue Maybe SlotNo
mLowBound
                 Maybe SlotNo
mUpperBound [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certs [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
wdrls [RequiredSigner]
reqSigners TxMetadataJsonSchema
metadataSchema [ScriptFile]
scriptFiles
                 [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams Maybe UpdateProposalFile
mUpProp Maybe Word
mOverrideWits TxBuildOutputOptions
output
    TxBuildRaw AnyCardanoEra
era Maybe ScriptValidity
mScriptValidity [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins [TxIn]
readOnlyRefIns [TxIn]
txinsc Maybe TxOutAnyEra
mReturnColl Maybe Lovelace
mTotColl [RequiredSigner]
reqSigners
               [TxOutAnyEra]
txouts Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue Maybe SlotNo
mLowBound Maybe SlotNo
mUpperBound Maybe Lovelace
fee [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certs [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
wdrls TxMetadataJsonSchema
metadataSchema [ScriptFile]
scriptFiles
               [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams Maybe UpdateProposalFile
mUpProp TxBodyFile
out ->
      AnyCardanoEra
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> [TxIn]
-> [TxIn]
-> Maybe TxOutAnyEra
-> Maybe Lovelace
-> [TxOutAnyEra]
-> Maybe SlotNo
-> Maybe SlotNo
-> Maybe Lovelace
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [RequiredSigner]
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw AnyCardanoEra
era Maybe ScriptValidity
mScriptValidity [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins [TxIn]
readOnlyRefIns [TxIn]
txinsc Maybe TxOutAnyEra
mReturnColl Maybe Lovelace
mTotColl [TxOutAnyEra]
txouts
                    Maybe SlotNo
mLowBound Maybe SlotNo
mUpperBound Maybe Lovelace
fee Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certs [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
wdrls [RequiredSigner]
reqSigners TxMetadataJsonSchema
metadataSchema
                    [ScriptFile]
scriptFiles [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams Maybe UpdateProposalFile
mUpProp TxBodyFile
out
    TxSign InputTxBodyOrTxFile
txinfile [WitnessSigningData]
skfiles Maybe NetworkId
network TxFile
txoutfile ->
      InputTxBodyOrTxFile
-> [WitnessSigningData]
-> Maybe NetworkId
-> TxFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSign InputTxBodyOrTxFile
txinfile [WitnessSigningData]
skfiles Maybe NetworkId
network TxFile
txoutfile
    TxSubmit AnyConsensusModeParams
anyConensusModeParams NetworkId
network String
txFp ->
      AnyConsensusModeParams
-> NetworkId -> String -> ExceptT ShelleyTxCmdError IO ()
runTxSubmit AnyConsensusModeParams
anyConensusModeParams NetworkId
network String
txFp
    TxCalculateMinFee TxBodyFile
txbody Maybe NetworkId
mnw ProtocolParamsSourceSpec
pGenesisOrParamsFile TxInCount
nInputs TxOutCount
nOutputs
                      TxShelleyWitnessCount
nShelleyKeyWitnesses TxByronWitnessCount
nByronKeyWitnesses ->
      TxBodyFile
-> Maybe NetworkId
-> ProtocolParamsSourceSpec
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee TxBodyFile
txbody Maybe NetworkId
mnw ProtocolParamsSourceSpec
pGenesisOrParamsFile TxInCount
nInputs TxOutCount
nOutputs
                           TxShelleyWitnessCount
nShelleyKeyWitnesses TxByronWitnessCount
nByronKeyWitnesses
    TxCalculateMinRequiredUTxO AnyCardanoEra
era ProtocolParamsSourceSpec
pParamSpec TxOutAnyEra
txOuts -> AnyCardanoEra
-> ProtocolParamsSourceSpec
-> TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinRequiredUTxO AnyCardanoEra
era ProtocolParamsSourceSpec
pParamSpec TxOutAnyEra
txOuts
    TxHashScriptData ScriptDataOrFile
scriptDataOrFile -> ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ()
runTxHashScriptData ScriptDataOrFile
scriptDataOrFile
    TxGetTxId InputTxBodyOrTxFile
txinfile -> InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runTxGetTxId InputTxBodyOrTxFile
txinfile
    TxView InputTxBodyOrTxFile
txinfile -> InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runTxView InputTxBodyOrTxFile
txinfile
    TxMintedPolicyId ScriptFile
sFile -> ScriptFile -> ExceptT ShelleyTxCmdError IO ()
runTxCreatePolicyId ScriptFile
sFile
    TxCreateWitness TxBodyFile
txBodyfile WitnessSigningData
witSignData Maybe NetworkId
mbNw OutputFile
outFile ->
      TxBodyFile
-> WitnessSigningData
-> Maybe NetworkId
-> OutputFile
-> ExceptT ShelleyTxCmdError IO ()
runTxCreateWitness TxBodyFile
txBodyfile WitnessSigningData
witSignData Maybe NetworkId
mbNw OutputFile
outFile
    TxAssembleTxBodyWitness TxBodyFile
txBodyFile [WitnessFile]
witnessFile OutputFile
outFile ->
      TxBodyFile
-> [WitnessFile] -> OutputFile -> ExceptT ShelleyTxCmdError IO ()
runTxSignWitness TxBodyFile
txBodyFile [WitnessFile]
witnessFile OutputFile
outFile

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

runTxBuildRaw
  :: AnyCardanoEra
  -> Maybe ScriptValidity
  -- ^ Mark script as expected to pass or fail validation
  -> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
  -- ^ TxIn with potential script witness
  -> [TxIn]
  -- ^ Read only reference inputs
  -> [TxIn]
  -- ^ TxIn for collateral
  -> Maybe TxOutAnyEra
  -- ^ Return collateral
  -> Maybe Lovelace
  -- ^ Total collateral
  -> [TxOutAnyEra]
  -> Maybe SlotNo
  -- ^ Tx lower bound
  -> Maybe SlotNo
  -- ^ Tx upper bound
  -> Maybe Lovelace
  -- ^ Tx fee
  -> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
  -- ^ Multi-Asset value(s)
  -> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
  -> [RequiredSigner]
  -- ^ Required signers
  -> TxMetadataJsonSchema
  -> [ScriptFile]
  -> [MetadataFile]
  -> Maybe ProtocolParamsSourceSpec
  -> Maybe UpdateProposalFile
  -> TxBodyFile
  -> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw :: AnyCardanoEra
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> [TxIn]
-> [TxIn]
-> Maybe TxOutAnyEra
-> Maybe Lovelace
-> [TxOutAnyEra]
-> Maybe SlotNo
-> Maybe SlotNo
-> Maybe Lovelace
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [RequiredSigner]
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw (AnyCardanoEra CardanoEra era
era)
              Maybe ScriptValidity
mScriptValidity [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles
              [TxIn]
readOnlyRefIns [TxIn]
txinsc
              Maybe TxOutAnyEra
mReturnCollateral Maybe Lovelace
mTotCollateral [TxOutAnyEra]
txouts
              Maybe SlotNo
mLowerBound Maybe SlotNo
mUpperBound
              Maybe Lovelace
mFee Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue
              [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals [RequiredSigner]
reqSigners
              TxMetadataJsonSchema
metadataSchema [ScriptFile]
scriptFiles
              [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams Maybe UpdateProposalFile
mUpdatePropFile
              (TxBodyFile String
fpath) = do

    [TxIn]
allReferenceInputs
      <- CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
forall era.
CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
getAllReferenceInputs CardanoEra era
era [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals [TxIn]
readOnlyRefIns
    [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits <- CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall era.
CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
readScriptWitnessFiles CardanoEra era
era [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles
    TxInsCollateral era
validatedCollateralTxIns <- CardanoEra era
-> [TxIn] -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
forall era.
CardanoEra era
-> [TxIn] -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
validateTxInsCollateral CardanoEra era
era [TxIn]
txinsc
    TxInsReference BuildTx era
validatedRefInputs <- CardanoEra era
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall era.
CardanoEra era
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
validateTxInsReference CardanoEra era
era [TxIn]
allReferenceInputs
    [TxOut CtxTx era]
validatedTxOuts <- CardanoEra era
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
forall era.
CardanoEra era
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
validateTxOuts CardanoEra era
era [TxOutAnyEra]
txouts
    TxTotalCollateral era
validatedTotCollateral <- CardanoEra era
-> Maybe Lovelace
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall era.
CardanoEra era
-> Maybe Lovelace
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
validateTxTotalCollateral CardanoEra era
era Maybe Lovelace
mTotCollateral
    TxReturnCollateral CtxTx era
validatedRetCol <- CardanoEra era
-> Maybe TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall era.
CardanoEra era
-> Maybe TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
validateTxReturnCollateral CardanoEra era
era Maybe TxOutAnyEra
mReturnCollateral
    TxFee era
validatedFee <- CardanoEra era
-> Maybe Lovelace -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall era.
CardanoEra era
-> Maybe Lovelace -> ExceptT ShelleyTxCmdError IO (TxFee era)
validateTxFee CardanoEra era
era Maybe Lovelace
mFee
    (TxValidityLowerBound era, TxValidityUpperBound era)
validatedBounds <- (,) (TxValidityLowerBound era
 -> TxValidityUpperBound era
 -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (TxValidityUpperBound era
      -> (TxValidityLowerBound era, TxValidityUpperBound era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
forall era.
CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
validateTxValidityLowerBound CardanoEra era
era Maybe SlotNo
mLowerBound
                           ExceptT
  ShelleyTxCmdError
  IO
  (TxValidityUpperBound era
   -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (TxValidityLowerBound era, TxValidityUpperBound era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall era.
CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
validateTxValidityUpperBound CardanoEra era
era Maybe SlotNo
mUpperBound
    TxMetadataInEra era
validatedTxMetadata <- CardanoEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
forall era.
CardanoEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
validateTxMetadataInEra CardanoEra era
era TxMetadataJsonSchema
metadataSchema [MetadataFile]
metadataFiles
    TxAuxScripts era
validatedTxAuxScripts <- CardanoEra era
-> [ScriptFile] -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall era.
CardanoEra era
-> [ScriptFile] -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
validateTxAuxScripts CardanoEra era
era [ScriptFile]
scriptFiles
    TxExtraKeyWitnesses era
validatedReqSigners <- CardanoEra era
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall era.
CardanoEra era
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
validateRequiredSigners CardanoEra era
era [RequiredSigner]
reqSigners
    BuildTxWith BuildTx (Maybe ProtocolParameters)
validatedPParams <- CardanoEra era
-> Maybe ProtocolParamsSourceSpec
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall era.
CardanoEra era
-> Maybe ProtocolParamsSourceSpec
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
validateProtocolParameters CardanoEra era
era Maybe ProtocolParamsSourceSpec
mpparams
    TxWithdrawals BuildTx era
validatedTxWtdrwls <- CardanoEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
forall era.
CardanoEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
validateTxWithdrawals CardanoEra era
era [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
    TxCertificates BuildTx era
validatedTxCerts <- CardanoEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall era.
CardanoEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
validateTxCertificates CardanoEra era
era [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles
    TxUpdateProposal era
validatedTxUpProp <- CardanoEra era
-> Maybe UpdateProposalFile
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
forall era.
CardanoEra era
-> Maybe UpdateProposalFile
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
validateTxUpdateProposal CardanoEra era
era Maybe UpdateProposalFile
mUpdatePropFile
    TxMintValue BuildTx era
validatedMintValue <- CardanoEra era
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
forall era.
CardanoEra era
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
validateTxMintValue CardanoEra era
era Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue
    TxScriptValidity era
validatedTxScriptValidity <- CardanoEra era
-> Maybe ScriptValidity
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall era.
CardanoEra era
-> Maybe ScriptValidity
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
validateTxScriptValidity CardanoEra era
era Maybe ScriptValidity
mScriptValidity

    let txBodyContent :: TxBodyContent BuildTx era
txBodyContent = TxIns BuildTx era
-> TxInsCollateral era
-> TxInsReference BuildTx era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
-> TxWithdrawals BuildTx era
-> TxCertificates BuildTx era
-> TxUpdateProposal era
-> TxMintValue BuildTx era
-> TxScriptValidity era
-> TxBodyContent BuildTx era
forall build era.
TxIns build era
-> TxInsCollateral era
-> TxInsReference build era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> TxScriptValidity era
-> TxBodyContent build era
TxBodyContent
                          ([(TxIn, Maybe (ScriptWitness WitCtxTxIn era))] -> TxIns BuildTx era
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits)
                          TxInsCollateral era
validatedCollateralTxIns
                          TxInsReference BuildTx era
validatedRefInputs
                          [TxOut CtxTx era]
validatedTxOuts
                          TxTotalCollateral era
validatedTotCollateral
                          TxReturnCollateral CtxTx era
validatedRetCol
                          TxFee era
validatedFee
                          (TxValidityLowerBound era, TxValidityUpperBound era)
validatedBounds
                          TxMetadataInEra era
validatedTxMetadata
                          TxAuxScripts era
validatedTxAuxScripts
                          TxExtraKeyWitnesses era
validatedReqSigners
                          BuildTxWith BuildTx (Maybe ProtocolParameters)
validatedPParams
                          TxWithdrawals BuildTx era
validatedTxWtdrwls
                          TxCertificates BuildTx era
validatedTxCerts
                          TxUpdateProposal era
validatedTxUpProp
                          TxMintValue BuildTx era
validatedMintValue
                          TxScriptValidity era
validatedTxScriptValidity

    TxBody era
txBody <-
      (TxBodyError -> ShelleyTxCmdError)
-> ExceptT TxBodyError IO (TxBody era)
-> ExceptT ShelleyTxCmdError IO (TxBody era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT TxBodyError -> ShelleyTxCmdError
ShelleyTxCmdTxBodyError (ExceptT TxBodyError IO (TxBody era)
 -> ExceptT ShelleyTxCmdError IO (TxBody era))
-> (Either TxBodyError (TxBody era)
    -> ExceptT TxBodyError IO (TxBody era))
-> Either TxBodyError (TxBody era)
-> ExceptT ShelleyTxCmdError IO (TxBody era)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either TxBodyError (TxBody era)
-> ExceptT TxBodyError IO (TxBody era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxBodyError (TxBody era)
 -> ExceptT ShelleyTxCmdError IO (TxBody era))
-> Either TxBodyError (TxBody era)
-> ExceptT ShelleyTxCmdError IO (TxBody era)
forall a b. (a -> b) -> a -> b
$
        TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
IsCardanoEra era =>
TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
createAndValidateTransactionBody TxBodyContent BuildTx era
txBodyContent

    let noWitTx :: Tx era
noWitTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
txBody
    (FileError () -> ShelleyTxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyTxCmdError
ShelleyTxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 ShelleyTxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
      String -> Tx era -> IO (Either (FileError ()) ())
forall era.
IsCardanoEra era =>
String -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl String
fpath Tx era
noWitTx

runTxBuild
  :: AnyCardanoEra
  -> AnyConsensusModeParams
  -> NetworkId
  -> Maybe ScriptValidity
  -- ^ Mark script as expected to pass or fail validation
  -> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
  -- ^ Read only reference inputs
  -> [TxIn]
  -- ^ TxIn with potential script witness
  -> [TxIn]
  -- ^ TxIn for collateral
  -> Maybe TxOutAnyEra
  -- ^ Return collateral
  -> Maybe Lovelace
  -- ^ Total collateral
  -> [TxOutAnyEra]
  -- ^ Normal outputs
  -> TxOutChangeAddress
  -- ^ A change output
  -> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
  -- ^ Multi-Asset value(s)
  -> Maybe SlotNo
  -- ^ Tx lower bound
  -> Maybe SlotNo
  -- ^ Tx upper bound
  -> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
  -- ^ Certificate with potential script witness
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
  -> [RequiredSigner]
  -- ^ Required signers
  -> TxMetadataJsonSchema
  -> [ScriptFile]
  -> [MetadataFile]
  -> Maybe ProtocolParamsSourceSpec
  -> Maybe UpdateProposalFile
  -> Maybe Word
  -> TxBuildOutputOptions
  -> ExceptT ShelleyTxCmdError IO ()
runTxBuild :: AnyCardanoEra
-> AnyConsensusModeParams
-> NetworkId
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> [TxIn]
-> [TxIn]
-> Maybe TxOutAnyEra
-> Maybe Lovelace
-> [TxOutAnyEra]
-> TxOutChangeAddress
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> Maybe SlotNo
-> Maybe SlotNo
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [RequiredSigner]
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> Maybe Word
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO ()
runTxBuild (AnyCardanoEra CardanoEra era
era) (AnyConsensusModeParams ConsensusModeParams mode
cModeParams) NetworkId
networkId Maybe ScriptValidity
mScriptValidity
           [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles [TxIn]
readOnlyRefIns [TxIn]
txinsc Maybe TxOutAnyEra
mReturnCollateral Maybe Lovelace
mTotCollateral [TxOutAnyEra]
txouts (TxOutChangeAddress AddressAny
changeAddr) Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue Maybe SlotNo
mLowerBound Maybe SlotNo
mUpperBound
           [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals [RequiredSigner]
reqSigners TxMetadataJsonSchema
metadataSchema [ScriptFile]
scriptFiles [MetadataFile]
metadataFiles Maybe ProtocolParamsSourceSpec
mpparams
           Maybe UpdateProposalFile
mUpdatePropFile Maybe Word
mOverrideWits TxBuildOutputOptions
outputOptions = do
  let consensusMode :: ConsensusMode mode
consensusMode = ConsensusModeParams mode -> ConsensusMode mode
forall mode. ConsensusModeParams mode -> ConsensusMode mode
consensusModeOnly ConsensusModeParams mode
cModeParams
      dummyFee :: Maybe Lovelace
dummyFee = Lovelace -> Maybe Lovelace
forall a. a -> Maybe a
Just (Lovelace -> Maybe Lovelace) -> Lovelace -> Maybe Lovelace
forall a b. (a -> b) -> a -> b
$ Integer -> Lovelace
Lovelace Integer
0
      inputsThatRequireWitnessing :: [TxIn]
inputsThatRequireWitnessing = [TxIn
input | (TxIn
input,Maybe (ScriptWitnessFiles WitCtxTxIn)
_) <- [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles]

  [TxIn]
allReferenceInputs <- CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
forall era.
CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
getAllReferenceInputs CardanoEra era
era [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals [TxIn]
readOnlyRefIns
  [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits <- CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall era.
CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
readScriptWitnessFiles CardanoEra era
era [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
inputsAndScriptFiles
  TxInsCollateral era
validatedCollateralTxIns <- CardanoEra era
-> [TxIn] -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
forall era.
CardanoEra era
-> [TxIn] -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
validateTxInsCollateral CardanoEra era
era [TxIn]
txinsc
  TxInsReference BuildTx era
validatedRefInputs <- CardanoEra era
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall era.
CardanoEra era
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
validateTxInsReference CardanoEra era
era [TxIn]
allReferenceInputs
  [TxOut CtxTx era]
validatedTxOuts <- CardanoEra era
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
forall era.
CardanoEra era
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
validateTxOuts CardanoEra era
era [TxOutAnyEra]
txouts
  TxTotalCollateral era
validatedTotCollateral <- CardanoEra era
-> Maybe Lovelace
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall era.
CardanoEra era
-> Maybe Lovelace
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
validateTxTotalCollateral CardanoEra era
era Maybe Lovelace
mTotCollateral
  TxReturnCollateral CtxTx era
validatedRetCol <- CardanoEra era
-> Maybe TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall era.
CardanoEra era
-> Maybe TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
validateTxReturnCollateral CardanoEra era
era Maybe TxOutAnyEra
mReturnCollateral
  TxFee era
dFee <- CardanoEra era
-> Maybe Lovelace -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall era.
CardanoEra era
-> Maybe Lovelace -> ExceptT ShelleyTxCmdError IO (TxFee era)
validateTxFee CardanoEra era
era Maybe Lovelace
dummyFee
  (TxValidityLowerBound era, TxValidityUpperBound era)
validatedBounds <- (,) (TxValidityLowerBound era
 -> TxValidityUpperBound era
 -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (TxValidityUpperBound era
      -> (TxValidityLowerBound era, TxValidityUpperBound era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
forall era.
CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
validateTxValidityLowerBound CardanoEra era
era Maybe SlotNo
mLowerBound
                         ExceptT
  ShelleyTxCmdError
  IO
  (TxValidityUpperBound era
   -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (TxValidityLowerBound era, TxValidityUpperBound era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall era.
CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
validateTxValidityUpperBound CardanoEra era
era Maybe SlotNo
mUpperBound
  TxMetadataInEra era
validatedTxMetadata <- CardanoEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
forall era.
CardanoEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
validateTxMetadataInEra CardanoEra era
era TxMetadataJsonSchema
metadataSchema [MetadataFile]
metadataFiles
  TxAuxScripts era
validatedTxAuxScripts <- CardanoEra era
-> [ScriptFile] -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall era.
CardanoEra era
-> [ScriptFile] -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
validateTxAuxScripts CardanoEra era
era [ScriptFile]
scriptFiles
  TxExtraKeyWitnesses era
validatedReqSigners <- CardanoEra era
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall era.
CardanoEra era
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
validateRequiredSigners CardanoEra era
era [RequiredSigner]
reqSigners
  BuildTxWith BuildTx (Maybe ProtocolParameters)
validatedPParams <- CardanoEra era
-> Maybe ProtocolParamsSourceSpec
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall era.
CardanoEra era
-> Maybe ProtocolParamsSourceSpec
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
validateProtocolParameters CardanoEra era
era Maybe ProtocolParamsSourceSpec
mpparams
  TxWithdrawals BuildTx era
validatedTxWtdrwls <- CardanoEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
forall era.
CardanoEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
validateTxWithdrawals CardanoEra era
era [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
  TxCertificates BuildTx era
validatedTxCerts <- CardanoEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall era.
CardanoEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
validateTxCertificates CardanoEra era
era [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles
  TxUpdateProposal era
validatedTxUpProp <- CardanoEra era
-> Maybe UpdateProposalFile
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
forall era.
CardanoEra era
-> Maybe UpdateProposalFile
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
validateTxUpdateProposal CardanoEra era
era Maybe UpdateProposalFile
mUpdatePropFile
  TxMintValue BuildTx era
validatedMintValue <- CardanoEra era
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
forall era.
CardanoEra era
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
validateTxMintValue CardanoEra era
era Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue
  TxScriptValidity era
validatedTxScriptValidity <- CardanoEra era
-> Maybe ScriptValidity
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall era.
CardanoEra era
-> Maybe ScriptValidity
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
validateTxScriptValidity CardanoEra era
era Maybe ScriptValidity
mScriptValidity

  case (ConsensusMode mode
consensusMode, CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle CardanoEra era
era) of
    (ConsensusMode mode
CardanoMode, ShelleyBasedEra ShelleyBasedEra era
_sbe) -> do
      let txBodyContent :: TxBodyContent BuildTx era
txBodyContent = TxIns BuildTx era
-> TxInsCollateral era
-> TxInsReference BuildTx era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
-> TxWithdrawals BuildTx era
-> TxCertificates BuildTx era
-> TxUpdateProposal era
-> TxMintValue BuildTx era
-> TxScriptValidity era
-> TxBodyContent BuildTx era
forall build era.
TxIns build era
-> TxInsCollateral era
-> TxInsReference build era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> TxScriptValidity era
-> TxBodyContent build era
TxBodyContent
                            ([(TxIn, Maybe (ScriptWitness WitCtxTxIn era))] -> TxIns BuildTx era
forall era.
[(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
validateTxIns [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
inputsAndMaybeScriptWits)
                            TxInsCollateral era
validatedCollateralTxIns
                            TxInsReference BuildTx era
validatedRefInputs
                            [TxOut CtxTx era]
validatedTxOuts
                            TxTotalCollateral era
validatedTotCollateral
                            TxReturnCollateral CtxTx era
validatedRetCol
                            TxFee era
dFee
                            (TxValidityLowerBound era, TxValidityUpperBound era)
validatedBounds
                            TxMetadataInEra era
validatedTxMetadata
                            TxAuxScripts era
validatedTxAuxScripts
                            TxExtraKeyWitnesses era
validatedReqSigners
                            BuildTxWith BuildTx (Maybe ProtocolParameters)
validatedPParams
                            TxWithdrawals BuildTx era
validatedTxWtdrwls
                            TxCertificates BuildTx era
validatedTxCerts
                            TxUpdateProposal era
validatedTxUpProp
                            TxMintValue BuildTx era
validatedMintValue
                            TxScriptValidity era
validatedTxScriptValidity

      EraInMode era CardanoMode
eInMode <- case CardanoEra era
-> ConsensusMode CardanoMode -> Maybe (EraInMode era CardanoMode)
forall era mode.
CardanoEra era -> ConsensusMode mode -> Maybe (EraInMode era mode)
toEraInMode CardanoEra era
era ConsensusMode CardanoMode
CardanoMode of
                   Just EraInMode era CardanoMode
result -> EraInMode era CardanoMode
-> ExceptT ShelleyTxCmdError IO (EraInMode era CardanoMode)
forall (m :: * -> *) a. Monad m => a -> m a
return EraInMode era CardanoMode
result
                   Maybe (EraInMode era CardanoMode)
Nothing ->
                     ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (EraInMode era CardanoMode)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (TxBuildOutputOptions
-> AnyConsensusMode -> AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdEraConsensusModeMismatchTxBalance TxBuildOutputOptions
outputOptions
                            (ConsensusMode CardanoMode -> AnyConsensusMode
forall mode. ConsensusMode mode -> AnyConsensusMode
AnyConsensusMode ConsensusMode CardanoMode
CardanoMode) (CardanoEra era -> AnyCardanoEra
forall era. IsCardanoEra era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra CardanoEra era
era))

      SocketPath String
sockPath <- (EnvSocketError -> ShelleyTxCmdError)
-> ExceptT EnvSocketError IO SocketPath
-> ExceptT ShelleyTxCmdError IO SocketPath
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT EnvSocketError -> ShelleyTxCmdError
ShelleyTxCmdSocketEnvError
                             (ExceptT EnvSocketError IO SocketPath
 -> ExceptT ShelleyTxCmdError IO SocketPath)
-> ExceptT EnvSocketError IO SocketPath
-> ExceptT ShelleyTxCmdError IO SocketPath
forall a b. (a -> b) -> a -> b
$ IO (Either EnvSocketError SocketPath)
-> ExceptT EnvSocketError IO SocketPath
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT IO (Either EnvSocketError SocketPath)
readEnvSocketPath

      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 CardanoMode
localNodeConnInfo = LocalNodeConnectInfo :: forall mode.
ConsensusModeParams mode
-> NetworkId -> String -> LocalNodeConnectInfo mode
LocalNodeConnectInfo
                                     { localConsensusModeParams :: ConsensusModeParams CardanoMode
localConsensusModeParams = EpochSlots -> ConsensusModeParams CardanoMode
CardanoModeParams (EpochSlots -> ConsensusModeParams CardanoMode)
-> EpochSlots -> ConsensusModeParams CardanoMode
forall a b. (a -> b) -> a -> b
$ Word64 -> EpochSlots
EpochSlots Word64
21600
                                     , localNodeNetworkId :: NetworkId
localNodeNetworkId = NetworkId
networkId
                                     , localNodeSocketPath :: String
localNodeSocketPath = String
sockPath
                                     }
      AnyCardanoEra CardanoEra era
nodeEra
        <- (AcquiringFailure -> ShelleyTxCmdError)
-> ExceptT AcquiringFailure IO AnyCardanoEra
-> ExceptT ShelleyTxCmdError IO AnyCardanoEra
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (QueryConvenienceError -> ShelleyTxCmdError
ShelleyTxCmdQueryConvenienceError (QueryConvenienceError -> ShelleyTxCmdError)
-> (AcquiringFailure -> QueryConvenienceError)
-> AcquiringFailure
-> ShelleyTxCmdError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AcquiringFailure -> QueryConvenienceError
AcqFailure)
             (ExceptT AcquiringFailure IO AnyCardanoEra
 -> ExceptT ShelleyTxCmdError IO AnyCardanoEra)
-> (IO (Either AcquiringFailure AnyCardanoEra)
    -> ExceptT AcquiringFailure IO AnyCardanoEra)
-> IO (Either AcquiringFailure AnyCardanoEra)
-> ExceptT ShelleyTxCmdError IO AnyCardanoEra
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IO (Either AcquiringFailure AnyCardanoEra)
-> ExceptT AcquiringFailure IO AnyCardanoEra
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either AcquiringFailure AnyCardanoEra)
 -> ExceptT ShelleyTxCmdError IO AnyCardanoEra)
-> IO (Either AcquiringFailure AnyCardanoEra)
-> ExceptT ShelleyTxCmdError IO AnyCardanoEra
forall a b. (a -> b) -> a -> b
$ ConsensusModeParams mode
-> LocalNodeConnectInfo mode
-> IO (Either AcquiringFailure AnyCardanoEra)
forall mode.
ConsensusModeParams mode
-> LocalNodeConnectInfo mode
-> IO (Either AcquiringFailure AnyCardanoEra)
determineEra ConsensusModeParams mode
cModeParams LocalNodeConnectInfo mode
LocalNodeConnectInfo CardanoMode
localNodeConnInfo

      (UTxO era
nodeEraUTxO, ProtocolParameters
pparams, EraHistory CardanoMode
eraHistory, SystemStart
systemStart, Set PoolId
stakePools) <-
        (QueryConvenienceError -> ShelleyTxCmdError)
-> ExceptT
     QueryConvenienceError
     IO
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId)
-> ExceptT
     ShelleyTxCmdError
     IO
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT QueryConvenienceError -> ShelleyTxCmdError
ShelleyTxCmdQueryConvenienceError (ExceptT
   QueryConvenienceError
   IO
   (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
    Set PoolId)
 -> ExceptT
      ShelleyTxCmdError
      IO
      (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
       Set PoolId))
-> (IO
      (Either
         QueryConvenienceError
         (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
          Set PoolId))
    -> ExceptT
         QueryConvenienceError
         IO
         (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
          Set PoolId))
-> IO
     (Either
        QueryConvenienceError
        (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
         Set PoolId))
-> ExceptT
     ShelleyTxCmdError
     IO
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IO
  (Either
     QueryConvenienceError
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId))
-> ExceptT
     QueryConvenienceError
     IO
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
          (IO
   (Either
      QueryConvenienceError
      (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
       Set PoolId))
 -> ExceptT
      ShelleyTxCmdError
      IO
      (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
       Set PoolId))
-> IO
     (Either
        QueryConvenienceError
        (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
         Set PoolId))
-> ExceptT
     ShelleyTxCmdError
     IO
     (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
      Set PoolId)
forall a b. (a -> b) -> a -> b
$ CardanoEra era
-> NetworkId
-> [TxIn]
-> IO
     (Either
        QueryConvenienceError
        (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
         Set PoolId))
forall era.
CardanoEra era
-> NetworkId
-> [TxIn]
-> IO
     (Either
        QueryConvenienceError
        (UTxO era, ProtocolParameters, EraHistory CardanoMode, SystemStart,
         Set PoolId))
queryStateForBalancedTx CardanoEra era
nodeEra NetworkId
networkId [TxIn]
allTxInputs

      (TxInsExistError -> ShelleyTxCmdError)
-> ExceptT TxInsExistError IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT TxInsExistError -> ShelleyTxCmdError
ShelleyTxCmdTxInsDoNotExist
        (ExceptT TxInsExistError IO () -> ExceptT ShelleyTxCmdError IO ())
-> (Either TxInsExistError () -> ExceptT TxInsExistError IO ())
-> Either TxInsExistError ()
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either TxInsExistError () -> ExceptT TxInsExistError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxInsExistError () -> ExceptT ShelleyTxCmdError IO ())
-> Either TxInsExistError () -> ExceptT ShelleyTxCmdError 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
nodeEraUTxO
      (ScriptLockedTxInsError -> ShelleyTxCmdError)
-> ExceptT ScriptLockedTxInsError IO ()
-> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ScriptLockedTxInsError -> ShelleyTxCmdError
ShelleyTxCmdQueryNotScriptLocked
        (ExceptT ScriptLockedTxInsError IO ()
 -> ExceptT ShelleyTxCmdError IO ())
-> (Either ScriptLockedTxInsError ()
    -> ExceptT ScriptLockedTxInsError IO ())
-> Either ScriptLockedTxInsError ()
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ScriptLockedTxInsError ()
-> ExceptT ScriptLockedTxInsError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ScriptLockedTxInsError ()
 -> ExceptT ShelleyTxCmdError IO ())
-> Either ScriptLockedTxInsError ()
-> ExceptT ShelleyTxCmdError 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
nodeEraUTxO

      let cAddr :: AddressInEra era
cAddr = case CardanoEra era -> AddressAny -> Maybe (AddressInEra era)
forall era.
CardanoEra era -> AddressAny -> Maybe (AddressInEra era)
anyAddressInEra CardanoEra era
era AddressAny
changeAddr of
                    Just AddressInEra era
addr -> AddressInEra era
addr
                    Maybe (AddressInEra era)
Nothing -> String -> AddressInEra era
forall a. HasCallStack => String -> a
error (String -> AddressInEra era) -> String -> AddressInEra era
forall a b. (a -> b) -> a -> b
$ String
"runTxBuild: Byron address used: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> AddressAny -> String
forall a b. (Show a, ConvertText String b) => a -> b
show AddressAny
changeAddr

      -- Why do we cast the era? The user can specify an era prior to the era that the node is currently in.
      -- We cannot use the user specified era to construct a query against a node because it may differ
      -- from the node's era and this will result in the 'QueryEraMismatch' failure.
      UTxO era
txEraUtxo <- case (EraCastError -> ShelleyTxCmdError)
-> Either EraCastError (UTxO era)
-> Either ShelleyTxCmdError (UTxO era)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first EraCastError -> ShelleyTxCmdError
ShelleyTxCmdTxEraCastErr (CardanoEra era -> UTxO era -> Either EraCastError (UTxO era)
forall (f :: * -> *) fromEra toEra.
(EraCast f, IsCardanoEra fromEra, IsCardanoEra toEra) =>
CardanoEra toEra -> f fromEra -> Either EraCastError (f toEra)
eraCast CardanoEra era
era UTxO era
nodeEraUTxO) of
                     Right UTxO era
txEraUtxo -> UTxO era -> ExceptT ShelleyTxCmdError IO (UTxO era)
forall (m :: * -> *) a. Monad m => a -> m a
return UTxO era
txEraUtxo
                     Left ShelleyTxCmdError
e -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO (UTxO era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ShelleyTxCmdError
e

      (BalancedTxBody TxBody era
balancedTxBody TxOut CtxTx era
_ Lovelace
fee) <-
        (TxBodyErrorAutoBalance -> ShelleyTxCmdError)
-> ExceptT TxBodyErrorAutoBalance IO (BalancedTxBody era)
-> ExceptT ShelleyTxCmdError IO (BalancedTxBody era)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT TxBodyErrorAutoBalance -> ShelleyTxCmdError
ShelleyTxCmdBalanceTxBody
          (ExceptT TxBodyErrorAutoBalance IO (BalancedTxBody era)
 -> ExceptT ShelleyTxCmdError IO (BalancedTxBody era))
-> (Either TxBodyErrorAutoBalance (BalancedTxBody era)
    -> ExceptT TxBodyErrorAutoBalance IO (BalancedTxBody era))
-> Either TxBodyErrorAutoBalance (BalancedTxBody era)
-> ExceptT ShelleyTxCmdError IO (BalancedTxBody era)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either TxBodyErrorAutoBalance (BalancedTxBody era)
-> ExceptT TxBodyErrorAutoBalance IO (BalancedTxBody era)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
          (Either TxBodyErrorAutoBalance (BalancedTxBody era)
 -> ExceptT ShelleyTxCmdError IO (BalancedTxBody era))
-> Either TxBodyErrorAutoBalance (BalancedTxBody era)
-> ExceptT ShelleyTxCmdError IO (BalancedTxBody era)
forall a b. (a -> b) -> a -> b
$ EraInMode era CardanoMode
-> SystemStart
-> EraHistory CardanoMode
-> ProtocolParameters
-> Set PoolId
-> UTxO era
-> TxBodyContent BuildTx era
-> AddressInEra era
-> Maybe Word
-> Either TxBodyErrorAutoBalance (BalancedTxBody era)
forall era mode.
IsShelleyBasedEra era =>
EraInMode era mode
-> SystemStart
-> EraHistory mode
-> ProtocolParameters
-> Set PoolId
-> UTxO era
-> TxBodyContent BuildTx era
-> AddressInEra era
-> Maybe Word
-> Either TxBodyErrorAutoBalance (BalancedTxBody era)
makeTransactionBodyAutoBalance EraInMode era CardanoMode
eInMode SystemStart
systemStart EraHistory CardanoMode
eraHistory
                                           ProtocolParameters
pparams Set PoolId
stakePools UTxO era
txEraUtxo TxBodyContent BuildTx era
txBodyContent
                                           AddressInEra era
cAddr Maybe Word
mOverrideWits

      String -> ExceptT ShelleyTxCmdError IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
putStrLn (String -> ExceptT ShelleyTxCmdError IO ())
-> String -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String
"Estimated transaction fee: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (Lovelace -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Lovelace
fee :: String)

      case TxBuildOutputOptions
outputOptions of
        OutputScriptCostOnly String
fp -> do
          case ProtocolParameters -> Maybe ExecutionUnitPrices
protocolParamPrices ProtocolParameters
pparams of
            Just ExecutionUnitPrices
executionUnitPrices -> do
              Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
scriptExecUnitsMap <- (TransactionValidityError -> ShelleyTxCmdError)
-> ExceptT
     TransactionValidityError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
-> ExceptT
     ShelleyTxCmdError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT TransactionValidityError -> ShelleyTxCmdError
ShelleyTxCmdTxExecUnitsErr (ExceptT
   TransactionValidityError
   IO
   (Map
      ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
 -> ExceptT
      ShelleyTxCmdError
      IO
      (Map
         ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)))
-> ExceptT
     TransactionValidityError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
-> ExceptT
     ShelleyTxCmdError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
forall a b. (a -> b) -> a -> b
$ Either
  TransactionValidityError
  (Map
     ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
-> ExceptT
     TransactionValidityError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
                                      (Either
   TransactionValidityError
   (Map
      ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
 -> ExceptT
      TransactionValidityError
      IO
      (Map
         ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)))
-> Either
     TransactionValidityError
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
-> ExceptT
     TransactionValidityError
     IO
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
forall a b. (a -> b) -> a -> b
$ EraInMode era CardanoMode
-> SystemStart
-> EraHistory CardanoMode
-> ProtocolParameters
-> UTxO era
-> TxBody era
-> Either
     TransactionValidityError
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
forall era mode.
EraInMode era mode
-> SystemStart
-> EraHistory mode
-> ProtocolParameters
-> UTxO era
-> TxBody era
-> Either
     TransactionValidityError
     (Map
        ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
evaluateTransactionExecutionUnits
                                          EraInMode era CardanoMode
eInMode SystemStart
systemStart EraHistory CardanoMode
eraHistory
                                          ProtocolParameters
pparams UTxO era
txEraUtxo TxBody era
balancedTxBody
              [ScriptCostOutput]
scriptCostOutput <- (PlutusScriptCostError -> ShelleyTxCmdError)
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
-> ExceptT ShelleyTxCmdError IO [ScriptCostOutput]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT PlutusScriptCostError -> ShelleyTxCmdError
ShelleyTxCmdPlutusScriptCostErr (ExceptT PlutusScriptCostError IO [ScriptCostOutput]
 -> ExceptT ShelleyTxCmdError IO [ScriptCostOutput])
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
-> ExceptT ShelleyTxCmdError IO [ScriptCostOutput]
forall a b. (a -> b) -> a -> b
$ Either PlutusScriptCostError [ScriptCostOutput]
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
                                    (Either PlutusScriptCostError [ScriptCostOutput]
 -> ExceptT PlutusScriptCostError IO [ScriptCostOutput])
-> Either PlutusScriptCostError [ScriptCostOutput]
-> ExceptT PlutusScriptCostError IO [ScriptCostOutput]
forall a b. (a -> b) -> a -> b
$ UTxO era
-> ExecutionUnitPrices
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> Map
     ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
-> Either PlutusScriptCostError [ScriptCostOutput]
forall era.
UTxO era
-> ExecutionUnitPrices
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> Map
     ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
-> Either PlutusScriptCostError [ScriptCostOutput]
renderScriptCosts
                                        UTxO era
txEraUtxo
                                        ExecutionUnitPrices
executionUnitPrices
                                        (TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txBodyContent)
                                        Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
scriptExecUnitsMap
              IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ShelleyTxCmdError IO ())
-> IO () -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> ByteString -> IO ()
LBS.writeFile String
fp (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ [ScriptCostOutput] -> ByteString
forall a. ToJSON a => a -> ByteString
encodePretty [ScriptCostOutput]
scriptCostOutput

            Maybe ExecutionUnitPrices
Nothing -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ShelleyTxCmdError
ShelleyTxCmdPParamExecutionUnitsNotAvailable
        OutputTxBodyOnly (TxBodyFile String
fpath)  ->
          let noWitTx :: Tx era
noWitTx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
balancedTxBody
          in (FileError () -> ShelleyTxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyTxCmdError
ShelleyTxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 ShelleyTxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
               String -> Tx era -> IO (Either (FileError ()) ())
forall era.
IsCardanoEra era =>
String -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl String
fpath Tx era
noWitTx

    (ConsensusMode mode
CardanoMode, CardanoEraStyle era
LegacyByronEra) -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ShelleyTxCmdError
ShelleyTxCmdByronEra

    (ConsensusMode mode
wrongMode, CardanoEraStyle era
_) -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (AnyConsensusMode -> ShelleyTxCmdError
ShelleyTxCmdUnsupportedMode (ConsensusMode mode -> AnyConsensusMode
forall mode. ConsensusMode mode -> AnyConsensusMode
AnyConsensusMode ConsensusMode mode
wrongMode))

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

-- | An enumeration of era-dependent features where we have to check that it
-- is permissible to use this feature in this era.
--
data TxFeature = TxFeatureShelleyAddresses
               | TxFeatureExplicitFees
               | TxFeatureImplicitFees
               | TxFeatureValidityLowerBound
               | TxFeatureValidityUpperBound
               | TxFeatureValidityNoUpperBound
               | TxFeatureTxMetadata
               | TxFeatureAuxScripts
               | TxFeatureWithdrawals
               | TxFeatureCertificates
               | TxFeatureMintValue
               | TxFeatureMultiAssetOutputs
               | TxFeatureScriptWitnesses
               | TxFeatureShelleyKeys
               | TxFeatureCollateral
               | TxFeatureProtocolParameters
               | TxFeatureTxOutDatum
               | TxFeatureScriptValidity
               | TxFeatureExtraKeyWits
               | TxFeatureInlineDatums
               | TxFeatureTotalCollateral
               | TxFeatureReferenceInputs
               | TxFeatureReturnCollateral
  deriving Int -> TxFeature -> String -> String
[TxFeature] -> String -> String
TxFeature -> String
(Int -> TxFeature -> String -> String)
-> (TxFeature -> String)
-> ([TxFeature] -> String -> String)
-> Show TxFeature
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [TxFeature] -> String -> String
$cshowList :: [TxFeature] -> String -> String
show :: TxFeature -> String
$cshow :: TxFeature -> String
showsPrec :: Int -> TxFeature -> String -> String
$cshowsPrec :: Int -> TxFeature -> String -> String
Show

txFeatureMismatch :: CardanoEra era
                  -> TxFeature
                  -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch :: CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
feature =
    ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO a
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (AnyCardanoEra -> TxFeature -> ShelleyTxCmdError
ShelleyTxCmdTxFeatureMismatch (CardanoEra era -> AnyCardanoEra
forall era. CardanoEra era -> AnyCardanoEra
anyCardanoEra CardanoEra era
era) TxFeature
feature)

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

readScriptWitnessFiles
  :: CardanoEra era
  -> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
  -> ExceptT ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
readScriptWitnessFiles :: CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
readScriptWitnessFiles CardanoEra era
era = ((TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
 -> ExceptT
      ShelleyTxCmdError IO (TxIn, Maybe (ScriptWitness WitCtxTxIn era)))
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT
     ShelleyTxCmdError IO [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
-> ExceptT
     ShelleyTxCmdError IO (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
readSwitFile
 where
  readSwitFile :: (TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
-> ExceptT
     ShelleyTxCmdError IO (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
readSwitFile (TxIn
tIn, Just ScriptWitnessFiles WitCtxTxIn
switFile) = do
      ScriptWitness WitCtxTxIn era
sWit <- CardanoEra era
-> ScriptWitnessFiles WitCtxTxIn
-> ExceptT ShelleyTxCmdError IO (ScriptWitness WitCtxTxIn era)
forall era witctx.
CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era ScriptWitnessFiles WitCtxTxIn
switFile
      (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
-> ExceptT
     ShelleyTxCmdError IO (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
forall (m :: * -> *) a. Monad m => a -> m a
return (TxIn
tIn, ScriptWitness WitCtxTxIn era
-> Maybe (ScriptWitness WitCtxTxIn era)
forall a. a -> Maybe a
Just ScriptWitness WitCtxTxIn era
sWit)
  readSwitFile (TxIn
tIn, Maybe (ScriptWitnessFiles WitCtxTxIn)
Nothing) = (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
-> ExceptT
     ShelleyTxCmdError IO (TxIn, Maybe (ScriptWitness WitCtxTxIn era))
forall (m :: * -> *) a. Monad m => a -> m a
return (TxIn
tIn, Maybe (ScriptWitness WitCtxTxIn era)
forall a. Maybe a
Nothing)


validateTxInsCollateral :: CardanoEra era
                        -> [TxIn]
                        -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
validateTxInsCollateral :: CardanoEra era
-> [TxIn] -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
validateTxInsCollateral CardanoEra era
_   []    = TxInsCollateral era
-> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
validateTxInsCollateral CardanoEra era
era [TxIn]
txins =
    case CardanoEra era -> Maybe (CollateralSupportedInEra era)
forall era. CardanoEra era -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra CardanoEra era
era of
      Maybe (CollateralSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureCollateral
      Just CollateralSupportedInEra era
supported -> TxInsCollateral era
-> ExceptT ShelleyTxCmdError IO (TxInsCollateral era)
forall (m :: * -> *) a. Monad m => a -> m a
return (CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
forall era.
CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
TxInsCollateral CollateralSupportedInEra era
supported [TxIn]
txins)

validateTxInsReference
  :: forall era. CardanoEra era
  -> [TxIn]
  -> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
validateTxInsReference :: CardanoEra era
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
validateTxInsReference CardanoEra era
_ []  = TxInsReference BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxInsReference BuildTx era
forall build era. TxInsReference build era
TxInsReferenceNone
validateTxInsReference CardanoEra era
era [TxIn]
allRefIns =
  case CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra era
era of
    Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureReferenceInputs
    Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp -> TxInsReference BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxInsReference BuildTx era
 -> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era))
-> TxInsReference BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxInsReference BuildTx era)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> [TxIn] -> TxInsReference BuildTx era
forall era build.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> [TxIn] -> TxInsReference build era
TxInsReference ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp [TxIn]
allRefIns


getAllReferenceInputs
 :: CardanoEra era
 -> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
 -> Maybe (Value, [ScriptWitnessFiles WitCtxMint ])
 -> [(CertificateFile , Maybe (ScriptWitnessFiles WitCtxStake ))]
 -> [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake ))]
 -> [TxIn]
 -> ExceptT ShelleyTxCmdError IO [TxIn]
getAllReferenceInputs :: CardanoEra era
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> [TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
getAllReferenceInputs CardanoEra era
era [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals [TxIn]
readOnlyRefIns = do
  [Maybe TxIn]
txinsWitByRefInputs <- ((TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-> ExceptT ShelleyTxCmdError IO [Maybe TxIn]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Maybe (ScriptWitnessFiles WitCtxTxIn)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall witctx.
Maybe (ScriptWitnessFiles witctx)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
getWitnessingReferenceInput (Maybe (ScriptWitnessFiles WitCtxTxIn)
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> ((TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
    -> Maybe (ScriptWitnessFiles WitCtxTxIn))
-> (TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))
-> Maybe (ScriptWitnessFiles WitCtxTxIn)
forall a b. (a, b) -> b
snd) [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
txins
  [Maybe TxIn]
mintingRefInputs <-
    case Maybe (Value, [ScriptWitnessFiles WitCtxMint])
mValue of
      Maybe (Value, [ScriptWitnessFiles WitCtxMint])
Nothing -> [Maybe TxIn] -> ExceptT ShelleyTxCmdError IO [Maybe TxIn]
forall (m :: * -> *) a. Monad m => a -> m a
return []
      Just (Value
_, [ScriptWitnessFiles WitCtxMint]
mintWitnesses) ->
       (ScriptWitnessFiles WitCtxMint
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> [ScriptWitnessFiles WitCtxMint]
-> ExceptT ShelleyTxCmdError IO [Maybe TxIn]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Maybe (ScriptWitnessFiles WitCtxMint)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall witctx.
Maybe (ScriptWitnessFiles witctx)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
getWitnessingReferenceInput (Maybe (ScriptWitnessFiles WitCtxMint)
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> (ScriptWitnessFiles WitCtxMint
    -> Maybe (ScriptWitnessFiles WitCtxMint))
-> ScriptWitnessFiles WitCtxMint
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ScriptWitnessFiles WitCtxMint
-> Maybe (ScriptWitnessFiles WitCtxMint)
forall a. a -> Maybe a
Just) [ScriptWitnessFiles WitCtxMint]
mintWitnesses

  [Maybe TxIn]
certsWitByRefInputs <- ((CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO [Maybe TxIn]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Maybe (ScriptWitnessFiles WitCtxStake)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall witctx.
Maybe (ScriptWitnessFiles witctx)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
getWitnessingReferenceInput (Maybe (ScriptWitnessFiles WitCtxStake)
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> ((CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
    -> Maybe (ScriptWitnessFiles WitCtxStake))
-> (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> Maybe (ScriptWitnessFiles WitCtxStake)
forall a b. (a, b) -> b
snd) [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles

  [Maybe TxIn]
withdrawalsWitByRefInputs
    <- ((StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))
 -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO [Maybe TxIn]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(StakeAddress
_, Lovelace
_, Maybe (ScriptWitnessFiles WitCtxStake)
mSwit) -> Maybe (ScriptWitnessFiles WitCtxStake)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall witctx.
Maybe (ScriptWitnessFiles witctx)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
getWitnessingReferenceInput Maybe (ScriptWitnessFiles WitCtxStake)
mSwit) [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals

  [TxIn] -> ExceptT ShelleyTxCmdError IO [TxIn]
forall (m :: * -> *) a. Monad m => a -> m a
return ([TxIn] -> ExceptT ShelleyTxCmdError IO [TxIn])
-> ([Maybe TxIn] -> [TxIn])
-> [Maybe TxIn]
-> ExceptT ShelleyTxCmdError IO [TxIn]
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [Maybe TxIn] -> [TxIn]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe TxIn] -> ExceptT ShelleyTxCmdError IO [TxIn])
-> [Maybe TxIn] -> ExceptT ShelleyTxCmdError IO [TxIn]
forall a b. (a -> b) -> a -> b
$ [[Maybe TxIn]] -> [Maybe TxIn]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ [Maybe TxIn]
txinsWitByRefInputs
                     , [Maybe TxIn]
mintingRefInputs
                     , [Maybe TxIn]
certsWitByRefInputs
                     , [Maybe TxIn]
withdrawalsWitByRefInputs
                     , (TxIn -> Maybe TxIn) -> [TxIn] -> [Maybe TxIn]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just [TxIn]
readOnlyRefIns
                     ]
 where
  getWitnessingReferenceInput
    :: Maybe (ScriptWitnessFiles witctx)
    -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
  getWitnessingReferenceInput :: Maybe (ScriptWitnessFiles witctx)
-> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
getWitnessingReferenceInput Maybe (ScriptWitnessFiles witctx)
mScriptWitnessFiles =
    case Maybe (ScriptWitnessFiles witctx)
mScriptWitnessFiles of
      Just ScriptWitnessFiles witctx
scriptWitnessFiles -> do
        ScriptWitness witctx era
sWit <- CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall era witctx.
CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era ScriptWitnessFiles witctx
scriptWitnessFiles
        case ScriptWitness witctx era
sWit of
          PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ (PReferenceScript TxIn
refIn Maybe ScriptHash
_) ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_ ->
            Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall a b. (a -> b) -> a -> b
$ TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
refIn
          PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ PScript{} ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_ ->
            Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TxIn
forall a. Maybe a
Nothing
          SimpleScriptWitness ScriptLanguageInEra lang era
_ SimpleScriptVersion lang
_ (SReferenceScript TxIn
refIn Maybe ScriptHash
_)  ->
            Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn))
-> Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall a b. (a -> b) -> a -> b
$ TxIn -> Maybe TxIn
forall a. a -> Maybe a
Just TxIn
refIn
          SimpleScriptWitness ScriptLanguageInEra lang era
_ SimpleScriptVersion lang
_ SScript{}  ->
            Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TxIn
forall a. Maybe a
Nothing
      Maybe (ScriptWitnessFiles witctx)
Nothing -> Maybe TxIn -> ExceptT ShelleyTxCmdError IO (Maybe TxIn)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TxIn
forall a. Maybe a
Nothing

validateTxOuts :: forall era.
                  CardanoEra era
               -> [TxOutAnyEra]
               -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
validateTxOuts :: CardanoEra era
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
validateTxOuts CardanoEra era
era = (TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era))
-> [TxOutAnyEra] -> ExceptT ShelleyTxCmdError IO [TxOut CtxTx era]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CardanoEra era
-> TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
forall era.
CardanoEra era
-> TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra CardanoEra era
era)

toAddressInAnyEra
  :: CardanoEra era
  -> AddressAny
  -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
toAddressInAnyEra :: CardanoEra era
-> AddressAny -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
toAddressInAnyEra CardanoEra era
era AddressAny
addrAny =
  case AddressAny
addrAny of
    AddressByron   Address ByronAddr
bAddr -> AddressInEra era -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return (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 ->
      case CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle CardanoEra era
era of
        CardanoEraStyle era
LegacyByronEra -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureShelleyAddresses
        ShelleyBasedEra ShelleyBasedEra era
era' ->
          AddressInEra era -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return (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
era') Address ShelleyAddr
sAddr)

toTxOutValueInAnyEra
  :: CardanoEra era
  -> Value
  -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
toTxOutValueInAnyEra :: CardanoEra era
-> Value -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
toTxOutValueInAnyEra CardanoEra era
era Value
val =
  case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
era of
    Left OnlyAdaSupportedInEra era
adaOnlyInEra ->
      case Value -> Maybe Lovelace
valueToLovelace Value
val of
        Just Lovelace
l  -> TxOutValue era -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
forall (m :: * -> *) a. Monad m => a -> m a
return (OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra era
adaOnlyInEra Lovelace
l)
        Maybe Lovelace
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureMultiAssetOutputs
    Right MultiAssetSupportedInEra era
multiAssetInEra -> TxOutValue era -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
forall (m :: * -> *) a. Monad m => a -> m a
return (MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
multiAssetInEra Value
val)

toTxOutInAnyEra :: CardanoEra era
                -> TxOutAnyEra
                -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra :: CardanoEra era
-> TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra CardanoEra era
era (TxOutAnyEra AddressAny
addr' Value
val' TxOutDatumAnyEra
mDatumHash ReferenceScriptAnyEra
refScriptFp) = do
  AddressInEra era
addr <- CardanoEra era
-> AddressAny -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
forall era.
CardanoEra era
-> AddressAny -> ExceptT ShelleyTxCmdError IO (AddressInEra era)
toAddressInAnyEra CardanoEra era
era AddressAny
addr'
  TxOutValue era
val <- CardanoEra era
-> Value -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
forall era.
CardanoEra era
-> Value -> ExceptT ShelleyTxCmdError IO (TxOutValue era)
toTxOutValueInAnyEra CardanoEra era
era Value
val'
  (TxOutDatum CtxTx era
datum, ReferenceScript era
refScript)
    <- case (CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra era
era, CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra era
era) of
         (Maybe (ScriptDataSupportedInEra era)
Nothing, Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing) -> (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone, ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone)
         (Just ScriptDataSupportedInEra era
sup, Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing)->
           (,) (TxOutDatum CtxTx era
 -> ReferenceScript era
 -> (TxOutDatum CtxTx era, ReferenceScript era))
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (ReferenceScript era
      -> (TxOutDatum CtxTx era, ReferenceScript era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptDataSupportedInEra era
-> TxOutDatumAnyEra
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall era.
ScriptDataSupportedInEra era
-> TxOutDatumAnyEra
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum ScriptDataSupportedInEra era
sup TxOutDatumAnyEra
mDatumHash ExceptT
  ShelleyTxCmdError
  IO
  (ReferenceScript era
   -> (TxOutDatum CtxTx era, ReferenceScript era))
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
         (Just ScriptDataSupportedInEra era
sup, Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineDatumRefScriptSupp) ->
           ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> TxOutDatumAnyEra
-> ReferenceScriptAnyEra
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall era.
ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> TxOutDatumAnyEra
-> ReferenceScriptAnyEra
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
toTxDatumReferenceScriptBabbage ScriptDataSupportedInEra era
sup ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineDatumRefScriptSupp TxOutDatumAnyEra
mDatumHash ReferenceScriptAnyEra
refScriptFp
         (Maybe (ScriptDataSupportedInEra era)
Nothing, Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_) ->
           -- TODO: Figure out how to make this state unrepresentable
           Text
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall a. HasCallStack => Text -> a
panic Text
"toTxOutInAnyEra: Should not be possible that inline datums are allowed but datums are not"
  TxOut CtxTx era -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOut CtxTx era -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era))
-> TxOut CtxTx era
-> ExceptT ShelleyTxCmdError 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
 where
  getReferenceScript
    :: ReferenceScriptAnyEra
    -> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
    -> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
  getReferenceScript :: ReferenceScriptAnyEra
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
getReferenceScript ReferenceScriptAnyEra
ReferenceScriptAnyEraNone ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ = ReferenceScript era
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
  getReferenceScript (ReferenceScriptAnyEra String
fp) ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp = do
    ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
forall era.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
ReferenceScript ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp
      (ScriptInAnyLang -> ReferenceScript era)
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FileError ScriptDecodeError -> ShelleyTxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyTxCmdError
ShelleyTxCmdScriptFileError (String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
fp)

  toTxDatumReferenceScriptBabbage
    :: ScriptDataSupportedInEra era
    -> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
    -> TxOutDatumAnyEra
    -> ReferenceScriptAnyEra
    -> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
  toTxDatumReferenceScriptBabbage :: ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> TxOutDatumAnyEra
-> ReferenceScriptAnyEra
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
toTxDatumReferenceScriptBabbage ScriptDataSupportedInEra era
sDataSupp ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineRefSupp TxOutDatumAnyEra
cliDatum ReferenceScriptAnyEra
refScriptFp' = do
    ReferenceScript era
refScript <- ReferenceScriptAnyEra
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
forall era.
ReferenceScriptAnyEra
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ExceptT ShelleyTxCmdError IO (ReferenceScript era)
getReferenceScript ReferenceScriptAnyEra
refScriptFp' ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineRefSupp
    case TxOutDatumAnyEra
cliDatum of
       TxOutDatumAnyEra
TxOutDatumByNone -> do
         (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone, ReferenceScript era
refScript)
       TxOutDatumByHashOnly Hash ScriptRedeemer
dh -> do
         (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
sDataSupp Hash ScriptRedeemer
dh, ReferenceScript era
refScript)
       TxOutDatumByHashOf ScriptDataOrFile
fileOrSdata -> do
         ScriptRedeemer
sData <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
fileOrSdata
         (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
sDataSupp (Hash ScriptRedeemer -> TxOutDatum CtxTx era)
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$ ScriptRedeemer -> Hash ScriptRedeemer
hashScriptData ScriptRedeemer
sData, ReferenceScript era
refScript)
       TxOutDatumByValue ScriptDataOrFile
fileOrSdata -> do
         ScriptRedeemer
sData <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
fileOrSdata
         (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> ScriptRedeemer -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> ScriptRedeemer -> TxOutDatum CtxTx era
TxOutDatumInTx ScriptDataSupportedInEra era
sDataSupp ScriptRedeemer
sData, ReferenceScript era
refScript)
       TxOutInlineDatumByValue ScriptDataOrFile
fileOrSdata -> do
         ScriptRedeemer
sData <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
fileOrSdata
         (TxOutDatum CtxTx era, ReferenceScript era)
-> ExceptT
     ShelleyTxCmdError IO (TxOutDatum CtxTx era, ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineRefSupp ScriptRedeemer
sData, ReferenceScript era
refScript)

  toTxAlonzoDatum
    :: ScriptDataSupportedInEra era
    -> TxOutDatumAnyEra
    -> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
  toTxAlonzoDatum :: ScriptDataSupportedInEra era
-> TxOutDatumAnyEra
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
toTxAlonzoDatum ScriptDataSupportedInEra era
supp TxOutDatumAnyEra
cliDatum =
    case TxOutDatumAnyEra
cliDatum of
      TxOutDatumByHashOnly Hash ScriptRedeemer
h -> TxOutDatum CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supp Hash ScriptRedeemer
h)
      TxOutDatumByHashOf ScriptDataOrFile
sDataOrFile -> do
        ScriptRedeemer
sData <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
sDataOrFile
        TxOutDatum CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptRedeemer -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supp (Hash ScriptRedeemer -> TxOutDatum CtxTx era)
-> Hash ScriptRedeemer -> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$ ScriptRedeemer -> Hash ScriptRedeemer
hashScriptData ScriptRedeemer
sData)
      TxOutDatumByValue ScriptDataOrFile
sDataOrFile -> do
        ScriptRedeemer
sData <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
sDataOrFile
        TxOutDatum CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptDataSupportedInEra era
-> ScriptRedeemer -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> ScriptRedeemer -> TxOutDatum CtxTx era
TxOutDatumInTx ScriptDataSupportedInEra era
supp ScriptRedeemer
sData)
      TxOutInlineDatumByValue ScriptDataOrFile
_ ->
        CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureInlineDatums
      TxOutDatumAnyEra
TxOutDatumByNone -> TxOutDatum CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxOutDatum CtxTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone

validateTxFee :: CardanoEra era
              -> Maybe Lovelace
              -> ExceptT ShelleyTxCmdError IO (TxFee era)
validateTxFee :: CardanoEra era
-> Maybe Lovelace -> ExceptT ShelleyTxCmdError IO (TxFee era)
validateTxFee CardanoEra era
era Maybe Lovelace
mfee =
    case (CardanoEra era
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra era)
forall era.
CardanoEra era
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra era)
txFeesExplicitInEra CardanoEra era
era, Maybe Lovelace
mfee) of
      (Left  TxFeesImplicitInEra era
implicit, Maybe Lovelace
Nothing)  -> TxFee era -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxFeesImplicitInEra era -> TxFee era
forall era. TxFeesImplicitInEra era -> TxFee era
TxFeeImplicit TxFeesImplicitInEra era
implicit)
      (Right TxFeesExplicitInEra era
explicit, Just Lovelace
fee) -> TxFee era -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxFeesExplicitInEra era -> Lovelace -> TxFee era
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra era
explicit Lovelace
fee)

      (Right TxFeesExplicitInEra era
_, Maybe Lovelace
Nothing) -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureImplicitFees
      (Left  TxFeesImplicitInEra era
_, Just Lovelace
_)  -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxFee era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureExplicitFees

validateTxTotalCollateral :: CardanoEra era
                          -> Maybe Lovelace
                          -> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
validateTxTotalCollateral :: CardanoEra era
-> Maybe Lovelace
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
validateTxTotalCollateral CardanoEra era
_ Maybe Lovelace
Nothing = TxTotalCollateral era
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
validateTxTotalCollateral CardanoEra era
era (Just Lovelace
coll) =
  case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra CardanoEra era
era of
    Just TxTotalAndReturnCollateralSupportedInEra era
supp -> TxTotalCollateral era
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxTotalCollateral era
 -> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era))
-> TxTotalCollateral era
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall a b. (a -> b) -> a -> b
$ TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
forall era.
TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
TxTotalCollateral TxTotalAndReturnCollateralSupportedInEra era
supp Lovelace
coll
    Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxTotalCollateral era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureTotalCollateral

validateTxReturnCollateral :: CardanoEra era
                           -> Maybe TxOutAnyEra
                           -> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
validateTxReturnCollateral :: CardanoEra era
-> Maybe TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
validateTxReturnCollateral CardanoEra era
_ Maybe TxOutAnyEra
Nothing = TxReturnCollateral CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
validateTxReturnCollateral CardanoEra era
era (Just TxOutAnyEra
retColTxOut) = do
  TxOut CtxTx era
txout <- CardanoEra era
-> TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
forall era.
CardanoEra era
-> TxOutAnyEra -> ExceptT ShelleyTxCmdError IO (TxOut CtxTx era)
toTxOutInAnyEra CardanoEra era
era TxOutAnyEra
retColTxOut
  case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra CardanoEra era
era of
    Just TxTotalAndReturnCollateralSupportedInEra era
supp -> TxReturnCollateral CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxReturnCollateral CtxTx era
 -> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era))
-> TxReturnCollateral CtxTx era
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall a b. (a -> b) -> a -> b
$ TxTotalAndReturnCollateralSupportedInEra era
-> TxOut CtxTx era -> TxReturnCollateral CtxTx era
forall era ctx.
TxTotalAndReturnCollateralSupportedInEra era
-> TxOut ctx era -> TxReturnCollateral ctx era
TxReturnCollateral TxTotalAndReturnCollateralSupportedInEra era
supp TxOut CtxTx era
txout
    Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxReturnCollateral CtxTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureReturnCollateral



validateTxValidityLowerBound :: CardanoEra era
                             -> Maybe SlotNo
                             -> ExceptT ShelleyTxCmdError IO
                                        (TxValidityLowerBound era)
validateTxValidityLowerBound :: CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
validateTxValidityLowerBound CardanoEra era
_ Maybe SlotNo
Nothing = TxValidityLowerBound era
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
validateTxValidityLowerBound CardanoEra era
era (Just SlotNo
slot) =
    case CardanoEra era -> Maybe (ValidityLowerBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityLowerBoundSupportedInEra era)
validityLowerBoundSupportedInEra CardanoEra era
era of
      Maybe (ValidityLowerBoundSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureValidityLowerBound
      Just ValidityLowerBoundSupportedInEra era
supported -> TxValidityLowerBound era
-> ExceptT ShelleyTxCmdError IO (TxValidityLowerBound era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra era
supported SlotNo
slot)


validateTxValidityUpperBound :: CardanoEra era
                             -> Maybe SlotNo
                             -> ExceptT ShelleyTxCmdError IO
                                        (TxValidityUpperBound era)
validateTxValidityUpperBound :: CardanoEra era
-> Maybe SlotNo
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
validateTxValidityUpperBound CardanoEra era
era Maybe SlotNo
Nothing =
    case CardanoEra era -> Maybe (ValidityNoUpperBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityNoUpperBoundSupportedInEra era)
validityNoUpperBoundSupportedInEra CardanoEra era
era of
      Maybe (ValidityNoUpperBoundSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureValidityNoUpperBound
      Just ValidityNoUpperBoundSupportedInEra era
supported -> TxValidityUpperBound era
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
supported)
validateTxValidityUpperBound CardanoEra era
era (Just SlotNo
slot) =
    case CardanoEra era -> Maybe (ValidityUpperBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityUpperBoundSupportedInEra era)
validityUpperBoundSupportedInEra CardanoEra era
era of
      Maybe (ValidityUpperBoundSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureValidityUpperBound
      Just ValidityUpperBoundSupportedInEra era
supported -> TxValidityUpperBound era
-> ExceptT ShelleyTxCmdError IO (TxValidityUpperBound era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound ValidityUpperBoundSupportedInEra era
supported SlotNo
slot)


validateTxMetadataInEra :: CardanoEra era
                        -> TxMetadataJsonSchema
                        -> [MetadataFile]
                        -> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
validateTxMetadataInEra :: CardanoEra era
-> TxMetadataJsonSchema
-> [MetadataFile]
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
validateTxMetadataInEra CardanoEra era
_ TxMetadataJsonSchema
_ [] = TxMetadataInEra era
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
validateTxMetadataInEra CardanoEra era
era TxMetadataJsonSchema
schema [MetadataFile]
files =
    case CardanoEra era -> Maybe (TxMetadataSupportedInEra era)
forall era. CardanoEra era -> Maybe (TxMetadataSupportedInEra era)
txMetadataSupportedInEra CardanoEra era
era of
      Maybe (TxMetadataSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureTxMetadata
      Just TxMetadataSupportedInEra era
supported -> do
        TxMetadata
metadata <- [TxMetadata] -> TxMetadata
forall a. Monoid a => [a] -> a
mconcat ([TxMetadata] -> TxMetadata)
-> ExceptT ShelleyTxCmdError IO [TxMetadata]
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MetadataFile -> ExceptT ShelleyTxCmdError IO TxMetadata)
-> [MetadataFile] -> ExceptT ShelleyTxCmdError IO [TxMetadata]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TxMetadataJsonSchema
-> MetadataFile -> ExceptT ShelleyTxCmdError IO TxMetadata
readFileTxMetadata TxMetadataJsonSchema
schema) [MetadataFile]
files
        TxMetadataInEra era
-> ExceptT ShelleyTxCmdError IO (TxMetadataInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra era
supported TxMetadata
metadata)


validateTxAuxScripts :: CardanoEra era
                     -> [ScriptFile]
                     -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
validateTxAuxScripts :: CardanoEra era
-> [ScriptFile] -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
validateTxAuxScripts CardanoEra era
_ [] = TxAuxScripts era -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
validateTxAuxScripts CardanoEra era
era [ScriptFile]
files =
  case CardanoEra era -> Maybe (AuxScriptsSupportedInEra era)
forall era. CardanoEra era -> Maybe (AuxScriptsSupportedInEra era)
auxScriptsSupportedInEra CardanoEra era
era of
    Maybe (AuxScriptsSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureAuxScripts
    Just AuxScriptsSupportedInEra era
supported -> do
      [ScriptInEra era]
scripts <- [ExceptT ShelleyTxCmdError IO (ScriptInEra era)]
-> ExceptT ShelleyTxCmdError IO [ScriptInEra era]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
        [ do ScriptInAnyLang
script <- (FileError ScriptDecodeError -> ShelleyTxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyTxCmdError
ShelleyTxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
 -> ExceptT ShelleyTxCmdError IO ScriptInAnyLang)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall a b. (a -> b) -> a -> b
$
                         String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
file
             CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
forall era.
CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
validateScriptSupportedInEra CardanoEra era
era ScriptInAnyLang
script
        | ScriptFile String
file <- [ScriptFile]
files ]
      TxAuxScripts era -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxAuxScripts era
 -> ExceptT ShelleyTxCmdError IO (TxAuxScripts era))
-> TxAuxScripts era
-> ExceptT ShelleyTxCmdError IO (TxAuxScripts era)
forall a b. (a -> b) -> a -> b
$ AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra era
supported [ScriptInEra era]
scripts

validateRequiredSigners :: CardanoEra era
                        -> [RequiredSigner]
                        -> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
validateRequiredSigners :: CardanoEra era
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
validateRequiredSigners CardanoEra era
_ [] = TxExtraKeyWitnesses era
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
validateRequiredSigners CardanoEra era
era [RequiredSigner]
reqSigs =
  case CardanoEra era -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall era.
CardanoEra era -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
extraKeyWitnessesSupportedInEra CardanoEra era
era of
    Maybe (TxExtraKeyWitnessesSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureExtraKeyWits
    Just TxExtraKeyWitnessesSupportedInEra era
supported -> do
      [Hash PaymentKey]
rSignerHashes <- (RequiredSigner -> ExceptT ShelleyTxCmdError IO (Hash PaymentKey))
-> [RequiredSigner]
-> ExceptT ShelleyTxCmdError IO [Hash PaymentKey]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RequiredSigner -> ExceptT ShelleyTxCmdError IO (Hash PaymentKey)
readRequiredSigner [RequiredSigner]
reqSigs
      TxExtraKeyWitnesses era
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxExtraKeyWitnesses era
 -> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era))
-> TxExtraKeyWitnesses era
-> ExceptT ShelleyTxCmdError IO (TxExtraKeyWitnesses era)
forall a b. (a -> b) -> a -> b
$ TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
forall era.
TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses TxExtraKeyWitnessesSupportedInEra era
supported [Hash PaymentKey]
rSignerHashes


validateTxWithdrawals
  :: forall era.
     CardanoEra era
  -> [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
  -> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
validateTxWithdrawals :: CardanoEra era
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
validateTxWithdrawals CardanoEra era
_ [] = TxWithdrawals BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxWithdrawals BuildTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
validateTxWithdrawals CardanoEra era
era [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals =
  case CardanoEra era -> Maybe (WithdrawalsSupportedInEra era)
forall era. CardanoEra era -> Maybe (WithdrawalsSupportedInEra era)
withdrawalsSupportedInEra CardanoEra era
era of
    Maybe (WithdrawalsSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureWithdrawals
    Just WithdrawalsSupportedInEra era
supported -> do
      [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
convWithdrawals <- ((StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))
 -> ExceptT
      ShelleyTxCmdError
      IO
      (StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era)))
-> [(StakeAddress, Lovelace,
     Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ShelleyTxCmdError
     IO
     [(StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))
-> ExceptT
     ShelleyTxCmdError
     IO
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
convert [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
withdrawals
      TxWithdrawals BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxWithdrawals BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> TxWithdrawals BuildTx era
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra era
supported [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
convWithdrawals)
 where
  convert
    :: (StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))
    -> ExceptT ShelleyTxCmdError IO
              (StakeAddress,
               Lovelace,
               BuildTxWith BuildTx (Witness WitCtxStake era))
  convert :: (StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))
-> ExceptT
     ShelleyTxCmdError
     IO
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
convert (StakeAddress
sAddr, Lovelace
ll, Maybe (ScriptWitnessFiles WitCtxStake)
mScriptWitnessFiles) =
    case Maybe (ScriptWitnessFiles WitCtxStake)
mScriptWitnessFiles of
      Just ScriptWitnessFiles WitCtxStake
scriptWitnessFiles -> do
        ScriptWitness WitCtxStake era
sWit <- CardanoEra era
-> ScriptWitnessFiles WitCtxStake
-> ExceptT ShelleyTxCmdError IO (ScriptWitness WitCtxStake era)
forall era witctx.
CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era ScriptWitnessFiles WitCtxStake
scriptWitnessFiles
        (StakeAddress, Lovelace,
 BuildTxWith BuildTx (Witness WitCtxStake era))
-> ExceptT
     ShelleyTxCmdError
     IO
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
forall (m :: * -> *) a. Monad m => a -> m a
return ( StakeAddress
sAddr
               , Lovelace
ll
               , Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxStake era
 -> BuildTxWith BuildTx (Witness WitCtxStake era))
-> Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$ ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit
               )
      Maybe (ScriptWitnessFiles WitCtxStake)
Nothing -> (StakeAddress, Lovelace,
 BuildTxWith BuildTx (Witness WitCtxStake era))
-> ExceptT
     ShelleyTxCmdError
     IO
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
forall (m :: * -> *) a. Monad m => a -> m a
return (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)

validateTxCertificates
  :: forall era.
     CardanoEra era
  -> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
  -> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
validateTxCertificates :: CardanoEra era
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
validateTxCertificates CardanoEra era
_ [] = TxCertificates BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxCertificates BuildTx era
forall build era. TxCertificates build era
TxCertificatesNone
validateTxCertificates CardanoEra era
era [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles =
  case CardanoEra era -> Maybe (CertificatesSupportedInEra era)
forall era.
CardanoEra era -> Maybe (CertificatesSupportedInEra era)
certificatesSupportedInEra CardanoEra era
era of
    Maybe (CertificatesSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureCertificates
    Just CertificatesSupportedInEra era
supported -> do
      [Certificate]
certs <- [ExceptT ShelleyTxCmdError IO Certificate]
-> ExceptT ShelleyTxCmdError IO [Certificate]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
                 [ (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO Certificate
-> ExceptT ShelleyTxCmdError IO Certificate
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> ShelleyTxCmdError
ShelleyTxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO Certificate
 -> ExceptT ShelleyTxCmdError IO Certificate)
-> (IO (Either (FileError TextEnvelopeError) Certificate)
    -> ExceptT (FileError TextEnvelopeError) IO Certificate)
-> IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT ShelleyTxCmdError IO Certificate
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT (FileError TextEnvelopeError) IO Certificate
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) Certificate)
 -> ExceptT ShelleyTxCmdError IO Certificate)
-> IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT ShelleyTxCmdError IO Certificate
forall a b. (a -> b) -> a -> b
$
                     AsType Certificate
-> String -> IO (Either (FileError TextEnvelopeError) Certificate)
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType Certificate
AsCertificate String
certFile
                 | CertificateFile String
certFile <- ((CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
 -> CertificateFile)
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> [CertificateFile]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> CertificateFile
forall a b. (a, b) -> a
fst [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles ]
      Map StakeCredential (Witness WitCtxStake era)
reqWits <- [(StakeCredential, Witness WitCtxStake era)]
-> Map StakeCredential (Witness WitCtxStake era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(StakeCredential, Witness WitCtxStake era)]
 -> Map StakeCredential (Witness WitCtxStake era))
-> ([Maybe (StakeCredential, Witness WitCtxStake era)]
    -> [(StakeCredential, Witness WitCtxStake era)])
-> [Maybe (StakeCredential, Witness WitCtxStake era)]
-> Map StakeCredential (Witness WitCtxStake era)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [Maybe (StakeCredential, Witness WitCtxStake era)]
-> [(StakeCredential, Witness WitCtxStake era)]
forall a. [Maybe a] -> [a]
catMaybes  ([Maybe (StakeCredential, Witness WitCtxStake era)]
 -> Map StakeCredential (Witness WitCtxStake era))
-> ExceptT
     ShelleyTxCmdError
     IO
     [Maybe (StakeCredential, Witness WitCtxStake era)]
-> ExceptT
     ShelleyTxCmdError
     IO
     (Map StakeCredential (Witness WitCtxStake era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
 -> ExceptT
      ShelleyTxCmdError
      IO
      (Maybe (StakeCredential, Witness WitCtxStake era)))
-> [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-> ExceptT
     ShelleyTxCmdError
     IO
     [Maybe (StakeCredential, Witness WitCtxStake era)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
convert [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
certFiles
      TxCertificates BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxCertificates BuildTx era
 -> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era))
-> TxCertificates BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxCertificates BuildTx era)
forall a b. (a -> b) -> a -> b
$ CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates BuildTx era
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates CertificatesSupportedInEra era
supported [Certificate]
certs (BuildTxWith
   BuildTx (Map StakeCredential (Witness WitCtxStake era))
 -> TxCertificates BuildTx era)
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates BuildTx era
forall a b. (a -> b) -> a -> b
$ Map StakeCredential (Witness WitCtxStake era)
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Map StakeCredential (Witness WitCtxStake era)
reqWits
  where
   -- We get the stake credential witness for a certificate that requires it.
   -- NB: Only stake address deregistration and delegation requires
   -- witnessing (witness can be script or key)
   deriveStakeCredentialWitness
     :: CertificateFile
     -> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
   deriveStakeCredentialWitness :: CertificateFile
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
deriveStakeCredentialWitness (CertificateFile String
certFile) = do
     Certificate
cert <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO Certificate
-> ExceptT ShelleyTxCmdError IO Certificate
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> ShelleyTxCmdError
ShelleyTxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO Certificate
 -> ExceptT ShelleyTxCmdError IO Certificate)
-> (IO (Either (FileError TextEnvelopeError) Certificate)
    -> ExceptT (FileError TextEnvelopeError) IO Certificate)
-> IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT ShelleyTxCmdError IO Certificate
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT (FileError TextEnvelopeError) IO Certificate
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
               (IO (Either (FileError TextEnvelopeError) Certificate)
 -> ExceptT ShelleyTxCmdError IO Certificate)
-> IO (Either (FileError TextEnvelopeError) Certificate)
-> ExceptT ShelleyTxCmdError IO Certificate
forall a b. (a -> b) -> a -> b
$ AsType Certificate
-> String -> IO (Either (FileError TextEnvelopeError) Certificate)
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType Certificate
AsCertificate String
certFile
     case Certificate
cert of
       StakeAddressDeregistrationCertificate StakeCredential
sCred -> Maybe StakeCredential
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe StakeCredential
 -> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential))
-> Maybe StakeCredential
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
forall a b. (a -> b) -> a -> b
$ StakeCredential -> Maybe StakeCredential
forall a. a -> Maybe a
Just StakeCredential
sCred
       StakeAddressDelegationCertificate StakeCredential
sCred PoolId
_ -> Maybe StakeCredential
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe StakeCredential
 -> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential))
-> Maybe StakeCredential
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
forall a b. (a -> b) -> a -> b
$ StakeCredential -> Maybe StakeCredential
forall a. a -> Maybe a
Just StakeCredential
sCred
       Certificate
_ -> Maybe StakeCredential
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe StakeCredential
forall a. Maybe a
Nothing

   convert
     :: (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
     -> ExceptT ShelleyTxCmdError IO
                (Maybe (StakeCredential, Witness WitCtxStake era))
   convert :: (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
convert (CertificateFile
cert, Maybe (ScriptWitnessFiles WitCtxStake)
mScriptWitnessFiles) = do
     Maybe StakeCredential
mStakeCred <- CertificateFile
-> ExceptT ShelleyTxCmdError IO (Maybe StakeCredential)
deriveStakeCredentialWitness CertificateFile
cert
     case Maybe StakeCredential
mStakeCred of
       Maybe StakeCredential
Nothing -> Maybe (StakeCredential, Witness WitCtxStake era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (StakeCredential, Witness WitCtxStake era)
forall a. Maybe a
Nothing
       Just StakeCredential
sCred ->
         case Maybe (ScriptWitnessFiles WitCtxStake)
mScriptWitnessFiles of
           Just ScriptWitnessFiles WitCtxStake
scriptWitnessFiles -> do
            ScriptWitness WitCtxStake era
sWit <- CardanoEra era
-> ScriptWitnessFiles WitCtxStake
-> ExceptT ShelleyTxCmdError IO (ScriptWitness WitCtxStake era)
forall era witctx.
CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era ScriptWitnessFiles WitCtxStake
scriptWitnessFiles
            Maybe (StakeCredential, Witness WitCtxStake era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (StakeCredential, Witness WitCtxStake era)
 -> ExceptT
      ShelleyTxCmdError
      IO
      (Maybe (StakeCredential, Witness WitCtxStake era)))
-> Maybe (StakeCredential, Witness WitCtxStake era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
forall a b. (a -> b) -> a -> b
$ (StakeCredential, Witness WitCtxStake era)
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall a. a -> Maybe a
Just ( StakeCredential
sCred
                          , ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit
                          )

           Maybe (ScriptWitnessFiles WitCtxStake)
Nothing -> Maybe (StakeCredential, Witness WitCtxStake era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (StakeCredential, Witness WitCtxStake era)
 -> ExceptT
      ShelleyTxCmdError
      IO
      (Maybe (StakeCredential, Witness WitCtxStake era)))
-> Maybe (StakeCredential, Witness WitCtxStake era)
-> ExceptT
     ShelleyTxCmdError
     IO
     (Maybe (StakeCredential, Witness WitCtxStake era))
forall a b. (a -> b) -> a -> b
$ (StakeCredential, Witness WitCtxStake era)
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall a. a -> Maybe a
Just (StakeCredential
sCred, KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr)

validateProtocolParameters
  :: CardanoEra era
  -> Maybe ProtocolParamsSourceSpec
  -> ExceptT ShelleyTxCmdError IO
            (BuildTxWith BuildTx (Maybe ProtocolParameters))
validateProtocolParameters :: CardanoEra era
-> Maybe ProtocolParamsSourceSpec
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
validateProtocolParameters CardanoEra era
_ Maybe ProtocolParamsSourceSpec
Nothing = BuildTxWith BuildTx (Maybe ProtocolParameters)
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Maybe ProtocolParameters
forall a. Maybe a
Nothing)
validateProtocolParameters CardanoEra era
era (Just ProtocolParamsSourceSpec
pparamsspec) =
    case CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra era
era of
      Maybe (ScriptDataSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureProtocolParameters
      Just ScriptDataSupportedInEra era
_  -> Maybe ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Maybe ProtocolParameters
 -> BuildTxWith BuildTx (Maybe ProtocolParameters))
-> (ProtocolParameters -> Maybe ProtocolParameters)
-> ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ProtocolParameters -> Maybe ProtocolParameters
forall a. a -> Maybe a
Just (ProtocolParameters
 -> BuildTxWith BuildTx (Maybe ProtocolParameters))
-> ExceptT ShelleyTxCmdError IO ProtocolParameters
-> ExceptT
     ShelleyTxCmdError
     IO
     (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                   ProtocolParamsSourceSpec
-> ExceptT ShelleyTxCmdError IO ProtocolParameters
readProtocolParametersSourceSpec ProtocolParamsSourceSpec
pparamsspec

validateTxUpdateProposal :: CardanoEra era
                         -> Maybe UpdateProposalFile
                         -> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
validateTxUpdateProposal :: CardanoEra era
-> Maybe UpdateProposalFile
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
validateTxUpdateProposal CardanoEra era
_ Maybe UpdateProposalFile
Nothing = TxUpdateProposal era
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
validateTxUpdateProposal CardanoEra era
era (Just (UpdateProposalFile String
file)) =
    case CardanoEra era -> Maybe (UpdateProposalSupportedInEra era)
forall era.
CardanoEra era -> Maybe (UpdateProposalSupportedInEra era)
updateProposalSupportedInEra CardanoEra era
era of
      Maybe (UpdateProposalSupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureCertificates
      Just UpdateProposalSupportedInEra era
supported -> do
         UpdateProposal
prop <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO UpdateProposal
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError TextEnvelopeError -> ShelleyTxCmdError
ShelleyTxCmdReadTextViewFileError (ExceptT (FileError TextEnvelopeError) IO UpdateProposal
 -> ExceptT ShelleyTxCmdError IO UpdateProposal)
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO UpdateProposal
forall a b. (a -> b) -> a -> b
$ IO (Either (FileError TextEnvelopeError) UpdateProposal)
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) UpdateProposal)
 -> ExceptT (FileError TextEnvelopeError) IO UpdateProposal)
-> IO (Either (FileError TextEnvelopeError) UpdateProposal)
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
forall a b. (a -> b) -> a -> b
$
                   AsType UpdateProposal
-> String
-> IO (Either (FileError TextEnvelopeError) UpdateProposal)
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
readFileTextEnvelope AsType UpdateProposal
AsUpdateProposal String
file
         TxUpdateProposal era
-> ExceptT ShelleyTxCmdError IO (TxUpdateProposal era)
forall (m :: * -> *) a. Monad m => a -> m a
return (UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra era
supported UpdateProposal
prop)

validateTxScriptValidity :: forall era.
     CardanoEra era
  -> Maybe ScriptValidity
  -> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
validateTxScriptValidity :: CardanoEra era
-> Maybe ScriptValidity
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
validateTxScriptValidity CardanoEra era
_ Maybe ScriptValidity
Nothing = TxScriptValidity era
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
validateTxScriptValidity CardanoEra era
era (Just ScriptValidity
scriptValidity) =
  case CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
forall era.
CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInCardanoEra CardanoEra era
era of
    Maybe (TxScriptValiditySupportedInEra era)
Nothing -> CardanoEra era
-> TxFeature -> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureScriptValidity
    Just TxScriptValiditySupportedInEra era
supported -> TxScriptValidity era
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxScriptValidity era
 -> ExceptT ShelleyTxCmdError IO (TxScriptValidity era))
-> TxScriptValidity era
-> ExceptT ShelleyTxCmdError IO (TxScriptValidity era)
forall a b. (a -> b) -> a -> b
$ TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
forall era.
TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
TxScriptValidity TxScriptValiditySupportedInEra era
supported ScriptValidity
scriptValidity

-- 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).
validateTxMintValue :: forall era.
                       CardanoEra era
                    -> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
                    -> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
validateTxMintValue :: CardanoEra era
-> Maybe (Value, [ScriptWitnessFiles WitCtxMint])
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
validateTxMintValue CardanoEra era
_ Maybe (Value, [ScriptWitnessFiles WitCtxMint])
Nothing = TxMintValue BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxMintValue BuildTx era
forall build era. TxMintValue build era
TxMintNone
validateTxMintValue CardanoEra era
era (Just (Value
val, [ScriptWitnessFiles WitCtxMint]
scriptWitnessFiles)) = do
    case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
era of
      Left OnlyAdaSupportedInEra era
_ -> CardanoEra era
-> TxFeature
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
forall era a.
CardanoEra era -> TxFeature -> ExceptT ShelleyTxCmdError IO a
txFeatureMismatch CardanoEra era
era TxFeature
TxFeatureMintValue
      Right MultiAssetSupportedInEra era
supported -> do
        -- The set of policy ids for which we need witnesses:
        let witnessesNeededSet :: Set PolicyId
            witnessesNeededSet :: Set PolicyId
witnessesNeededSet =
              [PolicyId] -> Set PolicyId
forall a. Ord a => [a] -> Set a
Set.fromList [ PolicyId
pid | (AssetId PolicyId
pid AssetName
_, Quantity
_) <- Value -> [(AssetId, Quantity)]
valueToList Value
val ]

        -- The set (and map) of policy ids for which we have witnesses:
        [ScriptWitness WitCtxMint era]
witnesses <- (ScriptWitnessFiles WitCtxMint
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness WitCtxMint era))
-> [ScriptWitnessFiles WitCtxMint]
-> ExceptT ShelleyTxCmdError IO [ScriptWitness WitCtxMint era]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CardanoEra era
-> ScriptWitnessFiles WitCtxMint
-> ExceptT ShelleyTxCmdError IO (ScriptWitness WitCtxMint era)
forall era witctx.
CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era) [ScriptWitnessFiles WitCtxMint]
scriptWitnessFiles
        let witnessesProvidedMap :: Map PolicyId (ScriptWitness WitCtxMint era)
            witnessesProvidedMap :: Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap = [(PolicyId, ScriptWitness WitCtxMint era)]
-> Map PolicyId (ScriptWitness WitCtxMint era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(PolicyId, ScriptWitness WitCtxMint era)]
 -> Map PolicyId (ScriptWitness WitCtxMint era))
-> [(PolicyId, ScriptWitness WitCtxMint era)]
-> Map PolicyId (ScriptWitness WitCtxMint era)
forall a b. (a -> b) -> a -> b
$ [ScriptWitness WitCtxMint era]
-> [(PolicyId, ScriptWitness WitCtxMint era)]
gatherMintingWitnesses [ScriptWitness WitCtxMint era]
witnesses

            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 -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *).
Monad m =>
Set PolicyId -> Set PolicyId -> ExceptT ShelleyTxCmdError m ()
validateAllWitnessesProvided   Set PolicyId
witnessesNeededSet Set PolicyId
witnessesProvidedSet
        Set PolicyId -> Set PolicyId -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *).
Monad m =>
Set PolicyId -> Set PolicyId -> ExceptT ShelleyTxCmdError m ()
validateNoUnnecessaryWitnesses Set PolicyId
witnessesNeededSet Set PolicyId
witnessesProvidedSet

        TxMintValue BuildTx era
-> ExceptT ShelleyTxCmdError IO (TxMintValue BuildTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (MultiAssetSupportedInEra era
-> Value
-> BuildTxWith
     BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue BuildTx era
forall era build.
MultiAssetSupportedInEra era
-> Value
-> BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MultiAssetSupportedInEra era
supported Value
val (Map PolicyId (ScriptWitness WitCtxMint era)
-> BuildTxWith
     BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Map PolicyId (ScriptWitness WitCtxMint era)
witnessesProvidedMap))
 where
  gatherMintingWitnesses
    :: [ScriptWitness WitCtxMint era]
    -> [(PolicyId, ScriptWitness WitCtxMint era)]
  gatherMintingWitnesses :: [ScriptWitness WitCtxMint era]
-> [(PolicyId, ScriptWitness WitCtxMint era)]
gatherMintingWitnesses [] = []
  gatherMintingWitnesses (ScriptWitness WitCtxMint era
sWit : [ScriptWitness WitCtxMint era]
rest) =
    case ScriptWitness WitCtxMint era -> Maybe PolicyId
forall witctx era. ScriptWitness witctx era -> Maybe PolicyId
scriptWitnessPolicyId ScriptWitness WitCtxMint era
sWit of
      Maybe PolicyId
Nothing -> [ScriptWitness WitCtxMint era]
-> [(PolicyId, ScriptWitness WitCtxMint era)]
gatherMintingWitnesses [ScriptWitness WitCtxMint era]
rest
      Just PolicyId
pid -> (PolicyId
pid, ScriptWitness WitCtxMint era
sWit) (PolicyId, ScriptWitness WitCtxMint era)
-> [(PolicyId, ScriptWitness WitCtxMint era)]
-> [(PolicyId, ScriptWitness WitCtxMint era)]
forall a. a -> [a] -> [a]
: [ScriptWitness WitCtxMint era]
-> [(PolicyId, ScriptWitness WitCtxMint era)]
gatherMintingWitnesses [ScriptWitness WitCtxMint era]
rest

  validateAllWitnessesProvided :: Set PolicyId -> Set PolicyId -> ExceptT ShelleyTxCmdError m ()
validateAllWitnessesProvided Set PolicyId
witnessesNeeded Set PolicyId
witnessesProvided
    | [PolicyId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PolicyId]
witnessesMissing = () -> ExceptT ShelleyTxCmdError m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    | Bool
otherwise = ShelleyTxCmdError -> ExceptT ShelleyTxCmdError m ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ([PolicyId] -> ShelleyTxCmdError
ShelleyTxCmdPolicyIdsMissing [PolicyId]
witnessesMissing)
    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 -> ExceptT ShelleyTxCmdError m ()
validateNoUnnecessaryWitnesses Set PolicyId
witnessesNeeded Set PolicyId
witnessesProvided
    | [PolicyId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PolicyId]
witnessesExtra = () -> ExceptT ShelleyTxCmdError m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    | Bool
otherwise = ShelleyTxCmdError -> ExceptT ShelleyTxCmdError m ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ([PolicyId] -> ShelleyTxCmdError
ShelleyTxCmdPolicyIdsExcess [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)

scriptWitnessPolicyId :: ScriptWitness witctx era -> Maybe PolicyId
scriptWitnessPolicyId :: ScriptWitness witctx era -> Maybe PolicyId
scriptWitnessPolicyId (SimpleScriptWitness ScriptLanguageInEra lang era
_ SimpleScriptVersion lang
version (SScript SimpleScript lang
script)) =
   PolicyId -> Maybe PolicyId
forall a. a -> Maybe a
Just (PolicyId -> Maybe PolicyId)
-> (Script lang -> PolicyId) -> Script lang -> Maybe PolicyId
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Script lang -> PolicyId
forall lang. Script lang -> PolicyId
scriptPolicyId (Script lang -> Maybe PolicyId) -> Script lang -> Maybe PolicyId
forall a b. (a -> b) -> a -> b
$ SimpleScriptVersion lang -> SimpleScript lang -> Script lang
forall lang.
SimpleScriptVersion lang -> SimpleScript lang -> Script lang
SimpleScript SimpleScriptVersion lang
version SimpleScript lang
script
scriptWitnessPolicyId (SimpleScriptWitness ScriptLanguageInEra lang era
_ SimpleScriptVersion lang
_ (SReferenceScript TxIn
_ Maybe ScriptHash
mPid)) =
   ScriptHash -> PolicyId
PolicyId (ScriptHash -> PolicyId) -> Maybe ScriptHash -> Maybe PolicyId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ScriptHash
mPid
scriptWitnessPolicyId (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
version (PScript PlutusScript lang
script) ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_) =
   PolicyId -> Maybe PolicyId
forall a. a -> Maybe a
Just (PolicyId -> Maybe PolicyId)
-> (Script lang -> PolicyId) -> Script lang -> Maybe PolicyId
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Script lang -> PolicyId
forall lang. Script lang -> PolicyId
scriptPolicyId (Script lang -> Maybe PolicyId) -> Script lang -> Maybe PolicyId
forall a b. (a -> b) -> a -> b
$ PlutusScriptVersion lang -> PlutusScript lang -> Script lang
forall lang.
PlutusScriptVersion lang -> PlutusScript lang -> Script lang
PlutusScript PlutusScriptVersion lang
version PlutusScript lang
script
scriptWitnessPolicyId (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ (PReferenceScript TxIn
_ Maybe ScriptHash
mPid) ScriptDatum witctx
_ ScriptRedeemer
_ ExecutionUnits
_) =
   ScriptHash -> PolicyId
PolicyId (ScriptHash -> PolicyId) -> Maybe ScriptHash -> Maybe PolicyId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ScriptHash
mPid

createScriptWitness
  :: CardanoEra era
  -> ScriptWitnessFiles witctx
  -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness :: CardanoEra era
-> ScriptWitnessFiles witctx
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
createScriptWitness CardanoEra era
era (SimpleScriptWitnessFile (ScriptFile String
scriptFile)) = do
    script :: ScriptInAnyLang
script@(ScriptInAnyLang ScriptLanguage lang
lang Script lang
_) <- (FileError ScriptDecodeError -> ShelleyTxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyTxCmdError
ShelleyTxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
 -> ExceptT ShelleyTxCmdError IO ScriptInAnyLang)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall a b. (a -> b) -> a -> b
$
                                         String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
scriptFile
    ScriptInEra ScriptLanguageInEra lang era
langInEra Script lang
script'   <- CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
forall era.
CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
validateScriptSupportedInEra CardanoEra era
era ScriptInAnyLang
script
    case Script lang
script' of
      SimpleScript SimpleScriptVersion lang
version SimpleScript lang
sscript ->
        ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptWitness witctx era
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> (SimpleScriptOrReferenceInput lang -> ScriptWitness witctx era)
-> SimpleScriptOrReferenceInput lang
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
SimpleScriptWitness
                   ScriptLanguageInEra lang era
langInEra SimpleScriptVersion lang
version (SimpleScriptOrReferenceInput lang
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> SimpleScriptOrReferenceInput lang
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ SimpleScript lang -> SimpleScriptOrReferenceInput lang
forall lang. SimpleScript lang -> SimpleScriptOrReferenceInput lang
SScript SimpleScript lang
sscript

      -- If the supplied cli flags were for a simple script (i.e. the user did
      -- not supply the datum, redeemer or ex units), but the script file turns
      -- out to be a valid plutus script, then we must fail.
      PlutusScript{} ->
        ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ String -> AnyScriptLanguage -> ShelleyTxCmdError
ShelleyTxCmdScriptExpectedSimple
                 String
scriptFile
                 (ScriptLanguage lang -> AnyScriptLanguage
forall lang. ScriptLanguage lang -> AnyScriptLanguage
AnyScriptLanguage ScriptLanguage lang
lang)

createScriptWitness CardanoEra era
era (PlutusScriptWitnessFiles
                          (ScriptFile String
scriptFile)
                          ScriptDatumOrFile witctx
datumOrFile
                          ScriptDataOrFile
redeemerOrFile
                          ExecutionUnits
execUnits) = do
    script :: ScriptInAnyLang
script@(ScriptInAnyLang ScriptLanguage lang
lang Script lang
_) <- (FileError ScriptDecodeError -> ShelleyTxCmdError)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyTxCmdError
ShelleyTxCmdScriptFileError (ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
 -> ExceptT ShelleyTxCmdError IO ScriptInAnyLang)
-> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO ScriptInAnyLang
forall a b. (a -> b) -> a -> b
$
                                         String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
scriptFile
    ScriptInEra ScriptLanguageInEra lang era
langInEra Script lang
script'   <- CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
forall era.
CardanoEra era
-> ScriptInAnyLang
-> ExceptT ShelleyTxCmdError IO (ScriptInEra era)
validateScriptSupportedInEra CardanoEra era
era ScriptInAnyLang
script
    case Script lang
script' of
      PlutusScript PlutusScriptVersion lang
version PlutusScript lang
pscript -> do
        ScriptDatum witctx
datum    <- ScriptDatumOrFile witctx
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
forall witctx.
ScriptDatumOrFile witctx
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
readScriptDatumOrFile    ScriptDatumOrFile witctx
datumOrFile
        ScriptRedeemer
redeemer <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptRedeemerOrFile ScriptDataOrFile
redeemerOrFile
        ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptWitness witctx era
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness
                   ScriptLanguageInEra lang era
langInEra PlutusScriptVersion lang
version (PlutusScript lang -> PlutusScriptOrReferenceInput lang
forall lang. PlutusScript lang -> PlutusScriptOrReferenceInput lang
PScript PlutusScript lang
pscript)
                   ScriptDatum witctx
datum
                   ScriptRedeemer
redeemer
                   ExecutionUnits
execUnits

      -- If the supplied cli flags were for a plutus script (i.e. the user did
      -- supply the datum, redeemer and ex units), but the script file turns
      -- out to be a valid simple script, then we must fail.
      SimpleScript{} ->
        ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ String -> AnyScriptLanguage -> ShelleyTxCmdError
ShelleyTxCmdScriptExpectedPlutus
                 String
scriptFile
                 (ScriptLanguage lang -> AnyScriptLanguage
forall lang. ScriptLanguage lang -> AnyScriptLanguage
AnyScriptLanguage ScriptLanguage lang
lang)

createScriptWitness CardanoEra era
era (PlutusReferenceScriptWitnessFiles TxIn
refTxIn
                          anyScrLang :: AnyScriptLanguage
anyScrLang@(AnyScriptLanguage ScriptLanguage lang
anyScriptLanguage)
                          ScriptDatumOrFile witctx
datumOrFile ScriptDataOrFile
redeemerOrFile ExecutionUnits
execUnits Maybe PolicyId
mPid) = do
  case CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra era
era of
    Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing -> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdReferenceScriptsNotSupportedInEra
                    (AnyCardanoEra -> ShelleyTxCmdError)
-> AnyCardanoEra -> ShelleyTxCmdError
forall a b. (a -> b) -> a -> b
$ CardanoEra era
-> (IsCardanoEra era => AnyCardanoEra) -> AnyCardanoEra
forall era a. CardanoEra era -> (IsCardanoEra era => a) -> a
getIsCardanoEraConstraint CardanoEra era
era (CardanoEra era -> AnyCardanoEra
forall era. IsCardanoEra era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra CardanoEra era
era)
    Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ -> do

      case CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
anyScriptLanguage of
        Just ScriptLanguageInEra lang era
sLangInEra ->
          case ScriptLanguageInEra lang era -> ScriptLanguage lang
forall lang era.
ScriptLanguageInEra lang era -> ScriptLanguage lang
languageOfScriptLanguageInEra ScriptLanguageInEra lang era
sLangInEra of
            SimpleScriptLanguage SimpleScriptVersion lang
_v ->
              -- TODO: We likely need another datatype eg data ReferenceScriptWitness lang
              -- in order to make this branch unrepresentable.
              Text -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a. HasCallStack => Text -> a
panic Text
"createScriptWitness: Should not be possible to specify a simple script"
            PlutusScriptLanguage PlutusScriptVersion lang
version -> do
              ScriptDatum witctx
datum    <- ScriptDatumOrFile witctx
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
forall witctx.
ScriptDatumOrFile witctx
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
readScriptDatumOrFile    ScriptDatumOrFile witctx
datumOrFile
              ScriptRedeemer
redeemer <- ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptRedeemerOrFile ScriptDataOrFile
redeemerOrFile
              ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptWitness witctx era
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness
                         ScriptLanguageInEra lang era
sLangInEra
                         PlutusScriptVersion lang
version
                         (TxIn -> Maybe ScriptHash -> PlutusScriptOrReferenceInput lang
forall lang.
TxIn -> Maybe ScriptHash -> PlutusScriptOrReferenceInput lang
PReferenceScript TxIn
refTxIn (PolicyId -> ScriptHash
unPolicyId (PolicyId -> ScriptHash) -> Maybe PolicyId -> Maybe ScriptHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe PolicyId
mPid))
                         ScriptDatum witctx
datum ScriptRedeemer
redeemer ExecutionUnits
execUnits
        Maybe (ScriptLanguageInEra lang era)
Nothing ->
          ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ AnyScriptLanguage -> AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdScriptLanguageNotSupportedInEra AnyScriptLanguage
anyScrLang (CardanoEra era -> AnyCardanoEra
forall era. CardanoEra era -> AnyCardanoEra
anyCardanoEra CardanoEra era
era)
createScriptWitness CardanoEra era
era (SimpleReferenceScriptWitnessFiles TxIn
refTxIn
                         anyScrLang :: AnyScriptLanguage
anyScrLang@(AnyScriptLanguage ScriptLanguage lang
anyScriptLanguage) Maybe PolicyId
mPid) = do
  case CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra era
era of
    Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing -> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdReferenceScriptsNotSupportedInEra
                    (AnyCardanoEra -> ShelleyTxCmdError)
-> AnyCardanoEra -> ShelleyTxCmdError
forall a b. (a -> b) -> a -> b
$ CardanoEra era
-> (IsCardanoEra era => AnyCardanoEra) -> AnyCardanoEra
forall era a. CardanoEra era -> (IsCardanoEra era => a) -> a
getIsCardanoEraConstraint CardanoEra era
era (CardanoEra era -> AnyCardanoEra
forall era. IsCardanoEra era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra CardanoEra era
era)
    Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ -> do
      case CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
anyScriptLanguage of
        Just ScriptLanguageInEra lang era
sLangInEra ->
          case ScriptLanguageInEra lang era -> ScriptLanguage lang
forall lang era.
ScriptLanguageInEra lang era -> ScriptLanguage lang
languageOfScriptLanguageInEra ScriptLanguageInEra lang era
sLangInEra of
            SimpleScriptLanguage SimpleScriptVersion lang
v ->
              ScriptWitness witctx era
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptWitness witctx era
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> (SimpleScriptOrReferenceInput lang -> ScriptWitness witctx era)
-> SimpleScriptOrReferenceInput lang
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
SimpleScriptWitness ScriptLanguageInEra lang era
sLangInEra SimpleScriptVersion lang
v
                     (SimpleScriptOrReferenceInput lang
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> SimpleScriptOrReferenceInput lang
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ TxIn -> Maybe ScriptHash -> SimpleScriptOrReferenceInput lang
forall lang.
TxIn -> Maybe ScriptHash -> SimpleScriptOrReferenceInput lang
SReferenceScript TxIn
refTxIn (PolicyId -> ScriptHash
unPolicyId (PolicyId -> ScriptHash) -> Maybe PolicyId -> Maybe ScriptHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe PolicyId
mPid)
            PlutusScriptLanguage{} ->
              Text -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a. HasCallStack => Text -> a
panic Text
"createScriptWitness: Should not be possible to specify a plutus script"
        Maybe (ScriptLanguageInEra lang era)
Nothing ->
          ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError
 -> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era))
-> ShelleyTxCmdError
-> ExceptT ShelleyTxCmdError IO (ScriptWitness witctx era)
forall a b. (a -> b) -> a -> b
$ AnyScriptLanguage -> AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdScriptLanguageNotSupportedInEra AnyScriptLanguage
anyScrLang (CardanoEra era -> AnyCardanoEra
forall era. CardanoEra era -> AnyCardanoEra
anyCardanoEra CardanoEra era
era)

readScriptDatumOrFile :: ScriptDatumOrFile witctx
                      -> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
readScriptDatumOrFile :: ScriptDatumOrFile witctx
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
readScriptDatumOrFile (ScriptDatumOrFileForTxIn ScriptDataOrFile
df) = ScriptRedeemer -> ScriptDatum WitCtxTxIn
ScriptDatumForTxIn (ScriptRedeemer -> ScriptDatum WitCtxTxIn)
-> ExceptT ShelleyTxCmdError IO ScriptRedeemer
-> ExceptT ShelleyTxCmdError IO (ScriptDatum WitCtxTxIn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                                                        ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile ScriptDataOrFile
df
readScriptDatumOrFile ScriptDatumOrFile witctx
InlineDatumPresentAtTxIn      = ScriptDatum WitCtxTxIn
-> ExceptT ShelleyTxCmdError IO (ScriptDatum WitCtxTxIn)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScriptDatum WitCtxTxIn
InlineScriptDatum
readScriptDatumOrFile ScriptDatumOrFile witctx
NoScriptDatumOrFileForMint    = ScriptDatum WitCtxMint
-> ExceptT ShelleyTxCmdError IO (ScriptDatum WitCtxMint)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScriptDatum WitCtxMint
NoScriptDatumForMint
readScriptDatumOrFile ScriptDatumOrFile witctx
NoScriptDatumOrFileForStake   = ScriptDatum WitCtxStake
-> ExceptT ShelleyTxCmdError IO (ScriptDatum WitCtxStake)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScriptDatum WitCtxStake
NoScriptDatumForStake

readScriptRedeemerOrFile :: ScriptRedeemerOrFile
                         -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptRedeemerOrFile :: ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptRedeemerOrFile = ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile

readScriptDataOrFile :: ScriptDataOrFile
                     -> ExceptT ShelleyTxCmdError IO ScriptData
readScriptDataOrFile :: ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
readScriptDataOrFile (ScriptDataValue ScriptRedeemer
d) = ScriptRedeemer -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall (m :: * -> *) a. Monad m => a -> m a
return ScriptRedeemer
d
readScriptDataOrFile (ScriptDataJsonFile String
fp) = do
  ByteString
bs <- (IOException -> ShelleyTxCmdError)
-> IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString
forall (m :: * -> *) x a.
MonadIO m =>
(IOException -> x) -> IO a -> ExceptT x m a
handleIOExceptT (FileError () -> ShelleyTxCmdError
ShelleyTxCmdReadFileError (FileError () -> ShelleyTxCmdError)
-> (IOException -> FileError ())
-> IOException
-> ShelleyTxCmdError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> IOException -> FileError ()
forall e. String -> IOException -> FileError e
FileIOError String
fp) (IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString)
-> IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString
forall a b. (a -> b) -> a -> b
$ String -> IO ByteString
LBS.readFile String
fp
  Value
v  <- (String -> ShelleyTxCmdError)
-> ExceptT String IO Value -> ExceptT ShelleyTxCmdError IO Value
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> String -> ShelleyTxCmdError
ShelleyTxCmdScriptDataJsonParseError String
fp)
          (ExceptT String IO Value -> ExceptT ShelleyTxCmdError IO Value)
-> ExceptT String IO Value -> ExceptT ShelleyTxCmdError IO Value
forall a b. (a -> b) -> a -> b
$ Either String Value -> ExceptT String IO Value
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either String Value -> ExceptT String IO Value)
-> Either String Value -> ExceptT String IO Value
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String Value
forall a. FromJSON a => ByteString -> Either String a
Aeson.eitherDecode' ByteString
bs
  ScriptRedeemer
sd <- (ScriptDataJsonError -> ShelleyTxCmdError)
-> ExceptT ScriptDataJsonError IO ScriptRedeemer
-> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> ScriptDataJsonError -> ShelleyTxCmdError
ShelleyTxCmdScriptDataConversionError String
fp)
          (ExceptT ScriptDataJsonError IO ScriptRedeemer
 -> ExceptT ShelleyTxCmdError IO ScriptRedeemer)
-> ExceptT ScriptDataJsonError IO ScriptRedeemer
-> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ Either ScriptDataJsonError ScriptRedeemer
-> ExceptT ScriptDataJsonError IO ScriptRedeemer
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ScriptDataJsonError ScriptRedeemer
 -> ExceptT ScriptDataJsonError IO ScriptRedeemer)
-> Either ScriptDataJsonError ScriptRedeemer
-> ExceptT ScriptDataJsonError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ ScriptDataJsonSchema
-> Value -> Either ScriptDataJsonError ScriptRedeemer
scriptDataFromJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema Value
v
  (ScriptDataRangeError -> ShelleyTxCmdError)
-> ExceptT ScriptDataRangeError IO ()
-> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> ScriptDataRangeError -> ShelleyTxCmdError
ShelleyTxCmdScriptDataValidationError String
fp)
          (ExceptT ScriptDataRangeError IO ()
 -> ExceptT ShelleyTxCmdError IO ())
-> ExceptT ScriptDataRangeError IO ()
-> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Either ScriptDataRangeError ()
-> ExceptT ScriptDataRangeError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ScriptDataRangeError ()
 -> ExceptT ScriptDataRangeError IO ())
-> Either ScriptDataRangeError ()
-> ExceptT ScriptDataRangeError IO ()
forall a b. (a -> b) -> a -> b
$ ScriptRedeemer -> Either ScriptDataRangeError ()
validateScriptData ScriptRedeemer
sd
  ScriptRedeemer -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall (m :: * -> *) a. Monad m => a -> m a
return ScriptRedeemer
sd
readScriptDataOrFile (ScriptDataCborFile String
fp) = do
  ByteString
bs <- (IOException -> ShelleyTxCmdError)
-> IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString
forall (m :: * -> *) x a.
MonadIO m =>
(IOException -> x) -> IO a -> ExceptT x m a
handleIOExceptT (FileError () -> ShelleyTxCmdError
ShelleyTxCmdReadFileError (FileError () -> ShelleyTxCmdError)
-> (IOException -> FileError ())
-> IOException
-> ShelleyTxCmdError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> IOException -> FileError ()
forall e. String -> IOException -> FileError e
FileIOError String
fp)
          (IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString)
-> IO ByteString -> ExceptT ShelleyTxCmdError IO ByteString
forall a b. (a -> b) -> a -> b
$ String -> IO ByteString
BS.readFile String
fp
  ScriptRedeemer
sd <- (DecoderError -> ShelleyTxCmdError)
-> ExceptT DecoderError IO ScriptRedeemer
-> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> DecoderError -> ShelleyTxCmdError
ShelleyTxCmdMetaDecodeError String
fp)
          (ExceptT DecoderError IO ScriptRedeemer
 -> ExceptT ShelleyTxCmdError IO ScriptRedeemer)
-> ExceptT DecoderError IO ScriptRedeemer
-> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ Either DecoderError ScriptRedeemer
-> ExceptT DecoderError IO ScriptRedeemer
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either DecoderError ScriptRedeemer
 -> ExceptT DecoderError IO ScriptRedeemer)
-> Either DecoderError ScriptRedeemer
-> ExceptT DecoderError IO ScriptRedeemer
forall a b. (a -> b) -> a -> b
$ AsType ScriptRedeemer
-> ByteString -> Either DecoderError ScriptRedeemer
forall a.
SerialiseAsCBOR a =>
AsType a -> ByteString -> Either DecoderError a
deserialiseFromCBOR AsType ScriptRedeemer
AsScriptData ByteString
bs
  (ScriptDataRangeError -> ShelleyTxCmdError)
-> ExceptT ScriptDataRangeError IO ()
-> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> ScriptDataRangeError -> ShelleyTxCmdError
ShelleyTxCmdScriptDataValidationError String
fp)
          (ExceptT ScriptDataRangeError IO ()
 -> ExceptT ShelleyTxCmdError IO ())
-> ExceptT ScriptDataRangeError IO ()
-> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Either ScriptDataRangeError ()
-> ExceptT ScriptDataRangeError IO ()
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ScriptDataRangeError ()
 -> ExceptT ScriptDataRangeError IO ())
-> Either ScriptDataRangeError ()
-> ExceptT ScriptDataRangeError IO ()
forall a b. (a -> b) -> a -> b
$ ScriptRedeemer -> Either ScriptDataRangeError ()
validateScriptData ScriptRedeemer
sd
  ScriptRedeemer -> ExceptT ShelleyTxCmdError IO ScriptRedeemer
forall (m :: * -> *) a. Monad m => a -> m a
return ScriptRedeemer
sd

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

runTxSign :: InputTxBodyOrTxFile
          -> [WitnessSigningData]
          -> Maybe NetworkId
          -> TxFile
          -> ExceptT ShelleyTxCmdError IO ()
runTxSign :: InputTxBodyOrTxFile
-> [WitnessSigningData]
-> Maybe NetworkId
-> TxFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSign InputTxBodyOrTxFile
txOrTxBody [WitnessSigningData]
witSigningData Maybe NetworkId
mnw (TxFile String
outTxFile) = do
  [SomeWitness]
sks <- (ReadWitnessSigningDataError -> ShelleyTxCmdError)
-> ExceptT ReadWitnessSigningDataError IO [SomeWitness]
-> ExceptT ShelleyTxCmdError IO [SomeWitness]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ReadWitnessSigningDataError -> ShelleyTxCmdError
ShelleyTxCmdReadWitnessSigningDataError (ExceptT ReadWitnessSigningDataError IO [SomeWitness]
 -> ExceptT ShelleyTxCmdError IO [SomeWitness])
-> ExceptT ReadWitnessSigningDataError IO [SomeWitness]
-> ExceptT ShelleyTxCmdError IO [SomeWitness]
forall a b. (a -> b) -> a -> b
$
            (WitnessSigningData
 -> ExceptT ReadWitnessSigningDataError IO SomeWitness)
-> [WitnessSigningData]
-> ExceptT ReadWitnessSigningDataError IO [SomeWitness]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM WitnessSigningData
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
readWitnessSigningData [WitnessSigningData]
witSigningData

  let ([ShelleyBootstrapWitnessSigningKeyData]
sksByron, [ShelleyWitnessSigningKey]
sksShelley) = [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
partitionSomeWitnesses ([ByronOrShelleyWitness]
 -> ([ShelleyBootstrapWitnessSigningKeyData],
     [ShelleyWitnessSigningKey]))
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
    [ShelleyWitnessSigningKey])
forall a b. (a -> b) -> a -> b
$ (SomeWitness -> ByronOrShelleyWitness)
-> [SomeWitness] -> [ByronOrShelleyWitness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map SomeWitness -> ByronOrShelleyWitness
categoriseSomeWitness [SomeWitness]
sks

  case InputTxBodyOrTxFile
txOrTxBody of
    (InputTxFile (TxFile String
inputTxFile)) -> do
      InAnyCardanoEra Tx
anyTx <- String -> ExceptT ShelleyTxCmdError IO (InAnyCardanoEra Tx)
readFileTx String
inputTxFile

      InAnyShelleyBasedEra ShelleyBasedEra era
_era Tx era
tx <-
          Text
-> InAnyCardanoEra Tx
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra Tx)
forall (a :: * -> *).
Text
-> InAnyCardanoEra a
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra a)
onlyInShelleyBasedEras Text
"sign for Byron era transactions" InAnyCardanoEra Tx
anyTx

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

      [KeyWitness era]
byronWitnesses <- (ShelleyBootstrapWitnessError -> ShelleyTxCmdError)
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyBootstrapWitnessError -> ShelleyTxCmdError
ShelleyTxCmdBootstrapWitnessError
                          (ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> (Either ShelleyBootstrapWitnessError [KeyWitness era]
    -> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
                          (Either ShelleyBootstrapWitnessError [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
forall era.
IsShelleyBasedEra era =>
Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses Maybe NetworkId
mnw TxBody era
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron

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

      (FileError () -> ShelleyTxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyTxCmdError
ShelleyTxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 ShelleyTxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
        String -> Tx era -> IO (Either (FileError ()) ())
forall era.
IsCardanoEra era =>
String -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl String
outTxFile Tx era
signedTx

    (InputTxBodyFile (TxBodyFile String
txbodyFile)) -> do
      IncompleteTx
unwitnessed <- String -> ExceptT ShelleyTxCmdError IO IncompleteTx
readFileTxBody String
txbodyFile

      case IncompleteTx
unwitnessed of
        IncompleteCddlFormattedTx InAnyCardanoEra Tx
anyTx -> do
         InAnyShelleyBasedEra ShelleyBasedEra era
_era Tx era
unwitTx <-
           Text
-> InAnyCardanoEra Tx
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra Tx)
forall (a :: * -> *).
Text
-> InAnyCardanoEra a
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra a)
onlyInShelleyBasedEras Text
"sign for Byron era transactions" InAnyCardanoEra Tx
anyTx

         let txbody :: TxBody era
txbody = Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
unwitTx
         -- Byron witnesses require the network ID. This can either be provided
         -- directly or derived from a provided Byron address.
         [KeyWitness era]
byronWitnesses <- (ShelleyBootstrapWitnessError -> ShelleyTxCmdError)
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyBootstrapWitnessError -> ShelleyTxCmdError
ShelleyTxCmdBootstrapWitnessError
           (ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> (Either ShelleyBootstrapWitnessError [KeyWitness era]
    -> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
           (Either ShelleyBootstrapWitnessError [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
forall era.
IsShelleyBasedEra era =>
Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses Maybe NetworkId
mnw TxBody era
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron

         let shelleyKeyWitnesses :: [KeyWitness era]
shelleyKeyWitnesses = (ShelleyWitnessSigningKey -> KeyWitness era)
-> [ShelleyWitnessSigningKey] -> [KeyWitness era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness 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

         (FileError () -> ShelleyTxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyTxCmdError
ShelleyTxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 ShelleyTxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
                      String -> Tx era -> IO (Either (FileError ()) ())
forall era.
IsCardanoEra era =>
String -> Tx era -> IO (Either (FileError ()) ())
writeTxFileTextEnvelopeCddl String
outTxFile Tx era
tx

        UnwitnessedCliFormattedTxBody InAnyCardanoEra TxBody
anyTxbody -> do
          InAnyShelleyBasedEra ShelleyBasedEra era
_era TxBody era
txbody <-
            --TODO: in principle we should be able to support Byron era txs too
            Text
-> InAnyCardanoEra TxBody
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra TxBody)
forall (a :: * -> *).
Text
-> InAnyCardanoEra a
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra a)
onlyInShelleyBasedEras Text
"sign for Byron era transactions" InAnyCardanoEra TxBody
anyTxbody
          -- Byron witnesses require the network ID. This can either be provided
          -- directly or derived from a provided Byron address.
          [KeyWitness era]
byronWitnesses <- (ShelleyBootstrapWitnessError -> ShelleyTxCmdError)
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyBootstrapWitnessError -> ShelleyTxCmdError
ShelleyTxCmdBootstrapWitnessError
            (ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> (Either ShelleyBootstrapWitnessError [KeyWitness era]
    -> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyBootstrapWitnessError IO [KeyWitness era]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
            (Either ShelleyBootstrapWitnessError [KeyWitness era]
 -> ExceptT ShelleyTxCmdError IO [KeyWitness era])
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
-> ExceptT ShelleyTxCmdError IO [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
forall era.
IsShelleyBasedEra era =>
Maybe NetworkId
-> TxBody era
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [KeyWitness era]
mkShelleyBootstrapWitnesses Maybe NetworkId
mnw TxBody era
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron

          let shelleyKeyWitnesses :: [KeyWitness era]
shelleyKeyWitnesses = (ShelleyWitnessSigningKey -> KeyWitness era)
-> [ShelleyWitnessSigningKey] -> [KeyWitness era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness 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

          (FileError () -> ShelleyTxCmdError)
-> ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyTxCmdError
ShelleyTxCmdWriteFileError (ExceptT (FileError ()) IO () -> ExceptT ShelleyTxCmdError IO ())
-> (IO (Either (FileError ()) ()) -> ExceptT (FileError ()) IO ())
-> IO (Either (FileError ()) ())
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 ShelleyTxCmdError IO ())
-> IO (Either (FileError ()) ()) -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$
            String
-> Maybe TextEnvelopeDescr
-> Tx era
-> IO (Either (FileError ()) ())
forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
writeFileTextEnvelope String
outTxFile Maybe TextEnvelopeDescr
forall a. Maybe a
Nothing Tx era
tx

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


runTxSubmit
  :: AnyConsensusModeParams
  -> NetworkId
  -> FilePath
  -> ExceptT ShelleyTxCmdError IO ()
runTxSubmit :: AnyConsensusModeParams
-> NetworkId -> String -> ExceptT ShelleyTxCmdError IO ()
runTxSubmit (AnyConsensusModeParams ConsensusModeParams mode
cModeParams) NetworkId
network String
txFile = do
    SocketPath String
sockPath <- (EnvSocketError -> ShelleyTxCmdError)
-> ExceptT EnvSocketError IO SocketPath
-> ExceptT ShelleyTxCmdError IO SocketPath
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT EnvSocketError -> ShelleyTxCmdError
ShelleyTxCmdSocketEnvError
                             (ExceptT EnvSocketError IO SocketPath
 -> ExceptT ShelleyTxCmdError IO SocketPath)
-> ExceptT EnvSocketError IO SocketPath
-> ExceptT ShelleyTxCmdError IO SocketPath
forall a b. (a -> b) -> a -> b
$ IO (Either EnvSocketError SocketPath)
-> ExceptT EnvSocketError IO SocketPath
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT IO (Either EnvSocketError SocketPath)
readEnvSocketPath

    InAnyCardanoEra CardanoEra era
era Tx era
tx <- String -> ExceptT ShelleyTxCmdError IO (InAnyCardanoEra Tx)
readFileTx String
txFile
    let cMode :: AnyConsensusMode
cMode = ConsensusMode mode -> AnyConsensusMode
forall mode. ConsensusMode mode -> AnyConsensusMode
AnyConsensusMode (ConsensusMode mode -> AnyConsensusMode)
-> ConsensusMode mode -> AnyConsensusMode
forall a b. (a -> b) -> a -> b
$ ConsensusModeParams mode -> ConsensusMode mode
forall mode. ConsensusModeParams mode -> ConsensusMode mode
consensusModeOnly ConsensusModeParams mode
cModeParams
    EraInMode era mode
eraInMode <- ShelleyTxCmdError
-> Maybe (EraInMode era mode)
-> ExceptT ShelleyTxCmdError IO (EraInMode era mode)
forall (m :: * -> *) x a. Monad m => x -> Maybe a -> ExceptT x m a
hoistMaybe
                   (Maybe String
-> AnyConsensusMode -> AnyCardanoEra -> ShelleyTxCmdError
ShelleyTxCmdEraConsensusModeMismatch (String -> Maybe String
forall a. a -> Maybe a
Just String
txFile) AnyConsensusMode
cMode (CardanoEra era -> AnyCardanoEra
forall era. IsCardanoEra era => CardanoEra era -> AnyCardanoEra
AnyCardanoEra CardanoEra era
era))
                   (CardanoEra era -> ConsensusMode mode -> Maybe (EraInMode era mode)
forall era mode.
CardanoEra era -> ConsensusMode mode -> Maybe (EraInMode era mode)
toEraInMode CardanoEra era
era (ConsensusMode mode -> Maybe (EraInMode era mode))
-> ConsensusMode mode -> Maybe (EraInMode era mode)
forall a b. (a -> b) -> a -> b
$ ConsensusModeParams mode -> ConsensusMode mode
forall mode. ConsensusModeParams mode -> ConsensusMode mode
consensusModeOnly ConsensusModeParams mode
cModeParams)
    let txInMode :: TxInMode mode
txInMode = Tx era -> EraInMode era mode -> TxInMode mode
forall era mode. Tx era -> EraInMode era mode -> TxInMode mode
TxInMode Tx era
tx EraInMode era mode
eraInMode
        localNodeConnInfo :: LocalNodeConnectInfo mode
localNodeConnInfo = LocalNodeConnectInfo :: forall mode.
ConsensusModeParams mode
-> NetworkId -> String -> LocalNodeConnectInfo mode
LocalNodeConnectInfo
                              { localConsensusModeParams :: ConsensusModeParams mode
localConsensusModeParams = ConsensusModeParams mode
cModeParams
                              , localNodeNetworkId :: NetworkId
localNodeNetworkId = NetworkId
network
                              , localNodeSocketPath :: String
localNodeSocketPath = String
sockPath
                              }

    SubmitResult (TxValidationErrorInMode mode)
res <- IO (SubmitResult (TxValidationErrorInMode mode))
-> ExceptT
     ShelleyTxCmdError IO (SubmitResult (TxValidationErrorInMode mode))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (SubmitResult (TxValidationErrorInMode mode))
 -> ExceptT
      ShelleyTxCmdError IO (SubmitResult (TxValidationErrorInMode mode)))
-> IO (SubmitResult (TxValidationErrorInMode mode))
-> ExceptT
     ShelleyTxCmdError IO (SubmitResult (TxValidationErrorInMode mode))
forall a b. (a -> b) -> a -> b
$ LocalNodeConnectInfo mode
-> TxInMode mode
-> IO (SubmitResult (TxValidationErrorInMode mode))
forall mode.
LocalNodeConnectInfo mode
-> TxInMode mode
-> IO (SubmitResult (TxValidationErrorInMode mode))
submitTxToNodeLocal LocalNodeConnectInfo mode
localNodeConnInfo TxInMode mode
txInMode
    case SubmitResult (TxValidationErrorInMode mode)
res of
      SubmitResult (TxValidationErrorInMode mode)
Net.Tx.SubmitSuccess -> IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ShelleyTxCmdError IO ())
-> IO () -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Text -> IO ()
putTextLn Text
"Transaction successfully submitted."
      Net.Tx.SubmitFail TxValidationErrorInMode mode
reason ->
        case TxValidationErrorInMode mode
reason of
          TxValidationErrorInMode TxValidationError era
err EraInMode era mode
_eraInMode -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ())
-> (String -> ShelleyTxCmdError)
-> String
-> ExceptT ShelleyTxCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitError (Text -> ShelleyTxCmdError)
-> (String -> Text) -> String -> ShelleyTxCmdError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> Text
Text.pack (String -> ExceptT ShelleyTxCmdError IO ())
-> String -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ TxValidationError era -> String
forall a b. (Show a, ConvertText String b) => a -> b
show TxValidationError era
err
          TxValidationEraMismatch EraMismatch
mismatchErr -> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ())
-> ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ EraMismatch -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorEraMismatch EraMismatch
mismatchErr

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

runTxCalculateMinFee
  :: TxBodyFile
  -> Maybe NetworkId
  -> ProtocolParamsSourceSpec
  -> TxInCount
  -> TxOutCount
  -> TxShelleyWitnessCount
  -> TxByronWitnessCount
  -> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee :: TxBodyFile
-> Maybe NetworkId
-> ProtocolParamsSourceSpec
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee (TxBodyFile String
txbodyFile) Maybe NetworkId
nw ProtocolParamsSourceSpec
protocolParamsSourceSpec
                     (TxInCount Int
nInputs) (TxOutCount Int
nOutputs)
                     (TxShelleyWitnessCount Int
nShelleyKeyWitnesses)
                     (TxByronWitnessCount Int
nByronKeyWitnesses) = do

    IncompleteTx
unwitnessed <- String -> ExceptT ShelleyTxCmdError IO IncompleteTx
readFileTxBody String
txbodyFile
    ProtocolParameters
pparams <- ProtocolParamsSourceSpec
-> ExceptT ShelleyTxCmdError IO ProtocolParameters
readProtocolParametersSourceSpec ProtocolParamsSourceSpec
protocolParamsSourceSpec
    case IncompleteTx
unwitnessed of
      IncompleteCddlFormattedTx InAnyCardanoEra Tx
anyTx -> do
        InAnyShelleyBasedEra ShelleyBasedEra era
_era Tx era
unwitTx <-
          Text
-> InAnyCardanoEra Tx
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra Tx)
forall (a :: * -> *).
Text
-> InAnyCardanoEra a
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra a)
onlyInShelleyBasedEras Text
"sign for Byron era transactions" InAnyCardanoEra Tx
anyTx
        let txbody :: TxBody era
txbody =  Tx era -> TxBody era
forall era. Tx era -> TxBody era
getTxBody Tx era
unwitTx
        let tx :: Tx era
tx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
txbody
            Lovelace Integer
fee = NetworkId
-> Natural
-> Natural
-> Tx era
-> Int
-> Int
-> Int
-> Int
-> Lovelace
forall era.
IsShelleyBasedEra era =>
NetworkId
-> Natural
-> Natural
-> Tx era
-> Int
-> Int
-> Int
-> Int
-> Lovelace
estimateTransactionFee
                             (NetworkId -> Maybe NetworkId -> NetworkId
forall a. a -> Maybe a -> a
fromMaybe NetworkId
Mainnet Maybe NetworkId
nw)
                             (ProtocolParameters -> Natural
protocolParamTxFeeFixed ProtocolParameters
pparams)
                             (ProtocolParameters -> Natural
protocolParamTxFeePerByte ProtocolParameters
pparams)
                             Tx era
tx
                             Int
nInputs Int
nOutputs
                             Int
nByronKeyWitnesses Int
nShelleyKeyWitnesses

        IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ShelleyTxCmdError IO ())
-> IO () -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ (Integer -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Integer
fee :: String) String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" Lovelace"

      UnwitnessedCliFormattedTxBody InAnyCardanoEra TxBody
anyTxBody -> do
        InAnyShelleyBasedEra ShelleyBasedEra era
_era TxBody era
txbody <-
              --TODO: in principle we should be able to support Byron era txs too
              Text
-> InAnyCardanoEra TxBody
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra TxBody)
forall (a :: * -> *).
Text
-> InAnyCardanoEra a
-> ExceptT ShelleyTxCmdError IO (InAnyShelleyBasedEra a)
onlyInShelleyBasedEras Text
"calculate-min-fee for Byron era transactions" InAnyCardanoEra TxBody
anyTxBody

        let tx :: Tx era
tx = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] TxBody era
txbody
            Lovelace Integer
fee = NetworkId
-> Natural
-> Natural
-> Tx era
-> Int
-> Int
-> Int
-> Int
-> Lovelace
forall era.
IsShelleyBasedEra era =>
NetworkId
-> Natural
-> Natural
-> Tx era
-> Int
-> Int
-> Int
-> Int
-> Lovelace
estimateTransactionFee
                             (NetworkId -> Maybe NetworkId -> NetworkId
forall a. a -> Maybe a -> a
fromMaybe NetworkId
Mainnet Maybe NetworkId
nw)
                             (ProtocolParameters -> Natural
protocolParamTxFeeFixed ProtocolParameters
pparams)
                             (ProtocolParameters -> Natural
protocolParamTxFeePerByte ProtocolParameters
pparams)
                             Tx era
tx
                             Int
nInputs Int
nOutputs
                             Int
nByronKeyWitnesses Int
nShelleyKeyWitnesses

        IO () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ShelleyTxCmdError IO ())
-> IO () -> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ (Integer -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Integer
fee