#![no_std] use soroban_sdk::{contract, contractimpl, contracttype, symbol_short, Env, Symbol}; #[contracttype] #[derive(Clone, Debug, Eq, PartialEq)] pub struct State { pub count: u32, pub last_incr: u32, } const STATE: Symbol = symbol_short!("STATE"); #[contract] pub struct IncrementContract; #[contractimpl] impl IncrementContract { /// Increment increments an internal counter, and returns the value. pub fn increment(env: Env, incr: u32) -> u32 { // Get the current count. let mut state = Self::get_state(env.clone()); // Increment the count. state.count += incr; state.last_incr = incr; // Save the count. env.storage().instance().set(&STATE, &state); // Return the count to the caller. state.count } /// Return the current state. pub fn get_state(env: Env) -> State { env.storage().instance().get(&STATE).unwrap_or(State { count: 0, last_incr: 0, }) // If no value set, assume 0. } } mod test;