From ee573739fae3c4a722b283bcb81a92b7e82a0a57 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 10 Nov 2020 15:38:24 +0100 Subject: [PATCH 1/2] Fix parsing of SMASHPoolId, thanks to Piotr --- lib/core/src/Cardano/Pool/Metadata.hs | 37 ++++++++++++++---------- lib/core/src/Cardano/Wallet/Api/Types.hs | 3 ++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/core/src/Cardano/Pool/Metadata.hs b/lib/core/src/Cardano/Pool/Metadata.hs index f2ae2b95e89..89d251b7bc4 100644 --- a/lib/core/src/Cardano/Pool/Metadata.hs +++ b/lib/core/src/Cardano/Pool/Metadata.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NumericUnderscores #-} @@ -34,6 +35,8 @@ import Cardano.BM.Data.Severity ( Severity (..) ) import Cardano.BM.Data.Tracer ( HasPrivacyAnnotation (..), HasSeverityAnnotation (..) ) +import Cardano.Wallet.Api.Types + ( defaultRecordTypeOptions ) import Cardano.Wallet.Primitive.AddressDerivation ( hex ) import Cardano.Wallet.Primitive.Types @@ -41,6 +44,7 @@ import Cardano.Wallet.Primitive.Types , StakePoolMetadata (..) , StakePoolMetadataHash (..) , StakePoolMetadataUrl (..) + , decodePoolIdBech32 ) import Control.Exception ( IOException, handle ) @@ -58,10 +62,9 @@ import Data.Aeson ( FromJSON (..) , ToJSON (..) , eitherDecodeStrict - , object - , withObject - , (.:) - , (.=) + , fieldLabelModifier + , genericParseJSON + , genericToJSON ) import Data.Bifunctor ( first ) @@ -77,6 +80,8 @@ import Data.Text.Class ( TextDecodingError (..), ToText (..), fromText ) import Fmt ( pretty ) +import GHC.Generics + ( Generic ) import Network.HTTP.Client ( HttpException (..) , Manager @@ -112,22 +117,22 @@ metadaFetchEp pid (StakePoolMetadataHash bytes) pidStr = T.unpack $ toText pid -- | TODO: import SMASH types -newtype SMASHPoolId = SMASHPoolId T.Text - deriving stock (Eq, Show, Ord) - -instance ToJSON SMASHPoolId where - toJSON (SMASHPoolId poolId) = - object - [ "poolId" .= poolId - ] +newtype SMASHPoolId = SMASHPoolId + { poolId :: T.Text + } deriving stock (Eq, Show, Ord) + deriving (Generic) instance FromJSON SMASHPoolId where - parseJSON = withObject "SMASHPoolId" $ \o -> do - poolId <- o .: "poolId" - return $ SMASHPoolId poolId + parseJSON = genericParseJSON defaultRecordTypeOptions + { fieldLabelModifier = id } + +instance ToJSON SMASHPoolId where + toJSON = genericToJSON defaultRecordTypeOptions + { fieldLabelModifier = id } toPoolId :: SMASHPoolId -> Either TextDecodingError PoolId -toPoolId (SMASHPoolId pid) = fromText pid +toPoolId (SMASHPoolId pid) = + either (\_ -> decodePoolIdBech32 pid) Right (fromText @PoolId pid) -- | Some default settings, overriding some of the library's default with -- stricter values. diff --git a/lib/core/src/Cardano/Wallet/Api/Types.hs b/lib/core/src/Cardano/Wallet/Api/Types.hs index 2f028d48870..9bc8e961292 100644 --- a/lib/core/src/Cardano/Wallet/Api/Types.hs +++ b/lib/core/src/Cardano/Wallet/Api/Types.hs @@ -147,6 +147,9 @@ module Cardano.Wallet.Api.Types , PostTransactionDataT , PostTransactionFeeDataT , ApiWalletMigrationPostDataT + + -- * other + , defaultRecordTypeOptions ) where import Prelude From b24e2a568f11712e21b3c92e9a69320e3ccbf93d Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 10 Nov 2020 16:16:12 +0100 Subject: [PATCH 2/2] Add SMASH to README compatibility matrix --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 626891d4a7d..be2dc06ba42 100644 --- a/README.md +++ b/README.md @@ -68,13 +68,13 @@ See **Installation Instructions** for each available [release](https://github.co > ### Latest releases > -> | cardano-wallet | jörmungandr (compatible versions) | cardano-node (compatible versions) -> | --- | --- | --- -> | `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) -> | [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) -> | [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) -> | [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) -> | [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) +> | cardano-wallet | jörmungandr (compatible versions) | cardano-node (compatible versions) | SMASH (compatible versions) +> | --- | --- | --- | --- +> | `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) +> | [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) +> | [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) +> | [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) +> | [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) ## How to build from sources