|
9 | 9 | {-# LANGUAGE TypeApplications #-} |
10 | 10 | {-# LANGUAGE TypeFamilies #-} |
11 | 11 |
|
12 | | -{- HLINT ignore "Avoid lambda using `infix`" -} |
13 | | - |
14 | 12 | -- | Cardano addresses: payment and stake addresses. |
15 | 13 | module Cardano.Api.Address |
16 | 14 | ( -- * Payment addresses |
@@ -55,6 +53,7 @@ module Cardano.Api.Address |
55 | 53 | , StakeExtendedKey |
56 | 54 |
|
57 | 55 | -- * Conversion functions |
| 56 | + , shelleyPayAddrToPaymentKeyHash |
58 | 57 | , shelleyPayAddrToPlutusPubKHash |
59 | 58 |
|
60 | 59 | -- * Internal conversion functions |
@@ -115,6 +114,7 @@ import Data.Bifunctor (first) |
115 | 114 | import Data.ByteString.Base58 qualified as Base58 |
116 | 115 | import Data.Char (isAsciiLower, isAsciiUpper, isDigit) |
117 | 116 | import Data.Either.Combinators (rightToMaybe) |
| 117 | +import Data.Maybe (isJust) |
118 | 118 | import Data.Text (Text) |
119 | 119 | import Data.Text qualified as Text |
120 | 120 | import Data.Text.Encoding qualified as Text |
@@ -614,10 +614,13 @@ makeStakeAddress nw sc = |
614 | 614 | -- | Is the UTxO at the address only spendable via a key witness. |
615 | 615 | isKeyAddress :: AddressInEra era -> Bool |
616 | 616 | isKeyAddress (AddressInEra ByronAddressInAnyEra _) = True |
617 | | -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 _) = |
618 | 621 | case fromShelleyPaymentCredential pCred of |
619 | | - PaymentCredentialByKey _ -> True |
620 | | - PaymentCredentialByScript _ -> False |
| 622 | + PaymentCredentialByKey key -> Just key |
| 623 | + PaymentCredentialByScript _ -> Nothing |
621 | 624 |
|
622 | 625 | -- | Converts a Shelley payment address to a Plutus public key hash. |
623 | 626 | shelleyPayAddrToPlutusPubKHash :: Address ShelleyAddr -> Maybe PlutusAPI.PubKeyHash |
|
0 commit comments