Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADP-3359] Simplify construction of API errors relating to recent eras. #4603

Merged
merged 11 commits into from
May 22, 2024

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented May 22, 2024

This PR:

  • adds a new constant recentEras :: Set AnyRecentEra
    • this constant defines the complete set of recent eras that are supported for transaction construction.
  • uses this constant to simplify the construction of the following API errors:
    • ApiErrorNodeNotYetInRecentEra
    • ApiErrorUnsupportedEra

Issue

ADP-3359

Follow-on from #4595.

@jonathanknowles jonathanknowles changed the title Simplify construction of API errors relating to supported recent eras. [ADP-3359] Simplify construction of API errors relating to supported recent eras. May 22, 2024
This commit adjusts the golden file for `ApiError.json` so that
`supported_recent_eras` fields:

    - do not include duplicate eras
    - list eras in alphabetic order

This is necessary, as the Haskell type for this field has changed from a
list to a `Set`, which changes the behaviour of the generator for the
`ApiErrorNodeNotYetInRecentEra` data type.
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/all-recent-eras branch from 52a29bf to e7481b6 Compare May 22, 2024 11:44
@@ -463,13 +471,21 @@ instance Bounded AnyRecentEra where
minBound = AnyRecentEra RecentEraBabbage
maxBound = AnyRecentEra RecentEraConway

instance Ord AnyRecentEra where
compare = compare `on` fromEnum
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instance is needed in order to have a Set AnyRecentEra.

instance Show AnyRecentEra where
show (AnyRecentEra era) = "AnyRecentEra " <> show era

instance Eq AnyRecentEra where
AnyRecentEra e1 == AnyRecentEra e2 =
isJust $ testEquality e1 e2

-- | The complete set of supported recent eras.
--
supportedRecentEras :: Set AnyRecentEra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supportedRecentEras

What would an unsupported recent era be?

It seems like it's saying the same things twice. I.e. could it be more suitable to name it allRecentEras or supportedErasForTxConstruction (the latter more for the api, not here) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anviking good point, thanks for this feedback!

I've adjusted this in 18a34f0.

Copy link
Collaborator

@paolino paolino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (I think the api is the wrong place for computations, but this is not relevant for the refactoring)

@jonathanknowles
Copy link
Member Author

jonathanknowles commented May 22, 2024

👍 (I think the api is the wrong place for computations, but this is not relevant for the refactoring)

I agree with you!

Though hopefully this refactoring goes in the right direction: the definition of the set of recent eras is now in the Write layer (and no longer in the Api layer).

@jonathanknowles jonathanknowles changed the title [ADP-3359] Simplify construction of API errors relating to supported recent eras. [ADP-3359] Simplify construction of API errors relating to recent eras. May 22, 2024
@jonathanknowles jonathanknowles added this pull request to the merge queue May 22, 2024
Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2024
@jonathanknowles jonathanknowles added this pull request to the merge queue May 22, 2024
Merged via the queue into master with commit 9734568 May 22, 2024
3 checks passed
@jonathanknowles jonathanknowles deleted the jonathanknowles/all-recent-eras branch May 22, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants