Skip to main content

TransactionPayloadDecoder

Struct TransactionPayloadDecoder 

Source
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 of Self::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 in SimpleWalletBase::execute(), see OUTPUT_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>

Source

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.

Source

pub fn declared_outputs(&self) -> &[DeclaredOutput]

Outputs that the payload declares, by output index

Source

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§

Source§

impl<'payload, 'outputs> Debug for TransactionPayloadDecoder<'payload, 'outputs>

Source§

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

Formats the value using the given formatter. Read more

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> 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.