Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 1626f65

Browse files
authored
Merge pull request #3707 from input-output-hk/paweljakubas/CO-413/remove-wallet-dep-from-orphans
[CO-413] Removing wallet-new/src/Cardano/Wallet/Orphans*
2 parents bbb1543 + bf33d9f commit 1626f65

File tree

12 files changed

+49
-110
lines changed

12 files changed

+49
-110
lines changed

wallet-new/cardano-sl-wallet-new.cabal

-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ library
116116
Cardano.Wallet.Kernel.Util.StrictNonEmpty
117117
Cardano.Wallet.Kernel.Util.StrictStateT
118118
Cardano.Wallet.Kernel.Wallets
119-
Cardano.Wallet.Orphans
120-
Cardano.Wallet.Orphans.Aeson
121-
Cardano.Wallet.Orphans.Arbitrary
122-
Cardano.Wallet.Orphans.Bi
123119
Cardano.Wallet.Server
124120
Cardano.Wallet.Server.CLI
125121
Cardano.Wallet.Server.Middlewares

wallet-new/src/Cardano/Wallet/API/V1/Swagger/Example.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Data.Swagger (Definitions, NamedSchema (..), Schema,
88
import Data.Swagger.Declare (Declare)
99
import Data.Typeable (typeOf)
1010

11-
import Cardano.Wallet.Orphans.Arbitrary ()
1211
import Test.QuickCheck (Arbitrary (..), listOf1)
1312
import Test.QuickCheck.Gen (Gen (..), resize)
1413
import Test.QuickCheck.Random (mkQCGen)
@@ -21,7 +20,7 @@ class Arbitrary a => Example a where
2120
example = arbitrary
2221

2322
instance Example ()
24-
instance Example a => Example (NonEmpty a)
23+
instance (Example a, Arbitrary (NonEmpty a) ) => Example (NonEmpty a)
2524

2625
-- NOTE: we don't want to see empty list examples in our swagger doc :)
2726
instance Example a => Example [a] where

wallet-new/src/Cardano/Wallet/API/V1/Types.hs

+40-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{-# LANGUAGE StandaloneDeriving #-}
1212
{-# LANGUAGE StrictData #-}
1313
{-# LANGUAGE TemplateHaskell #-}
14-
14+
{-# LANGUAGE ViewPatterns #-}
1515
-- The hlint parser fails on the `pattern` function, so we disable the
1616
-- language extension here.
1717
{-# LANGUAGE NoPatternSynonyms #-}
@@ -161,8 +161,9 @@ import Data.Swagger.Internal.TypeShape (GenericHasSimpleShape,
161161
GenericShape)
162162
import Data.Text (Text, dropEnd, toLower)
163163
import qualified Data.Text as T
164-
import Data.Version (Version)
165-
import Formatting (bprint, build, fconst, int, sformat, stext, (%))
164+
import Data.Version (Version (..), parseVersion, showVersion)
165+
import Formatting (bprint, build, fconst, int, sformat, shown, stext,
166+
(%))
166167
import qualified Formatting.Buildable
167168
import Generics.SOP.TH (deriveGeneric)
168169
import GHC.Generics (Generic, Rep)
@@ -186,7 +187,6 @@ import Cardano.Wallet.API.V1.Generic (jsendErrorGenericParseJSON,
186187
jsendErrorGenericToJSON)
187188
import Cardano.Wallet.API.V1.Swagger.Example (Example, example,
188189
genExample)
189-
import Cardano.Wallet.Orphans.Aeson ()
190190
import Cardano.Wallet.Types.UtxoStatistics
191191
import Cardano.Wallet.Util (mkJsonKey, showApiUtcTime)
192192

@@ -195,7 +195,6 @@ import qualified Pos.Binary.Class as Bi
195195
import qualified Pos.Chain.Txp as Txp
196196
import qualified Pos.Chain.Update as Core
197197
import qualified Pos.Client.Txp.Util as Core
198-
import Pos.Core (addressF)
199198
import qualified Pos.Core as Core
200199
import Pos.Crypto (Hash, PublicKey (..), decodeHash, hashHexF)
201200
import qualified Pos.Crypto.Signing as Core
@@ -206,7 +205,10 @@ import Pos.Infra.Util.LogSafe (BuildableSafeGen (..), SecureLog (..),
206205
buildSafe, buildSafeList, buildSafeMaybe,
207206
deriveSafeBuildable, plainOrSecureF)
208207
import Pos.Util.Servant (Flaggable (..))
208+
209+
import Test.Pos.Chain.Update.Arbitrary ()
209210
import Test.Pos.Core.Arbitrary ()
211+
import Text.ParserCombinators.ReadP (readP_to_S)
210212

211213
-- | Declare generic schema, while documenting properties
212214
-- For instance:
@@ -312,7 +314,7 @@ instance Bounded a => Bounded (V1 a) where
312314
minBound = V1 $ minBound @a
313315
maxBound = V1 $ maxBound @a
314316

315-
instance Buildable a => Buildable (V1 a) where
317+
instance {-# OVERLAPPABLE #-} Buildable a => Buildable (V1 a) where
316318
build (V1 x) = bprint build x
317319

318320
instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where
@@ -321,7 +323,6 @@ instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where
321323
instance (Buildable a, Buildable b) => Buildable (a, b) where
322324
build (a, b) = bprint ("("%build%", "%build%")") a b
323325

324-
325326
--
326327
-- Benign instances
327328
--
@@ -380,8 +381,17 @@ instance ToSchema (V1 Core.Coin) where
380381
& type_ .~ SwaggerNumber
381382
& maximum_ .~ Just (fromIntegral Core.maxCoinVal)
382383

384+
instance ToHttpApiData Core.Coin where
385+
toQueryParam = pretty . Core.coinToInteger
386+
387+
instance FromHttpApiData Core.Coin where
388+
parseUrlPiece p = do
389+
c <- Core.Coin <$> parseQueryParam p
390+
Core.checkCoin c
391+
pure c
392+
383393
instance ToJSON (V1 Core.Address) where
384-
toJSON (V1 c) = String $ sformat addressF c
394+
toJSON (V1 c) = String $ sformat Core.addressF c
385395

386396
instance FromJSON (V1 Core.Address) where
387397
parseJSON (String a) = case Core.decodeTextAddress a of
@@ -2405,17 +2415,36 @@ instance BuildableSafeGen SlotDuration where
24052415
data NodeSettings = NodeSettings {
24062416
setSlotDuration :: !SlotDuration
24072417
, setSoftwareInfo :: !(V1 Core.SoftwareVersion)
2408-
, setProjectVersion :: !Version
2418+
, setProjectVersion :: !(V1 Version)
24092419
, setGitRevision :: !Text
24102420
} deriving (Show, Eq, Generic)
24112421

24122422
#if !(MIN_VERSION_swagger2(2,2,2))
24132423
-- See note [Version Orphan]
2414-
instance ToSchema Version where
2424+
instance ToSchema (V1 Version) where
24152425
declareNamedSchema _ =
2416-
pure $ NamedSchema (Just "Version") $ mempty
2426+
pure $ NamedSchema (Just "V1Version") $ mempty
24172427
& type_ .~ SwaggerString
24182428

2429+
instance Buildable (V1 Version) where
2430+
build (V1 v) = bprint shown v
2431+
2432+
instance Buildable (SecureLog (V1 Version)) where
2433+
build (SecureLog x) = Formatting.Buildable.build x
2434+
2435+
instance ToJSON (V1 Version) where
2436+
toJSON (V1 v) = toJSON (showVersion v)
2437+
2438+
instance FromJSON (V1 Version) where
2439+
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of
2440+
(reverse -> ((ver,_):_)) -> pure (V1 ver)
2441+
_ -> mempty
2442+
parseJSON x = typeMismatch "Not a valid Version" x
2443+
2444+
instance Arbitrary (V1 Version) where
2445+
arbitrary = fmap V1 arbitrary
2446+
2447+
24192448
-- Note [Version Orphan]
24202449
-- I have opened a PR to add an instance of 'Version' to the swagger2
24212450
-- library. When the PR is merged, we can delete the instance here and remove the warning from the file.

wallet-new/src/Cardano/Wallet/Kernel/DB/Util/AcidState.hs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import Cardano.Wallet.Kernel.DB.Util.IxSet (HasPrimKey, Indexable,
4747
import qualified Cardano.Wallet.Kernel.DB.Util.IxSet as IxSet
4848
import qualified Cardano.Wallet.Kernel.DB.Util.Zoomable as Z
4949
import Cardano.Wallet.Kernel.Util.StrictStateT
50-
import Cardano.Wallet.Orphans ()
5150
import UTxO.Util (mustBeRight)
5251

5352
{-------------------------------------------------------------------------------

wallet-new/src/Cardano/Wallet/Orphans.hs

-19
This file was deleted.

wallet-new/src/Cardano/Wallet/Orphans/Aeson.hs

-11
This file was deleted.

wallet-new/src/Cardano/Wallet/Orphans/Arbitrary.hs

-52
This file was deleted.

wallet-new/src/Cardano/Wallet/Orphans/Bi.hs

-3
This file was deleted.

wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Settings.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ getNodeSettings w = liftIO $
2222
V1.NodeSettings
2323
<$> (mkSlotDuration <$> Node.getNextEpochSlotDuration node)
2424
<*> (V1 <$> Node.curSoftwareVersion node)
25-
<*> pure version
25+
<*> pure (V1 version)
2626
<*> (mkGitRevision <$> Node.compileInfo node)
2727
where
2828
mkSlotDuration :: Millisecond -> V1.SlotDuration

wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Cardano.Wallet.WalletLayer.QuickCheck
99
import Universum
1010

1111
import Cardano.Wallet.Kernel.Diffusion (WalletDiffusion (..))
12-
import Cardano.Wallet.Orphans.Arbitrary ()
1312
import Cardano.Wallet.WalletLayer (ActiveWalletLayer (..),
1413
DeleteAccountError (..), DeleteWalletError (..),
1514
GetAccountError (..), GetAccountsError (..),

wallet-new/test/MarshallingSpec.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import Universum
99
import Control.Lens (from, to)
1010
import Data.Aeson
1111
import qualified Data.ByteString as BS
12-
import Data.SafeCopy hiding (Migrate)
12+
import Data.SafeCopy hiding (Migrate, Version)
1313
import Data.Serialize (runGet, runPut)
1414
import Data.Time (UTCTime (..), fromGregorian)
1515
import Data.Time.Clock.POSIX (POSIXTime)
1616
import Data.Typeable (typeRep)
17+
import Data.Version (Version)
1718
import Pos.Client.Txp.Util (InputSelectionPolicy)
1819
import qualified Pos.Crypto as Crypto
1920
import Servant.API (FromHttpApiData (..), ToHttpApiData (..))
@@ -43,7 +44,6 @@ import Cardano.Wallet.API.V1.Types
4344
import Cardano.Wallet.Kernel.DB.HdWallet (HdRoot)
4445
import Cardano.Wallet.Kernel.DB.InDb (InDb (..))
4546
import qualified Cardano.Wallet.Kernel.Util.Strict as Strict
46-
import Cardano.Wallet.Orphans ()
4747
import qualified Cardano.Wallet.Util as Util
4848

4949
-- | Tests whether or not some instances (JSON, Bi, etc) roundtrips.
@@ -84,6 +84,7 @@ spec = parallel $ describe "Marshalling & Unmarshalling" $ do
8484
aesonRoundtripProp @SyncThroughput Proxy
8585
aesonRoundtripProp @AccountIndex Proxy
8686
aesonRoundtripProp @(V1 AddressOwnership) Proxy
87+
aesonRoundtripProp @(V1 Version) Proxy
8788

8889
-- HttpApiData roundtrips
8990
httpApiDataRoundtripProp @AccountIndex Proxy

wallet-new/test/SwaggerSpec.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import Cardano.Wallet.API.Response (ValidJSON)
2121
import qualified Cardano.Wallet.API.V1 as V1
2222
import Cardano.Wallet.API.V1.Swagger ()
2323
import qualified Cardano.Wallet.API.V1.Swagger as Swagger
24-
import Cardano.Wallet.Orphans.Aeson ()
25-
import Cardano.Wallet.Orphans.Arbitrary ()
2624
import Pos.Chain.Update (ApplicationName (..), SoftwareVersion (..))
2725
import Pos.Util.CompileInfo (CompileTimeInfo (CompileTimeInfo),
2826
gitRev)
@@ -31,7 +29,7 @@ import Pos.Util.CompileInfo (CompileTimeInfo (CompileTimeInfo),
3129
import Data.Aeson (ToJSON)
3230
import Servant.Swagger.Internal.Test (props)
3331
import Servant.Swagger.Internal.TypeLevel (BodyTypes, Every, TMap)
34-
import Test.QuickCheck (Arbitrary)
32+
import Test.QuickCheck (Arbitrary, arbitrary)
3533

3634
-- Syntethic instances and orphans to be able to use `validateEveryToJSON`.
3735
-- In the future, hopefully, we will never need these.
@@ -52,6 +50,9 @@ instance ToSchema NoContent where
5250
& type_ .~ SwaggerArray
5351
& maxLength .~ Just 0
5452

53+
instance Arbitrary NoContent where
54+
arbitrary = pure NoContent
55+
5556
spec :: Spec
5657
spec = modifyMaxSuccess (const 10) $ do
5758
describe "Swagger Integration" $ do

0 commit comments

Comments
 (0)