Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend {
    // Required methods
    fn read_32(&self, key: &[u8; 32]) -> Result<[u8; 32]>;
    fn write_32(&mut self, key: [u8; 32], value: [u8; 32]) -> Result<()>;
}
Expand description

Trait for storage backends that support 32-byte slot read/write operations.

All storage in TruthLinked contracts operates on fixed 32-byte slots. This trait abstracts the underlying storage mechanism, allowing contracts to work with both on-chain storage (via WASM host) and in-memory storage (for testing).

Required Methods§

Source

fn read_32(&self, key: &[u8; 32]) -> Result<[u8; 32]>

Reads a 32-byte value from the specified storage slot.

§Arguments
  • key - The 32-byte storage slot address
§Returns

The 32-byte value stored at the slot, or [0u8; 32] if uninitialized.

Source

fn write_32(&mut self, key: [u8; 32], value: [u8; 32]) -> Result<()>

Writes a 32-byte value to the specified storage slot.

§Arguments
  • key - The 32-byte storage slot address
  • value - The 32-byte value to store

Implementors§