module Hydra.Cardano.Api.TxOutDatum where

import Hydra.Cardano.Api.Prelude

import Hydra.Cardano.Api.ScriptData (ToScriptData, toScriptData)

-- | Construct a 'TxOutDatum' to be included in the tx from some serialisable data.
mkTxOutDatum ::
  forall era a.
  (ToScriptData a, IsAlonzoBasedEra era) =>
  a ->
  TxOutDatum CtxTx era
mkTxOutDatum :: forall era a.
(ToScriptData a, IsAlonzoBasedEra era) =>
a -> TxOutDatum CtxTx era
mkTxOutDatum =
  AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
forall era.
AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx (forall era. IsAlonzoBasedEra era => AlonzoEraOnwards era
alonzoBasedEra @era) (HashableScriptData -> TxOutDatum CtxTx era)
-> (a -> HashableScriptData) -> a -> TxOutDatum CtxTx era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> HashableScriptData
forall a. ToScriptData a => a -> HashableScriptData
toScriptData

-- | Construct a 'TxOutDatum' as a 'ScriptData' hash from some serialisable data.
mkTxOutDatumHash ::
  forall era a ctx.
  (ToScriptData a, IsAlonzoBasedEra era) =>
  a ->
  TxOutDatum ctx era
mkTxOutDatumHash :: forall era a ctx.
(ToScriptData a, IsAlonzoBasedEra era) =>
a -> TxOutDatum ctx era
mkTxOutDatumHash =
  AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash (forall era. IsAlonzoBasedEra era => AlonzoEraOnwards era
alonzoBasedEra @era) (Hash ScriptData -> TxOutDatum ctx era)
-> (a -> Hash ScriptData) -> a -> TxOutDatum ctx era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashableScriptData -> Hash ScriptData
hashScriptDataBytes (HashableScriptData -> Hash ScriptData)
-> (a -> HashableScriptData) -> a -> Hash ScriptData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> HashableScriptData
forall a. ToScriptData a => a -> HashableScriptData
toScriptData

-- | Construct an inline 'TxOutDatum' from some serialisable data.
mkTxOutDatumInline ::
  forall era a ctx.
  (ToScriptData a, IsBabbageBasedEra era) =>
  a ->
  TxOutDatum ctx era
mkTxOutDatumInline :: forall era a ctx.
(ToScriptData a, IsBabbageBasedEra era) =>
a -> TxOutDatum ctx era
mkTxOutDatumInline =
  BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline (forall era. IsBabbageBasedEra era => BabbageEraOnwards era
babbageBasedEra @era) (HashableScriptData -> TxOutDatum ctx era)
-> (a -> HashableScriptData) -> a -> TxOutDatum ctx era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> HashableScriptData
forall a. ToScriptData a => a -> HashableScriptData
toScriptData