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>
impl<'a> TransactionPayloadCaller<'a>
Sourcepub 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>
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.
Sourcepub fn call_next_method(
self,
env: &Env<'_>,
) -> Result<Option<Self>, TransactionPayloadCallError>
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§
Auto Trait Implementations§
impl<'a> !Send for TransactionPayloadCaller<'a>
impl<'a> !Sync for TransactionPayloadCaller<'a>
impl<'a> !UnwindSafe for TransactionPayloadCaller<'a>
impl<'a> Freeze for TransactionPayloadCaller<'a>
impl<'a> RefUnwindSafe for TransactionPayloadCaller<'a>
impl<'a> Unpin for TransactionPayloadCaller<'a>
impl<'a> UnsafeUnpin for TransactionPayloadCaller<'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