-
Notifications
You must be signed in to change notification settings - Fork 22
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
Avoid IsShelleyBasedEra
and IsCardanoEra
where possible
#313
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5f9537f
Move ShelleyBasedEraConstraints and shelleyBasedEraConstraints to She…
newhoggy 99f27e8
Move CardanoEraConstraints and cardanoraConstraints to Core module
newhoggy d1d6341
New functions anyShelleyBasedEra, inAnyCardanoEra and inAnyShelleyBas…
newhoggy 43027e5
Use ShelleyBasedEra instead of IsShelleyBasedEra. Use CardanoEra inst…
newhoggy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
{- HLINT ignore "Avoid lambda using `infix`" -} | ||
|
@@ -373,9 +374,11 @@ instance IsCardanoEra era => ToJSON (AddressInEra era) where | |
toJSON = Aeson.String . serialiseAddress | ||
|
||
instance IsShelleyBasedEra era => FromJSON (AddressInEra era) where | ||
parseJSON = withText "AddressInEra" $ \txt -> do | ||
addressAny <- runParsecParser parseAddressAny txt | ||
pure $ anyAddressInShelleyBasedEra addressAny | ||
parseJSON = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still retain the use of |
||
let sbe = shelleyBasedEra @era in | ||
withText "AddressInEra" $ \txt -> do | ||
addressAny <- runParsecParser parseAddressAny txt | ||
pure $ anyAddressInShelleyBasedEra sbe addressAny | ||
|
||
parseAddressAny :: Parsec.Parser AddressAny | ||
parseAddressAny = do | ||
|
@@ -467,15 +470,20 @@ byronAddressInEra :: Address ByronAddr -> AddressInEra era | |
byronAddressInEra = AddressInEra ByronAddressInAnyEra | ||
|
||
|
||
shelleyAddressInEra :: IsShelleyBasedEra era | ||
=> Address ShelleyAddr -> AddressInEra era | ||
shelleyAddressInEra = AddressInEra (ShelleyAddressInEra shelleyBasedEra) | ||
|
||
shelleyAddressInEra :: () | ||
=> ShelleyBasedEra era | ||
-> Address ShelleyAddr | ||
-> AddressInEra era | ||
shelleyAddressInEra sbe = | ||
AddressInEra (ShelleyAddressInEra sbe) | ||
|
||
anyAddressInShelleyBasedEra :: IsShelleyBasedEra era | ||
=> AddressAny -> AddressInEra era | ||
anyAddressInShelleyBasedEra (AddressByron addr) = byronAddressInEra addr | ||
anyAddressInShelleyBasedEra (AddressShelley addr) = shelleyAddressInEra addr | ||
anyAddressInShelleyBasedEra :: () | ||
=> ShelleyBasedEra era | ||
-> AddressAny | ||
-> AddressInEra era | ||
anyAddressInShelleyBasedEra sbe = \case | ||
AddressByron addr -> byronAddressInEra addr | ||
AddressShelley addr -> shelleyAddressInEra sbe addr | ||
|
||
|
||
anyAddressInEra :: CardanoEra era | ||
|
@@ -500,13 +508,14 @@ makeByronAddressInEra nw vk = | |
byronAddressInEra (makeByronAddress nw vk) | ||
|
||
|
||
makeShelleyAddressInEra :: IsShelleyBasedEra era | ||
=> NetworkId | ||
-> PaymentCredential | ||
-> StakeAddressReference | ||
-> AddressInEra era | ||
makeShelleyAddressInEra nw pc scr = | ||
shelleyAddressInEra (makeShelleyAddress nw pc scr) | ||
makeShelleyAddressInEra :: () | ||
=> ShelleyBasedEra era | ||
-> NetworkId | ||
-> PaymentCredential | ||
-> StakeAddressReference | ||
-> AddressInEra era | ||
makeShelleyAddressInEra sbe nw pc scr = | ||
shelleyAddressInEra sbe (makeShelleyAddress nw pc scr) | ||
|
||
|
||
-- ---------------------------------------------------------------------------- | ||
|
@@ -659,15 +668,15 @@ toShelleyStakeReference (StakeAddressByPointer ptr) = | |
toShelleyStakeReference NoStakeAddress = | ||
Shelley.StakeRefNull | ||
|
||
fromShelleyAddrIsSbe :: IsShelleyBasedEra era | ||
=> Shelley.Addr StandardCrypto -> AddressInEra era | ||
fromShelleyAddrIsSbe (Shelley.AddrBootstrap (Shelley.BootstrapAddress addr)) = | ||
AddressInEra ByronAddressInAnyEra (ByronAddress addr) | ||
|
||
fromShelleyAddrIsSbe (Shelley.Addr nw pc scr) = | ||
AddressInEra | ||
(ShelleyAddressInEra shelleyBasedEra) | ||
(ShelleyAddress nw pc scr) | ||
fromShelleyAddrIsSbe :: () | ||
=> ShelleyBasedEra era | ||
-> Shelley.Addr StandardCrypto | ||
-> AddressInEra era | ||
fromShelleyAddrIsSbe sbe = \case | ||
Shelley.AddrBootstrap (Shelley.BootstrapAddress addr) -> | ||
AddressInEra ByronAddressInAnyEra (ByronAddress addr) | ||
Shelley.Addr nw pc scr -> | ||
AddressInEra (ShelleyAddressInEra sbe) (ShelleyAddress nw pc scr) | ||
|
||
fromShelleyAddr | ||
:: ShelleyBasedEra era | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shelleyAddressInEra
is an example of a function that previously demanded a constraint, but now demands a witness instead. It is often the case that the witness is just available somewhere in the context.