Skip to content

Commit

Permalink
Merge #2136
Browse files Browse the repository at this point in the history
2136: Update query cli commands to handle Allegra and Mary eras r=dcoutts a=Jimbo4350



Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
Co-authored-by: Duncan Coutts <duncan@well-typed.com>
  • Loading branch information
3 people committed Dec 1, 2020
2 parents f2f724c + 99ac681 commit c2bbcbe
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 167 deletions.
15 changes: 7 additions & 8 deletions cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ module Cardano.Api.Shelley
-- * Payment addresses
-- | Constructing and inspecting Shelley payment addresses
Address(ShelleyAddress),
fromShelleyAddr,
fromShelleyStakeAddr,
toShelleyAddr,
toShelleyStakeAddr,
fromShelleyAddr,
toShelleyStakeCredential,
fromShelleyStakeCredential,
NetworkId(Mainnet, Testnet),

-- * Stake addresses
PaymentCredential(..),
StakeAddress(..),
StakeAddressReference(..),
StakeCredential(..),
toShelleyStakeAddr,
fromShelleyStakeAddr,
fromShelleyStakeReference,
fromShelleyPaymentCredential,

-- * Building transactions
-- | Constructing and inspecting transactions
Expand Down Expand Up @@ -78,11 +82,6 @@ module Cardano.Api.Shelley
EpochNo(..),
NetworkMagic(..),

-- * Credentials & stake references
fromShelleyPaymentCredential,
fromShelleyStakeCredential,
fromShelleyStakeReference,

-- * Scripts
toShelleyScript,
toShelleyMultiSig,
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ renderPoolCmd cmd =
PoolMetaDataHash {} -> "stake-pool metadata-hash"

data QueryCmd =
QueryProtocolParameters Protocol NetworkId (Maybe OutputFile)
QueryProtocolParameters AnyCardanoEra Protocol NetworkId (Maybe OutputFile)
| QueryTip Protocol NetworkId (Maybe OutputFile)
| QueryStakeDistribution Protocol NetworkId (Maybe OutputFile)
| QueryStakeAddressInfo Protocol StakeAddress NetworkId (Maybe OutputFile)
| QueryUTxO Protocol QueryFilter NetworkId (Maybe OutputFile)
| QueryLedgerState Protocol NetworkId (Maybe OutputFile)
| QueryProtocolState Protocol NetworkId (Maybe OutputFile)
| QueryStakeDistribution AnyCardanoEra Protocol NetworkId (Maybe OutputFile)
| QueryStakeAddressInfo AnyCardanoEra Protocol StakeAddress NetworkId (Maybe OutputFile)
| QueryUTxO AnyCardanoEra Protocol QueryFilter NetworkId (Maybe OutputFile)
| QueryLedgerState AnyCardanoEra Protocol NetworkId (Maybe OutputFile)
| QueryProtocolState AnyCardanoEra Protocol NetworkId (Maybe OutputFile)
deriving (Eq, Show)

renderQueryCmd :: QueryCmd -> Text
Expand Down
61 changes: 58 additions & 3 deletions cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import Cardano.Crypto.Hash.Class as Crypto
import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..))
import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..))
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..))
import Ouroboros.Consensus.Shelley.Eras (ShelleyBasedEra, StandardCrypto, StandardShelley)
import Ouroboros.Consensus.Shelley.Eras
(ShelleyBasedEra, StandardCrypto,
StandardShelley, StandardAllegra, StandardMary)
import Ouroboros.Network.Block (BlockNo (..), HeaderHash, Tip (..))

import qualified Cardano.Ledger.Core as Core
Expand All @@ -50,6 +52,8 @@ import qualified Shelley.Spec.Ledger.STS.Tickn as Ledger
import Shelley.Spec.Ledger.TxBody (TxId (..), TxIn (..), TxOut (..))
import Shelley.Spec.Ledger.UTxO (UTxO (..))

import qualified Cardano.Ledger.Mary.Value as Ledger.Mary

instance ShelleyBasedEra era => ToJSONKey (TxIn era) where
toJSONKey = ToJSONKeyText txInToText (Aeson.text . txInToText)

Expand Down Expand Up @@ -108,22 +112,33 @@ deriving newtype instance ToJSON (HashHeader era)
deriving newtype instance ToJSON (MetaDataHash era)
deriving newtype instance ToJSON Ledger.LogWeight
deriving newtype instance ToJSON Ledger.Likelihood
deriving newtype instance ToJSON (Ledger.Stake StandardShelley)
deriving newtype instance ToJSON (Ledger.PoolDistr StandardCrypto)
deriving newtype instance ToJSON DeltaCoin

deriving newtype instance ToJSON (Ledger.Stake StandardShelley)
deriving newtype instance ToJSON (Ledger.Stake StandardAllegra)
deriving newtype instance ToJSON (Ledger.Stake StandardMary)

deriving anyclass instance ToJSON (Ledger.GenDelegs StandardCrypto)
deriving anyclass instance ToJSON (Ledger.IndividualPoolStake StandardCrypto)

deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardShelley)
deriving anyclass instance ToJSON (Ledger.PPUPState StandardShelley)
deriving anyclass instance ToJSON (Ledger.BlocksMade StandardShelley)

deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardAllegra)
deriving anyclass instance ToJSON (Ledger.PPUPState StandardAllegra)
deriving anyclass instance ToJSON (Ledger.BlocksMade StandardAllegra)

deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardMary)
deriving anyclass instance ToJSON (Ledger.PPUPState StandardMary)
deriving anyclass instance ToJSON (Ledger.BlocksMade StandardMary)

deriving instance ToJSON Ledger.Ptr
deriving instance ToJSON Ledger.AccountState

deriving instance ToJSON (Ledger.DPState StandardShelley)
deriving instance ToJSON (Ledger.DState StandardShelley)
deriving instance ToJSON (Ledger.FutureGenDeleg StandardCrypto)
deriving instance ToJSON (Ledger.InstantaneousRewards StandardShelley)
deriving instance ToJSON (Ledger.SnapShot StandardShelley)
deriving instance ToJSON (Ledger.SnapShots StandardShelley)
Expand All @@ -136,12 +151,52 @@ deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardShelley)
deriving instance ToJSON (Ledger.PState StandardShelley)
deriving instance ToJSON (Ledger.StakeReference StandardShelley)
deriving instance ToJSON (Ledger.UTxOState StandardShelley)

deriving instance ToJSON (Ledger.DPState StandardAllegra)
deriving instance ToJSON (Ledger.DState StandardAllegra)
deriving instance ToJSON (Ledger.InstantaneousRewards StandardAllegra)
deriving instance ToJSON (Ledger.SnapShot StandardAllegra)
deriving instance ToJSON (Ledger.SnapShots StandardAllegra)
deriving instance ToJSON (Ledger.NonMyopic StandardAllegra)
deriving instance ToJSON (Ledger.LedgerState StandardAllegra)
deriving instance ToJSON (Ledger.EpochState StandardAllegra)
deriving instance ToJSON (Ledger.RewardUpdate StandardAllegra)
deriving instance ToJSON (Ledger.NewEpochState StandardAllegra)
deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardAllegra)
deriving instance ToJSON (Ledger.PState StandardAllegra)
deriving instance ToJSON (Ledger.StakeReference StandardAllegra)
deriving instance ToJSON (Ledger.UTxOState StandardAllegra)

deriving instance ToJSON (Ledger.DPState StandardMary)
deriving instance ToJSON (Ledger.DState StandardMary)
deriving instance ToJSON (Ledger.InstantaneousRewards StandardMary)
deriving instance ToJSON (Ledger.SnapShot StandardMary)
deriving instance ToJSON (Ledger.SnapShots StandardMary)
deriving instance ToJSON (Ledger.NonMyopic StandardMary)
deriving instance ToJSON (Ledger.LedgerState StandardMary)
deriving instance ToJSON (Ledger.EpochState StandardMary)
deriving instance ToJSON (Ledger.RewardUpdate StandardMary)
deriving instance ToJSON (Ledger.NewEpochState StandardMary)
deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardMary)
deriving instance ToJSON (Ledger.PState StandardMary)
deriving instance ToJSON (Ledger.StakeReference StandardMary)
deriving instance ToJSON (Ledger.UTxOState StandardMary)

deriving instance ToJSON (Ledger.FutureGenDeleg StandardCrypto)
deriving instance ToJSON (Ledger.PrtclState StandardCrypto)
deriving instance ToJSON Ledger.TicknState
deriving instance ToJSON (Ledger.ChainDepState StandardCrypto)

deriving instance ToJSONKey Ledger.Ptr
deriving instance ToJSONKey (Ledger.FutureGenDeleg StandardCrypto)

deriving anyclass instance ToJSON (Ledger.Mary.Value StandardMary)
deriving newtype instance ToJSON (Ledger.Mary.PolicyID StandardMary)
deriving anyclass instance ToJSONKey (Ledger.Mary.PolicyID StandardMary)
deriving anyclass instance ToJSONKey Ledger.Mary.AssetName

instance ToJSON Ledger.Mary.AssetName where
toJSON (Ledger.Mary.AssetName bs) = toJSON (Text.decodeLatin1 bs)

instance (ToJSONKey k, ToJSON v) => ToJSON (SetAlgebra.BiMap v k v) where
toJSON = toJSON . SetAlgebra.forwards -- to normal Map
43 changes: 27 additions & 16 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -670,41 +670,52 @@ pQueryCmd =
pQueryProtocolParameters :: Parser QueryCmd
pQueryProtocolParameters =
QueryProtocolParameters
<$> pProtocol
<$> pCardanoEra
<*> pProtocol
<*> pNetworkId
<*> pMaybeOutputFile

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

pQueryUTxO :: Parser QueryCmd
pQueryUTxO =
QueryUTxO
<$> pProtocol
<$> pCardanoEra
<*> pProtocol
<*> pQueryFilter
<*> pNetworkId
<*> pMaybeOutputFile

pQueryStakeDistribution :: Parser QueryCmd
pQueryStakeDistribution =
QueryStakeDistribution
<$> pProtocol
<$> pCardanoEra
<*> pProtocol
<*> pNetworkId
<*> pMaybeOutputFile

pQueryStakeAddressInfo :: Parser QueryCmd
pQueryStakeAddressInfo =
QueryStakeAddressInfo
<$> pProtocol
<$> pCardanoEra
<*> pProtocol
<*> pFilterByStakeAddress
<*> pNetworkId
<*> pMaybeOutputFile

pQueryLedgerState :: Parser QueryCmd
pQueryLedgerState = QueryLedgerState <$> pProtocol <*> pNetworkId <*> pMaybeOutputFile
pQueryLedgerState = QueryLedgerState <$> pCardanoEra <*> pProtocol <*> pNetworkId <*> pMaybeOutputFile

pQueryProtocolState :: Parser QueryCmd
pQueryProtocolState = QueryProtocolState <$> pProtocol <*> pNetworkId <*> pMaybeOutputFile
pQueryProtocolState = QueryProtocolState
<$> pCardanoEra
<*> pProtocol
<*> pNetworkId
<*> pMaybeOutputFile

pGovernanceCmd :: Parser GovernanceCmd
pGovernanceCmd =
Expand Down Expand Up @@ -2262,36 +2273,36 @@ pProtocol =
( Opt.long "shelley-mode"
<> Opt.help "For talking to a node running in Shelley-only mode."
)
*> pShelley
*> pShelleyMode
)
<|>
( Opt.flag' ()
( Opt.long "byron-mode"
<> Opt.help "For talking to a node running in Byron-only mode."
)
*> pByron
*> pByronMode
)
<|>
( Opt.flag' ()
( Opt.long "cardano-mode"
<> Opt.help "For talking to a node running in full Cardano mode (default)."
)
*> pCardano
*> pCardanoMode
)
<|>
-- Default to the Cardano protocol.
pure
(CardanoProtocol
(EpochSlots defaultByronEpochSlots))
where
pByron :: Parser Protocol
pByron = ByronProtocol <$> pEpochSlots
pByronMode :: Parser Protocol
pByronMode = ByronProtocol <$> pEpochSlots

pShelley :: Parser Protocol
pShelley = pure ShelleyProtocol
pShelleyMode :: Parser Protocol
pShelleyMode = pure ShelleyProtocol

pCardano :: Parser Protocol
pCardano = CardanoProtocol <$> pEpochSlots
pCardanoMode :: Parser Protocol
pCardanoMode = CardanoProtocol <$> pEpochSlots

pEpochSlots :: Parser EpochSlots
pEpochSlots =
Expand Down
Loading

0 comments on commit c2bbcbe

Please sign in to comment.