Skip to main content

TransactionPayloadCaller

Struct TransactionPayloadCaller 

Source
pub struct TransactionPayloadCaller<'a> { /* private fields */ }
Expand description

Caller of methods in a transaction payload created using TransactionPayloadBuilder.

The payload must be trusted (see SimpleWalletBase::execute()): what it declares about the arguments of each method can’t be checked without the method’s metadata. The size of a return value must be the size of the return type, and the capacity of a declared output must be enough for the type of every #[output] that writes it. TransactionPayloadDecoder applies the same rules without calling methods, so a payload can be checked and shown to the user before it is signed.

All outputs that the payload declares are allocated in the output buffer when the caller is created, so a payload whose outputs don’t fit is rejected before any method is called.

Outputs are given to methods empty, with size 0, whatever was written into their memory before, so methods called from transactions must accept empty outputs, see TransactionPayloadBuilder::with_method_call().

Return values are given their size when a method is decoded, before it is called, since executors only write the value (see TransactionOutput). Each method is called right after it is decoded and calling stops at the first method that fails, so later methods can only refer to return values of methods that succeeded and wrote them.

Implementations§

Source§

impl<'a> TransactionPayloadCaller<'a>

Source

pub fn new( payload: &'a [u128], external_args_buffer: &'a mut [*mut c_void; 16], output_buffer: &'a mut [MaybeUninit<u128>], declared_outputs: &'a mut [MaybeUninit<DeclaredOutput>; 16], map_context: fn(TransactionMethodContext) -> MethodContext, ) -> Result<Self, TransactionPayloadDecoderError>

Create a new instance, read the outputs that the payload declares, at most MAX_OUTPUTS, into declared_outputs and allocate them in output_buffer.

The size of external_args_buffer defines the max number of bytes allocated for ExternalArgs, which impacts the number of arguments that can be represented by ExternalArgs. The size is specified in pointers with #[slot] argument using one pointer, while #[input] and #[output] use one pointer and size + capacity each.

The size of output_buffer defines how large the outputs that the payload declares can be together. Each of them starts at the next multiple of [Alignment::MAX] after the previous one.

Returns an error if the outputs that the payload declares can’t be read or don’t fit, so that no method of such a payload is called. Every payload starts with the outputs that it declares, so an empty payload is too small.

Source

pub fn call_next_method( self, env: &Env<'_>, ) -> Result<Option<Self>, TransactionPayloadCallError>

Decode the next method (if any) in the payload and call it.

Returns the caller for the remaining methods if the method succeeded, or None if there are no more methods in the payload. The caller is consumed when decoding or the method fails, since later methods might refer to return values that the failed method didn’t write.

Trait Implementations§

Source§

impl<'a> Debug for TransactionPayloadCaller<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.