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

Commit 8c4fc47

Browse files
committed
[CO-413] Removing wallet-new/src/Cardano/Wallet/Orphans*
[CO-413] Relocating NoContent instance and adopt
1 parent ebde06f commit 8c4fc47

File tree

12 files changed

+48
-110
lines changed

12 files changed

+48
-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

+39-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,9 @@ import Pos.Infra.Util.LogSafe (BuildableSafeGen (..), SecureLog (..),
206205
buildSafe, buildSafeList, buildSafeMaybe,
207206
deriveSafeBuildable, plainOrSecureF)
208207
import Pos.Util.Servant (Flaggable (..))
208+
import Test.Pos.Chain.Update.Arbitrary ()
209209
import Test.Pos.Core.Arbitrary ()
210+
import Text.ParserCombinators.ReadP (readP_to_S)
210211

211212
-- | Declare generic schema, while documenting properties
212213
-- For instance:
@@ -312,7 +313,7 @@ instance Bounded a => Bounded (V1 a) where
312313
minBound = V1 $ minBound @a
313314
maxBound = V1 $ maxBound @a
314315

315-
instance Buildable a => Buildable (V1 a) where
316+
instance {-# OVERLAPPABLE #-} Buildable a => Buildable (V1 a) where
316317
build (V1 x) = bprint build x
317318

318319
instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where
@@ -321,7 +322,6 @@ instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where
321322
instance (Buildable a, Buildable b) => Buildable (a, b) where
322323
build (a, b) = bprint ("("%build%", "%build%")") a b
323324

324-
325325
--
326326
-- Benign instances
327327
--
@@ -380,8 +380,17 @@ instance ToSchema (V1 Core.Coin) where
380380
& type_ .~ SwaggerNumber
381381
& maximum_ .~ Just (fromIntegral Core.maxCoinVal)
382382

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

386395
instance FromJSON (V1 Core.Address) where
387396
parseJSON (String a) = case Core.decodeTextAddress a of
@@ -2405,17 +2414,36 @@ instance BuildableSafeGen SlotDuration where
24052414
data NodeSettings = NodeSettings {
24062415
setSlotDuration :: !SlotDuration
24072416
, setSoftwareInfo :: !(V1 Core.SoftwareVersion)
2408-
, setProjectVersion :: !Version
2417+
, setProjectVersion :: !(V1 Version)
24092418
, setGitRevision :: !Text
24102419
} deriving (Show, Eq, Generic)
24112420

24122421
#if !(MIN_VERSION_swagger2(2,2,2))
24132422
-- See note [Version Orphan]
2414-
instance ToSchema Version where
2423+
instance ToSchema (V1 Version) where
24152424
declareNamedSchema _ =
2416-
pure $ NamedSchema (Just "Version") $ mempty
2425+
pure $ NamedSchema (Just "V1Version") $ mempty
24172426
& type_ .~ SwaggerString
24182427

2428+
instance Buildable (V1 Version) where
2429+
build (V1 v) = bprint shown v
2430+
2431+
instance Buildable (SecureLog (V1 Version)) where
2432+
build (SecureLog x) = Formatting.Buildable.build x
2433+
2434+
instance ToJSON (V1 Version) where
2435+
toJSON (V1 v) = toJSON (showVersion v)
2436+
2437+
instance FromJSON (V1 Version) where
2438+
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of
2439+
(reverse -> ((ver,_):_)) -> pure (V1 ver)
2440+
_ -> mempty
2441+
parseJSON x = typeMismatch "Not a valid Version" x
2442+
2443+
instance Arbitrary (V1 Version) where
2444+
arbitrary = fmap V1 arbitrary
2445+
2446+
24192447
-- Note [Version Orphan]
24202448
-- I have opened a PR to add an instance of 'Version' to the swagger2
24212449
-- 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)