From 71a5ec6ff5177f7caf059522c411fb40b8e5fc23 Mon Sep 17 00:00:00 2001 From: Yoshihiro Kawamoto Date: Fri, 13 Dec 2024 23:50:40 +0900 Subject: [PATCH] Fix issue #1406: Update lib.rs to see the expected output when deploying the Increment contract --- .../contracts/increment/src/lib.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 soroban-hello-world/contracts/increment/src/lib.rs diff --git a/soroban-hello-world/contracts/increment/src/lib.rs b/soroban-hello-world/contracts/increment/src/lib.rs new file mode 100644 index 000000000..69fae0a09 --- /dev/null +++ b/soroban-hello-world/contracts/increment/src/lib.rs @@ -0,0 +1,31 @@ +#![no_std] +// use soroban_sdk::{contract, contractimpl, vec, Env, String, Vec}; +use soroban_sdk::{contract, contractimpl, log, symbol_short, Env, Symbol}; + +// const COUNTER: Symbol = Symbol::new("counter"); +const COUNTER: Symbol = symbol_short!("COUNTER"); + +#[contract] +pub struct Contract; + +#[contractimpl] +impl Contract { + // pub fn hello(env: Env, to: String) -> Vec { + // vec![&env, String::from_str(&env, "Hello"), to] + + pub fn increment(env: Env) -> u32 { + let mut count: u32 = env.storage().instance().get(&COUNTER).unwrap_or(0); + + count += 1; + + log!(&env, "count: {}", count); + + env.storage().instance().set(&COUNTER, &count); + + env.storage().instance().extend_ttl(100, 100); + + count + } +} + +mod test;