From 2f964fc2b56cd24ab979b356cd9ec9f02745f8f0 Mon Sep 17 00:00:00 2001 From: John Ky Date: Thu, 23 Feb 2023 20:40:32 +1100 Subject: [PATCH] Add slotsInEpoch and slotsToEpochEnd to query tip command --- cardano-cli/src/Cardano/CLI/Shelley/Output.hs | 16 ++++++++++++++++ cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Output.hs b/cardano-cli/src/Cardano/CLI/Shelley/Output.hs index d0f35712c9a..9cc7b5820e1 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Output.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Output.hs @@ -150,6 +150,8 @@ data QueryTipLocalStateOutput = QueryTipLocalStateOutput { localStateChainTip :: ChainTip , mEra :: Maybe AnyCardanoEra , mEpoch :: Maybe EpochNo + , mSlotInEpoch :: Maybe Word64 + , mSlotsToEpochEnd :: Maybe Word64 , mSyncProgress :: Maybe Text } deriving Show @@ -169,6 +171,8 @@ instance ToJSON QueryTipLocalStateOutput where object $ ( ("era" ..=? mEra a) . ("epoch" ..=? mEpoch a) + . ("slotInEpoch" ..=? mSlotInEpoch a) + . ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a) . ("syncProgress" ..=? mSyncProgress a) ) [] ChainTip slotNo blockHeader blockNo -> @@ -178,6 +182,8 @@ instance ToJSON QueryTipLocalStateOutput where . ("block" ..= blockNo) . ("era" ..=? mEra a) . ("epoch" ..=? mEpoch a) + . ("slotInEpoch" ..=? mSlotInEpoch a) + . ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a) . ("syncProgress" ..=? mSyncProgress a) ) [] toEncoding a = case localStateChainTip a of @@ -185,6 +191,8 @@ instance ToJSON QueryTipLocalStateOutput where pairs $ mconcat $ ( ("era" ..=? mEra a) . ("epoch" ..=? mEpoch a) + . ("slotInEpoch" ..=? mSlotInEpoch a) + . ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a) . ("syncProgress" ..=? mSyncProgress a) ) [] ChainTip slotNo blockHeader blockNo -> @@ -194,6 +202,8 @@ instance ToJSON QueryTipLocalStateOutput where . ("block" ..= blockNo) . ("era" ..=? mEra a) . ("epoch" ..=? mEpoch a) + . ("slotInEpoch" ..=? mSlotInEpoch a) + . ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a) . ("syncProgress" ..=? mSyncProgress a) ) [] @@ -206,18 +216,24 @@ instance FromJSON QueryTipLocalStateOutput where mSlot <- o .:? "slot" mHash <- o .:? "hash" mBlock <- o .:? "block" + mSlotInEpoch' <- o .:? "slotInEpoch" + mSlotsToEpochEnd' <- o .:? "slotsToEpochEnd" case (mSlot, mHash, mBlock) of (Nothing, Nothing, Nothing) -> pure $ QueryTipLocalStateOutput ChainTipAtGenesis mEra' mEpoch' + mSlotInEpoch' + mSlotsToEpochEnd' mSyncProgress' (Just slot, Just hash, Just block) -> pure $ QueryTipLocalStateOutput (ChainTip slot hash block) mEra' mEpoch' + mSlotInEpoch' + mSlotsToEpochEnd' mSyncProgress' (_,_,_) -> fail $ mconcat diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs index 9e0318c8688..3a239ba254c 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs @@ -340,9 +340,11 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do , O.mEra = Nothing , O.mEpoch = Nothing , O.mSyncProgress = Nothing + , O.mSlotInEpoch = Nothing + , O.mSlotsToEpochEnd = Nothing } - Right (epochNo, _, _) -> do + Right (epochNo, SlotsInEpoch slotsInEpoch, SlotsToEpochEnd slotsToEpochEnd) -> do syncProgressResult <- runExceptT $ do systemStart <- fmap getSystemStart (O.mSystemStart localState) & hoistMaybe ShelleyQueryCmdSystemStartUnavailable nowSeconds <- toRelativeTime (SystemStart systemStart) <$> liftIO getCurrentTime @@ -359,6 +361,8 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do { O.localStateChainTip = chainTip , O.mEra = Just (O.era localState) , O.mEpoch = Just epochNo + , O.mSlotInEpoch = Just slotsInEpoch + , O.mSlotsToEpochEnd = Just slotsToEpochEnd , O.mSyncProgress = mSyncProgress }