{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module Cardano.CLI.Shelley.Run.Transaction
( ShelleyTxCmdError
, renderShelleyTxCmdError
, runTransactionCmd
) where
import Cardano.Prelude hiding (All, Any)
import Prelude (String)
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as Text
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither, left,
newExceptT)
import qualified Cardano.Binary as CBOR
import qualified Shelley.Spec.Ledger.PParams as Shelley
import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..), HardForkApplyTxErr (..))
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
import Cardano.CLI.Environment (EnvSocketError, readEnvSocketPath, renderEnvSocketError)
import Cardano.CLI.Shelley.Key (InputDecodeError, readSigningKeyFileAnyOf)
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Types
import Cardano.Api.MetaData
import Cardano.Api.Protocol
import Cardano.Api.TxSubmit as Api
import Cardano.Api.Typed as Api
data ShelleyTxCmdError
= ShelleyTxCmdAesonDecodeProtocolParamsError !FilePath !Text
| ShelleyTxCmdReadFileError !(FileError ())
| ShelleyTxCmdReadTextViewFileError !(FileError TextEnvelopeError)
| ShelleyTxCmdReadWitnessSigningDataError !ReadWitnessSigningDataError
| ShelleyTxCmdWriteFileError !(FileError ())
| ShelleyTxCmdMetaDataJsonParseError !FilePath !String
| ShelleyTxCmdMetaDataConversionError !FilePath !TxMetadataJsonError
| ShelleyTxCmdMetaValidationError !FilePath !TxMetadataRangeError
| ShelleyTxCmdMetaDecodeError !FilePath !CBOR.DecoderError
| ShelleyTxCmdBootstrapWitnessError !ShelleyBootstrapWitnessError
| ShelleyTxCmdSocketEnvError !EnvSocketError
| ShelleyTxCmdTxSubmitErrorByron !(ApplyTxErr ByronBlock)
| ShelleyTxCmdTxSubmitErrorShelley !(ApplyTxErr (ShelleyBlock StandardShelley))
| ShelleyTxCmdTxSubmitErrorEraMismatch !EraMismatch
deriving Int -> ShelleyTxCmdError -> ShowS
[ShelleyTxCmdError] -> ShowS
ShelleyTxCmdError -> String
(Int -> ShelleyTxCmdError -> ShowS)
-> (ShelleyTxCmdError -> String)
-> ([ShelleyTxCmdError] -> ShowS)
-> Show ShelleyTxCmdError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShelleyTxCmdError] -> ShowS
$cshowList :: [ShelleyTxCmdError] -> ShowS
show :: ShelleyTxCmdError -> String
$cshow :: ShelleyTxCmdError -> String
showsPrec :: Int -> ShelleyTxCmdError -> ShowS
$cshowsPrec :: Int -> ShelleyTxCmdError -> ShowS
Show
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)
ShelleyTxCmdReadWitnessSigningDataError ReadWitnessSigningDataError
witSignDataErr ->
ReadWitnessSigningDataError -> Text
renderReadWitnessSigningDataError ReadWitnessSigningDataError
witSignDataErr
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 TxMetadataRangeError
valErr ->
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
<> String -> Text
Text.pack (TxMetadataRangeError -> String
forall e. Error e => e -> String
displayError TxMetadataRangeError
valErr)
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
ShelleyTxCmdTxSubmitErrorByron ApplyTxErr ByronBlock
res ->
Text
"Error while submitting tx: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (ApplyMempoolPayloadErr -> String
forall a b. (Show a, ConvertText String b) => a -> b
show ApplyMempoolPayloadErr
ApplyTxErr ByronBlock
res)
ShelleyTxCmdTxSubmitErrorShelley ApplyTxErr (ShelleyBlock StandardShelley)
res ->
Text
"Error while submitting tx: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (ApplyTxError StandardShelley -> String
forall a b. (Show a, ConvertText String b) => a -> b
show ApplyTxErr (ShelleyBlock StandardShelley)
ApplyTxError StandardShelley
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
runTransactionCmd :: TransactionCmd -> ExceptT ShelleyTxCmdError IO ()
runTransactionCmd :: TransactionCmd -> ExceptT ShelleyTxCmdError IO ()
runTransactionCmd TransactionCmd
cmd =
case TransactionCmd
cmd of
TxBuildRaw [TxIn]
txins [TxOut Shelley]
txouts SlotNo
ttl Lovelace
fee [CertificateFile]
certs [(StakeAddress, Lovelace)]
wdrls
TxMetadataJsonSchema
metadataSchema [MetaDataFile]
metadataFiles Maybe UpdateProposalFile
mUpProp TxBodyFile
out ->
[TxIn]
-> [TxOut Shelley]
-> SlotNo
-> Lovelace
-> [CertificateFile]
-> [(StakeAddress, Lovelace)]
-> TxMetadataJsonSchema
-> [MetaDataFile]
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw [TxIn]
txins [TxOut Shelley]
txouts SlotNo
ttl Lovelace
fee [CertificateFile]
certs [(StakeAddress, Lovelace)]
wdrls
TxMetadataJsonSchema
metadataSchema [MetaDataFile]
metadataFiles Maybe UpdateProposalFile
mUpProp TxBodyFile
out
TxSign TxBodyFile
txinfile [WitnessSigningData]
skfiles Maybe NetworkId
network TxFile
txoutfile ->
TxBodyFile
-> [WitnessSigningData]
-> Maybe NetworkId
-> TxFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSign TxBodyFile
txinfile [WitnessSigningData]
skfiles Maybe NetworkId
network TxFile
txoutfile
TxSubmit Protocol
protocol NetworkId
network String
txFp ->
Protocol -> NetworkId -> String -> ExceptT ShelleyTxCmdError IO ()
runTxSubmit Protocol
protocol NetworkId
network String
txFp
TxCalculateMinFee TxBodyFile
txbody Maybe NetworkId
mnw ProtocolParamsFile
pParamsFile TxInCount
nInputs TxOutCount
nOutputs
TxShelleyWitnessCount
nShelleyKeyWitnesses TxByronWitnessCount
nByronKeyWitnesses ->
TxBodyFile
-> Maybe NetworkId
-> ProtocolParamsFile
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee TxBodyFile
txbody Maybe NetworkId
mnw ProtocolParamsFile
pParamsFile TxInCount
nInputs TxOutCount
nOutputs
TxShelleyWitnessCount
nShelleyKeyWitnesses TxByronWitnessCount
nByronKeyWitnesses
TxGetTxId TxBodyFile
txinfile ->
TxBodyFile -> ExceptT ShelleyTxCmdError IO ()
runTxGetTxId TxBodyFile
txinfile
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
runTxBuildRaw
:: [Api.TxIn]
-> [Api.TxOut Api.Shelley]
-> SlotNo
-> Api.Lovelace
-> [CertificateFile]
-> [(Api.StakeAddress, Api.Lovelace)]
-> TxMetadataJsonSchema
-> [MetaDataFile]
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw :: [TxIn]
-> [TxOut Shelley]
-> SlotNo
-> Lovelace
-> [CertificateFile]
-> [(StakeAddress, Lovelace)]
-> TxMetadataJsonSchema
-> [MetaDataFile]
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw [TxIn]
txins [TxOut Shelley]
txouts SlotNo
ttl Lovelace
fee
[CertificateFile]
certFiles [(StakeAddress, Lovelace)]
withdrawals
TxMetadataJsonSchema
metadataSchema [MetaDataFile]
metadataFiles
Maybe UpdateProposalFile
mUpdatePropFile
(TxBodyFile String
fpath) = 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)
Api.readFileTextEnvelope AsType Certificate
Api.AsCertificate String
certFile
| CertificateFile String
certFile <- [CertificateFile]
certFiles ]
Maybe TxMetadata
mMetaData <- case [MetaDataFile]
metadataFiles of
[] -> Maybe TxMetadata -> ExceptT ShelleyTxCmdError IO (Maybe TxMetadata)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TxMetadata
forall a. Maybe a
Nothing
[MetaDataFile]
files -> TxMetadata -> Maybe TxMetadata
forall a. a -> Maybe a
Just (TxMetadata -> Maybe TxMetadata)
-> ([TxMetadata] -> TxMetadata) -> [TxMetadata] -> Maybe TxMetadata
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [TxMetadata] -> TxMetadata
forall a. Monoid a => [a] -> a
mconcat ([TxMetadata] -> Maybe TxMetadata)
-> ExceptT ShelleyTxCmdError IO [TxMetadata]
-> ExceptT ShelleyTxCmdError IO (Maybe 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
metadataSchema) [MetaDataFile]
files
Maybe UpdateProposal
mUpdateProp <-
case Maybe UpdateProposalFile
mUpdatePropFile of
Maybe UpdateProposalFile
Nothing -> Maybe UpdateProposal
-> ExceptT ShelleyTxCmdError IO (Maybe UpdateProposal)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe UpdateProposal
forall a. Maybe a
Nothing
Just (UpdateProposalFile String
file) ->
(UpdateProposal -> Maybe UpdateProposal)
-> ExceptT ShelleyTxCmdError IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO (Maybe UpdateProposal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap UpdateProposal -> Maybe UpdateProposal
forall a. a -> Maybe a
Just (ExceptT ShelleyTxCmdError IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO (Maybe UpdateProposal))
-> (ExceptT (FileError TextEnvelopeError) IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO UpdateProposal)
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO (Maybe UpdateProposal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (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 (Maybe UpdateProposal))
-> ExceptT (FileError TextEnvelopeError) IO UpdateProposal
-> ExceptT ShelleyTxCmdError IO (Maybe 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)
Api.readFileTextEnvelope AsType UpdateProposal
Api.AsUpdateProposal String
file
let txBody :: TxBody Shelley
txBody = TxExtraContent
-> SlotNo
-> Lovelace
-> [TxIn]
-> [TxOut Shelley]
-> TxBody Shelley
forall anyera.
TxExtraContent
-> SlotNo -> Lovelace -> [TxIn] -> [TxOut anyera] -> TxBody Shelley
Api.makeShelleyTransaction
TxExtraContent
Api.txExtraContentEmpty {
txCertificates :: [Certificate]
Api.txCertificates = [Certificate]
certs,
txWithdrawals :: [(StakeAddress, Lovelace)]
Api.txWithdrawals = [(StakeAddress, Lovelace)]
withdrawals,
txMetadata :: Maybe TxMetadata
Api.txMetadata = Maybe TxMetadata
mMetaData,
txUpdateProposal :: Maybe UpdateProposal
Api.txUpdateProposal = Maybe UpdateProposal
mUpdateProp
}
SlotNo
ttl
Lovelace
fee
[TxIn]
txins
[TxOut Shelley]
txouts
(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
-> TxBody Shelley
-> IO (Either (FileError ()) ())
forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
Api.writeFileTextEnvelope String
fpath Maybe TextEnvelopeDescr
forall a. Maybe a
Nothing TxBody Shelley
txBody
runTxSign :: TxBodyFile
-> [WitnessSigningData]
-> Maybe Api.NetworkId
-> TxFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSign :: TxBodyFile
-> [WitnessSigningData]
-> Maybe NetworkId
-> TxFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSign (TxBodyFile String
txbodyFile) [WitnessSigningData]
witSigningData Maybe NetworkId
mnw (TxFile String
txFile) = do
TxBody Shelley
txbody <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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 (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
forall a b. (a -> b) -> a -> b
$
AsType (TxBody Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (TxBody Shelley)
Api.AsShelleyTxBody String
txbodyFile
[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, [MultiSigScript]
scsShelley) = [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
partitionSomeWitnesses ([ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript]))
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
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
[Witness Shelley]
byronWitnesses <- (ShelleyBootstrapWitnessError -> ShelleyTxCmdError)
-> ExceptT ShelleyBootstrapWitnessError IO [Witness Shelley]
-> ExceptT ShelleyTxCmdError IO [Witness Shelley]
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyBootstrapWitnessError -> ShelleyTxCmdError
ShelleyTxCmdBootstrapWitnessError
(ExceptT ShelleyBootstrapWitnessError IO [Witness Shelley]
-> ExceptT ShelleyTxCmdError IO [Witness Shelley])
-> (Either ShelleyBootstrapWitnessError [Witness Shelley]
-> ExceptT ShelleyBootstrapWitnessError IO [Witness Shelley])
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
-> ExceptT ShelleyTxCmdError IO [Witness Shelley]
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ShelleyBootstrapWitnessError [Witness Shelley]
-> ExceptT ShelleyBootstrapWitnessError IO [Witness Shelley]
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
(Either ShelleyBootstrapWitnessError [Witness Shelley]
-> ExceptT ShelleyTxCmdError IO [Witness Shelley])
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
-> ExceptT ShelleyTxCmdError IO [Witness Shelley]
forall a b. (a -> b) -> a -> b
$ Maybe NetworkId
-> TxBody Shelley
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
mkShelleyBootstrapWitnesses Maybe NetworkId
mnw TxBody Shelley
txbody [ShelleyBootstrapWitnessSigningKeyData]
sksByron
let shelleyKeyWitnesses :: [Witness Shelley]
shelleyKeyWitnesses = (ShelleyWitnessSigningKey -> Witness Shelley)
-> [ShelleyWitnessSigningKey] -> [Witness Shelley]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (TxBody Shelley -> ShelleyWitnessSigningKey -> Witness Shelley
Api.makeShelleyKeyWitness TxBody Shelley
txbody) [ShelleyWitnessSigningKey]
sksShelley
shelleyScriptWitnesses :: [Witness Shelley]
shelleyScriptWitnesses = (MultiSigScript -> Witness Shelley)
-> [MultiSigScript] -> [Witness Shelley]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (Script -> Witness Shelley
makeShelleyScriptWitness (Script -> Witness Shelley)
-> (MultiSigScript -> Script) -> MultiSigScript -> Witness Shelley
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. MultiSigScript -> Script
makeMultiSigScript) [MultiSigScript]
scsShelley
shelleyWitnesses :: [Witness Shelley]
shelleyWitnesses = [Witness Shelley]
shelleyKeyWitnesses [Witness Shelley] -> [Witness Shelley] -> [Witness Shelley]
forall a. [a] -> [a] -> [a]
++ [Witness Shelley]
shelleyScriptWitnesses
tx :: Tx Shelley
tx = [Witness Shelley] -> TxBody Shelley -> Tx Shelley
forall era. [Witness era] -> TxBody era -> Tx era
Api.makeSignedTransaction ([Witness Shelley]
byronWitnesses [Witness Shelley] -> [Witness Shelley] -> [Witness Shelley]
forall a. [a] -> [a] -> [a]
++ [Witness Shelley]
shelleyWitnesses) TxBody Shelley
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 Shelley
-> IO (Either (FileError ()) ())
forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
Api.writeFileTextEnvelope String
txFile Maybe TextEnvelopeDescr
forall a. Maybe a
Nothing Tx Shelley
tx
runTxSubmit :: Protocol -> NetworkId -> FilePath
-> ExceptT ShelleyTxCmdError IO ()
runTxSubmit :: Protocol -> NetworkId -> String -> ExceptT ShelleyTxCmdError IO ()
runTxSubmit Protocol
protocol 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
readEnvSocketPath
Either (Tx Byron) (Tx Shelley)
tx <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT
(FileError TextEnvelopeError) IO (Either (Tx Byron) (Tx Shelley))
-> ExceptT ShelleyTxCmdError IO (Either (Tx Byron) (Tx Shelley))
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 (Either (Tx Byron) (Tx Shelley))
-> ExceptT ShelleyTxCmdError IO (Either (Tx Byron) (Tx Shelley)))
-> (IO
(Either
(FileError TextEnvelopeError) (Either (Tx Byron) (Tx Shelley)))
-> ExceptT
(FileError TextEnvelopeError) IO (Either (Tx Byron) (Tx Shelley)))
-> IO
(Either
(FileError TextEnvelopeError) (Either (Tx Byron) (Tx Shelley)))
-> ExceptT ShelleyTxCmdError IO (Either (Tx Byron) (Tx Shelley))
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) (Either (Tx Byron) (Tx Shelley)))
-> ExceptT
(FileError TextEnvelopeError) IO (Either (Tx Byron) (Tx Shelley))
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
(IO
(Either
(FileError TextEnvelopeError) (Either (Tx Byron) (Tx Shelley)))
-> ExceptT ShelleyTxCmdError IO (Either (Tx Byron) (Tx Shelley)))
-> IO
(Either
(FileError TextEnvelopeError) (Either (Tx Byron) (Tx Shelley)))
-> ExceptT ShelleyTxCmdError IO (Either (Tx Byron) (Tx Shelley))
forall a b. (a -> b) -> a -> b
$ [FromSomeType HasTextEnvelope (Either (Tx Byron) (Tx Shelley))]
-> String
-> IO
(Either
(FileError TextEnvelopeError) (Either (Tx Byron) (Tx Shelley)))
forall b.
[FromSomeType HasTextEnvelope b]
-> String -> IO (Either (FileError TextEnvelopeError) b)
Api.readFileTextEnvelopeAnyOf
[ AsType (Tx Byron)
-> (Tx Byron -> Either (Tx Byron) (Tx Shelley))
-> FromSomeType HasTextEnvelope (Either (Tx Byron) (Tx Shelley))
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType AsType (Tx Byron)
Api.AsByronTx Tx Byron -> Either (Tx Byron) (Tx Shelley)
forall a b. a -> Either a b
Left
, AsType (Tx Shelley)
-> (Tx Shelley -> Either (Tx Byron) (Tx Shelley))
-> FromSomeType HasTextEnvelope (Either (Tx Byron) (Tx Shelley))
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType AsType (Tx Shelley)
Api.AsShelleyTx Tx Shelley -> Either (Tx Byron) (Tx Shelley)
forall a b. b -> Either a b
Right ]
String
txFile
Protocol
-> NetworkId
-> String
-> (forall mode block.
RunNode block =>
LocalNodeConnectInfo mode block -> ExceptT ShelleyTxCmdError IO ())
-> ExceptT ShelleyTxCmdError IO ()
forall a.
Protocol
-> NetworkId
-> String
-> (forall mode block.
RunNode block =>
LocalNodeConnectInfo mode block -> a)
-> a
withlocalNodeConnectInfo Protocol
protocol NetworkId
network String
sockPath ((forall mode block.
RunNode block =>
LocalNodeConnectInfo mode block -> ExceptT ShelleyTxCmdError IO ())
-> ExceptT ShelleyTxCmdError IO ())
-> (forall mode block.
RunNode block =>
LocalNodeConnectInfo mode block -> ExceptT ShelleyTxCmdError IO ())
-> ExceptT ShelleyTxCmdError IO ()
forall a b. (a -> b) -> a -> b
$ \LocalNodeConnectInfo mode block
connectInfo ->
case (LocalNodeConnectInfo mode block -> NodeConsensusMode mode block
forall mode block.
LocalNodeConnectInfo mode block -> NodeConsensusMode mode block
localNodeConsensusMode LocalNodeConnectInfo mode block
connectInfo, Either (Tx Byron) (Tx Shelley)
tx) of
(ByronMode{}, Left tx') -> do
TxSubmitResultForMode mode
result <- IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode))
-> IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall a b. (a -> b) -> a -> b
$ LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
forall mode block.
LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
Api.submitTx LocalNodeConnectInfo mode block
connectInfo (Tx Byron -> TxForMode ByronMode
TxForByronMode Tx Byron
tx')
case TxSubmitResultForMode mode
result of
TxSubmitResultForMode mode
TxSubmitSuccess -> () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
TxSubmitFailureByronMode ApplyTxErr ByronBlock
err ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr ByronBlock -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorByron ApplyTxErr ByronBlock
err)
(ByronMode{}, Right{}) ->
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 :: Text -> Text -> EraMismatch
EraMismatch {
ledgerEraName :: Text
ledgerEraName = Text
"Byron",
otherEraName :: Text
otherEraName = Text
"Shelley"
}
(ShelleyMode{}, Right tx') -> do
TxSubmitResultForMode mode
result <- IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode))
-> IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall a b. (a -> b) -> a -> b
$ LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
forall mode block.
LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
Api.submitTx LocalNodeConnectInfo mode block
connectInfo (Tx Shelley -> TxForMode ShelleyMode
TxForShelleyMode Tx Shelley
tx')
case TxSubmitResultForMode mode
result of
TxSubmitResultForMode mode
TxSubmitSuccess -> () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
TxSubmitFailureShelleyMode ApplyTxErr (ShelleyBlock StandardShelley)
err ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr (ShelleyBlock StandardShelley) -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorShelley ApplyTxErr (ShelleyBlock StandardShelley)
err)
(ShelleyMode{}, Left{}) ->
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 :: Text -> Text -> EraMismatch
EraMismatch {
ledgerEraName :: Text
ledgerEraName = Text
"Shelley",
otherEraName :: Text
otherEraName = Text
"Byron"
}
(CardanoMode{}, Either (Tx Byron) (Tx Shelley)
tx') -> do
TxSubmitResultForMode mode
result <- IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode))
-> IO (TxSubmitResultForMode mode)
-> ExceptT ShelleyTxCmdError IO (TxSubmitResultForMode mode)
forall a b. (a -> b) -> a -> b
$ LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
forall mode block.
LocalNodeConnectInfo mode block
-> TxForMode mode -> IO (TxSubmitResultForMode mode)
Api.submitTx LocalNodeConnectInfo mode block
connectInfo (Either (Tx Byron) (Tx Shelley) -> TxForMode CardanoMode
TxForCardanoMode Either (Tx Byron) (Tx Shelley)
tx')
case TxSubmitResultForMode mode
result of
TxSubmitResultForMode mode
TxSubmitSuccess -> () -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
TxSubmitFailureCardanoMode (ApplyTxErrByron ApplyTxErr ByronBlock
err) ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr ByronBlock -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorByron ApplyTxErr ByronBlock
err)
TxSubmitFailureCardanoMode (ApplyTxErrShelley ApplyTxErr (ShelleyBlock StandardShelley)
err) ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr (ShelleyBlock StandardShelley) -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorShelley ApplyTxErr (ShelleyBlock StandardShelley)
err)
TxSubmitFailureCardanoMode (ApplyTxErrAllegra ApplyTxErr (ShelleyBlock StandardShelley)
err) ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr (ShelleyBlock StandardShelley) -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorShelley ApplyTxErr (ShelleyBlock StandardShelley)
err)
TxSubmitFailureCardanoMode (ApplyTxErrMary ApplyTxErr (ShelleyBlock StandardShelley)
err) ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ApplyTxErr (ShelleyBlock StandardShelley) -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorShelley ApplyTxErr (ShelleyBlock StandardShelley)
err)
TxSubmitFailureCardanoMode (ApplyTxErrWrongEra EraMismatch
mismatch) ->
ShelleyTxCmdError -> ExceptT ShelleyTxCmdError IO ()
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (EraMismatch -> ShelleyTxCmdError
ShelleyTxCmdTxSubmitErrorEraMismatch EraMismatch
mismatch)
runTxCalculateMinFee
:: TxBodyFile
-> Maybe Api.NetworkId
-> ProtocolParamsFile
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee :: TxBodyFile
-> Maybe NetworkId
-> ProtocolParamsFile
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee (TxBodyFile String
txbodyFile) Maybe NetworkId
nw ProtocolParamsFile
pParamsFile
(TxInCount Int
nInputs) (TxOutCount Int
nOutputs)
(TxShelleyWitnessCount Int
nShelleyKeyWitnesses)
(TxByronWitnessCount Int
nByronKeyWitnesses) = do
TxBody Shelley
txbody <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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 (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
forall a b. (a -> b) -> a -> b
$
AsType (TxBody Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (TxBody Shelley)
Api.AsShelleyTxBody String
txbodyFile
PParams StandardShelley
pparams <- ProtocolParamsFile
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley)
readProtocolParameters ProtocolParamsFile
pParamsFile
let tx :: Tx Shelley
tx = [Witness Shelley] -> TxBody Shelley -> Tx Shelley
forall era. [Witness era] -> TxBody era -> Tx era
Api.makeSignedTransaction [] TxBody Shelley
txbody
Api.Lovelace Integer
fee = NetworkId
-> Natural
-> Natural
-> Tx Shelley
-> Int
-> Int
-> Int
-> Int
-> Lovelace
Api.estimateTransactionFee
(NetworkId -> Maybe NetworkId -> NetworkId
forall a. a -> Maybe a -> a
fromMaybe NetworkId
Api.Mainnet Maybe NetworkId
nw)
(PParams StandardShelley -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
Shelley._minfeeB PParams StandardShelley
pparams)
(PParams StandardShelley -> HKD Identity Natural
forall (f :: * -> *) era. PParams' f era -> HKD f Natural
Shelley._minfeeA PParams StandardShelley
pparams)
Tx Shelley
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 -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" Lovelace"
readProtocolParameters :: ProtocolParamsFile
-> ExceptT ShelleyTxCmdError IO (Shelley.PParams StandardShelley)
readProtocolParameters :: ProtocolParamsFile
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley)
readProtocolParameters (ProtocolParamsFile String
fpath) = do
ByteString
pparams <- (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
fpath) (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
fpath
(String -> ShelleyTxCmdError)
-> ExceptT String IO (PParams StandardShelley)
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> Text -> ShelleyTxCmdError
ShelleyTxCmdAesonDecodeProtocolParamsError String
fpath (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) (ExceptT String IO (PParams StandardShelley)
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley))
-> (Either String (PParams StandardShelley)
-> ExceptT String IO (PParams StandardShelley))
-> Either String (PParams StandardShelley)
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either String (PParams StandardShelley)
-> ExceptT String IO (PParams StandardShelley)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either String (PParams StandardShelley)
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley))
-> Either String (PParams StandardShelley)
-> ExceptT ShelleyTxCmdError IO (PParams StandardShelley)
forall a b. (a -> b) -> a -> b
$
ByteString -> Either String (PParams StandardShelley)
forall a. FromJSON a => ByteString -> Either String a
Aeson.eitherDecode' ByteString
pparams
data SomeWitness
= AByronSigningKey (Api.SigningKey Api.ByronKey) (Maybe (Address Byron))
| APaymentSigningKey (Api.SigningKey Api.PaymentKey)
| APaymentExtendedSigningKey (Api.SigningKey Api.PaymentExtendedKey)
| AStakeSigningKey (Api.SigningKey Api.StakeKey)
| AStakeExtendedSigningKey (Api.SigningKey Api.StakeExtendedKey)
| AStakePoolSigningKey (Api.SigningKey Api.StakePoolKey)
| AGenesisSigningKey (Api.SigningKey Api.GenesisKey)
| AGenesisExtendedSigningKey (Api.SigningKey Api.GenesisExtendedKey)
| AGenesisDelegateSigningKey (Api.SigningKey Api.GenesisDelegateKey)
| AGenesisDelegateExtendedSigningKey
(Api.SigningKey Api.GenesisDelegateExtendedKey)
| AGenesisUTxOSigningKey (Api.SigningKey Api.GenesisUTxOKey)
| AShelleyMultiSigScript Api.MultiSigScript
newtype ScriptJsonDecodeError = ScriptJsonDecodeError String
deriving Int -> ScriptJsonDecodeError -> ShowS
[ScriptJsonDecodeError] -> ShowS
ScriptJsonDecodeError -> String
(Int -> ScriptJsonDecodeError -> ShowS)
-> (ScriptJsonDecodeError -> String)
-> ([ScriptJsonDecodeError] -> ShowS)
-> Show ScriptJsonDecodeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScriptJsonDecodeError] -> ShowS
$cshowList :: [ScriptJsonDecodeError] -> ShowS
show :: ScriptJsonDecodeError -> String
$cshow :: ScriptJsonDecodeError -> String
showsPrec :: Int -> ScriptJsonDecodeError -> ShowS
$cshowsPrec :: Int -> ScriptJsonDecodeError -> ShowS
Show
instance Error ScriptJsonDecodeError where
displayError :: ScriptJsonDecodeError -> String
displayError (ScriptJsonDecodeError String
errStr) = String
errStr
data ReadWitnessSigningDataError
= ReadWitnessSigningDataSigningKeyDecodeError !(FileError InputDecodeError)
| ReadWitnessSigningDataScriptError !(FileError ScriptJsonDecodeError)
| ReadWitnessSigningDataSigningKeyAndAddressMismatch
deriving Int -> ReadWitnessSigningDataError -> ShowS
[ReadWitnessSigningDataError] -> ShowS
ReadWitnessSigningDataError -> String
(Int -> ReadWitnessSigningDataError -> ShowS)
-> (ReadWitnessSigningDataError -> String)
-> ([ReadWitnessSigningDataError] -> ShowS)
-> Show ReadWitnessSigningDataError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReadWitnessSigningDataError] -> ShowS
$cshowList :: [ReadWitnessSigningDataError] -> ShowS
show :: ReadWitnessSigningDataError -> String
$cshow :: ReadWitnessSigningDataError -> String
showsPrec :: Int -> ReadWitnessSigningDataError -> ShowS
$cshowsPrec :: Int -> ReadWitnessSigningDataError -> ShowS
Show
renderReadWitnessSigningDataError :: ReadWitnessSigningDataError -> Text
renderReadWitnessSigningDataError :: ReadWitnessSigningDataError -> Text
renderReadWitnessSigningDataError ReadWitnessSigningDataError
err =
case ReadWitnessSigningDataError
err of
ReadWitnessSigningDataSigningKeyDecodeError FileError InputDecodeError
fileErr ->
Text
"Error reading signing key: " 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)
ReadWitnessSigningDataScriptError FileError ScriptJsonDecodeError
fileErr ->
Text
"Error reading script: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (FileError ScriptJsonDecodeError -> String
forall e. Error e => e -> String
displayError FileError ScriptJsonDecodeError
fileErr)
ReadWitnessSigningDataError
ReadWitnessSigningDataSigningKeyAndAddressMismatch ->
Text
"Only a Byron signing key may be accompanied by a Byron address."
readWitnessSigningData
:: WitnessSigningData
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
readWitnessSigningData :: WitnessSigningData
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
readWitnessSigningData (ScriptWitnessSigningData (ScriptFile String
fp)) = do
ByteString
msJson <- (IOException -> ReadWitnessSigningDataError)
-> IO ByteString
-> ExceptT ReadWitnessSigningDataError IO ByteString
forall (m :: * -> *) x a.
MonadIO m =>
(IOException -> x) -> IO a -> ExceptT x m a
handleIOExceptT (FileError ScriptJsonDecodeError -> ReadWitnessSigningDataError
ReadWitnessSigningDataScriptError (FileError ScriptJsonDecodeError -> ReadWitnessSigningDataError)
-> (IOException -> FileError ScriptJsonDecodeError)
-> IOException
-> ReadWitnessSigningDataError
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 ScriptJsonDecodeError
forall e. String -> IOException -> FileError e
FileIOError String
fp)
(IO ByteString
-> ExceptT ReadWitnessSigningDataError IO ByteString)
-> IO ByteString
-> ExceptT ReadWitnessSigningDataError IO ByteString
forall a b. (a -> b) -> a -> b
$ String -> IO ByteString
LBS.readFile String
fp
Either ReadWitnessSigningDataError SomeWitness
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ReadWitnessSigningDataError SomeWitness
-> ExceptT ReadWitnessSigningDataError IO SomeWitness)
-> Either ReadWitnessSigningDataError SomeWitness
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall a b. (a -> b) -> a -> b
$ (String -> ReadWitnessSigningDataError)
-> (MultiSigScript -> SomeWitness)
-> Either String MultiSigScript
-> Either ReadWitnessSigningDataError SomeWitness
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap
(FileError ScriptJsonDecodeError -> ReadWitnessSigningDataError
ReadWitnessSigningDataScriptError (FileError ScriptJsonDecodeError -> ReadWitnessSigningDataError)
-> (String -> FileError ScriptJsonDecodeError)
-> String
-> ReadWitnessSigningDataError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> ScriptJsonDecodeError -> FileError ScriptJsonDecodeError
forall e. String -> e -> FileError e
FileError String
fp (ScriptJsonDecodeError -> FileError ScriptJsonDecodeError)
-> (String -> ScriptJsonDecodeError)
-> String
-> FileError ScriptJsonDecodeError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> ScriptJsonDecodeError
ScriptJsonDecodeError)
MultiSigScript -> SomeWitness
AShelleyMultiSigScript
(ByteString -> Either String MultiSigScript
forall a. FromJSON a => ByteString -> Either String a
Aeson.eitherDecode' ByteString
msJson)
readWitnessSigningData (KeyWitnessSigningData SigningKeyFile
skFile Maybe (Address Byron)
mbByronAddr) = do
SomeWitness
res <- (FileError InputDecodeError -> ReadWitnessSigningDataError)
-> ExceptT (FileError InputDecodeError) IO SomeWitness
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError InputDecodeError -> ReadWitnessSigningDataError
ReadWitnessSigningDataSigningKeyDecodeError
(ExceptT (FileError InputDecodeError) IO SomeWitness
-> ExceptT ReadWitnessSigningDataError IO SomeWitness)
-> (IO (Either (FileError InputDecodeError) SomeWitness)
-> ExceptT (FileError InputDecodeError) IO SomeWitness)
-> IO (Either (FileError InputDecodeError) SomeWitness)
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
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 InputDecodeError) SomeWitness)
-> ExceptT (FileError InputDecodeError) IO SomeWitness
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
(IO (Either (FileError InputDecodeError) SomeWitness)
-> ExceptT ReadWitnessSigningDataError IO SomeWitness)
-> IO (Either (FileError InputDecodeError) SomeWitness)
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall a b. (a -> b) -> a -> b
$ [FromSomeType SerialiseAsBech32 SomeWitness]
-> [FromSomeType HasTextEnvelope SomeWitness]
-> SigningKeyFile
-> IO (Either (FileError InputDecodeError) SomeWitness)
forall b.
[FromSomeType SerialiseAsBech32 b]
-> [FromSomeType HasTextEnvelope b]
-> SigningKeyFile
-> IO (Either (FileError InputDecodeError) b)
readSigningKeyFileAnyOf [FromSomeType SerialiseAsBech32 SomeWitness]
bech32FileTypes [FromSomeType HasTextEnvelope SomeWitness]
textEnvFileTypes SigningKeyFile
skFile
case (SomeWitness
res, Maybe (Address Byron)
mbByronAddr) of
(AByronSigningKey SigningKey ByronKey
_ Maybe (Address Byron)
_, Just Address Byron
_) -> SomeWitness -> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (f :: * -> *) a. Applicative f => a -> f a
pure SomeWitness
res
(AByronSigningKey SigningKey ByronKey
_ Maybe (Address Byron)
_, Maybe (Address Byron)
Nothing) -> SomeWitness -> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (f :: * -> *) a. Applicative f => a -> f a
pure SomeWitness
res
(SomeWitness
_, Maybe (Address Byron)
Nothing) -> SomeWitness -> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (f :: * -> *) a. Applicative f => a -> f a
pure SomeWitness
res
(SomeWitness
_, Just Address Byron
_) ->
ReadWitnessSigningDataError
-> ExceptT ReadWitnessSigningDataError IO SomeWitness
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left ReadWitnessSigningDataError
ReadWitnessSigningDataSigningKeyAndAddressMismatch
where
textEnvFileTypes :: [FromSomeType HasTextEnvelope SomeWitness]
textEnvFileTypes =
[ AsType (SigningKey ByronKey)
-> (SigningKey ByronKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType ByronKey -> AsType (SigningKey ByronKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType ByronKey
Api.AsByronKey)
(SigningKey ByronKey -> Maybe (Address Byron) -> SomeWitness
`AByronSigningKey` Maybe (Address Byron)
mbByronAddr)
, AsType (SigningKey PaymentKey)
-> (SigningKey PaymentKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType PaymentKey -> AsType (SigningKey PaymentKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType PaymentKey
Api.AsPaymentKey)
SigningKey PaymentKey -> SomeWitness
APaymentSigningKey
, AsType (SigningKey PaymentExtendedKey)
-> (SigningKey PaymentExtendedKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType PaymentExtendedKey -> AsType (SigningKey PaymentExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType PaymentExtendedKey
Api.AsPaymentExtendedKey)
SigningKey PaymentExtendedKey -> SomeWitness
APaymentExtendedSigningKey
, AsType (SigningKey StakeKey)
-> (SigningKey StakeKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakeKey -> AsType (SigningKey StakeKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakeKey
Api.AsStakeKey)
SigningKey StakeKey -> SomeWitness
AStakeSigningKey
, AsType (SigningKey StakeExtendedKey)
-> (SigningKey StakeExtendedKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakeExtendedKey -> AsType (SigningKey StakeExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakeExtendedKey
Api.AsStakeExtendedKey)
SigningKey StakeExtendedKey -> SomeWitness
AStakeExtendedSigningKey
, AsType (SigningKey StakePoolKey)
-> (SigningKey StakePoolKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakePoolKey -> AsType (SigningKey StakePoolKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakePoolKey
Api.AsStakePoolKey)
SigningKey StakePoolKey -> SomeWitness
AStakePoolSigningKey
, AsType (SigningKey GenesisKey)
-> (SigningKey GenesisKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType GenesisKey -> AsType (SigningKey GenesisKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType GenesisKey
Api.AsGenesisKey)
SigningKey GenesisKey -> SomeWitness
AGenesisSigningKey
, AsType (SigningKey GenesisExtendedKey)
-> (SigningKey GenesisExtendedKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType GenesisExtendedKey -> AsType (SigningKey GenesisExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType GenesisExtendedKey
Api.AsGenesisExtendedKey)
SigningKey GenesisExtendedKey -> SomeWitness
AGenesisExtendedSigningKey
, AsType (SigningKey GenesisDelegateKey)
-> (SigningKey GenesisDelegateKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType GenesisDelegateKey -> AsType (SigningKey GenesisDelegateKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType GenesisDelegateKey
Api.AsGenesisDelegateKey)
SigningKey GenesisDelegateKey -> SomeWitness
AGenesisDelegateSigningKey
, AsType (SigningKey GenesisDelegateExtendedKey)
-> (SigningKey GenesisDelegateExtendedKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType GenesisDelegateExtendedKey
-> AsType (SigningKey GenesisDelegateExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType GenesisDelegateExtendedKey
Api.AsGenesisDelegateExtendedKey)
SigningKey GenesisDelegateExtendedKey -> SomeWitness
AGenesisDelegateExtendedSigningKey
, AsType (SigningKey GenesisUTxOKey)
-> (SigningKey GenesisUTxOKey -> SomeWitness)
-> FromSomeType HasTextEnvelope SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType GenesisUTxOKey -> AsType (SigningKey GenesisUTxOKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType GenesisUTxOKey
Api.AsGenesisUTxOKey)
SigningKey GenesisUTxOKey -> SomeWitness
AGenesisUTxOSigningKey
]
bech32FileTypes :: [FromSomeType SerialiseAsBech32 SomeWitness]
bech32FileTypes =
[ AsType (SigningKey ByronKey)
-> (SigningKey ByronKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType ByronKey -> AsType (SigningKey ByronKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType ByronKey
Api.AsByronKey)
(SigningKey ByronKey -> Maybe (Address Byron) -> SomeWitness
`AByronSigningKey` Maybe (Address Byron)
mbByronAddr)
, AsType (SigningKey PaymentKey)
-> (SigningKey PaymentKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType PaymentKey -> AsType (SigningKey PaymentKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType PaymentKey
Api.AsPaymentKey)
SigningKey PaymentKey -> SomeWitness
APaymentSigningKey
, AsType (SigningKey PaymentExtendedKey)
-> (SigningKey PaymentExtendedKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType PaymentExtendedKey -> AsType (SigningKey PaymentExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType PaymentExtendedKey
Api.AsPaymentExtendedKey)
SigningKey PaymentExtendedKey -> SomeWitness
APaymentExtendedSigningKey
, AsType (SigningKey StakeKey)
-> (SigningKey StakeKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakeKey -> AsType (SigningKey StakeKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakeKey
Api.AsStakeKey)
SigningKey StakeKey -> SomeWitness
AStakeSigningKey
, AsType (SigningKey StakeExtendedKey)
-> (SigningKey StakeExtendedKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakeExtendedKey -> AsType (SigningKey StakeExtendedKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakeExtendedKey
Api.AsStakeExtendedKey)
SigningKey StakeExtendedKey -> SomeWitness
AStakeExtendedSigningKey
, AsType (SigningKey StakePoolKey)
-> (SigningKey StakePoolKey -> SomeWitness)
-> FromSomeType SerialiseAsBech32 SomeWitness
forall (c :: * -> Constraint) a b.
c a =>
AsType a -> (a -> b) -> FromSomeType c b
Api.FromSomeType (AsType StakePoolKey -> AsType (SigningKey StakePoolKey)
forall a. AsType a -> AsType (SigningKey a)
Api.AsSigningKey AsType StakePoolKey
Api.AsStakePoolKey)
SigningKey StakePoolKey -> SomeWitness
AStakePoolSigningKey
]
partitionSomeWitnesses
:: [ByronOrShelleyWitness]
-> ( [ShelleyBootstrapWitnessSigningKeyData]
, [Api.ShelleyWitnessSigningKey]
, [Api.MultiSigScript]
)
partitionSomeWitnesses :: [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
partitionSomeWitnesses = ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
forall a a a. ([a], [a], [a]) -> ([a], [a], [a])
reversePartitionedWits (([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript]))
-> ([ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript]))
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> ByronOrShelleyWitness
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript]))
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> [ByronOrShelleyWitness]
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> ByronOrShelleyWitness
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
go ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
forall a. Monoid a => a
mempty
where
reversePartitionedWits :: ([a], [a], [a]) -> ([a], [a], [a])
reversePartitionedWits ([a]
bw, [a]
skw, [a]
ssw) =
([a] -> [a]
forall a. [a] -> [a]
reverse [a]
bw, [a] -> [a]
forall a. [a] -> [a]
reverse [a]
skw, [a] -> [a]
forall a. [a] -> [a]
reverse [a]
ssw)
go :: ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
-> ByronOrShelleyWitness
-> ([ShelleyBootstrapWitnessSigningKeyData],
[ShelleyWitnessSigningKey], [MultiSigScript])
go ([ShelleyBootstrapWitnessSigningKeyData]
byronAcc, [ShelleyWitnessSigningKey]
shelleyKeyAcc, [MultiSigScript]
shelleyScriptAcc) ByronOrShelleyWitness
byronOrShelleyWit =
case ByronOrShelleyWitness
byronOrShelleyWit of
AByronWitness ShelleyBootstrapWitnessSigningKeyData
byronWit ->
(ShelleyBootstrapWitnessSigningKeyData
byronWitShelleyBootstrapWitnessSigningKeyData
-> [ShelleyBootstrapWitnessSigningKeyData]
-> [ShelleyBootstrapWitnessSigningKeyData]
forall a. a -> [a] -> [a]
:[ShelleyBootstrapWitnessSigningKeyData]
byronAcc, [ShelleyWitnessSigningKey]
shelleyKeyAcc, [MultiSigScript]
shelleyScriptAcc)
AShelleyKeyWitness ShelleyWitnessSigningKey
shelleyKeyWit ->
([ShelleyBootstrapWitnessSigningKeyData]
byronAcc, ShelleyWitnessSigningKey
shelleyKeyWitShelleyWitnessSigningKey
-> [ShelleyWitnessSigningKey] -> [ShelleyWitnessSigningKey]
forall a. a -> [a] -> [a]
:[ShelleyWitnessSigningKey]
shelleyKeyAcc, [MultiSigScript]
shelleyScriptAcc)
AShelleyScriptWitness MultiSigScript
shelleyScriptWit ->
([ShelleyBootstrapWitnessSigningKeyData]
byronAcc, [ShelleyWitnessSigningKey]
shelleyKeyAcc, MultiSigScript
shelleyScriptWitMultiSigScript -> [MultiSigScript] -> [MultiSigScript]
forall a. a -> [a] -> [a]
:[MultiSigScript]
shelleyScriptAcc)
data ByronOrShelleyWitness
= AByronWitness !ShelleyBootstrapWitnessSigningKeyData
| AShelleyKeyWitness !Api.ShelleyWitnessSigningKey
| AShelleyScriptWitness !Api.MultiSigScript
categoriseSomeWitness :: SomeWitness -> ByronOrShelleyWitness
categoriseSomeWitness :: SomeWitness -> ByronOrShelleyWitness
categoriseSomeWitness SomeWitness
swsk =
case SomeWitness
swsk of
AByronSigningKey SigningKey ByronKey
sk Maybe (Address Byron)
addr -> ShelleyBootstrapWitnessSigningKeyData -> ByronOrShelleyWitness
AByronWitness (SigningKey ByronKey
-> Maybe (Address Byron) -> ShelleyBootstrapWitnessSigningKeyData
ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
sk Maybe (Address Byron)
addr)
APaymentSigningKey SigningKey PaymentKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey PaymentKey -> ShelleyWitnessSigningKey
Api.WitnessPaymentKey SigningKey PaymentKey
sk)
APaymentExtendedSigningKey SigningKey PaymentExtendedKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey PaymentExtendedKey -> ShelleyWitnessSigningKey
Api.WitnessPaymentExtendedKey SigningKey PaymentExtendedKey
sk)
AStakeSigningKey SigningKey StakeKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey StakeKey -> ShelleyWitnessSigningKey
Api.WitnessStakeKey SigningKey StakeKey
sk)
AStakeExtendedSigningKey SigningKey StakeExtendedKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey StakeExtendedKey -> ShelleyWitnessSigningKey
Api.WitnessStakeExtendedKey SigningKey StakeExtendedKey
sk)
AStakePoolSigningKey SigningKey StakePoolKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey StakePoolKey -> ShelleyWitnessSigningKey
Api.WitnessStakePoolKey SigningKey StakePoolKey
sk)
AGenesisSigningKey SigningKey GenesisKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey GenesisKey -> ShelleyWitnessSigningKey
Api.WitnessGenesisKey SigningKey GenesisKey
sk)
AGenesisExtendedSigningKey SigningKey GenesisExtendedKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey GenesisExtendedKey -> ShelleyWitnessSigningKey
Api.WitnessGenesisExtendedKey SigningKey GenesisExtendedKey
sk)
AGenesisDelegateSigningKey SigningKey GenesisDelegateKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey GenesisDelegateKey -> ShelleyWitnessSigningKey
Api.WitnessGenesisDelegateKey SigningKey GenesisDelegateKey
sk)
AGenesisDelegateExtendedSigningKey SigningKey GenesisDelegateExtendedKey
sk
-> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey GenesisDelegateExtendedKey -> ShelleyWitnessSigningKey
Api.WitnessGenesisDelegateExtendedKey SigningKey GenesisDelegateExtendedKey
sk)
AGenesisUTxOSigningKey SigningKey GenesisUTxOKey
sk -> ShelleyWitnessSigningKey -> ByronOrShelleyWitness
AShelleyKeyWitness (SigningKey GenesisUTxOKey -> ShelleyWitnessSigningKey
Api.WitnessGenesisUTxOKey SigningKey GenesisUTxOKey
sk)
AShelleyMultiSigScript MultiSigScript
scr -> MultiSigScript -> ByronOrShelleyWitness
AShelleyScriptWitness MultiSigScript
scr
data ShelleyBootstrapWitnessSigningKeyData
= ShelleyBootstrapWitnessSigningKeyData
!(SigningKey ByronKey)
!(Maybe (Address Byron))
data ShelleyBootstrapWitnessError
= MissingNetworkIdOrByronAddressError
deriving Int -> ShelleyBootstrapWitnessError -> ShowS
[ShelleyBootstrapWitnessError] -> ShowS
ShelleyBootstrapWitnessError -> String
(Int -> ShelleyBootstrapWitnessError -> ShowS)
-> (ShelleyBootstrapWitnessError -> String)
-> ([ShelleyBootstrapWitnessError] -> ShowS)
-> Show ShelleyBootstrapWitnessError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShelleyBootstrapWitnessError] -> ShowS
$cshowList :: [ShelleyBootstrapWitnessError] -> ShowS
show :: ShelleyBootstrapWitnessError -> String
$cshow :: ShelleyBootstrapWitnessError -> String
showsPrec :: Int -> ShelleyBootstrapWitnessError -> ShowS
$cshowsPrec :: Int -> ShelleyBootstrapWitnessError -> ShowS
Show
renderShelleyBootstrapWitnessError :: ShelleyBootstrapWitnessError -> Text
renderShelleyBootstrapWitnessError :: ShelleyBootstrapWitnessError -> Text
renderShelleyBootstrapWitnessError ShelleyBootstrapWitnessError
MissingNetworkIdOrByronAddressError =
Text
"Transactions witnessed by a Byron signing key must be accompanied by a "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"network ID. Either provide a network ID or provide a Byron "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"address with each Byron signing key (network IDs can be derived "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"from Byron addresses)."
mkShelleyBootstrapWitness
:: Maybe NetworkId
-> TxBody Shelley
-> ShelleyBootstrapWitnessSigningKeyData
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
mkShelleyBootstrapWitness :: Maybe NetworkId
-> TxBody Shelley
-> ShelleyBootstrapWitnessSigningKeyData
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
mkShelleyBootstrapWitness Maybe NetworkId
Nothing TxBody Shelley
_ (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
_ Maybe (Address Byron)
Nothing) =
ShelleyBootstrapWitnessError
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
forall a b. a -> Either a b
Left ShelleyBootstrapWitnessError
MissingNetworkIdOrByronAddressError
mkShelleyBootstrapWitness (Just NetworkId
nw) TxBody Shelley
txBody (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
skey Maybe (Address Byron)
Nothing) =
Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
forall a b. b -> Either a b
Right (Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley))
-> Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ WitnessNetworkIdOrByronAddress
-> TxBody Shelley -> SigningKey ByronKey -> Witness Shelley
makeShelleyBootstrapWitness (NetworkId -> WitnessNetworkIdOrByronAddress
WitnessNetworkId NetworkId
nw) TxBody Shelley
txBody SigningKey ByronKey
skey
mkShelleyBootstrapWitness Maybe NetworkId
_ TxBody Shelley
txBody (ShelleyBootstrapWitnessSigningKeyData SigningKey ByronKey
skey (Just Address Byron
addr)) =
Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
forall a b. b -> Either a b
Right (Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley))
-> Witness Shelley
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ WitnessNetworkIdOrByronAddress
-> TxBody Shelley -> SigningKey ByronKey -> Witness Shelley
makeShelleyBootstrapWitness (Address Byron -> WitnessNetworkIdOrByronAddress
WitnessByronAddress Address Byron
addr) TxBody Shelley
txBody SigningKey ByronKey
skey
mkShelleyBootstrapWitnesses
:: Maybe NetworkId
-> TxBody Shelley
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
mkShelleyBootstrapWitnesses :: Maybe NetworkId
-> TxBody Shelley
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
mkShelleyBootstrapWitnesses Maybe NetworkId
mnw TxBody Shelley
txBody =
(ShelleyBootstrapWitnessSigningKeyData
-> Either ShelleyBootstrapWitnessError (Witness Shelley))
-> [ShelleyBootstrapWitnessSigningKeyData]
-> Either ShelleyBootstrapWitnessError [Witness Shelley]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Maybe NetworkId
-> TxBody Shelley
-> ShelleyBootstrapWitnessSigningKeyData
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
mkShelleyBootstrapWitness Maybe NetworkId
mnw TxBody Shelley
txBody)
runTxGetTxId :: TxBodyFile -> ExceptT ShelleyTxCmdError IO ()
runTxGetTxId :: TxBodyFile -> ExceptT ShelleyTxCmdError IO ()
runTxGetTxId (TxBodyFile String
txbodyFile) = do
TxBody Shelley
txbody <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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 (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
forall a b. (a -> b) -> a -> b
$
AsType (TxBody Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (TxBody Shelley)
Api.AsShelleyTxBody String
txbodyFile
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
$ ByteString -> IO ()
BS.putStrLn (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
Api.serialiseToRawBytesHex (TxBody Shelley -> TxId
forall era. TxBody era -> TxId
Api.getTxId TxBody Shelley
txbody)
runTxCreateWitness
:: TxBodyFile
-> WitnessSigningData
-> Maybe NetworkId
-> OutputFile
-> ExceptT ShelleyTxCmdError IO ()
runTxCreateWitness :: TxBodyFile
-> WitnessSigningData
-> Maybe NetworkId
-> OutputFile
-> ExceptT ShelleyTxCmdError IO ()
runTxCreateWitness (TxBodyFile String
txbodyFile) WitnessSigningData
witSignData Maybe NetworkId
mbNw (OutputFile String
oFile) = do
TxBody Shelley
txbody <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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 (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
(IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
forall a b. (a -> b) -> a -> b
$ AsType (TxBody Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (TxBody Shelley)
Api.AsShelleyTxBody String
txbodyFile
SomeWitness
someWit <- (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
readWitnessSigningData WitnessSigningData
witSignData
Witness Shelley
witness <-
case SomeWitness -> ByronOrShelleyWitness
categoriseSomeWitness SomeWitness
someWit of
AByronWitness ShelleyBootstrapWitnessSigningKeyData
bootstrapWitData ->
(ShelleyBootstrapWitnessError -> ShelleyTxCmdError)
-> ExceptT ShelleyBootstrapWitnessError IO (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyBootstrapWitnessError -> ShelleyTxCmdError
ShelleyTxCmdBootstrapWitnessError
(ExceptT ShelleyBootstrapWitnessError IO (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> (Either ShelleyBootstrapWitnessError (Witness Shelley)
-> ExceptT ShelleyBootstrapWitnessError IO (Witness Shelley))
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either ShelleyBootstrapWitnessError (Witness Shelley)
-> ExceptT ShelleyBootstrapWitnessError IO (Witness Shelley)
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither
(Either ShelleyBootstrapWitnessError (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ Maybe NetworkId
-> TxBody Shelley
-> ShelleyBootstrapWitnessSigningKeyData
-> Either ShelleyBootstrapWitnessError (Witness Shelley)
mkShelleyBootstrapWitness Maybe NetworkId
mbNw TxBody Shelley
txbody ShelleyBootstrapWitnessSigningKeyData
bootstrapWitData
AShelleyKeyWitness ShelleyWitnessSigningKey
skShelley ->
Witness Shelley -> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Witness Shelley -> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> Witness Shelley
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ TxBody Shelley -> ShelleyWitnessSigningKey -> Witness Shelley
makeShelleyKeyWitness TxBody Shelley
txbody ShelleyWitnessSigningKey
skShelley
AShelleyScriptWitness MultiSigScript
scShelley ->
Witness Shelley -> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Witness Shelley -> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> Witness Shelley
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ Script -> Witness Shelley
makeShelleyScriptWitness (MultiSigScript -> Script
makeMultiSigScript MultiSigScript
scShelley)
(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
-> Witness Shelley
-> IO (Either (FileError ()) ())
forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
Api.writeFileTextEnvelope String
oFile Maybe TextEnvelopeDescr
forall a. Maybe a
Nothing Witness Shelley
witness
runTxSignWitness
:: TxBodyFile
-> [WitnessFile]
-> OutputFile
-> ExceptT ShelleyTxCmdError IO ()
runTxSignWitness :: TxBodyFile
-> [WitnessFile] -> OutputFile -> ExceptT ShelleyTxCmdError IO ()
runTxSignWitness (TxBodyFile String
txBodyFile) [WitnessFile]
witnessFiles (OutputFile String
oFp) = do
TxBody Shelley
txBody <- (FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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 (TxBody Shelley)
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> (IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
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) (TxBody Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (TxBody Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT
(IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley))
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
-> ExceptT ShelleyTxCmdError IO (TxBody Shelley)
forall a b. (a -> b) -> a -> b
$ AsType (TxBody Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (TxBody Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (TxBody Shelley)
Api.AsShelleyTxBody String
txBodyFile
[Witness Shelley]
witnesses <- (WitnessFile -> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> [WitnessFile] -> ExceptT ShelleyTxCmdError IO [Witness Shelley]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM WitnessFile -> ExceptT ShelleyTxCmdError IO (Witness Shelley)
readWitnessFile [WitnessFile]
witnessFiles
let tx :: Tx Shelley
tx = [Witness Shelley] -> TxBody Shelley -> Tx Shelley
forall era. [Witness era] -> TxBody era -> Tx era
Api.makeSignedTransaction [Witness Shelley]
witnesses TxBody Shelley
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 Shelley
-> IO (Either (FileError ()) ())
forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
Api.writeFileTextEnvelope String
oFp Maybe TextEnvelopeDescr
forall a. Maybe a
Nothing Tx Shelley
tx
readWitnessFile :: WitnessFile -> ExceptT ShelleyTxCmdError IO (Witness Shelley)
readWitnessFile :: WitnessFile -> ExceptT ShelleyTxCmdError IO (Witness Shelley)
readWitnessFile (WitnessFile String
fp) =
(FileError TextEnvelopeError -> ShelleyTxCmdError)
-> ExceptT (FileError TextEnvelopeError) IO (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
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 (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (Witness Shelley)
-> ExceptT ShelleyTxCmdError IO (Witness Shelley)
forall a b. (a -> b) -> a -> b
$ IO (Either (FileError TextEnvelopeError) (Witness Shelley))
-> ExceptT (FileError TextEnvelopeError) IO (Witness Shelley)
forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT (AsType (Witness Shelley)
-> String
-> IO (Either (FileError TextEnvelopeError) (Witness Shelley))
forall a.
HasTextEnvelope a =>
AsType a -> String -> IO (Either (FileError TextEnvelopeError) a)
Api.readFileTextEnvelope AsType (Witness Shelley)
AsShelleyWitness String
fp)
readFileTxMetaData :: TxMetadataJsonSchema -> MetaDataFile
-> ExceptT ShelleyTxCmdError IO Api.TxMetadata
readFileTxMetaData :: TxMetadataJsonSchema
-> MetaDataFile -> ExceptT ShelleyTxCmdError IO TxMetadata
readFileTxMetaData TxMetadataJsonSchema
mapping (MetaDataFileJSON 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
ShelleyTxCmdMetaDataJsonParseError 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
(TxMetadataJsonError -> ShelleyTxCmdError)
-> ExceptT TxMetadataJsonError IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> TxMetadataJsonError -> ShelleyTxCmdError
ShelleyTxCmdMetaDataConversionError String
fp) (ExceptT TxMetadataJsonError IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata)
-> ExceptT TxMetadataJsonError IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall a b. (a -> b) -> a -> b
$ Either TxMetadataJsonError TxMetadata
-> ExceptT TxMetadataJsonError IO TxMetadata
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either TxMetadataJsonError TxMetadata
-> ExceptT TxMetadataJsonError IO TxMetadata)
-> Either TxMetadataJsonError TxMetadata
-> ExceptT TxMetadataJsonError IO TxMetadata
forall a b. (a -> b) -> a -> b
$
TxMetadataJsonSchema
-> Value -> Either TxMetadataJsonError TxMetadata
metadataFromJson TxMetadataJsonSchema
mapping Value
v
readFileTxMetaData TxMetadataJsonSchema
_ (MetaDataFileCBOR 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
TxMetadata
txMetadata <- (DecoderError -> ShelleyTxCmdError)
-> ExceptT DecoderError IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
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 TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata)
-> ExceptT DecoderError IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall a b. (a -> b) -> a -> b
$ Either DecoderError TxMetadata
-> ExceptT DecoderError IO TxMetadata
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either DecoderError TxMetadata
-> ExceptT DecoderError IO TxMetadata)
-> Either DecoderError TxMetadata
-> ExceptT DecoderError IO TxMetadata
forall a b. (a -> b) -> a -> b
$
AsType TxMetadata -> ByteString -> Either DecoderError TxMetadata
forall a.
SerialiseAsCBOR a =>
AsType a -> ByteString -> Either DecoderError a
Api.deserialiseFromCBOR AsType TxMetadata
Api.AsTxMetadata ByteString
bs
(NonEmpty TxMetadataRangeError -> ShelleyTxCmdError)
-> ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT (String -> TxMetadataRangeError -> ShelleyTxCmdError
ShelleyTxCmdMetaValidationError String
fp (TxMetadataRangeError -> ShelleyTxCmdError)
-> (NonEmpty TxMetadataRangeError -> TxMetadataRangeError)
-> NonEmpty TxMetadataRangeError
-> ShelleyTxCmdError
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NonEmpty TxMetadataRangeError -> TxMetadataRangeError
forall a. NonEmpty a -> a
NE.head) (ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata)
-> ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata
-> ExceptT ShelleyTxCmdError IO TxMetadata
forall a b. (a -> b) -> a -> b
$ Either (NonEmpty TxMetadataRangeError) TxMetadata
-> ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either (NonEmpty TxMetadataRangeError) TxMetadata
-> ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata)
-> Either (NonEmpty TxMetadataRangeError) TxMetadata
-> ExceptT (NonEmpty TxMetadataRangeError) IO TxMetadata
forall a b. (a -> b) -> a -> b
$
TxMetadata -> Either (NonEmpty TxMetadataRangeError) TxMetadata
validateTxMetadata TxMetadata
txMetadata