Skip to content

Commit

Permalink
add unsafe transient functions to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacolvin0 committed Dec 8, 2023
1 parent 298c531 commit c5b120f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions stylus-sdk/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ pub unsafe fn store_bytes32(key: U256, data: B256) {
unsafe { hostio::storage_store_bytes32(B256::from(key).as_ptr(), data.as_ptr()) };
}

/// Retrieves a 32-byte EVM word from transient storage directly, bypassing all caches.
///
/// # Safety
///
/// May alias storage.
pub unsafe fn transient_load_bytes32(key: U256) -> B256 {
let mut data = B256::ZERO;
unsafe { hostio::storage_transient_load_bytes32(B256::from(key).as_ptr(), data.as_mut_ptr()) };
data
}

/// Stores a 32-byte EVM word to transient storage directly, bypassing all caches.
///
/// # Safety
///
/// May alias storage.
pub unsafe fn transient_store_bytes32(key: U256, data: B256) {
unsafe { hostio::storage_transient_store_bytes32(B256::from(key).as_ptr(), data.as_ptr()) };
}

/// Overwrites the value in a cell.
#[inline]
fn overwrite_cell<T>(cell: &mut OnceCell<T>, value: T) {
Expand Down

0 comments on commit c5b120f

Please sign in to comment.