| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Script.Plutus
Description
Versioned compiled Plutus scripts with exact byte identity. Compiled bytes usually contain one CBOR bytestring around Flat code; script CBOR adds another bytestring layer. Import never guesses or removes a layer. Raw-byte import checks nonemptiness; CBOR import also checks outer framing. Neither checks whether code is executable for its version.
import qualified Cometa.Script.Plutus as Plutus import qualified Data.ByteString as ByteString script = Plutus.fromBytes Plutus.V3 (ByteString.pack [0x45, 1, 0, 0, 0x24, 0x99])
Synopsis
- data Version
- data PlutusScript
- fromBytes :: Version -> ByteString -> Either Error PlutusScript
- toBytes :: PlutusScript -> ByteString
- version :: PlutusScript -> Version
- encodeCbor :: PlutusScript -> ByteString
- decodeCbor :: Version -> ByteString -> Either Error PlutusScript
- hash :: PlutusScript -> IO (Either Error ScriptHash)
- applyParams :: PlutusScript -> [PlutusData] -> IO (Either Error PlutusScript)
Compiled scripts
Ledger language version; ordering follows version number. Availability depends on the ledger era; this type does not assert deployment support.
Instances
| Bounded Version Source # | |
| Enum Version Source # | |
| Show Version Source # | |
| Eq Version Source # | |
| Ord Version Source # | |
Defined in Cometa.Script.Plutus | |
data PlutusScript Source #
Nonempty immutable compiled bytes and their version, with the exact outer
script CBOR preserved on import. Equality compares version and outer encoding;
ordering is version first, then lexicographic encoding. Show is diagnostic.
Instances
| Show PlutusScript Source # | |
Defined in Cometa.Script.Plutus Methods showsPrec :: Int -> PlutusScript -> ShowS # show :: PlutusScript -> String # showList :: [PlutusScript] -> ShowS # | |
| Eq PlutusScript Source # | |
Defined in Cometa.Script.Plutus | |
| Ord PlutusScript Source # | |
Defined in Cometa.Script.Plutus Methods compare :: PlutusScript -> PlutusScript -> Ordering # (<) :: PlutusScript -> PlutusScript -> Bool # (<=) :: PlutusScript -> PlutusScript -> Bool # (>) :: PlutusScript -> PlutusScript -> Bool # (>=) :: PlutusScript -> PlutusScript -> Bool # max :: PlutusScript -> PlutusScript -> PlutusScript # min :: PlutusScript -> PlutusScript -> PlutusScript # | |
fromBytes :: Version -> ByteString -> Either Error PlutusScript Source #
Import opaque compiled bytes without decoding or normalizing their contents.
Empty input returns EmptyPlutusScript. Executability is checked only when a
VM operation such as applyParams decodes the program.
toBytes :: PlutusScript -> ByteString Source #
Exact compiled bytes, excluding the outer script CBOR bytestring layer.
version :: PlutusScript -> Version Source #
The declared ledger language version.
Script CBOR
encodeCbor :: PlutusScript -> ByteString Source #
Encode the outer script bytestring. Imported encodings retain their exact form, including nonminimal lengths and indefinite chunks. Compiled bytes are never normalized by this operation.
decodeCbor :: Version -> ByteString -> Either Error PlutusScript Source #
Decode exactly one nonempty outer bytestring for the supplied version.
Malformed, trailing or schema-invalid input returns InvalidScriptCbor; an
empty payload returns EmptyPlutusScript. Both outer and compiled bytes retain
their identity; this operation does not decode executable Flat code.
Hashing and parameter application
hash :: PlutusScript -> IO (Either Error ScriptHash) Source #
Compute BLAKE2b-224 over the version prefix (1 through 4) followed by exact
compiled bytes. The outer script encoding does not participate in the hash.
Native hashing failures return NativeError.
applyParams :: PlutusScript -> [PlutusData] -> IO (Either Error PlutusScript) Source #
Decode a single-CBOR-wrapped Flat program, apply data constants in list
order, and serialize a new program with the same declared language version.
The first parameter is the innermost application. Even an empty list invokes
the VM and can normalize a noncanonical program encoding. The original script
is unchanged. Malformed programs or native failures return NativeError.
This operation checks program decoding, not ledger-era or language validity.