pub struct Program<T> {
pub version: (usize, usize, usize),
pub term: Term<T>,
}Expand description
This represents a program in Untyped Plutus Core. A program contains a version tuple and a term. It is generic because Term requires a generic type.
Fields§
§version: (usize, usize, usize)§term: Term<T>Implementations§
Source§impl<T> Program<T>where
T: Clone,
impl<T> Program<T>where
T: Clone,
Sourcepub fn apply(&self, program: &Self) -> Self
pub fn apply(&self, program: &Self) -> Self
We use this to apply the validator to Datum, then redeemer, then ScriptContext. If datum is even necessary (i.e. minting policy).
Sourcepub fn apply_data(&self, plutus_data: PlutusData) -> Self
pub fn apply_data(&self, plutus_data: PlutusData) -> Self
A convenient and faster version that apply_term since the program doesn’t need to be
re-interned (constant Data do not introduce new bindings).
Source§impl Program<Name>
impl Program<Name>
Sourcepub fn apply_term(&self, term: &Term<Name>) -> Self
pub fn apply_term(&self, term: &Term<Name>) -> Self
We use this to apply the validator to Datum, then redeemer, then ScriptContext. If datum is even necessary (i.e. minting policy).
Sourcepub fn to_debruijn(self) -> Result<Program<DeBruijn>, Error>
pub fn to_debruijn(self) -> Result<Program<DeBruijn>, Error>
A convenient method to convery named programs to debruijn programs.
Sourcepub fn to_named_debruijn(self) -> Result<Program<NamedDeBruijn>, Error>
pub fn to_named_debruijn(self) -> Result<Program<NamedDeBruijn>, Error>
A convenient method to convery named programs to named debruijn programs.
Source§impl Program<DeBruijn>
impl Program<DeBruijn>
pub fn address( &self, network: Network, delegation: ShelleyDelegationPart, plutus_version: &Language, ) -> ShelleyAddress
Source§impl Program<NamedDeBruijn>
impl Program<NamedDeBruijn>
pub fn eval(self, initial_budget: ExBudget) -> EvalResult
Sourcepub fn eval_version(
self,
initial_budget: ExBudget,
version: &Language,
) -> EvalResult
pub fn eval_version( self, initial_budget: ExBudget, version: &Language, ) -> EvalResult
Evaluate a Program as a specific PlutusVersion
pub fn eval_as( self, version: &Language, costs: &[i64], initial_budget: Option<&ExBudget>, ) -> EvalResult
Source§impl Program<DeBruijn>
impl Program<DeBruijn>
pub fn eval(&self, initial_budget: ExBudget) -> EvalResult
pub fn eval_version( self, initial_budget: ExBudget, version: &Language, ) -> EvalResult
Source§impl<'b, T> Program<T>
impl<'b, T> Program<T>
pub fn from_cbor( bytes: &'b [u8], buffer: &'b mut Vec<u8>, ) -> Result<Self, Error>
pub fn from_flat(bytes: &'b [u8]) -> Result<Self, Error>
pub fn from_hex( hex_str: &str, cbor_buffer: &'b mut Vec<u8>, flat_buffer: &'b mut Vec<u8>, ) -> Result<Self, Error>
Sourcepub fn to_cbor(&self) -> Result<Vec<u8>, Error>
pub fn to_cbor(&self) -> Result<Vec<u8>, Error>
Convert a program to cbor bytes.
note: The cbor bytes of a program are merely the flat bytes of the program encoded as cbor bytes.
§Examples
use uplc::ast::{Program, Name, Term};
let term = Term::var("x").lambda("x");
let program = Program { version: (1, 0, 0), term };
assert_eq!(
program.to_debruijn().unwrap().to_cbor().unwrap(),
vec![
0x46, 0x01, 0x00, 0x00,
0x20, 0x01, 0x01
],
);Sourcepub fn to_flat(&self) -> Result<Vec<u8>, Error>
pub fn to_flat(&self) -> Result<Vec<u8>, Error>
Convert a program to a flat bytes.
note: Convenient so that people don’t need to depend on the flat crate directly to call programs flat function.
§Examples
use uplc::ast::{Program, Name, Term};
let term = Term::var("x").lambda("x");
let program = Program { version: (1, 0, 0), term };
assert_eq!(
program
.to_debruijn()
.unwrap()
.to_flat()
.unwrap(),
vec![
0x01, 0x00, 0x00,
0x20, 0x01, 0x01
],
);Sourcepub fn to_hex(&self) -> Result<String, Error>
pub fn to_hex(&self) -> Result<String, Error>
Convert a program to hex encoded cbor bytes
§Examples
use uplc::ast::{Program, Name, Term};
let term = Term::var("x").lambda("x");
let program = Program { version: (1, 0, 0), term };
assert_eq!(
program.to_debruijn().unwrap().to_hex().unwrap(),
"46010000200101".to_string(),
);Source§impl Program<Name>
impl Program<Name>
pub fn run_once_pass(self) -> Self
pub fn multi_pass(self) -> (Self, Context)
pub fn run_one_opt( self, inline_lambda: bool, with: &mut impl FnMut(Option<usize>, &mut Term<Name>, Vec<Args>, &Scope, &mut Context), ) -> Self
pub fn clean_up_no_inlines(self) -> Self
pub fn afterwards(self) -> Self
pub fn builtin_curry_reducer(self) -> Self
pub fn split_body_lambda_reducer(self) -> Self
Trait Implementations§
Source§impl From<Program<FakeNamedDeBruijn>> for Program<NamedDeBruijn>
impl From<Program<FakeNamedDeBruijn>> for Program<NamedDeBruijn>
Source§fn from(value: Program<FakeNamedDeBruijn>) -> Self
fn from(value: Program<FakeNamedDeBruijn>) -> Self
Source§impl From<Program<NamedDeBruijn>> for Program<DeBruijn>
impl From<Program<NamedDeBruijn>> for Program<DeBruijn>
Source§fn from(value: Program<NamedDeBruijn>) -> Self
fn from(value: Program<NamedDeBruijn>) -> Self
Source§impl From<Program<NamedDeBruijn>> for Program<FakeNamedDeBruijn>
impl From<Program<NamedDeBruijn>> for Program<FakeNamedDeBruijn>
Source§fn from(value: Program<NamedDeBruijn>) -> Self
fn from(value: Program<NamedDeBruijn>) -> Self
Source§impl TryFrom<Program<Name>> for Program<DeBruijn>
Convert a Parsed Program to a Program in Debruijn form.
This checks for any Free Uniques in the Program and returns an error if found.
impl TryFrom<Program<Name>> for Program<DeBruijn>
Convert a Parsed Program to a Program in Debruijn form.
This checks for any Free Uniques in the Program and returns an error if found.
Source§impl TryFrom<Program<Name>> for Program<NamedDeBruijn>
Convert a Parsed Program to a Program in NamedDebruijn form.
This checks for any Free Uniques in the Program and returns an error if found.
impl TryFrom<Program<Name>> for Program<NamedDeBruijn>
Convert a Parsed Program to a Program in NamedDebruijn form.
This checks for any Free Uniques in the Program and returns an error if found.
impl<T> StructuralPartialEq for Program<T>
Auto Trait Implementations§
impl<T> Freeze for Program<T>
impl<T> RefUnwindSafe for Program<T>where
T: RefUnwindSafe,
impl<T> !Send for Program<T>
impl<T> !Sync for Program<T>
impl<T> Unpin for Program<T>
impl<T> UnwindSafe for Program<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
Source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
Source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read moreSource§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.Source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
Source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.