Skip to main content

DelegateCtx

Struct DelegateCtx 

Source
pub struct DelegateCtx { /* private fields */ }
Expand description

Opaque handle to the delegate’s execution environment.

Provides access to:

  • Temporary context: State shared within a single message batch (reset between calls)
  • Persistent secrets: Encrypted storage that survives across all invocations
  • Contract state (V2): Direct synchronous access to local contract state

§Context Methods

§Secret Methods

§Contract Methods (V2)

Implementations§

Source§

impl DelegateCtx

Source

pub fn len(&self) -> usize

Returns the current context length in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the context is empty.

Source

pub fn read(&self) -> Vec<u8>

Read the current context bytes.

Returns an empty Vec if no context has been written.

Source

pub fn read_into(&self, buf: &mut [u8]) -> usize

Read context into a provided buffer.

Returns the number of bytes actually read.

Source

pub fn write(&mut self, data: &[u8]) -> bool

Write new context bytes, replacing any existing content.

Returns true on success, false on error.

Source

pub fn clear(&mut self)

Clear the context.

Source

pub fn get_secret_len(&self, key: &[u8]) -> Option<usize>

Get the length of a secret without retrieving its value.

Returns None if the secret does not exist.

Source

pub fn get_secret(&self, key: &[u8]) -> Option<Vec<u8>>

Get a secret by key.

Returns None if the secret does not exist.

Source

pub fn set_secret(&mut self, key: &[u8], value: &[u8]) -> bool

Store a secret.

Returns true on success, false on error.

Source

pub fn has_secret(&self, key: &[u8]) -> bool

Check if a secret exists.

Source

pub fn remove_secret(&mut self, key: &[u8]) -> bool

Remove a secret.

Returns true if the secret was removed, false if it didn’t exist.

Source

pub fn get_contract_state(&self, instance_id: &[u8; 32]) -> Option<Vec<u8>>

Get contract state by instance ID.

Returns Some(state_bytes) if the contract exists locally, None if not found or on error.

Uses a two-step protocol: first queries the state length, then reads the state bytes into an allocated buffer.

Source

pub fn put_contract_state( &mut self, instance_id: &[u8; 32], state: &[u8], ) -> bool

Store (PUT) contract state by instance ID.

The contract’s code must already be registered in the runtime’s contract store. Returns true on success, false on error.

Source

pub fn update_contract_state( &mut self, instance_id: &[u8; 32], state: &[u8], ) -> bool

Update contract state by instance ID.

Like put_contract_state, but only succeeds if the contract already has stored state. This performs a full state replacement (not a delta-based update through the contract’s update_state logic). Returns true on success, false if no prior state exists or on other errors.

Source

pub fn subscribe_contract(&mut self, instance_id: &[u8; 32]) -> bool

Subscribe to contract updates by instance ID.

Registers interest in receiving notifications when the contract’s state changes. Currently validates that the contract is known and returns success; actual notification delivery is a follow-up.

Returns true on success, false if the contract is unknown or on error.

Trait Implementations§

Source§

impl Debug for DelegateCtx

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for DelegateCtx

Source§

fn default() -> DelegateCtx

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = Infallible

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more