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

Wire up outstanding new IPC queries to the cli #2290

Merged
merged 6 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 23 additions & 13 deletions cardano-api/src/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,37 @@ module Cardano.Api.Block (

import Prelude

import Data.Aeson (ToJSON (..), object, (.=))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as SBS
import Data.Foldable (Foldable(toList))
import Data.Foldable (Foldable (toList))
import qualified Data.Text.Encoding as Text

import Cardano.Slotting.Block (BlockNo(..))
import Cardano.Slotting.Slot (SlotNo, EpochNo)
import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (EpochNo, SlotNo)

import qualified Ouroboros.Network.Block as Consensus

import qualified Ouroboros.Consensus.Block as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator.Degenerate as Consensus
import qualified Ouroboros.Consensus.Byron.Ledger as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import qualified Ouroboros.Consensus.Cardano.ByronHFC as Consensus
import qualified Ouroboros.Consensus.Cardano.ShelleyHFC as Consensus
import qualified Cardano.Crypto.Hash.Class
import qualified Cardano.Crypto.Hashing
import qualified Ouroboros.Consensus.Block as Consensus
import qualified Ouroboros.Consensus.Byron.Ledger as Consensus
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import qualified Ouroboros.Consensus.Cardano.ByronHFC as Consensus
import qualified Ouroboros.Consensus.Cardano.ShelleyHFC as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator.Degenerate as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus

import qualified Cardano.Chain.Block as Byron
import qualified Cardano.Chain.UTxO as Byron
import qualified Cardano.Chain.UTxO as Byron

import qualified Shelley.Spec.Ledger.BlockChain as Shelley

import Cardano.Api.Eras
import Cardano.Api.HasTypeProxy
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.Modes
import Cardano.Api.SerialiseRaw
import Cardano.Api.Tx
Expand Down Expand Up @@ -251,6 +254,13 @@ data ChainPoint = ChainPointAtGenesis
| ChainPoint !SlotNo !(Hash BlockHeader)
deriving (Eq, Show)

instance ToJSON ChainPoint where
toJSON ChainPointAtGenesis = Aeson.String "Tip is currently at genesis block"
Jimbo4350 marked this conversation as resolved.
Show resolved Hide resolved
toJSON (ChainPoint slot headerHash) =
object [ "Slot Number" .= slot
, "Slot Header Hash" .= Text.decodeUtf8 (serialiseToRawBytesHex headerHash)
]
Jimbo4350 marked this conversation as resolved.
Show resolved Hide resolved


toConsensusPointInMode :: ConsensusMode mode
-> ChainPoint
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ renderPoolCmd cmd =

data QueryCmd =
QueryProtocolParameters AnyCardanoEra AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryTip Protocol NetworkId (Maybe OutputFile)
| QueryTip AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeDistribution AnyCardanoEra AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeAddressInfo AnyCardanoEra AnyConsensusModeParams StakeAddress NetworkId (Maybe OutputFile)
| QueryUTxO AnyCardanoEra Protocol QueryFilter NetworkId (Maybe OutputFile)
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ pQueryCmd =

pQueryTip :: Parser QueryCmd
pQueryTip = QueryTip
<$> pProtocol
<$> pConsensusModeParams
<*> pNetworkId
<*> pMaybeOutputFile

Expand Down
27 changes: 14 additions & 13 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Cardano.Api.Byron
import qualified Cardano.Api.IPC as NewIPC
import Cardano.Api.LocalChainSync (getLocalTip)
import Cardano.Api.Modes (AnyConsensusMode (..), AnyConsensusModeParams (..), toEraInMode)
import qualified Cardano.Api.Modes as Mode
import Cardano.Api.Protocol (Protocol, withlocalNodeConnectInfo)
import Cardano.Api.ProtocolParameters
import Cardano.Api.Shelley
Expand Down Expand Up @@ -106,8 +107,8 @@ runQueryCmd cmd =
case cmd of
QueryProtocolParameters era consensusModeParams network mOutFile ->
runQueryProtocolParameters era consensusModeParams network mOutFile
QueryTip protocol network mOutFile ->
runQueryTip protocol network mOutFile
QueryTip consensusModeParams network mOutFile ->
runQueryTip consensusModeParams network mOutFile
QueryStakeDistribution era consensusModeParams network mOutFile ->
runQueryStakeDistribution era consensusModeParams network mOutFile
QueryStakeAddressInfo era consensusModeParams addr network mOutFile ->
Expand Down Expand Up @@ -162,21 +163,21 @@ writeProtocolParameters mOutFile pparams =
LBS.writeFile fpath (encodePretty pparams)

runQueryTip
:: Protocol
:: AnyConsensusModeParams
-> NetworkId
-> Maybe OutputFile
-> ExceptT ShelleyQueryCmdError IO ()
runQueryTip protocol network mOutFile = do
runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do
SocketPath sockPath <- firstExceptT ShelleyQueryCmdEnvVarSocketErr readEnvSocketPath
output <-
firstExceptT ShelleyQueryCmdLocalStateQueryError $
withlocalNodeConnectInfo protocol network sockPath $ \connectInfo -> do
tip <- liftIO $ getLocalTip connectInfo
let output = case localNodeConsensusMode connectInfo of
ByronMode{} -> encodePretty tip
ShelleyMode{} -> encodePretty tip
CardanoMode{} -> encodePretty tip
return output
let localNodeConnInfo = NewIPC.LocalNodeConnectInfo cModeParams network sockPath

tip <- liftIO $ NewIPC.getLocalChainTip localNodeConnInfo

let output = case NewIPC.localConsensusMode localNodeConnInfo of
Mode.ByronMode -> encodePretty tip
Mode.ShelleyMode -> encodePretty tip
Mode.CardanoMode -> encodePretty tip
Jimbo4350 marked this conversation as resolved.
Show resolved Hide resolved

case mOutFile of
Just (OutputFile fpath) -> liftIO $ LBS.writeFile fpath output
Nothing -> liftIO $ LBS.putStrLn output
Expand Down