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 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
8 changes: 6 additions & 2 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ library
--TODO: these should either be removed once the new IPC
-- is fully integrated, or re-exported via the export
-- modules above
Cardano.Api.Block
Cardano.Api.Crypto.Ed25519Bip32
Cardano.Api.Eras
Cardano.Api.LocalChainSync
Cardano.Api.Modes
Cardano.Api.Orphans
Cardano.Api.Protocol
Cardano.Api.ProtocolParameters
Cardano.Api.Protocol.Byron
Cardano.Api.Protocol.Cardano
Cardano.Api.Protocol.Shelley
Cardano.Api.Protocol.Types
Cardano.Api.Query
Cardano.Api.Shelley.Genesis
Cardano.Api.TxInMode
Cardano.Api.TxSubmit
Expand All @@ -48,7 +51,7 @@ library

-- Splitting up the big Typed module:
Cardano.Api.Address
Cardano.Api.Block
-- TODO: move here Cardano.Api.Block
Cardano.Api.Certificate
Cardano.Api.Error
Cardano.Api.Fees
Expand All @@ -62,7 +65,7 @@ library
Cardano.Api.NetworkId
Cardano.Api.OperationalCertificate
-- TODO: move here Cardano.Api.ProtocolParameters
Cardano.Api.Query
-- TODO: move here Cardano.Api.Query
Cardano.Api.Script
Cardano.Api.SerialiseBech32
Cardano.Api.SerialiseCBOR
Expand Down Expand Up @@ -121,6 +124,7 @@ library
, scientific
, serialise
, shelley-spec-ledger
, small-steps
, stm
, text
, time
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ module Cardano.Api (
deserialiseFromRawBytes,
serialiseToRawBytesHex,
deserialiseFromRawBytesHex,
serialiseToRawBytesHexText,

-- ** Text envelope
-- | Support for a envelope file format with text headers and a hex-encoded
Expand Down
7 changes: 6 additions & 1 deletion cardano-api/src/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ module Cardano.Api.Address (

import Prelude

import Data.Aeson (ToJSON (..))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Base58 as Base58
import Data.Text (Text)
import qualified Data.Text.Encoding as Text
Expand Down Expand Up @@ -312,6 +314,9 @@ data AddressInEra era where
-> Address addrtype
-> AddressInEra era

instance IsCardanoEra era => ToJSON (AddressInEra era) where
toJSON = Aeson.String . serialiseAddress

instance Eq (AddressInEra era) where
(==) (AddressInEra ByronAddressInAnyEra addr1)
(AddressInEra ByronAddressInAnyEra addr2) = addr1 == addr2
Expand Down Expand Up @@ -349,7 +354,7 @@ instance IsCardanoEra era => SerialiseAsRawBytes (AddressInEra era) where
serialiseToRawBytes (AddressInEra ShelleyAddressInEra{} addr) =
serialiseToRawBytes addr

deserialiseFromRawBytes _ bs = do
deserialiseFromRawBytes _ bs =
anyAddressInEra cardanoEra =<< deserialiseFromRawBytes AsAddressAny bs

instance IsCardanoEra era => SerialiseAddress (AddressInEra era) where
Expand Down
34 changes: 22 additions & 12 deletions cardano-api/src/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,30 @@ 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 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

Expand Down Expand Up @@ -326,6 +328,14 @@ data ChainTip = ChainTipAtGenesis
| ChainTip !SlotNo !(Hash BlockHeader) !BlockNo
deriving (Eq, Show)

instance ToJSON ChainTip where
toJSON ChainTipAtGenesis = Aeson.Null
toJSON (ChainTip slot headerHash (Consensus.BlockNo bNum)) =
object [ "slot" .= slot
, "hash" .= serialiseToRawBytesHexText headerHash
, "block" .= bNum
]

chainTipToChainPoint :: ChainTip -> ChainPoint
chainTipToChainPoint ChainTipAtGenesis = ChainPointAtGenesis
chainTipToChainPoint (ChainTip s h _) = ChainPoint s h
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/src/Cardano/Api/IPC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ submitTxToNodeLocal connctInfo tx = do
--


getLocalChainTip :: LocalNodeConnectInfo mode -> IO ChainPoint
getLocalChainTip :: LocalNodeConnectInfo mode -> IO ChainTip
getLocalChainTip localNodeConInfo = do
resultVar <- newEmptyTMVarIO
connectToLocalNode
Expand All @@ -497,7 +497,7 @@ getLocalChainTip localNodeConInfo = do
, localTxSubmissionClient = Nothing
, localStateQueryClient = Nothing
}
atomically $ chainTipToChainPoint <$> takeTMVar resultVar
atomically $ takeTMVar resultVar

chainSyncGetCurrentTip
:: forall mode. TMVar ChainTip
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/KeysByron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ instance Key ByronKey where

newtype VerificationKey ByronKey =
ByronVerificationKey Byron.VerificationKey
deriving stock (Eq)
deriving stock Eq
deriving (Show, IsString) via UsingRawBytesHex (VerificationKey ByronKey)
deriving newtype (ToCBOR, FromCBOR)
deriving anyclass SerialiseAsCBOR
Expand Down
Loading