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
impl DelegateCtx
Sourcepub fn read(&self) -> Vec<u8> ⓘ
pub fn read(&self) -> Vec<u8> ⓘ
Read the current context bytes.
Returns an empty Vec if no context has been written.
Sourcepub fn read_into(&self, buf: &mut [u8]) -> usize
pub fn read_into(&self, buf: &mut [u8]) -> usize
Read context into a provided buffer.
Returns the number of bytes actually read.
Sourcepub fn write(&mut self, data: &[u8]) -> bool
pub fn write(&mut self, data: &[u8]) -> bool
Write new context bytes, replacing any existing content.
Returns true on success, false on error.
Sourcepub fn get_secret_len(&self, key: &[u8]) -> Option<usize>
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.
Sourcepub fn get_secret(&self, key: &[u8]) -> Option<Vec<u8>>
pub fn get_secret(&self, key: &[u8]) -> Option<Vec<u8>>
Get a secret by key.
Returns None if the secret does not exist.
Sourcepub fn set_secret(&mut self, key: &[u8], value: &[u8]) -> bool
pub fn set_secret(&mut self, key: &[u8], value: &[u8]) -> bool
Store a secret.
Returns true on success, false on error.
Sourcepub fn has_secret(&self, key: &[u8]) -> bool
pub fn has_secret(&self, key: &[u8]) -> bool
Check if a secret exists.
Sourcepub fn remove_secret(&mut self, key: &[u8]) -> bool
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.
Sourcepub fn get_contract_state(&self, instance_id: &[u8; 32]) -> Option<Vec<u8>>
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.
Sourcepub fn put_contract_state(
&mut self,
instance_id: &[u8; 32],
state: &[u8],
) -> bool
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.
Sourcepub fn update_contract_state(
&mut self,
instance_id: &[u8; 32],
state: &[u8],
) -> bool
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.
Sourcepub fn subscribe_contract(&mut self, instance_id: &[u8; 32]) -> bool
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.