Skip to main content

PreparedMethod

Struct PreparedMethod 

Source
pub struct PreparedMethod<'a> {
    pub contract: Address,
    pub fingerprint: MethodFingerprint,
    pub external_args: NonNull<c_void>,
    pub method_context: MethodContext,
    /* private fields */
}
Expand description

Method to be called by the executor.

It only describes a method call and nothing in it is checked: the executor reads arguments behind external_args according to metadata of the method with fingerprint, and either checks them against that metadata or trusts the caller (like the native executor does). The arguments meet the safety requirements of Self::new_untyped() for the lifetime 'a, which Self::new() ensures with typed arguments. Fields can’t be modified after creation, so that a method prepared with Self::new() can’t be retargeted to a different method or arguments by accident.

Fields§

§contract: Address

Address of the contract that contains a function to the below fingerprint

§fingerprint: MethodFingerprint

Fingerprint of the method being called

§external_args: NonNull<c_void>

Anonymous pointer to a struct that implements ExternalArgs of the method with the above fingerprint

§method_context: MethodContext

Context for method call

Implementations§

Source§

impl<'a> PreparedMethod<'a>

Source

pub fn new<Args>( contract: Address, args: &'a mut Args, method_context: MethodContext, ) -> Self
where Args: ExternalArgs,

Prepare a single method for calling at specified address and with specified arguments.

The result is to be used with Env::call_prepared() afterward.

Source

pub unsafe fn new_untyped<Args>( contract: Address, fingerprint: MethodFingerprint, external_args: &'a mut Args, method_context: MethodContext, ) -> Self

Prepare a single method for calling with arguments laid out dynamically, like in a transaction payload.

Prefer Self::new() when the type of arguments is known.

§Safety

external_args must start with arguments laid out like ExternalArgs of the method with fingerprint, and for the lifetime 'a:

  • the pointer of each slot must be aligned and point to an [Address] valid for reads
  • the pointer of each input must be valid for reads of its size, with that many bytes initialized
  • the pointer of each output must be valid for writes of its capacity and for reads of its size, which must not exceed the capacity, with that many bytes initialized
  • the pointer of the return value (if the method has one) must be aligned and valid for writes of a value of the return type, while its contents don’t need to be initialized
  • outputs and the return value must not overlap each other, slot addresses, inputs or external_args, and must not be accessed other than through external_args, while slot addresses and inputs must not be written to

A call can leave contents behind in outputs that are not valid values of their types, even when it succeeds, and it only initializes the return value. Afterward, neither may be accessed as a value of its type without being parsed first, unless every bit pattern is a valid value.

Whether sizes, capacities and alignment of inputs and outputs match the method’s metadata is not part of this contract, since only the executor has the metadata and guarantees it: the RISC-V VM checks them, while the native executor trusts callers and only catches mismatches with debug assertions. Neither are their contents, which the called method parses.

Trait Implementations§

Source§

impl<'a> Debug for PreparedMethod<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Send for PreparedMethod<'a>

§

impl<'a> !Sync for PreparedMethod<'a>

§

impl<'a> Freeze for PreparedMethod<'a>

§

impl<'a> RefUnwindSafe for PreparedMethod<'a>

§

impl<'a> Unpin for PreparedMethod<'a>

§

impl<'a> UnsafeUnpin for PreparedMethod<'a>

§

impl<'a> UnwindSafe for PreparedMethod<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.