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

New mapSomeAddressVerification key function #225

Merged
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
21 changes: 21 additions & 0 deletions cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | Class of errors used in the Api.
Expand All @@ -17,6 +19,7 @@ module Cardano.Api.DeserialiseAnyOf
, deserialiseAnyVerificationKeyBech32
, deserialiseAnyVerificationKeyTextEnvelope
, renderSomeAddressVerificationKey
, mapSomeAddressVerificationKey
) where

import Cardano.Api.Address
Expand Down Expand Up @@ -229,6 +232,7 @@ deserialiseInputAnyOf bech32Types textEnvTypes inputBs =

-- The input was valid Bech32, but some other error occurred.
Left err -> DeserialiseInputError $ InputBech32DecodeError err

data SomeAddressVerificationKey
= AByronVerificationKey (VerificationKey ByronKey)
| APaymentVerificationKey (VerificationKey PaymentKey)
Expand Down Expand Up @@ -264,6 +268,23 @@ renderSomeAddressVerificationKey (AVrfVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AStakeVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AStakeExtendedVerificationKey vk) = serialiseToBech32 vk


mapSomeAddressVerificationKey :: ()
=> (forall keyrole. Key keyrole => VerificationKey keyrole -> a)
-> SomeAddressVerificationKey
-> a
mapSomeAddressVerificationKey f = \case
AByronVerificationKey vk -> f vk
APaymentVerificationKey vk -> f vk
APaymentExtendedVerificationKey vk -> f vk
AGenesisUTxOVerificationKey vk -> f vk
AKesVerificationKey vk -> f vk
AGenesisDelegateExtendedVerificationKey vk -> f vk
AGenesisExtendedVerificationKey vk -> f vk
AVrfVerificationKey vk -> f vk
AStakeVerificationKey vk -> f vk
AStakeExtendedVerificationKey vk -> f vk

-- | Internal function to pretty render byron keys
prettyByronVerificationKey :: VerificationKey ByronKey-> Text
prettyByronVerificationKey (ByronVerificationKey vk) =
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ module Cardano.Api (
deserialiseAnyVerificationKeyBech32,
deserialiseAnyVerificationKeyTextEnvelope,
renderSomeAddressVerificationKey,
mapSomeAddressVerificationKey,

-- ** CBOR
SerialiseAsCBOR,
Expand Down