Skip to content

Commit

Permalink
CAD-2337 api: fromShelley{Payment,Stake}{Credential,Reference}
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Nov 26, 2020
1 parent 627e76c commit 8c1afb3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cardano-api/src/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ module Cardano.Api.Address (
toShelleyStakeAddr,
toShelleyStakeCredential,
fromShelleyAddr,
fromShelleyPaymentCredential,
fromShelleyStakeAddr,
fromShelleyStakeCredential,
fromShelleyStakeReference,

-- * Serialising addresses
SerialiseAddress(..),
Expand Down Expand Up @@ -554,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 @@ -570,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

0 comments on commit 8c1afb3

Please sign in to comment.