1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Storage extensions for pwasm-ethereum.
//! Storage api is a key-value storage where both key and value are 32 bytes in len

use hash::H256;

extern "C" {
	fn storage_read(key: *const u8, dst: *mut u8);
	fn storage_write(key: *const u8, src: *const u8);
}

/// Performs read from the storage.
pub fn read(key: &H256) -> [u8; 32] {
	let mut dst = [0u8; 32];
	unsafe {
		storage_read(key.as_ptr(), dst.as_mut_ptr());
	}
	dst
}

/// Performs write to the storage
pub fn write(key: &H256, val: &[u8; 32]) {
	unsafe {
		storage_write(key.as_ptr(), val.as_ptr());
	}
}