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

CAD-2337 API extensions for address and credentials #2127

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module Cardano.API (
shelleyAddressInEra,
anyAddressInShelleyBasedEra,
anyAddressInEra,
toAddressAny,
makeByronAddressInEra,
makeShelleyAddressInEra,

Expand Down
22 changes: 21 additions & 1 deletion cardano-api/src/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Cardano.Api.Address (
shelleyAddressInEra,
anyAddressInShelleyBasedEra,
anyAddressInEra,
toAddressAny,
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this in the previous patch, where it gets defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

makeByronAddressInEra,
makeShelleyAddressInEra,

Expand All @@ -48,8 +49,10 @@ module Cardano.Api.Address (
toShelleyStakeAddr,
toShelleyStakeCredential,
fromShelleyAddr,
fromShelleyPaymentCredential,
fromShelleyStakeAddr,
fromShelleyStakeCredential,
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh? This is already exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thank you, missed it.

fromShelleyStakeReference,

-- * Serialising addresses
SerialiseAddress(..),
Expand Down Expand Up @@ -389,6 +392,9 @@ anyAddressInEra (AddressShelley addr) =
LegacyByronEra -> Nothing
ShelleyBasedEra era -> Just (AddressInEra (ShelleyAddressInEra era) addr)

toAddressAny :: Address addr -> AddressAny
toAddressAny a@ShelleyAddress{} = AddressShelley a
toAddressAny a@ByronAddress{} = AddressByron a

makeByronAddressInEra :: NetworkId
-> VerificationKey ByronKey
Expand Down Expand Up @@ -550,6 +556,21 @@ fromShelleyStakeCredential (Shelley.KeyHashObj kh) =
fromShelleyStakeCredential (Shelley.ScriptHashObj sh) =
StakeCredentialByScript (fromShelleyScriptHash sh)

fromShelleyPaymentCredential :: Shelley.PaymentCredential StandardShelley
-> PaymentCredential
fromShelleyPaymentCredential (Shelley.KeyHashObj kh) =
PaymentCredentialByKey (PaymentKeyHash kh)
fromShelleyPaymentCredential (Shelley.ScriptHashObj sh) =
PaymentCredentialByScript (ScriptHash sh)

fromShelleyStakeReference :: Shelley.StakeReference StandardShelley
-> StakeAddressReference
fromShelleyStakeReference (Shelley.StakeRefBase stakecred) =
StakeAddressByValue (fromShelleyStakeCredential stakecred)
fromShelleyStakeReference (Shelley.StakeRefPtr ptr) =
StakeAddressByPointer ptr
fromShelleyStakeReference Shelley.StakeRefNull =
NoStakeAddress

-- The era parameter in these types is a phantom type so it is safe to cast.
-- We choose to cast because we need to use an era-independent address
Expand All @@ -566,4 +587,3 @@ coerceShelleyStakeCredential = coerce
coerceShelleyStakeReference :: Shelley.StakeReference eraA
-> Shelley.StakeReference eraB
coerceShelleyStakeReference = coerce

5 changes: 5 additions & 0 deletions cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ module Cardano.Api.Shelley
EpochNo(..),
NetworkMagic(..),

-- * Credentials & stake references
fromShelleyPaymentCredential,
fromShelleyStakeCredential,
fromShelleyStakeReference,

-- * Scripts
-- | Both 'PaymentCredential's and 'StakeCredential's can use scripts.
-- Shelley supports multi-signatures via scripts.
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module Cardano.Api.Typed (
shelleyAddressInEra,
anyAddressInShelleyBasedEra,
anyAddressInEra,
toAddressAny,
makeByronAddressInEra,
makeShelleyAddressInEra,

Expand Down