-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathlib.rs
34 lines (26 loc) · 1.16 KB
/
lib.rs
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
26
27
28
29
30
31
32
33
34
#![no_std]
use soroban_sdk::{contract, contractimpl, log, symbol_short, Env, Symbol};
const COUNTER: Symbol = symbol_short!("COUNTER");
#[contract]
pub struct IncrementContract;
#[contractimpl]
impl IncrementContract {
/// Increment increments an internal counter, and returns the value.
pub fn increment(env: Env) -> u32 {
// Get the current count.
let mut count: u32 = env.storage().instance().get(&COUNTER).unwrap_or(0); // If no value set, assume 0.
log!(&env, "count: {}", count);
// Increment the count.
count += 1;
// Save the count.
env.storage().instance().set(&COUNTER, &count);
// The contract instance will be bumped to have a lifetime of at least 100 ledgers if the current expiration lifetime at most 50.
// If the lifetime is already more than 100 ledgers, this is a no-op. Otherwise,
// the lifetime is extended to 100 ledgers. This lifetime bump includes the contract
// instance itself and all entries in storage().instance(), i.e, COUNTER.
env.storage().instance().extend_ttl(50, 100);
// Return the count to the caller.
count
}
}
mod test;