Skip to main content

Module backend

Module backend 

Source
Expand description

Storage backend abstraction for contract state persistence.

This module provides a trait-based abstraction over storage operations, enabling both production (on-chain) and testing (in-memory) backends.

§Storage Backends

  • HostStorage: Production backend that delegates to WASM host imports. Used when contracts run on-chain.
  • MemoryStorage: In-memory backend using BTreeMap for testing. Enables fast, isolated unit tests without WASM runtime.

§Example

use truthlinked_sdk::backend::{StorageBackend, MemoryStorage};

// Testing with in-memory storage
let mut storage = MemoryStorage::new();
let slot = [1u8; 32];
storage.write_32(slot, [42u8; 32])?;
let value = storage.read_32(&slot)?;
assert_eq!(value[0], 42);

Structs§

HostStorage
Storage backend that delegates to WASM host imports.
MemoryStorage
In-memory storage backend for testing and development.

Traits§

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