From 4b7382c06da2610f28fef8427908c0a406c7c85e Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 15 Dec 2021 18:41:50 +0100 Subject: [PATCH] Add 'IsScriptWitnessInCtx' Makes it easier to write functions that are polymorphic in the witness context. --- cardano-api/src/Cardano/Api.hs | 1 + cardano-api/src/Cardano/Api/Script.hs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 7e5178c3354..3cde898d1e7 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -369,6 +369,7 @@ module Cardano.Api ( Witness(..), KeyWitnessInCtx(..), ScriptWitnessInCtx(..), + IsScriptWitnessInCtx(..), ScriptDatum(..), ScriptRedeemer, scriptWitnessScript, diff --git a/cardano-api/src/Cardano/Api/Script.hs b/cardano-api/src/Cardano/Api/Script.hs index 995d1c68471..84bb19ee123 100644 --- a/cardano-api/src/Cardano/Api/Script.hs +++ b/cardano-api/src/Cardano/Api/Script.hs @@ -53,6 +53,7 @@ module Cardano.Api.Script ( Witness(..), KeyWitnessInCtx(..), ScriptWitnessInCtx(..), + IsScriptWitnessInCtx(..), ScriptDatum(..), ScriptRedeemer, scriptWitnessScript, @@ -851,6 +852,17 @@ deriving instance Show (KeyWitnessInCtx witctx) deriving instance Eq (ScriptWitnessInCtx witctx) deriving instance Show (ScriptWitnessInCtx witctx) +class IsScriptWitnessInCtx ctx where + scriptWitnessInCtx :: ScriptWitnessInCtx ctx + +instance IsScriptWitnessInCtx WitCtxTxIn where + scriptWitnessInCtx = ScriptWitnessForSpending + +instance IsScriptWitnessInCtx WitCtxMint where + scriptWitnessInCtx = ScriptWitnessForMinting + +instance IsScriptWitnessInCtx WitCtxStake where + scriptWitnessInCtx = ScriptWitnessForStakeAddr -- ---------------------------------------------------------------------------- -- Script execution units