module Hydra.Cardano.Api.Witness where

import Hydra.Cardano.Api.Prelude

-- | Construct a full script witness from a datum, a redeemer and a full
-- 'PlutusScript'. That witness has no execution budget.
mkScriptWitness ::
  forall ctx era lang.
  ( IsPlutusScriptLanguage lang
  , HasScriptLanguageInEra lang era
  ) =>
  PlutusScript lang ->
  ScriptDatum ctx ->
  ScriptRedeemer ->
  ScriptWitness ctx era
mkScriptWitness :: forall ctx era lang.
(IsPlutusScriptLanguage lang, HasScriptLanguageInEra lang era) =>
PlutusScript lang
-> ScriptDatum ctx -> ScriptRedeemer -> ScriptWitness ctx era
mkScriptWitness PlutusScript lang
script ScriptDatum ctx
datum ScriptRedeemer
redeemer =
  ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum ctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness ctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness
    (forall lang era.
HasScriptLanguageInEra lang era =>
ScriptLanguageInEra lang era
scriptLanguageInEra @lang @era)
    (forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang
plutusScriptVersion @lang)
    (PlutusScript lang -> PlutusScriptOrReferenceInput lang
forall lang. PlutusScript lang -> PlutusScriptOrReferenceInput lang
PScript PlutusScript lang
script)
    ScriptDatum ctx
datum
    ScriptRedeemer
redeemer
    (Natural -> Natural -> ExecutionUnits
ExecutionUnits Natural
0 Natural
0)

-- | Construct a reference script witness, only referring to a 'TxIn' which is
-- expected to contain the given script (only required to satisfy types).
mkScriptReference ::
  forall ctx era lang.
  ( IsPlutusScriptLanguage lang
  , HasScriptLanguageInEra lang era
  ) =>
  TxIn ->
  PlutusScript lang ->
  ScriptDatum ctx ->
  ScriptRedeemer ->
  ScriptWitness ctx era
mkScriptReference :: forall ctx era lang.
(IsPlutusScriptLanguage lang, HasScriptLanguageInEra lang era) =>
TxIn
-> PlutusScript lang
-> ScriptDatum ctx
-> ScriptRedeemer
-> ScriptWitness ctx era
mkScriptReference TxIn
txIn PlutusScript lang
_script ScriptDatum ctx
datum ScriptRedeemer
redeemer =
  ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum ctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness ctx era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptRedeemer
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness
    (forall lang era.
HasScriptLanguageInEra lang era =>
ScriptLanguageInEra lang era
scriptLanguageInEra @lang @era)
    (forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang
plutusScriptVersion @lang)
    (TxIn -> Maybe ScriptHash -> PlutusScriptOrReferenceInput lang
forall lang.
TxIn -> Maybe ScriptHash -> PlutusScriptOrReferenceInput lang
PReferenceScript TxIn
txIn Maybe ScriptHash
forall a. Maybe a
Nothing)
    ScriptDatum ctx
datum
    ScriptRedeemer
redeemer
    (Natural -> Natural -> ExecutionUnits
ExecutionUnits Natural
0 Natural
0)