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

Commit c3d15d4

Browse files
committed
Merge pull request #3707 [remove wallet orphan instances] into CO-372/TheGreatCleanup
2 parents 2780b9f + d91f6ea commit c3d15d4

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 #-}
@@ -162,8 +162,9 @@ import Data.Swagger.Internal.TypeShape (GenericHasSimpleShape,
162162
GenericShape)
163163
import Data.Text (Text, dropEnd, toLower)
164164
import qualified Data.Text as T
165-
import Data.Version (Version)
166-
import Formatting (bprint, build, fconst, int, sformat, stext, (%))
165+
import Data.Version (Version (..), parseVersion, showVersion)
166+
import Formatting (bprint, build, fconst, int, sformat, shown, stext,
167+
(%))
167168
import qualified Formatting.Buildable
168169
import Generics.SOP.TH (deriveGeneric)
169170
import GHC.Generics (Generic, Rep)
@@ -187,7 +188,6 @@ import Cardano.Wallet.API.V1.Generic (jsendErrorGenericParseJSON,
187188
jsendErrorGenericToJSON)
188189
import Cardano.Wallet.API.V1.Swagger.Example (Example, example,
189190
genExample)
190-
import Cardano.Wallet.Orphans.Aeson ()
191191
import Cardano.Wallet.Types.UtxoStatistics
192192
import Cardano.Wallet.Util (mkJsonKey, showApiUtcTime)
193193

@@ -196,7 +196,6 @@ import qualified Pos.Binary.Class as Bi
196196
import qualified Pos.Chain.Txp as Txp
197197
import qualified Pos.Chain.Update as Core
198198
import qualified Pos.Client.Txp.Util as Core
199-
import Pos.Core (addressF)
200199
import qualified Pos.Core as Core
201200
import Pos.Crypto (PublicKey (..), decodeHash, hashHexF)
202201
import qualified Pos.Crypto.Signing as Core
@@ -207,7 +206,9 @@ import Pos.Infra.Util.LogSafe (BuildableSafeGen (..), SecureLog (..),
207206
buildSafe, buildSafeList, buildSafeMaybe,
208207
deriveSafeBuildable, plainOrSecureF)
209208
import Pos.Util.Servant (Flaggable (..))
209+
import Test.Pos.Chain.Update.Arbitrary ()
210210
import Test.Pos.Core.Arbitrary ()
211+
import Text.ParserCombinators.ReadP (readP_to_S)
211212

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

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

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

325-
326326
--
327327
-- Benign instances
328328
--
@@ -381,8 +381,17 @@ instance ToSchema (V1 Core.Coin) where
381381
& type_ .~ SwaggerNumber
382382
& maximum_ .~ Just (fromIntegral Core.maxCoinVal)
383383

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+
384393
instance ToJSON (V1 Core.Address) where
385-
toJSON (V1 c) = String $ sformat addressF c
394+
toJSON (V1 c) = String $ sformat Core.addressF c
386395

387396
instance FromJSON (V1 Core.Address) where
388397
parseJSON (String a) = case Core.decodeTextAddress a of
@@ -2346,17 +2355,36 @@ instance BuildableSafeGen SlotDuration where
23462355
data NodeSettings = NodeSettings {
23472356
setSlotDuration :: !SlotDuration
23482357
, setSoftwareInfo :: !(V1 Core.SoftwareVersion)
2349-
, setProjectVersion :: !Version
2358+
, setProjectVersion :: !(V1 Version)
23502359
, setGitRevision :: !Text
23512360
} deriving (Show, Eq, Generic)
23522361

23532362
#if !(MIN_VERSION_swagger2(2,2,2))
23542363
-- See note [Version Orphan]
2355-
instance ToSchema Version where
2364+
instance ToSchema (V1 Version) where
23562365
declareNamedSchema _ =
2357-
pure $ NamedSchema (Just "Version") $ mempty
2366+
pure $ NamedSchema (Just "V1Version") $ mempty
23582367
& type_ .~ SwaggerString
23592368

2369+
instance Buildable (V1 Version) where
2370+
build (V1 v) = bprint shown v
2371+
2372+
instance Buildable (SecureLog (V1 Version)) where
2373+
build (SecureLog x) = Formatting.Buildable.build x
2374+
2375+
instance ToJSON (V1 Version) where
2376+
toJSON (V1 v) = toJSON (showVersion v)
2377+
2378+
instance FromJSON (V1 Version) where
2379+
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of
2380+
(reverse -> ((ver,_):_)) -> pure (V1 ver)
2381+
_ -> mempty
2382+
parseJSON x = typeMismatch "Not a valid Version" x
2383+
2384+
instance Arbitrary (V1 Version) where
2385+
arbitrary = fmap V1 arbitrary
2386+
2387+
23602388
-- Note [Version Orphan]
23612389
-- I have opened a PR to add an instance of 'Version' to the swagger2
23622390
-- 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 Pos.Core.NetworkMagic (NetworkMagic (..))
1920
import qualified Pos.Crypto as Crypto
@@ -45,7 +46,6 @@ import Cardano.Wallet.API.V1.Types
4546
import Cardano.Wallet.Kernel.DB.HdWallet (HdRoot)
4647
import Cardano.Wallet.Kernel.DB.InDb (InDb (..))
4748
import qualified Cardano.Wallet.Kernel.Util.Strict as Strict
48-
import Cardano.Wallet.Orphans ()
4949
import qualified Cardano.Wallet.Util as Util
5050

5151
-- | Tests whether or not some instances (JSON, Bi, etc) roundtrips.
@@ -87,6 +87,7 @@ spec = parallel $ describe "Marshalling & Unmarshalling" $ do
8787
aesonRoundtripProp @SyncThroughput Proxy
8888
aesonRoundtripProp @AccountIndex Proxy
8989
aesonRoundtripProp @(V1 AddressOwnership) Proxy
90+
aesonRoundtripProp @(V1 Version) Proxy
9091

9192
-- HttpApiData roundtrips
9293
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)