-
Notifications
You must be signed in to change notification settings - Fork 631
[CO-413] Removing wallet-new/src/Cardano/Wallet/Orphans* #3707
Changes from all commits
af27e67
4511aad
876650e
08efbe2
f48828a
9e7afa8
263a2d0
bd5f7db
a3c5ad3
3ac8fff
a7aa43f
0422acf
89dbc08
1eda5e6
62b01e3
f10719e
f3d7bf3
5a7b414
5f7f8b6
d6825e5
ebde06f
8c4fc47
366da28
bf33d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE StrictData #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
{-# LANGUAGE ViewPatterns #-} | ||
-- The hlint parser fails on the `pattern` function, so we disable the | ||
-- language extension here. | ||
{-# LANGUAGE NoPatternSynonyms #-} | ||
|
@@ -161,8 +161,9 @@ import Data.Swagger.Internal.TypeShape (GenericHasSimpleShape, | |
GenericShape) | ||
import Data.Text (Text, dropEnd, toLower) | ||
import qualified Data.Text as T | ||
import Data.Version (Version) | ||
import Formatting (bprint, build, fconst, int, sformat, stext, (%)) | ||
import Data.Version (Version (..), parseVersion, showVersion) | ||
import Formatting (bprint, build, fconst, int, sformat, shown, stext, | ||
(%)) | ||
import qualified Formatting.Buildable | ||
import Generics.SOP.TH (deriveGeneric) | ||
import GHC.Generics (Generic, Rep) | ||
|
@@ -186,7 +187,6 @@ import Cardano.Wallet.API.V1.Generic (jsendErrorGenericParseJSON, | |
jsendErrorGenericToJSON) | ||
import Cardano.Wallet.API.V1.Swagger.Example (Example, example, | ||
genExample) | ||
import Cardano.Wallet.Orphans.Aeson () | ||
import Cardano.Wallet.Types.UtxoStatistics | ||
import Cardano.Wallet.Util (mkJsonKey, showApiUtcTime) | ||
|
||
|
@@ -195,7 +195,6 @@ import qualified Pos.Binary.Class as Bi | |
import qualified Pos.Chain.Txp as Txp | ||
import qualified Pos.Chain.Update as Core | ||
import qualified Pos.Client.Txp.Util as Core | ||
import Pos.Core (addressF) | ||
import qualified Pos.Core as Core | ||
import Pos.Crypto (Hash, PublicKey (..), decodeHash, hashHexF) | ||
import qualified Pos.Crypto.Signing as Core | ||
|
@@ -206,7 +205,10 @@ import Pos.Infra.Util.LogSafe (BuildableSafeGen (..), SecureLog (..), | |
buildSafe, buildSafeList, buildSafeMaybe, | ||
deriveSafeBuildable, plainOrSecureF) | ||
import Pos.Util.Servant (Flaggable (..)) | ||
|
||
import Test.Pos.Chain.Update.Arbitrary () | ||
import Test.Pos.Core.Arbitrary () | ||
import Text.ParserCombinators.ReadP (readP_to_S) | ||
|
||
-- | Declare generic schema, while documenting properties | ||
-- For instance: | ||
|
@@ -312,7 +314,7 @@ instance Bounded a => Bounded (V1 a) where | |
minBound = V1 $ minBound @a | ||
maxBound = V1 $ maxBound @a | ||
|
||
instance Buildable a => Buildable (V1 a) where | ||
instance {-# OVERLAPPABLE #-} Buildable a => Buildable (V1 a) where | ||
build (V1 x) = bprint build x | ||
|
||
instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where | ||
|
@@ -321,7 +323,6 @@ instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where | |
instance (Buildable a, Buildable b) => Buildable (a, b) where | ||
build (a, b) = bprint ("("%build%", "%build%")") a b | ||
|
||
|
||
-- | ||
-- Benign instances | ||
-- | ||
|
@@ -380,8 +381,17 @@ instance ToSchema (V1 Core.Coin) where | |
& type_ .~ SwaggerNumber | ||
& maximum_ .~ Just (fromIntegral Core.maxCoinVal) | ||
|
||
instance ToHttpApiData Core.Coin where | ||
toQueryParam = pretty . Core.coinToInteger | ||
|
||
instance FromHttpApiData Core.Coin where | ||
parseUrlPiece p = do | ||
c <- Core.Coin <$> parseQueryParam p | ||
Core.checkCoin c | ||
pure c | ||
|
||
instance ToJSON (V1 Core.Address) where | ||
toJSON (V1 c) = String $ sformat addressF c | ||
toJSON (V1 c) = String $ sformat Core.addressF c | ||
|
||
instance FromJSON (V1 Core.Address) where | ||
parseJSON (String a) = case Core.decodeTextAddress a of | ||
|
@@ -2405,17 +2415,36 @@ instance BuildableSafeGen SlotDuration where | |
data NodeSettings = NodeSettings { | ||
setSlotDuration :: !SlotDuration | ||
, setSoftwareInfo :: !(V1 Core.SoftwareVersion) | ||
, setProjectVersion :: !Version | ||
, setProjectVersion :: !(V1 Version) | ||
, setGitRevision :: !Text | ||
} deriving (Show, Eq, Generic) | ||
|
||
#if !(MIN_VERSION_swagger2(2,2,2)) | ||
-- See note [Version Orphan] | ||
instance ToSchema Version where | ||
instance ToSchema (V1 Version) where | ||
declareNamedSchema _ = | ||
pure $ NamedSchema (Just "Version") $ mempty | ||
pure $ NamedSchema (Just "V1Version") $ mempty | ||
& type_ .~ SwaggerString | ||
|
||
instance Buildable (V1 Version) where | ||
build (V1 v) = bprint shown v | ||
|
||
instance Buildable (SecureLog (V1 Version)) where | ||
build (SecureLog x) = Formatting.Buildable.build x | ||
|
||
instance ToJSON (V1 Version) where | ||
toJSON (V1 v) = toJSON (showVersion v) | ||
|
||
instance FromJSON (V1 Version) where | ||
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of | ||
(reverse -> ((ver,_):_)) -> pure (V1 ver) | ||
_ -> mempty | ||
parseJSON x = typeMismatch "Not a valid Version" x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's with the parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of
[(ver, _)] -> pure (V1 ver)
_ -> mempty Isn't that enough ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I need the last element. And I can have also [1,2] - hence the need to pattern match against the last element in the list There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arf. Okay. |
||
|
||
instance Arbitrary (V1 Version) where | ||
arbitrary = fmap V1 arbitrary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ho :o ! |
||
|
||
|
||
-- Note [Version Orphan] | ||
-- I have opened a PR to add an instance of 'Version' to the swagger2 | ||
-- library. When the PR is merged, we can delete the instance here and remove the warning from the file. | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We gotta need a roundtrip Aeson tests for that one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
certainly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is already in
wallet-new/test/MarshallingSpec.hs
line 95:but we are missing this one (although have
aesonRoundtripProp @(V1 Core.Coin) Proxy
):But if we test aeson roundtrips of
V1 Something
do we need to check aeson roundtrips ofSomething
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant the
httpAPIData
round trip of course :/ ...I didn't realize at first this was also (again) an orphan instance. I think we want instances to be on
V1 Core.Coin
here (like the others above). In such case (as for aeson instances, there's no point of doing a rountrip test on the non-wrapped type (Core.Coin
) itself, because we do want to test and use the wrapped instance. And chances are that there's not even an instance defined for the unwrapped type, which is good.May you do this change 🙏 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be addressed in https://iohk.myjetbrains.com/youtrack/issue/CO-422 for reasons specified therein