Skip to content

Commit b24fd89

Browse files
iohk-bors[bot]Julian Ospald
andauthored
Merge #2309
2309: Fix parsing of SMASHPoolId r=hasufell a=hasufell follow-up fix of #2249 found by @piotr-iohk https://smash.shelley-qa.dev.cardano.org/api/v1/delisted vs https://smash.cardano-mainnet.iohk.io/api/v1/delisted Co-authored-by: Julian Ospald <julian.ospald@iohk.io>
2 parents 6cdad95 + b24e2a5 commit b24fd89

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ See **Installation Instructions** for each available [release](https://github.co
6868

6969
> ### Latest releases
7070
>
71-
> | cardano-wallet | jörmungandr (compatible versions) | cardano-node (compatible versions)
72-
> | --- | --- | ---
73-
> | `master` branch | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1)
74-
> | [v2020-11-03](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-11-03) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1)
75-
> | [v2020-10-13](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-10-13) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1)
76-
> | [v2020-09-30](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-09-30) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.20.0](https://github.com/input-output-hk/cardano-node/releases/tag/1.20.0)
77-
> | [v2020-09-22](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-09-22) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.19.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.19.1) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.20.0](https://github.com/input-output-hk/cardano-node/releases/tag/1.20.0)
71+
> | cardano-wallet | jörmungandr (compatible versions) | cardano-node (compatible versions) | SMASH (compatible versions)
72+
> | --- | --- | --- | ---
73+
> | `master` branch | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1) | [1.2.0](https://github.com/input-output-hk/smash/releases/tag/1.2.0)
74+
> | [v2020-11-03](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-11-03) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1) | [1.2.0](https://github.com/input-output-hk/smash/releases/tag/1.2.0)
75+
> | [v2020-10-13](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-10-13) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.21.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.21.1) | [1.2.0](https://github.com/input-output-hk/smash/releases/tag/1.2.0)
76+
> | [v2020-09-30](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-09-30) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.20.0](https://github.com/input-output-hk/cardano-node/releases/tag/1.20.0) | [1.2.0](https://github.com/input-output-hk/smash/releases/tag/1.2.0)
77+
> | [v2020-09-22](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2020-09-22) | [v0.9.0](https://github.com/input-output-hk/jormungandr/releases/tag/v0.9.0) | [1.19.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.19.1) | [1.2.0](https://github.com/input-output-hk/smash/releases/tag/1.2.0)
7878
7979

8080
## How to build from sources

lib/core/src/Cardano/Pool/Metadata.hs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveGeneric #-}
12
{-# LANGUAGE DerivingStrategies #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NumericUnderscores #-}
@@ -34,13 +35,16 @@ import Cardano.BM.Data.Severity
3435
( Severity (..) )
3536
import Cardano.BM.Data.Tracer
3637
( HasPrivacyAnnotation (..), HasSeverityAnnotation (..) )
38+
import Cardano.Wallet.Api.Types
39+
( defaultRecordTypeOptions )
3740
import Cardano.Wallet.Primitive.AddressDerivation
3841
( hex )
3942
import Cardano.Wallet.Primitive.Types
4043
( PoolId
4144
, StakePoolMetadata (..)
4245
, StakePoolMetadataHash (..)
4346
, StakePoolMetadataUrl (..)
47+
, decodePoolIdBech32
4448
)
4549
import Control.Exception
4650
( IOException, handle )
@@ -58,10 +62,9 @@ import Data.Aeson
5862
( FromJSON (..)
5963
, ToJSON (..)
6064
, eitherDecodeStrict
61-
, object
62-
, withObject
63-
, (.:)
64-
, (.=)
65+
, fieldLabelModifier
66+
, genericParseJSON
67+
, genericToJSON
6568
)
6669
import Data.Bifunctor
6770
( first )
@@ -77,6 +80,8 @@ import Data.Text.Class
7780
( TextDecodingError (..), ToText (..), fromText )
7881
import Fmt
7982
( pretty )
83+
import GHC.Generics
84+
( Generic )
8085
import Network.HTTP.Client
8186
( HttpException (..)
8287
, Manager
@@ -112,22 +117,22 @@ metadaFetchEp pid (StakePoolMetadataHash bytes)
112117
pidStr = T.unpack $ toText pid
113118

114119
-- | TODO: import SMASH types
115-
newtype SMASHPoolId = SMASHPoolId T.Text
116-
deriving stock (Eq, Show, Ord)
117-
118-
instance ToJSON SMASHPoolId where
119-
toJSON (SMASHPoolId poolId) =
120-
object
121-
[ "poolId" .= poolId
122-
]
120+
newtype SMASHPoolId = SMASHPoolId
121+
{ poolId :: T.Text
122+
} deriving stock (Eq, Show, Ord)
123+
deriving (Generic)
123124

124125
instance FromJSON SMASHPoolId where
125-
parseJSON = withObject "SMASHPoolId" $ \o -> do
126-
poolId <- o .: "poolId"
127-
return $ SMASHPoolId poolId
126+
parseJSON = genericParseJSON defaultRecordTypeOptions
127+
{ fieldLabelModifier = id }
128+
129+
instance ToJSON SMASHPoolId where
130+
toJSON = genericToJSON defaultRecordTypeOptions
131+
{ fieldLabelModifier = id }
128132

129133
toPoolId :: SMASHPoolId -> Either TextDecodingError PoolId
130-
toPoolId (SMASHPoolId pid) = fromText pid
134+
toPoolId (SMASHPoolId pid) =
135+
either (\_ -> decodePoolIdBech32 pid) Right (fromText @PoolId pid)
131136

132137
-- | Some default settings, overriding some of the library's default with
133138
-- stricter values.

lib/core/src/Cardano/Wallet/Api/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ module Cardano.Wallet.Api.Types
147147
, PostTransactionDataT
148148
, PostTransactionFeeDataT
149149
, ApiWalletMigrationPostDataT
150+
151+
-- * other
152+
, defaultRecordTypeOptions
150153
) where
151154

152155
import Prelude

0 commit comments

Comments
 (0)