From 8661c8c742e7950a0ca3ffe28d1d88fa4f3ac480 Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Wed, 25 Nov 2020 23:48:06 +0300 Subject: [PATCH] CAD-2337 api: fromShelley{Payment,Stake}{Credential,Reference} --- cardano-api/src/Cardano/Api/Address.hs | 18 +++++++++++++++++- cardano-api/src/Cardano/Api/Shelley.hs | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cardano-api/src/Cardano/Api/Address.hs b/cardano-api/src/Cardano/Api/Address.hs index c721a89fa06..688b287bab7 100644 --- a/cardano-api/src/Cardano/Api/Address.hs +++ b/cardano-api/src/Cardano/Api/Address.hs @@ -49,8 +49,10 @@ module Cardano.Api.Address ( toShelleyStakeAddr, toShelleyStakeCredential, fromShelleyAddr, + fromShelleyPaymentCredential, fromShelleyStakeAddr, fromShelleyStakeCredential, + fromShelleyStakeReference, -- * Serialising addresses SerialiseAddress(..), @@ -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 @@ -570,4 +587,3 @@ coerceShelleyStakeCredential = coerce coerceShelleyStakeReference :: Shelley.StakeReference eraA -> Shelley.StakeReference eraB coerceShelleyStakeReference = coerce - diff --git a/cardano-api/src/Cardano/Api/Shelley.hs b/cardano-api/src/Cardano/Api/Shelley.hs index 0df8b7a5544..b0b56b4905f 100644 --- a/cardano-api/src/Cardano/Api/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Shelley.hs @@ -70,6 +70,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.