Skip to content

Commit

Permalink
Add 'IsScriptWitnessInCtx'
Browse files Browse the repository at this point in the history
  Makes it easier to write functions that are polymorphic in the witness context.
  • Loading branch information
KtorZ committed Dec 15, 2021
1 parent fc10f16 commit 581c568
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ module Cardano.Api (
Witness(..),
KeyWitnessInCtx(..),
ScriptWitnessInCtx(..),
IsScriptWitnessInCtx(..),
ScriptDatum(..),
ScriptRedeemer,
scriptWitnessScript,
Expand Down
12 changes: 12 additions & 0 deletions cardano-api/src/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Cardano.Api.Script (
Witness(..),
KeyWitnessInCtx(..),
ScriptWitnessInCtx(..),
IsScriptWitnessInCtx(..),
ScriptDatum(..),
ScriptRedeemer,
scriptWitnessScript,
Expand Down Expand Up @@ -770,6 +771,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
Expand Down

0 comments on commit 581c568

Please sign in to comment.