cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Compiled scripts

data Version Source #

Ledger language version; ordering follows version number. Availability depends on the ledger era; this type does not assert deployment support.

Constructors

V1 
V2 
V3 
V4 

Instances

Instances details
Bounded Version Source # 
Instance details

Defined in Cometa.Script.Plutus

Enum Version Source # 
Instance details

Defined in Cometa.Script.Plutus

Show Version Source # 
Instance details

Defined in Cometa.Script.Plutus

Eq Version Source # 
Instance details

Defined in Cometa.Script.Plutus

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #

Ord Version Source # 
Instance details

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.

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.