Skip to content

Commit

Permalink
move jormungandr-specific data-type into jormungandr package target
Browse files Browse the repository at this point in the history
This cleans up a bit the metadata-related types because it had become a mess. In the end, we'll keep in the core package
the types as they're expected by cardano-wallet-shelley and simply move the exceptional ones (jormungandr) inside its
relevant package.
  • Loading branch information
KtorZ committed Jun 17, 2020
1 parent 37eaf45 commit 68770fc
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 458 deletions.
28 changes: 0 additions & 28 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ module Cardano.Wallet.Api.Types
, ApiCoinSelectionInput (..)
, ApiStakePool (..)
, ApiStakePoolMetrics (..)
, ApiJormungandrStakePool (..)
, ApiJormungandrStakePoolMetrics (..)
, ApiWallet (..)
, ApiWalletPassphrase (..)
, ApiWalletPassphraseInfo (..)
Expand Down Expand Up @@ -407,22 +405,6 @@ data ApiStakePoolMetrics = ApiStakePoolMetrics
, producedBlocks :: !(Quantity "block" Natural)
} deriving (Eq, Generic, Show)

data ApiJormungandrStakePool = ApiJormungandrStakePool
{ id :: !(ApiT PoolId)
, metrics :: !ApiJormungandrStakePoolMetrics
, apparentPerformance :: !Double
, metadata :: !(Maybe (ApiT StakePoolMetadata))
, cost :: !(Quantity "lovelace" Natural)
, margin :: !(Quantity "percent" Percentage)
, desirability :: !Double
, saturation :: !Double
} deriving (Eq, Generic, Show)

data ApiJormungandrStakePoolMetrics = ApiJormungandrStakePoolMetrics
{ controlledStake :: !(Quantity "lovelace" Natural)
, producedBlocks :: !(Quantity "block" Natural)
} deriving (Eq, Generic, Show)

data ApiUtxoStatistics = ApiUtxoStatistics
{ total :: !(Quantity "lovelace" Natural)
, scale :: !(ApiT BoundType)
Expand Down Expand Up @@ -1082,16 +1064,6 @@ instance FromJSON ApiStakePoolMetrics where
instance ToJSON ApiStakePoolMetrics where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiJormungandrStakePool where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiJormungandrStakePool where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiJormungandrStakePoolMetrics where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiJormungandrStakePoolMetrics where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON (ApiT WalletName) where
parseJSON = parseJSON >=> eitherToParser . bimap ShowFmt ApiT . fromText
instance ToJSON (ApiT WalletName) where
Expand Down
19 changes: 2 additions & 17 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ module Cardano.Wallet.Primitive.Types
, StakePoolMetadata (..)
, StakePoolMetadataHash (..)
, StakePoolTicker (..)
, sameStakePoolMetadata

-- * Querying
, SortOrder (..)
Expand Down Expand Up @@ -599,35 +598,21 @@ instance ToText StakePoolMetadataHash where
instance FromText StakePoolMetadataHash where
fromText = fmap (StakePoolMetadataHash . getHash @"_") . hashFromText 32

-- | Information about a stake pool, published by a stake pool owner in the
-- stake pool registry.
--
-- The wallet searches for registrations involving the owner, to find metadata
-- for a given PoolID.
-- | Information about a stake pool.
--
-- The metadata information is not used directly by cardano-wallet, but rather
-- passed straight through to API consumers.
data StakePoolMetadata = StakePoolMetadata
{ owner :: PoolOwner
-- ^ Bech32-encoded ed25519 public key.
, ticker :: StakePoolTicker
{ ticker :: StakePoolTicker
-- ^ Very short human-readable ID for the stake pool.
, name :: Text
-- ^ Name of the stake pool.
, description :: Maybe Text
-- ^ Short description of the stake pool.
, homepage :: Text
-- ^ Absolute URL for the stake pool's homepage link.
, pledgeAddress :: Text
-- ^ Bech32-encoded address.
} deriving (Eq, Show, Generic)

-- | Returns 'True' iff metadata is exactly equal, modulo 'PoolOwner'.
sameStakePoolMetadata :: StakePoolMetadata -> StakePoolMetadata -> Bool
sameStakePoolMetadata a b = a { owner = same } == b { owner = same }
where
same = PoolOwner mempty

-- | Very short name for a stake pool.
newtype StakePoolTicker = StakePoolTicker { unStakePoolTicker :: Text }
deriving stock (Generic, Show, Eq)
Expand Down
292 changes: 0 additions & 292 deletions lib/core/test/data/Cardano/Wallet/Api/ApiJormungandrStakePool.json

This file was deleted.

1 change: 1 addition & 0 deletions lib/core/test/unit/Cardano/Pool/DB/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Test.QuickCheck
, choose
, elements
, listOf
, oneof
, scale
, shrinkIntegral
, shrinkList
Expand Down
Loading

0 comments on commit 68770fc

Please sign in to comment.