#[starknet::interface]
trait IMappings<TContractState> {
fn set_value(ref self: TContractState, key: u32, value: u128);
fn get_value(self: @TContractState, key: u32) -> u128;
}
#[starknet::contract]
mod Mappings {
use starknet::storage::{StorageMapReadAccess, StorageMapWriteAccess};
#[storage]
struct Storage {
// Simple mapping from u32 to u128
values: Map<u32, u128>,
}
#[abi(embed_v0)]
impl Mappings of super::IMappings<ContractState> {
fn set_value(ref self: ContractState, key: u32, value: u128) {
// Write a value to the map
self.values.write(key, value);
}
fn get_value(self: @ContractState, key: u32) -> u128 {
// Read a value from the map
self.values.read(key)
}
}
}