Skip to content

Commit

Permalink
Add slotsInEpoch and slotsToEpochEnd to query tip command (#4912)
Browse files Browse the repository at this point in the history
* Add slotsInEpoch and slotsToEpochEnd to query tip command

* Update changelog for new slotsInEpoch and slotsToEpochEnd fields in output of query tip command
  • Loading branch information
newhoggy authored Mar 3, 2023
1 parent 18d5ab4 commit de9178b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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

0 comments on commit de9178b

Please sign in to comment.