diff --git a/lib/api/src/Cardano/Wallet/Api/Http/Server/Error.hs b/lib/api/src/Cardano/Wallet/Api/Http/Server/Error.hs index 5b08b1f1202..2a78e51465a 100644 --- a/lib/api/src/Cardano/Wallet/Api/Http/Server/Error.hs +++ b/lib/api/src/Cardano/Wallet/Api/Http/Server/Error.hs @@ -171,6 +171,8 @@ import Fmt , pretty ) import Internal.Cardano.Write.Tx + ( KeyWitnessCounts (..) + ) import Network.Wai ( Request (pathInfo) ) @@ -189,6 +191,9 @@ import Servant.Server ) import qualified Cardano.Api as Cardano +import qualified Cardano.Wallet.Api.Types as Api + ( allRecentEras + ) import qualified Cardano.Wallet.Api.Types.Amount as ApiAmount import qualified Cardano.Wallet.Api.Types.WalletAssets as ApiWalletAssets import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle @@ -199,13 +204,11 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BL import qualified Data.Foldable as F import qualified Data.List as L -import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Internal.Cardano.Write.Tx as Write ( IsRecentEra , serializeTx - , toAnyCardanoEra ) import qualified Internal.Cardano.Write.Tx as WriteTx import qualified Internal.Cardano.Write.Tx.Balance as Write @@ -483,8 +486,7 @@ instance IsServerError ErrWriteTxEra where where info = ApiErrorNodeNotYetInRecentEra { nodeEra = toApiEra $ Cardano.AnyCardanoEra era - , supportedRecentEras = - map (toApiEra . Write.toAnyCardanoEra) [minBound .. maxBound] + , supportedRecentEras = Api.allRecentEras } ErrPartialTxNotInNodeEra nodeEra -> apiError err403 TxNotInNodeEra $ T.unwords @@ -647,19 +649,11 @@ instance IsServerError ErrPostTx where , "node because its mempool was full." ] e@(ErrPostTxEraUnsupported unsupported) -> - apiError err403 error' $ toText e - where - error' = - UnsupportedEra - $ ApiErrorUnsupportedEra - { unsupportedEra = toApiEra unsupported - , supportedEras = - Set.fromList - ( toApiEra - . Write.toAnyCardanoEra - <$> [minBound .. maxBound] - ) - } + flip (apiError err403) (toText e) $ UnsupportedEra + ApiErrorUnsupportedEra + { unsupportedEra = toApiEra unsupported + , supportedEras = Api.allRecentEras + } instance IsServerError ErrSubmitTransaction where toServerError = \case diff --git a/lib/api/src/Cardano/Wallet/Api/Types.hs b/lib/api/src/Cardano/Wallet/Api/Types.hs index dda0ecd3bce..541b4eb7435 100644 --- a/lib/api/src/Cardano/Wallet/Api/Types.hs +++ b/lib/api/src/Cardano/Wallet/Api/Types.hs @@ -168,6 +168,7 @@ module Cardano.Wallet.Api.Types , ApiWithdrawalPostData (..) , ApiRewardAccount (..) , fromApiEra + , allRecentEras , Iso8601Time (..) , KeyFormat (..) , MaintenanceAction (..) @@ -576,6 +577,9 @@ import Data.Proxy import Data.Quantity ( Quantity (..) ) +import Data.Set + ( Set + ) import Data.String ( IsString ) @@ -671,13 +675,16 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as BL import qualified Data.List as L import qualified Data.Map as Map +import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.Read as T import qualified Internal.Cardano.Write.Tx as Write ( DatumHash + , allRecentEras , datumHashFromBytes , datumHashToBytes + , toAnyCardanoEra ) {------------------------------------------------------------------------------- @@ -1641,6 +1648,11 @@ fromApiEra ApiAlonzo = AnyCardanoEra AlonzoEra fromApiEra ApiBabbage = AnyCardanoEra BabbageEra fromApiEra ApiConway = AnyCardanoEra ConwayEra +-- | The complete set of recent eras. +-- +allRecentEras :: Set ApiEra +allRecentEras = Set.map (toApiEra . Write.toAnyCardanoEra) Write.allRecentEras + instance FromJSON ApiEra where parseJSON = genericParseJSON $ Aeson.defaultOptions { constructorTagModifier = drop 4 . camelTo2 '_' } diff --git a/lib/api/src/Cardano/Wallet/Api/Types/Error.hs b/lib/api/src/Cardano/Wallet/Api/Types/Error.hs index 7c4a164b211..d9cd54bc699 100644 --- a/lib/api/src/Cardano/Wallet/Api/Types/Error.hs +++ b/lib/api/src/Cardano/Wallet/Api/Types/Error.hs @@ -288,7 +288,7 @@ data ApiErrorBalanceTxUnderestimatedFee = ApiErrorBalanceTxUnderestimatedFee data ApiErrorNodeNotYetInRecentEra = ApiErrorNodeNotYetInRecentEra { nodeEra :: ApiEra - , supportedRecentEras :: [ApiEra] + , supportedRecentEras :: Set ApiEra } deriving (Data, Eq, Generic, Show, Typeable) deriving (FromJSON, ToJSON) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs index 3f620398c64..04a24ec01bb 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs @@ -47,6 +47,7 @@ module Internal.Cardano.Write.Tx , toRecentEraGADT , LatestLedgerEra , RecentEraConstraints + , allRecentEras -- ** Key witness counts , KeyWitnessCounts (..) @@ -231,6 +232,9 @@ import Data.ByteString.Short import Data.Coerce ( coerce ) +import Data.Function + ( on + ) import Data.Generics.Internal.VL.Lens ( over , (^.) @@ -248,6 +252,9 @@ import Data.Maybe ( fromMaybe , isJust ) +import Data.Set + ( Set + ) import Data.Type.Equality ( TestEquality (testEquality) , (:~:) (Refl) @@ -289,6 +296,7 @@ import qualified Cardano.Wallet.Primitive.Types.Tx.Constraints as W ( txOutMaxCoin ) import qualified Data.Map as Map +import qualified Data.Set as Set -------------------------------------------------------------------------------- -- Eras @@ -463,6 +471,9 @@ instance Bounded AnyRecentEra where minBound = AnyRecentEra RecentEraBabbage maxBound = AnyRecentEra RecentEraConway +instance Ord AnyRecentEra where + compare = compare `on` fromEnum + instance Show AnyRecentEra where show (AnyRecentEra era) = "AnyRecentEra " <> show era @@ -470,6 +481,11 @@ instance Eq AnyRecentEra where AnyRecentEra e1 == AnyRecentEra e2 = isJust $ testEquality e1 e2 +-- | The complete set of recent eras. +-- +allRecentEras :: Set AnyRecentEra +allRecentEras = Set.fromList [minBound .. maxBound] + toAnyCardanoEra :: AnyRecentEra -> CardanoApi.AnyCardanoEra toAnyCardanoEra (AnyRecentEra era) = CardanoApi.AnyCardanoEra (fromRecentEra era) diff --git a/lib/unit/test/data/Cardano/Wallet/Api/ApiError.json b/lib/unit/test/data/Cardano/Wallet/Api/ApiError.json index adad3776aa0..a5e935649d6 100644 --- a/lib/unit/test/data/Cardano/Wallet/Api/ApiError.json +++ b/lib/unit/test/data/Cardano/Wallet/Api/ApiError.json @@ -174,8 +174,8 @@ "info": { "node_era": "byron", "supported_recent_eras": [ - "babbage", - "alonzo" + "alonzo", + "babbage" ] }, "message": "𧰏@qs𬤻DL\u0017􆊛'" @@ -231,7 +231,6 @@ "supported_recent_eras": [ "byron", "alonzo", - "byron", "babbage" ] }, @@ -294,10 +293,8 @@ "info": { "node_era": "byron", "supported_recent_eras": [ - "mary", - "babbage", - "byron", "byron", + "mary", "babbage" ] }, @@ -372,11 +369,8 @@ "info": { "node_era": "babbage", "supported_recent_eras": [ - "allegra", - "babbage", - "allegra", - "allegra", "shelley", + "allegra", "babbage" ] }, @@ -774,7 +768,6 @@ "node_era": "allegra", "supported_recent_eras": [ "allegra", - "mary", "mary" ] },