Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Api.Experimental.Plutus
Synopsis
- data PlutusScriptInEra (lang :: Language) era where
- PlutusScriptInEra :: forall (lang :: Language) era. PlutusRunnable lang -> PlutusScriptInEra lang era
- legacyWitnessToScriptRequirements :: forall era (witnessable :: WitnessableItem) ctx. AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness ctx era))] -> Either DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
- legacyWitnessConversion :: forall era (witnessable :: WitnessableItem) ctx. AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness ctx era))] -> Either DecoderError [(Witnessable witnessable (ShelleyLedgerEra era), AnyWitness (ShelleyLedgerEra era))]
- toPlutusSLanguage :: PlutusScriptVersion lang -> SLanguage (ToLedgerPlutusLanguage lang)
- data PlutusScriptWitness (lang :: Language) (purpose :: PlutusScriptPurpose) era where
- PlutusScriptWitness :: forall (lang :: Language) era (purpose :: PlutusScriptPurpose). SLanguage lang -> PlutusScriptOrReferenceInput lang era -> PlutusScriptDatum lang purpose -> ScriptRedeemer -> ExecutionUnits -> PlutusScriptWitness lang purpose era
- data PlutusScriptOrReferenceInput (lang :: Language) era
- = PScript (PlutusScriptInEra lang era)
- | PReferenceScript TxIn
- type ScriptRedeemer = HashableScriptData
- data PlutusScriptPurpose
- data PlutusScriptDatum (lang :: Language) (purpose :: PlutusScriptPurpose) where
- SpendingScriptDatum :: forall (lang :: Language). PlutusScriptDatumF lang 'SpendingScript -> PlutusScriptDatum lang 'SpendingScript
- InlineDatum :: forall (lang :: Language) (purpose :: PlutusScriptPurpose). PlutusScriptDatum lang purpose
- NoScriptDatum :: forall (lang :: Language) (purpose :: PlutusScriptPurpose). PlutusScriptDatum lang purpose
- data NoScriptDatum = NoScriptDatumAllowed
- mkPlutusScriptWitness :: forall era (plutuslang :: Language) (purpose :: PlutusScriptPurpose). AlonzoEraOnwards era -> SLanguage plutuslang -> PlutusRunnable plutuslang -> PlutusScriptDatum plutuslang purpose -> ScriptRedeemer -> ExecutionUnits -> PlutusScriptWitness plutuslang purpose (ShelleyLedgerEra era)
- getPlutusScriptWitnessLanguage :: forall (lang :: Language) (purpose :: PlutusScriptPurpose) era. PlutusScriptWitness lang purpose era -> Language
- data AnyIndexedPlutusScriptWitness era where
- AnyIndexedPlutusScriptWitness :: forall era (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose). GetPlutusScriptPurpose era => IndexedPlutusScriptWitness witnessable lang purpose era -> AnyIndexedPlutusScriptWitness era
- data IndexedPlutusScriptWitness (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose) era where
- IndexedPlutusScriptWitness :: forall era (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose). AlonzoEraScript era => Witnessable witnessable era -> PlutusPurpose AsIx era -> PlutusScriptWitness lang purpose era -> IndexedPlutusScriptWitness witnessable lang purpose era
- data Witnessable (thing :: WitnessableItem) era where
- WitTxIn :: forall era. AlonzoEraScript era => TxIn -> Witnessable 'TxInItem era
- WitTxCert :: forall era. (EraTxCert era, AlonzoEraScript era) => TxCert era -> StakeCredential -> Witnessable 'CertItem era
- WitMint :: forall era. AlonzoEraScript era => PolicyId -> PolicyAssets -> Witnessable 'MintItem era
- WitWithdrawal :: forall era. AlonzoEraScript era => StakeAddress -> Coin -> Witnessable 'WithdrawalItem era
- WitVote :: forall era. ConwayEraScript era => Voter -> Witnessable 'VoterItem era
- WitProposal :: forall era. (ConwayEraScript era, EraPParams era) => ProposalProcedure era -> Witnessable 'ProposalItem era
- data WitnessableItem
- class GetPlutusScriptPurpose era where
- toPlutusScriptPurpose :: forall (thing :: WitnessableItem). Word32 -> Witnessable thing era -> PlutusPurpose AsIx era
- createIndexedPlutusScriptWitnesses :: forall era (witnessable :: WitnessableItem). AlonzoEraScript era => [(Witnessable witnessable era, AnyWitness era)] -> [AnyIndexedPlutusScriptWitness era]
- getAnyWitnessRedeemerPointerMap :: forall era (witnessable :: WitnessableItem). AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), AnyWitness (ShelleyLedgerEra era))] -> Redeemers (ShelleyLedgerEra era)
- obtainAlonzoScriptPurposeConstraints :: AlonzoEraOnwards era -> ((GetPlutusScriptPurpose era, AlonzoEraScript (ShelleyLedgerEra era)) => a) -> a
- constructRedeeemerPointerMap :: AlonzoEraOnwards era -> [AnyIndexedPlutusScriptWitness (ShelleyLedgerEra era)] -> Redeemers (ShelleyLedgerEra era)
Plutus Script
data PlutusScriptInEra (lang :: Language) era where Source #
A Plutus script in a particular era.
Why PlutusRunnable? Mainly for deserialization benefits.
The deserialization of this type looks at the
major protocol version and the script language to determine if
indeed the script is runnable. This is a dramatic improvement over the old api
which essentially read a ByteString
and hoped for the best.
Any failures due to malformed/invalid scripts were caught upon transaction
submission or running the script when attempting to predict the necessary execution units.
Where do we get the major protocol version from?
In order to access the major protocol version we pass in an era
type parameter which
can be translated to the major protocol version.
Where do we get the script language from?
The serialized version of PlutusRunnable
encodes the script language.
See `DecCBOR (PlutusRunnable l)` in cardano-ledger for more details.
Constructors
PlutusScriptInEra :: forall (lang :: Language) era. PlutusRunnable lang -> PlutusScriptInEra lang era |
Instances
Show (PlutusScriptInEra lang era) Source # | |
Legacy Scripts
legacyWitnessToScriptRequirements :: forall era (witnessable :: WitnessableItem) ctx. AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness ctx era))] -> Either DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)) Source #
legacyWitnessConversion :: forall era (witnessable :: WitnessableItem) ctx. AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness ctx era))] -> Either DecoderError [(Witnessable witnessable (ShelleyLedgerEra era), AnyWitness (ShelleyLedgerEra era))] Source #
When it comes to using plutus scripts we need to provide the following to the tx:
- The redeemer pointer map
- The set of plutus languages in use
- The set of plutus scripts in use (present in the t)
- The datum map
toPlutusSLanguage :: PlutusScriptVersion lang -> SLanguage (ToLedgerPlutusLanguage lang) Source #
Plutus Script Witness
data PlutusScriptWitness (lang :: Language) (purpose :: PlutusScriptPurpose) era where Source #
This is a Plutus script witness. It possesses: 1. The plutus script or reference input 2. The script redeemer 3. The execution units 4. Potentially a script datum. See the PlutusScriptDatum type family for more details.
Note that Plutus script witnesses do not exist on their own. They must witness something
and a redeemer pointer must be constucted to point to the thing being witnessed.
See IndexedPlutusScriptWitness
for more details.
Constructors
PlutusScriptWitness :: forall (lang :: Language) era (purpose :: PlutusScriptPurpose). SLanguage lang -> PlutusScriptOrReferenceInput lang era -> PlutusScriptDatum lang purpose -> ScriptRedeemer -> ExecutionUnits -> PlutusScriptWitness lang purpose era |
Instances
Show (PlutusScriptWitness lang purpose era) Source # | |
Constructing a plutus script witness.
data PlutusScriptOrReferenceInput (lang :: Language) era Source #
You can provide the plutus script directly in the transaction or a reference input that points to the script in the UTxO. Using a reference script saves space in your transaction.
Constructors
PScript (PlutusScriptInEra lang era) | |
PReferenceScript TxIn |
Instances
Show (PlutusScriptOrReferenceInput lang era) Source # | |
type ScriptRedeemer = HashableScriptData Source #
data PlutusScriptPurpose Source #
Every Plutus script has a purpose that indicates what that script is witnessing.
Constructors
SpendingScript | Witnesses a transaction input |
MintingScript | Witnesses a minting policy |
WithdrawingScript | Witnesses a withdrawal |
CertifyingScript | Witnesses a certificate |
ProposingScript | Witnesses a proposal |
VotingScript | Witnesses a vote |
data PlutusScriptDatum (lang :: Language) (purpose :: PlutusScriptPurpose) where Source #
Constructors
SpendingScriptDatum :: forall (lang :: Language). PlutusScriptDatumF lang 'SpendingScript -> PlutusScriptDatum lang 'SpendingScript | |
InlineDatum :: forall (lang :: Language) (purpose :: PlutusScriptPurpose). PlutusScriptDatum lang purpose | |
NoScriptDatum :: forall (lang :: Language) (purpose :: PlutusScriptPurpose). PlutusScriptDatum lang purpose |
Instances
Show (PlutusScriptDatum lang purpose) Source # | |
data NoScriptDatum Source #
Constructors
NoScriptDatumAllowed |
Instances
mkPlutusScriptWitness :: forall era (plutuslang :: Language) (purpose :: PlutusScriptPurpose). AlonzoEraOnwards era -> SLanguage plutuslang -> PlutusRunnable plutuslang -> PlutusScriptDatum plutuslang purpose -> ScriptRedeemer -> ExecutionUnits -> PlutusScriptWitness plutuslang purpose (ShelleyLedgerEra era) Source #
getPlutusScriptWitnessLanguage :: forall (lang :: Language) (purpose :: PlutusScriptPurpose) era. PlutusScriptWitness lang purpose era -> Language Source #
Constuct an indexed plutus script witness.
data AnyIndexedPlutusScriptWitness era where Source #
Constructors
AnyIndexedPlutusScriptWitness :: forall era (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose). GetPlutusScriptPurpose era => IndexedPlutusScriptWitness witnessable lang purpose era -> AnyIndexedPlutusScriptWitness era |
Instances
data IndexedPlutusScriptWitness (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose) era where Source #
A Plutus script witness along the thing it is witnessing and the index of that thing. E.g transaction input, certificate, withdrawal, minting policy, etc. A Plutus script witness only makes sense in the context of what it is witnessing and the index of the thing it is witnessing.
Constructors
IndexedPlutusScriptWitness :: forall era (witnessable :: WitnessableItem) (lang :: Language) (purpose :: PlutusScriptPurpose). AlonzoEraScript era => Witnessable witnessable era -> PlutusPurpose AsIx era -> PlutusScriptWitness lang purpose era -> IndexedPlutusScriptWitness witnessable lang purpose era |
Instances
Show (IndexedPlutusScriptWitness witnessable lang purpose era) Source # | |
Witnessable things.
data Witnessable (thing :: WitnessableItem) era where Source #
These are all of the "things" a plutus script can witness. We include the relevant
type class constraint to avoid boilerplate when creating the PlutusPurpose
in
the GetPlutusScriptPurpose
instances.
Constructors
WitTxIn :: forall era. AlonzoEraScript era => TxIn -> Witnessable 'TxInItem era | |
WitTxCert :: forall era. (EraTxCert era, AlonzoEraScript era) => TxCert era -> StakeCredential -> Witnessable 'CertItem era | |
WitMint :: forall era. AlonzoEraScript era => PolicyId -> PolicyAssets -> Witnessable 'MintItem era | |
WitWithdrawal :: forall era. AlonzoEraScript era => StakeAddress -> Coin -> Witnessable 'WithdrawalItem era | |
WitVote :: forall era. ConwayEraScript era => Voter -> Witnessable 'VoterItem era | |
WitProposal :: forall era. (ConwayEraScript era, EraPParams era) => ProposalProcedure era -> Witnessable 'ProposalItem era |
Instances
Show (Witnessable thing era) Source # | |
Eq (Witnessable thing era) Source # | |
Defined in Cardano.Api.Experimental.Plutus.Internal.IndexedPlutusScriptWitness Methods (==) :: Witnessable thing era -> Witnessable thing era -> Bool Source # (/=) :: Witnessable thing era -> Witnessable thing era -> Bool Source # |
data WitnessableItem Source #
Constructors
TxInItem | |
CertItem | |
MintItem | |
WithdrawalItem | |
VoterItem | |
ProposalItem |
Create the index for a witnessable thing.
class GetPlutusScriptPurpose era where Source #
To reduce boilerplate, we reuse the PlutusPurpose
type from `cardano-ledger`.
This type is utilized in constructing the redeemer pointers map, which
links the redeemer and execution units with the entity being witnessed.
The map is indexed by the redeemer pointer.
A natural question arises: How do Plutus scripts determine which
execution units and redeemer are paired with them? The ledger constructs a redeemer pointer
for every Plutus script, and this pointer corresponds to the one in the transaction's
redeemer pointers map. For more details, refer to collectPlutusScriptsWithContext
in `cardano-ledger`.
Methods
toPlutusScriptPurpose :: forall (thing :: WitnessableItem). Word32 -> Witnessable thing era -> PlutusPurpose AsIx era Source #
Instances
GetPlutusScriptPurpose era Source # | |
Defined in Cardano.Api.Experimental.Plutus.Internal.IndexedPlutusScriptWitness Methods toPlutusScriptPurpose :: forall (thing :: WitnessableItem). Word32 -> Witnessable thing era -> PlutusPurpose AsIx era Source # |
createIndexedPlutusScriptWitnesses :: forall era (witnessable :: WitnessableItem). AlonzoEraScript era => [(Witnessable witnessable era, AnyWitness era)] -> [AnyIndexedPlutusScriptWitness era] Source #
Create a list of indexed plutus script witnesses from anything witnessable that has been witnesseed by a plutus script.
getAnyWitnessRedeemerPointerMap :: forall era (witnessable :: WitnessableItem). AlonzoEraOnwards era -> [(Witnessable witnessable (ShelleyLedgerEra era), AnyWitness (ShelleyLedgerEra era))] -> Redeemers (ShelleyLedgerEra era) Source #
The transaction's redeemer pointer map allows the ledger to connect a redeemer and execution unit pairing to the relevant script. The ledger basically reconstructs the indicies (redeemer pointers) of this map can then look up the relevant execution units/redeemer pairing. NB: the redeemer pointer has been renamed to 'PlutusPurpose AsIndex' in the ledger.
obtainAlonzoScriptPurposeConstraints :: AlonzoEraOnwards era -> ((GetPlutusScriptPurpose era, AlonzoEraScript (ShelleyLedgerEra era)) => a) -> a Source #
Low level functions
constructRedeeemerPointerMap :: AlonzoEraOnwards era -> [AnyIndexedPlutusScriptWitness (ShelleyLedgerEra era)] -> Redeemers (ShelleyLedgerEra era) Source #