Skip to content
Draft

stuff #1308

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ index-state:

packages:
cardano-cli
../cardano-api/cardano-api

program-options
ghc-options: -Werror
Expand Down
27 changes: 14 additions & 13 deletions cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ friendlyTx
:: MonadIO m
=> Vary [FormatJson, FormatYaml]
-> Maybe (File () Out)
-> ShelleyBasedEra era
-> Exp.Era era
-> Tx era
-> m (Either (FileError e) ())
friendlyTx format mOutFile era tx = do
Expand All @@ -103,7 +103,7 @@ friendlyTxBody
:: MonadIO m
=> Vary [FormatJson, FormatYaml]
-> Maybe (File () Out)
-> ShelleyBasedEra era
-> Exp.Era era
-> TxBody era
-> m (Either (FileError e) ())
friendlyTxBody format mOutFile era tx = do
Expand Down Expand Up @@ -141,7 +141,7 @@ friendlyProposalImpl

friendlyTxImpl
:: MonadWarning m
=> ShelleyBasedEra era
=> Exp.Era era
-> Tx era
-> m [Aeson.Pair]
friendlyTxImpl era tx =
Expand All @@ -162,26 +162,27 @@ friendlyKeyWitness =
friendlyTxBodyImpl
:: forall m era
. MonadWarning m
=> ShelleyBasedEra era
=> Exp.Era era
-> TxBody era
-> m [Aeson.Pair]
friendlyTxBodyImpl sbe tb = do
let era = convert sbe :: CardanoEra era
friendlyTxBodyImpl era tb = do
let cEra = convert era :: CardanoEra era
sbe = convert era :: ShelleyBasedEra era
return
( mconcat
[
[ "auxiliary scripts" .= friendlyAuxScripts txAuxScripts
, "certificates" .= forShelleyBasedEraInEon sbe Null (`friendlyCertificates` txCertificates)
, "collateral inputs" .= friendlyCollateralInputs txInsCollateral
, "era" .= era
, "era" .= cEra
, "fee" .= friendlyFee txFee
, "inputs" .= friendlyInputs txIns
, "metadata" .= friendlyMetadata txMetadata
, "mint" .= friendlyMintValue txMintValue
, "outputs" .= map (friendlyTxOut sbe) txOuts
, "outputs" .= map (friendlyTxOut era) txOuts
, "reference inputs" .= friendlyReferenceInputs txInsReference
, "total collateral" .= friendlyTotalCollateral txTotalCollateral
, "return collateral" .= friendlyReturnCollateral sbe txReturnCollateral
, "return collateral" .= friendlyReturnCollateral era txReturnCollateral
, "required signers (payment key hashes needed for scripts)"
.= friendlyExtraKeyWits txExtraKeyWits
, "update proposal" .= friendlyUpdateProposal txUpdateProposal
Expand Down Expand Up @@ -436,7 +437,7 @@ friendlyTotalCollateral (TxTotalCollateral _ coll) = toJSON coll

friendlyReturnCollateral
:: ()
=> ShelleyBasedEra era
=> Exp.Era era
-> TxReturnCollateral CtxTx era
-> Aeson.Value
friendlyReturnCollateral era = \case
Expand Down Expand Up @@ -486,9 +487,9 @@ friendlyStakeAddress (StakeAddress net cred) =
, friendlyStakeCredential cred
]

friendlyTxOut :: ShelleyBasedEra era -> TxOut CtxTx era -> Aeson.Value
friendlyTxOut sbe (TxOut addr amount mdatum script) =
shelleyBasedEraConstraints sbe $
friendlyTxOut :: Exp.Era era -> TxOut CtxTx era -> Aeson.Value
friendlyTxOut era (TxOut addr amount mdatum script) =
obtainCommonConstraints era $
object $
case addr of
AddressInEra ByronAddressInAnyEra byronAdr ->
Expand Down
14 changes: 7 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ runQueryUTxOCmd

case forEraInEonMaybe cEra id of
Nothing -> throwCliError $ QueryCmdEraNotSupported anyCEra
Just sbe -> do
utxo <- easyRunQuery (queryUtxo sbe queryFilter)
hoist liftIO $ writeFilteredUTxOs sbe outputFormat mOutFile utxo
Just cOn -> do
utxo <- easyRunQuery (queryUtxo (convert cOn) queryFilter)
hoist liftIO $ writeFilteredUTxOs cOn outputFormat mOutFile utxo
)
& fromEitherCIOCli

Expand Down Expand Up @@ -1212,18 +1212,18 @@ writePoolState era outputFormat mOutFile serialisedCurrentEpochState = do
$ writeLazyByteStringOutput mOutFile output

writeFilteredUTxOs
:: ShelleyBasedEra era
:: Exp.Era era
-> Vary [FormatCborBin, FormatCborHex, FormatJson, FormatText, FormatYaml]
-> Maybe (File () Out)
-> UTxO era
-> ExceptT QueryCmdError IO ()
writeFilteredUTxOs era format mOutFile utxo = do
let output =
shelleyBasedEraConstraints era $
obtainCommonConstraints era $
format
& ( id
. Vary.on (\FormatCborBin -> CBOR.serialize $ toLedgerUTxO era utxo)
. Vary.on (\FormatCborHex -> Base16.encode . CBOR.serialize $ toLedgerUTxO era utxo)
. Vary.on (\FormatCborBin -> CBOR.serialize $ toLedgerUTxO (convert era) utxo)
. Vary.on (\FormatCborHex -> Base16.encode . CBOR.serialize $ toLedgerUTxO (convert era) utxo)
. Vary.on (\FormatJson -> Json.encodeJson utxo)
. Vary.on (\FormatText -> strictTextToLazyBytestring $ filteredUTxOsToText utxo)
. Vary.on (\FormatYaml -> Json.encodeYaml utxo)
Expand Down
5 changes: 2 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,11 +1578,10 @@ buildTransactionContext
IO
(AnyCardanoEra, SystemStart, EraHistory, UTxO era, LedgerProtocolParameters era)
buildTransactionContext era systemStartOrGenesisFileSource mustUnsafeExtendSafeZone eraHistoryFile utxoFile protocolParamsFile =
shelleyBasedEraConstraints (convert era) $ do
obtainCommonConstraints era $ do
ledgerPParams <-
firstExceptT TxCmdProtocolParamsError $
obtainCommonConstraints era $
readProtocolParameters protocolParamsFile
readProtocolParameters protocolParamsFile
EraHistory interpreter <-
onLeft (left . TxCmdTextEnvError) $
liftIO $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module Cardano.CLI.EraIndependent.Debug.TransactionView.Run
where

import Cardano.Api
import Cardano.Api.Experimental qualified as Exp

import Cardano.CLI.Compatible.Exception
( CIO
, fromEitherCli
, fromEitherIOCli
)
import Cardano.CLI.Compatible.Json.Friendly
( friendlyTx
, friendlyTxBody
Expand All @@ -34,16 +39,18 @@ runTransactionViewCmd
unwitnessed <-
fromEitherIOCli $
readFileTxBody txbodyFile
InAnyShelleyBasedEra era txbody <- pure $ unIncompleteTxBody unwitnessed
InAnyShelleyBasedEra sbe txbody <- pure $ unIncompleteTxBody unwitnessed
-- Why are we differentiating between a transaction body and a transaction?
-- In the case of a transaction body, we /could/ simply call @makeSignedTransaction []@
-- to get a transaction which would allow us to reuse friendlyTxBS. However,
-- this would mean that we'd have an empty list of witnesses mentioned in the output, which
-- is arguably not part of the transaction body.
era <- fromEitherCli $ Exp.sbeToEra sbe
fromEitherIOCli @(FileError ()) $
friendlyTxBody outputFormat mOutFile era txbody
InputTxFile (File txFilePath) -> do
txFile <- liftIO $ fileOrPipe txFilePath
InAnyShelleyBasedEra era tx <- fromEitherIOCli (readFileTx txFile)
InAnyShelleyBasedEra sbe tx <- fromEitherIOCli (readFileTx txFile)
era <- fromEitherCli $ Exp.sbeToEra sbe
fromEitherIOCli @(FileError ()) $
friendlyTx outputFormat mOutFile era tx
Loading