Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slotsInEpoch and slotsToEpochEnd to query tip command #4912

Merged
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
2 changes: 2 additions & 0 deletions cardano-cli/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Allow assembling transactions with no witnesses ([PR 4408](https://github.com/input-output-hk/cardano-node/pull/4408))

- Add `slotInEpoch` and `slotsToEpochEnd` to output of `query tip` command ([PR 4912](https://github.com/input-output-hk/cardano-node/pull/4912))

### Bugs

- Allow reading signing keys from a pipe ([PR 4342](https://github.com/input-output-hk/cardano-node/pull/4342))
Expand Down
16 changes: 16 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ->
Expand All @@ -178,13 +182,17 @@ 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
ChainTipAtGenesis ->
pairs $ mconcat $
( ("era" ..=? mEra a)
. ("epoch" ..=? mEpoch a)
. ("slotInEpoch" ..=? mSlotInEpoch a)
. ("slotsToEpochEnd" ..=? mSlotsToEpochEnd a)
. ("syncProgress" ..=? mSyncProgress a)
) []
ChainTip slotNo blockHeader blockNo ->
Expand All @@ -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)
) []

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down