From 4da8114f50154e69e14336d458498550c2786095 Mon Sep 17 00:00:00 2001 From: Alberto Fanton Date: Tue, 16 Jul 2024 13:23:38 +0200 Subject: [PATCH] Add utils to convert stake pool key hashes (#186) --- src/base/lib/Convex/PlutusLedger.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/base/lib/Convex/PlutusLedger.hs b/src/base/lib/Convex/PlutusLedger.hs index a5a3b9f9..a1c80be7 100644 --- a/src/base/lib/Convex/PlutusLedger.hs +++ b/src/base/lib/Convex/PlutusLedger.hs @@ -19,6 +19,9 @@ module Convex.PlutusLedger( transStakeKeyHash, unTransStakeKeyHash, + transStakePoolKeyHash, + unTransStakePoolKeyHash, + -- * Asset names transAssetName, toMaryAssetName, @@ -139,6 +142,14 @@ unTransStakeKeyHash (PV1.PubKeyHash pkh) = let bsx = PlutusTx.fromBuiltin pkh in C.deserialiseFromRawBytes (C.AsHash C.AsStakeKey) bsx +transStakePoolKeyHash :: C.Hash C.StakePoolKey -> PV1.PubKeyHash +transStakePoolKeyHash = PV1.PubKeyHash . PlutusTx.toBuiltin . C.serialiseToRawBytes + +unTransStakePoolKeyHash :: PV1.PubKeyHash -> Either C.SerialiseAsRawBytesError (C.Hash C.StakePoolKey) +unTransStakePoolKeyHash (PV1.PubKeyHash pkh) = + let bsx = PlutusTx.fromBuiltin pkh + in C.deserialiseFromRawBytes (C.AsHash C.AsStakePoolKey) bsx + unTransCredential :: PV1.Credential -> Either C.SerialiseAsRawBytesError C.PaymentCredential unTransCredential = \case PV1.PubKeyCredential c -> C.PaymentCredentialByKey <$> unTransPubKeyHash c