{-# OPTIONS_GHC -Wno-orphans #-}
module Hydra.Cardano.Api.ScriptHash where
import Hydra.Cardano.Api.Prelude
import Cardano.Ledger.Credential qualified as Ledger
import Hydra.Cardano.Api.PlutusScript ()
getPaymentScriptHash :: AddressInEra era -> Maybe ScriptHash
getPaymentScriptHash :: forall era. AddressInEra era -> Maybe ScriptHash
getPaymentScriptHash = \case
AddressInEra AddressTypeInEra addrtype era
_ (ShelleyAddress Network
_ (Ledger.ScriptHashObj ScriptHash StandardCrypto
h) StakeReference StandardCrypto
_) ->
ScriptHash -> Maybe ScriptHash
forall a. a -> Maybe a
Just (ScriptHash StandardCrypto -> ScriptHash
fromShelleyScriptHash ScriptHash StandardCrypto
h)
AddressInEra era
_ ->
Maybe ScriptHash
forall a. Maybe a
Nothing
hashScriptInAnyLang :: ScriptInAnyLang -> ScriptHash
hashScriptInAnyLang :: ScriptInAnyLang -> ScriptHash
hashScriptInAnyLang (ScriptInAnyLang ScriptLanguage lang
_ Script lang
script) =
Script lang -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript Script lang
script
instance Arbitrary ScriptHash where
arbitrary :: Gen ScriptHash
arbitrary = do
Script PlutusScriptV3 -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript (Script PlutusScriptV3 -> ScriptHash)
-> (PlutusScript PlutusScriptV3 -> Script PlutusScriptV3)
-> PlutusScript PlutusScriptV3
-> ScriptHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PlutusScriptVersion PlutusScriptV3
-> PlutusScript PlutusScriptV3 -> Script PlutusScriptV3
forall lang.
PlutusScriptVersion lang -> PlutusScript lang -> Script lang
PlutusScript PlutusScriptVersion PlutusScriptV3
PlutusScriptV3 (PlutusScript PlutusScriptV3 -> ScriptHash)
-> Gen (PlutusScript PlutusScriptV3) -> Gen ScriptHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (PlutusScript PlutusScriptV3)
forall a. Arbitrary a => Gen a
arbitrary