Trait StateExt

Source
pub trait StateExt {
    // Required methods
    fn state_initialize(
        &mut self,
        method_context: MethodContext,
        contract: Address,
        contract_state: &Address,
        state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
    ) -> Result<(), ContractError>;
    fn state_write(
        &mut self,
        method_context: MethodContext,
        contract: Address,
        state: &Address,
        new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
    ) -> Result<(), ContractError>;
    fn state_compare_and_write(
        &mut self,
        method_context: MethodContext,
        contract: Address,
        state: &Address,
        old_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
        new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
    ) -> Result<bool, ContractError>;
    fn state_read(
        &self,
        contract: Address,
        contract_state: &Address,
        state: &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>,
    ) -> Result<(), ContractError>;
    fn state_is_empty(
        &self,
        contract: Address,
        contract_state: &Address,
    ) -> Result<bool, ContractError>;
}
Expand description

Extension trait that provides helper methods for calling State’s methods on Env for convenience purposes

Required Methods§

Source

fn state_initialize( &mut self, method_context: MethodContext, contract: Address, contract_state: &Address, state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Initialize state.

Similar to State::write(), but returns error if the state is not empty.

Source

fn state_write( &mut self, method_context: MethodContext, contract: Address, state: &Address, new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Write state.

Only direct caller is allowed to write its own state for security reasons.

Source

fn state_compare_and_write( &mut self, method_context: MethodContext, contract: Address, state: &Address, old_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<bool, ContractError>

Compare state with a given old state and write new state if old state matches.

Only direct caller is allowed to write its own state for security reasons.

Returns boolean indicating whether write happened or not.

Source

fn state_read( &self, contract: Address, contract_state: &Address, state: &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Read state

Source

fn state_is_empty( &self, contract: Address, contract_state: &Address, ) -> Result<bool, ContractError>

Check if the state is empty

Implementations on Foreign Types§

Source§

impl StateExt for Env<'_>

Source§

fn state_initialize( &mut self, method_context: MethodContext, contract: Address, contract_state: &Address, state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Source§

fn state_write( &mut self, method_context: MethodContext, contract: Address, state: &Address, new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Source§

fn state_compare_and_write( &mut self, method_context: MethodContext, contract: Address, state: &Address, old_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<bool, ContractError>

Source§

fn state_read( &self, contract: Address, contract_state: &Address, state: &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>

Source§

fn state_is_empty( &self, contract: Address, contract_state: &Address, ) -> Result<bool, ContractError>

Implementors§