Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 2.22 KB

20221222112604-referencescript.org

File metadata and controls

53 lines (41 loc) · 2.22 KB

ReferenceScript

A reference script is a script that can exist at a transaction output, TxOut

-- ----------------------------------------------------------------------------
-- Reference scripts
--

-- | A reference scripts is a script that can exist at a transaction output. This greatly
-- reduces the size of transactions that use scripts as the script no longer
-- has to be added to the transaction, they can now be referenced via a transaction output.

data ReferenceScript era where
     ReferenceScript :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
                     -> ScriptInAnyLang
                     -> ReferenceScript era

     ReferenceScriptNone :: ReferenceScript era

deriving instance Eq (ReferenceScript era)
deriving instance Show (ReferenceScript era)
deriving instance Typeable (ReferenceScript era)

instance IsCardanoEra era => ToJSON (ReferenceScript era) where
  toJSON (ReferenceScript _ s) = object ["referenceScript" .= s]
  toJSON ReferenceScriptNone = Aeson.Null

instance IsCardanoEra era => FromJSON (ReferenceScript era) where
  parseJSON = Aeson.withObject "ReferenceScript" $ \o ->
    case refInsScriptsAndInlineDatsSupportedInEra (cardanoEra :: CardanoEra era) of
      Nothing -> pure ReferenceScriptNone
      Just refSupInEra ->
        ReferenceScript refSupInEra <$> o .: "referenceScript"

instance EraCast ReferenceScript where
  eraCast toEra = \case
    ReferenceScriptNone -> pure ReferenceScriptNone
    v@(ReferenceScript (_ :: ReferenceTxInsScriptsInlineDatumsSupportedInEra fromEra) scriptInAnyLang) ->
      case refInsScriptsAndInlineDatsSupportedInEra toEra of
        Nothing -> Left $ EraCastError v (cardanoEra @fromEra) toEra
        Just supportedInEra -> Right $ ReferenceScript supportedInEra scriptInAnyLang

Constructors

ReferenceScript ∷ ReferenceTxInsScriptsInlineDatumsSupportedInEra era → ScriptInAnyLang→ ReferenceScript era ReferenceScriptNone ∷ ReferenceScript era