Skip to content

Commit

Permalink
Bump cardano-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 authored and carbolymer committed Aug 30, 2023
1 parent 10cb5d0 commit 8a313a7
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 163 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-08-08T19:56:09Z
, cardano-haskell-packages 2023-08-28T09:29:28Z
, cardano-haskell-packages 2023-08-30T15:15:49Z

packages:
cardano-cli
Expand Down
6 changes: 3 additions & 3 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.17.0
, cardano-api ^>= 8.18
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down Expand Up @@ -261,7 +261,7 @@ test-suite cardano-cli-test
, base16-bytestring
, bech32 >= 1.1.0
, bytestring
, cardano-api:{cardano-api, internal} ^>= 8.17.0
, cardano-api:{cardano-api, internal} ^>= 8.18
, cardano-api-gen ^>= 8.2.0.0
, cardano-cli
, cardano-cli:cardano-cli-test-lib
Expand Down Expand Up @@ -305,7 +305,7 @@ test-suite cardano-cli-golden
build-depends: aeson >= 1.5.6.0
, base16-bytestring
, bytestring
, cardano-api:{cardano-api, gen} ^>= 8.17.0
, cardano-api:{cardano-api, gen} ^>= 8.18
, cardano-binary
, cardano-cli
, cardano-cli:cardano-cli-test-lib
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Byron/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ txSpendGenesisUTxOByronPBFT gc nId sk (ByronAddress bAddr) outs = do
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txGovernanceActions = TxGovernanceActionsNone
, txProposalProcedures = Nothing
, txVotingProcedures = Nothing
}

Expand Down Expand Up @@ -220,7 +220,7 @@ txSpendUTxOByronPBFT nId sk txIns outs = do
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txGovernanceActions = TxGovernanceActionsNone
, txProposalProcedures = Nothing
, txVotingProcedures = Nothing
}

Expand Down
61 changes: 29 additions & 32 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Cardano.CLI.Legacy.Run.Query
import Cardano.Api hiding (QueryInShelleyBasedEra (..))
import qualified Cardano.Api as Api
import Cardano.Api.Byron hiding (QueryInShelleyBasedEra (..))
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.Helpers (hushM, pPrintCBOR)
Expand Down Expand Up @@ -66,7 +67,7 @@ import Control.Monad.IO.Unlift (MonadIO (..))
import Control.Monad.Trans.Class
import Control.Monad.Trans.Except (ExceptT (..), except, runExcept, runExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither,
hoistMaybe, left, onLeft, onNothing)
hoistMaybe, left, newExceptT, onLeft, onNothing)
import Data.Aeson as Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Aeson.Types as Aeson
Expand Down Expand Up @@ -176,36 +177,35 @@ runLegacyQueryProtocolParametersCmd
-> ExceptT ShelleyQueryCmdError IO ()
runLegacyQueryProtocolParametersCmd socketPath (AnyConsensusModeParams cModeParams) network mOutFile = do
let localNodeConnInfo = LocalNodeConnectInfo cModeParams network socketPath
anyE@(AnyCardanoEra era) <- firstExceptT ShelleyQueryCmdAcquireFailure $ newExceptT $ determineEra cModeParams localNodeConnInfo
sbe <- case cardanoEraStyle era of
LegacyByronEra -> left ShelleyQueryCmdByronEra
ShelleyBasedEra sbe -> return sbe

result <- liftIO $ executeLocalStateQueryExpr localNodeConnInfo Nothing $ runExceptT $ do
anyE@(AnyCardanoEra era) <- lift (determineEraExpr cModeParams)
& onLeft (left . ShelleyQueryCmdUnsupportedNtcVersion)

sbe <- requireShelleyBasedEra era
& onNothing (left ShelleyQueryCmdByronEra)

let cMode = consensusModeOnly cModeParams
let cMode = consensusModeOnly cModeParams

eInMode <- toEraInMode era cMode
& hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)
eInMode <- toEraInMode era cMode
& hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)

lift (queryProtocolParameters eInMode sbe)
& onLeft (left . ShelleyQueryCmdUnsupportedNtcVersion)
& onLeft (left . ShelleyQueryCmdEraMismatch)

writeProtocolParameters mOutFile =<< except (join (first ShelleyQueryCmdAcquireFailure result))
let qInMode = QueryInEra eInMode $ QueryInShelleyBasedEra sbe Api.QueryProtocolParameters
pp <- firstExceptT ShelleyQueryCmdConvenienceError
. newExceptT $ executeQueryAnyMode era localNodeConnInfo qInMode

writeProtocolParameters sbe mOutFile pp
where
-- TODO: Conway era - use ledger PParams JSON
writeProtocolParameters
:: Maybe (File () Out)
-> ProtocolParameters
:: ShelleyBasedEra era
-> Maybe (File () Out)
-> Ledger.PParams (ShelleyLedgerEra era)
-> ExceptT ShelleyQueryCmdError IO ()
writeProtocolParameters mOutFile' pparams =
case mOutFile' of
Nothing -> liftIO $ LBS.putStrLn (encodePretty pparams)
writeProtocolParameters sbe mOutFile' pparams =
let apiPParamsJSON = (encodePretty $ fromLedgerPParams sbe pparams)
in case mOutFile' of
Nothing -> liftIO $ LBS.putStrLn apiPParamsJSON
Just (File fpath) ->
handleIOExceptT (ShelleyQueryCmdWriteFileError . FileIOError fpath) $
LBS.writeFile fpath (encodePretty pparams)
LBS.writeFile fpath apiPParamsJSON

-- | Calculate the percentage sync rendered as text.
percentage
Expand Down Expand Up @@ -445,7 +445,7 @@ runLegacyQueryKesPeriodInfoCmd socketPath (AnyConsensusModeParams cModeParams) n
mode -> left . ShelleyQueryCmdUnsupportedMode $ AnyConsensusMode mode

where
currentKesPeriod :: ChainTip -> GenesisParameters -> CurrentKesPeriod
currentKesPeriod :: ChainTip -> GenesisParameters era -> CurrentKesPeriod
currentKesPeriod ChainTipAtGenesis _ = CurrentKesPeriod 0
currentKesPeriod (ChainTip currSlot _ _) gParams =
let slotsPerKesPeriod = fromIntegral $ protocolParamSlotsPerKESPeriod gParams
Expand All @@ -454,15 +454,15 @@ runLegacyQueryKesPeriodInfoCmd socketPath (AnyConsensusModeParams cModeParams) n
opCertStartingKesPeriod :: OperationalCertificate -> OpCertStartingKesPeriod
opCertStartingKesPeriod = OpCertStartingKesPeriod . fromIntegral . getKesPeriod

opCertEndKesPeriod :: GenesisParameters -> OperationalCertificate -> OpCertEndingKesPeriod
opCertEndKesPeriod :: GenesisParameters era -> OperationalCertificate -> OpCertEndingKesPeriod
opCertEndKesPeriod gParams oCert =
let OpCertStartingKesPeriod start = opCertStartingKesPeriod oCert
maxKesEvo = fromIntegral $ protocolParamMaxKESEvolutions gParams
in OpCertEndingKesPeriod $ start + maxKesEvo

-- See OCERT rule in Shelley Spec: https://hydra.iohk.io/job/Cardano/cardano-ledger-specs/shelleyLedgerSpec/latest/download-by-type/doc-pdf/ledger-spec
opCertIntervalInfo
:: GenesisParameters
:: GenesisParameters era
-> ChainTip
-> CurrentKesPeriod
-> OpCertStartingKesPeriod
Expand All @@ -488,7 +488,7 @@ runLegacyQueryKesPeriodInfoCmd socketPath (AnyConsensusModeParams cModeParams) n

opCertExpiryUtcTime
:: Tentative (EpochInfo (Either Text))
-> GenesisParameters
-> GenesisParameters era
-> OpCertEndingKesPeriod
-> Maybe UTCTime
opCertExpiryUtcTime eInfo gParams (OpCertEndingKesPeriod oCertExpiryKesPeriod) =
Expand Down Expand Up @@ -549,7 +549,7 @@ runLegacyQueryKesPeriodInfoCmd socketPath (AnyConsensusModeParams cModeParams) n
:: OpCertIntervalInformation
-> OpCertNodeAndOnDiskCounterInformation
-> Tentative (EpochInfo (Either Text))
-> GenesisParameters
-> GenesisParameters era
-> O.QueryKesPeriodInfoOutput
createQueryKesPeriodInfoOutput oCertIntervalInfo oCertCounterInfo eInfo gParams =
let (e, mStillExp) = case oCertIntervalInfo of
Expand Down Expand Up @@ -1313,9 +1313,6 @@ runLegacyQueryLeadershipScheduleCmd
& onLeft (left . ShelleyQueryCmdUnsupportedNtcVersion)
& onLeft (left . ShelleyQueryCmdLocalStateQueryError . EraMismatchError)

bpp <- hoistEither . first ShelleyQueryCmdProtocolParameterConversionError $
bundleProtocolParams era pparams

case whichSchedule of
CurrentEpoch -> do
serCurrentEpochState <- lift (queryPoolDistribution eInMode sbe (Just (Set.singleton poolid)))
Expand All @@ -1329,7 +1326,7 @@ runLegacyQueryLeadershipScheduleCmd
sbe
shelleyGenesis
eInfo
bpp
pparams
ptclState
poolid
vrkSkey
Expand All @@ -1349,7 +1346,7 @@ runLegacyQueryLeadershipScheduleCmd
schedule <- firstExceptT ShelleyQueryCmdLeaderShipError $ hoistEither
$ shelleyBasedEraConstraints sbe
$ nextEpochEligibleLeadershipSlots sbe shelleyGenesis
serCurrentEpochState ptclState poolid vrkSkey bpp
serCurrentEpochState ptclState poolid vrkSkey pparams
eInfo (tip, curentEpoch)

writeSchedule mJsonOutputFile eInfo shelleyGenesis schedule
Expand Down
Loading

0 comments on commit 8a313a7

Please sign in to comment.