/
githubmirror
/
sway
Обзор
Документация
Войти
/
githubmirror
/
sway
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/storage_example/src/main.sw
26 строк
580 B
Mohammad Fawaz
Replace old storage API with the new one explained in the `StorageKey` RFC (#4464)
21 апр 2023, 14:36
Не верифицирован
21 апр 2023, 14:36
1db8385
Код
Авторство
О чём код?
contract; use std::storage::storage_api::{read, write}; abi StorageExample { #[storage(write)] fn store_something(amount: u64); #[storage(read)] fn get_something() -> u64; } const STORAGE_KEY: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000; impl StorageExample for Contract { #[storage(write)] fn store_something(amount: u64) { write(STORAGE_KEY, 0, amount); } #[storage(read)] fn get_something() -> u64 { let value: Option<u64> = read::<u64>(STORAGE_KEY, 0); value.unwrap_or(0) } }