pub struct TransactionPayloadDecoder<'payload, 'outputs> { /* private fields */ }Expand description
Decoder that checks a payload created using TransactionPayloadBuilder and describes its
methods without calling them, for example to show a transaction to the user before it is
signed.
It runs the same decoding code as TransactionPayloadCaller, so it applies every rule that
depends only on the payload. A payload that it accepts can still be rejected by the caller in
two cases, which depend on execution:
- the declared outputs don’t fit into the output buffer of the caller, which allocates each of
them at a multiple of 16 bytes ([
Alignment::MAX]) after the previous one: they fit if the capacities ofSelf::declared_outputs(), each except the last rounded up to a multiple of 16, add up to at most the size of the output buffer (32 KiB inSimpleWalletBase::execute(), seeOUTPUT_BUFFER_SIZE); the caller checks this when it is created, before it calls any method - an
#[output]that a later method uses as a slot doesn’t hold an address after its method was called; the caller checks this when it reaches that slot, so when the caller rejects a payload for it, the decoder either accepts the payload or rejects it with an error from later in the payload
A payload can declare outputs that no method writes. The decoder and the caller accept it, the
memory of such an output is allocated but never used, while TransactionPayloadBuilder never
creates such a payload.
Descriptions contain no pointers into memory other than the payload, so any payload can be decoded safely.
Implementations§
Source§impl<'payload, 'outputs> TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> TransactionPayloadDecoder<'payload, 'outputs>
Sourcepub fn new(
payload: &'payload [u128],
declared_outputs: &'outputs mut [MaybeUninit<DeclaredOutput>; 16],
) -> Result<Self, TransactionPayloadDecoderError>
pub fn new( payload: &'payload [u128], declared_outputs: &'outputs mut [MaybeUninit<DeclaredOutput>; 16], ) -> Result<Self, TransactionPayloadDecoderError>
Create a new instance and read the outputs that the payload declares, at most
MAX_OUTPUTS, into declared_outputs.
Returns an error if the outputs that the payload declares can’t be read. Every payload starts with them, so an empty payload is too small.
Sourcepub fn declared_outputs(&self) -> &[DeclaredOutput]
pub fn declared_outputs(&self) -> &[DeclaredOutput]
Outputs that the payload declares, by output index
Sourcepub fn next_method(
&mut self,
) -> Result<Option<DecodedMethod<'_, 'payload>>, TransactionPayloadDecoderError>
pub fn next_method( &mut self, ) -> Result<Option<DecodedMethod<'_, 'payload>>, TransactionPayloadDecoderError>
Decode and check the next method, None if there are no more methods in the payload.
The method is returned only after all of it was checked. Its arguments are stored in the
decoder and replaced by the next call. After an error, every call returns
TransactionPayloadDecoderError::FailedEarlier.
Trait Implementations§
Auto Trait Implementations§
impl<'payload, 'outputs> !UnwindSafe for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> Freeze for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> RefUnwindSafe for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> Send for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> Sync for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> Unpin for TransactionPayloadDecoder<'payload, 'outputs>
impl<'payload, 'outputs> UnsafeUnpin for TransactionPayloadDecoder<'payload, 'outputs>
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