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: AddressAddress of the contract that contains a function to the below fingerprint
fingerprint: MethodFingerprintFingerprint 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: MethodContextContext for method call
Implementations§
Source§impl<'a> PreparedMethod<'a>
impl<'a> PreparedMethod<'a>
Sourcepub fn new<Args>(
contract: Address,
args: &'a mut Args,
method_context: MethodContext,
) -> Selfwhere
Args: ExternalArgs,
pub fn new<Args>(
contract: Address,
args: &'a mut Args,
method_context: MethodContext,
) -> Selfwhere
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.
Sourcepub unsafe fn new_untyped<Args>(
contract: Address,
fingerprint: MethodFingerprint,
external_args: &'a mut Args,
method_context: MethodContext,
) -> Self
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 throughexternal_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§
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> 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> 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 more