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

Light Mode: currentCardanoEra #3209

Merged
merged 4 commits into from
Apr 4, 2022
Merged

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented Mar 30, 2022

  • I have tested Epoch/Era translation in REPL manually.
  • wrote unit test for the Epoch/Era translation.

Comments

Blockfrost API doesn't expose current Era so its implemented as a translation from current epoch number using a hardcoded table.

┌───────┬───────┬─────────┐
│ Epoch │ Major │   Era   │
├───────┼───────┼─────────┤
│  ...  │   6   │ Alonzo  │
│  298  │   6   │ Alonzo  │
├───────┼───────┼─────────┤
│  297  │   5   │ Alonzo  │
│  ...  │   5   │ Alonzo  │
│  290  │   5   │ Alonzo  │
├───────┼───────┼─────────┤
│  289  │   4   │  Mary   │
│  ...  │   4   │  Mary   │
│  251  │   4   │  Mary   │
├───────┼───────┼─────────┤
│  250  │   3   │ Allegra │
│  ...  │   3   │ Allegra │
│  236  │   3   │ Allegra │
├───────┼───────┼─────────┤
│  235  │   2   │ Shelley │
│  ...  │   2   │ Shelley │
│  202  │   2   │ Shelley │
├───────┼───────┼─────────┤
│  201  │   1   │  Byron  │
│  ...  │   1   │  Byron  │
└───────┴───────┴─────────┘

When new era type is added its expected that compiler emits a warning about non-exhaustive pattern match, thus forcing developer to update translation table with the corresponding epoch number;

Issue Number

ADP-1504

@Unisay Unisay requested a review from HeinrichApfelmus March 30, 2022 17:15
@Unisay Unisay self-assigned this Mar 30, 2022
@Unisay Unisay marked this pull request as ready for review March 31, 2022 08:29
@Unisay Unisay force-pushed the yura/ADP-1504/current-node-era branch from 05278b2 to 926a4eb Compare April 1, 2022 10:52
@Unisay
Copy link
Contributor Author

Unisay commented Apr 4, 2022

bors try

iohk-bors bot added a commit that referenced this pull request Apr 4, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 4, 2022

try

Build succeeded:

Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Looks good to me! 😊 Again, I prefer the simply typed Either.

@HeinrichApfelmus
Copy link
Contributor

Oh, and I only remembered now: Maybe make it clear in the name that these are mainnet eras? E.g. eraMainnetByEpoch

Or even add a NetworkDiscriminant argument:

eraByEpoch :: NetworkDiscriminant -> EpochNo -> Either BlockfrostError AnyCardanoEra

Our main reason for supporting testnet is so that Piotr can use it for QA.

@Unisay Unisay force-pushed the yura/ADP-1504/current-node-era branch from ad64a4a to e965f80 Compare April 4, 2022 16:12
@Unisay
Copy link
Contributor Author

Unisay commented Apr 4, 2022

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 4, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit d3a5ad4 into master Apr 4, 2022
@iohk-bors iohk-bors bot deleted the yura/ADP-1504/current-node-era branch April 4, 2022 17:40
WilliamKingNoel-Bot pushed a commit that referenced this pull request Apr 4, 2022
Node.AnyCardanoEra Node.AlonzoEra -> 290
Node.AnyCardanoEra Node.MaryEra -> 251
Node.AnyCardanoEra Node.AllegraEra -> 236
Node.AnyCardanoEra Node.ShelleyEra -> 202
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not what the wallet on mainnet shows for shelley...

$ curl -X GET https://localhost:32787/v2/network/parameters | jq .eras
{
  "mary": {
    "epoch_start_time": "2021-03-01T21:44:51Z",
    "epoch_number": 251
  },
  "byron": {
    "epoch_start_time": "2017-09-23T21:44:51Z",
    "epoch_number": 0
  },
  "allegra": {
    "epoch_start_time": "2020-12-16T21:44:51Z",
    "epoch_number": 236
  },
  "alonzo": {
    "epoch_start_time": "2021-09-12T21:44:51Z",
    "epoch_number": 290
  },
  "shelley": {
    "epoch_start_time": "2020-07-29T21:44:51Z",
    "epoch_number": 208
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here 0bf442d

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.

3 participants