Skip to content

Commit a3d6ba2

Browse files
Add shelleyPayAddrToPaymentKeyHash helper function
1 parent bf5303b commit a3d6ba2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cardano-api/src/Cardano/Api/Address.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module Cardano.Api.Address
5353
, StakeExtendedKey
5454

5555
-- * Conversion functions
56+
, shelleyPayAddrToPaymentKeyHash
5657
, shelleyPayAddrToPlutusPubKHash
5758

5859
-- * Internal conversion functions
@@ -113,6 +114,7 @@ import Data.Bifunctor (first)
113114
import Data.ByteString.Base58 qualified as Base58
114115
import Data.Char (isAsciiLower, isAsciiUpper, isDigit)
115116
import Data.Either.Combinators (rightToMaybe)
117+
import Data.Maybe (isJust)
116118
import Data.Text (Text)
117119
import Data.Text qualified as Text
118120
import Data.Text.Encoding qualified as Text
@@ -612,10 +614,13 @@ makeStakeAddress nw sc =
612614
-- | Is the UTxO at the address only spendable via a key witness.
613615
isKeyAddress :: AddressInEra era -> Bool
614616
isKeyAddress (AddressInEra ByronAddressInAnyEra _) = True
615-
isKeyAddress (AddressInEra (ShelleyAddressInEra _) (ShelleyAddress _ pCred _)) =
617+
isKeyAddress (AddressInEra (ShelleyAddressInEra _) addr) = isJust $ shelleyPayAddrToPaymentKeyHash addr
618+
619+
shelleyPayAddrToPaymentKeyHash :: Address ShelleyAddr -> Maybe (Hash PaymentKey)
620+
shelleyPayAddrToPaymentKeyHash (ShelleyAddress _ pCred _) =
616621
case fromShelleyPaymentCredential pCred of
617-
PaymentCredentialByKey _ -> True
618-
PaymentCredentialByScript _ -> False
622+
PaymentCredentialByKey key -> Just key
623+
PaymentCredentialByScript _ -> Nothing
619624

620625
-- | Converts a Shelley payment address to a Plutus public key hash.
621626
shelleyPayAddrToPlutusPubKHash :: Address ShelleyAddr -> Maybe PlutusAPI.PubKeyHash

0 commit comments

Comments
 (0)