Skip to content

Commit

Permalink
Implement deserialisePlutusScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jul 15, 2024
1 parent d992acc commit e5566d0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cardano-api/internal/Cardano/Api/Scripts/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,31 @@ deserialiseNativeScript availableEra bs =
Just nScript -> Right nScript
Nothing -> Left NotASimpleScript
Left e -> Left $ NotAScript e

data PlutusScriptDeserializationError
= NotAPlutusScript
| NotAnyScript DecoderError

deserialisePlutusScript
:: DecCBOR (Ledger.AlonzoScript (ToConstrainedEra availableera))
=> Era availableera
-> ByteString
-> Either PlutusScriptDeserializationError (Ledger.PlutusScript (ToConstrainedEra availableera))
deserialisePlutusScript era bs =
case era of
CurrentEraInternal -> deserialise AsMainnetScript bs
UpcomingEraInternal -> deserialise AsUpcomingEraScript bs
where
deserialise
:: SerialiseAsCBOR (Script availableera)
=> Ledger.AlonzoEraScript (ToConstrainedEra availableera)
=> AsType (Script availableera)
-> ByteString
-> Either PlutusScriptDeserializationError (Ledger.PlutusScript (ToConstrainedEra availableera))
deserialise as bs' =
case deserialiseFromCBOR as bs' of
Right s -> case Ledger.toPlutusScript $ unScript s of
Just nScript -> Right nScript
Nothing -> Left NotAPlutusScript
Left e -> Left $ NotAnyScript e

0 comments on commit e5566d0

Please sign in to comment.