accumulator/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3pub use self::accumulator::{
4    Accumulator,
5    AccumulatorRef,
6};
7
8use ink_lang as ink;
9
10#[ink::contract]
11pub mod accumulator {
12    /// Holds a simple `i32` value that can be incremented and decremented.
13    #[ink(storage)]
14    pub struct Accumulator {
15        value: i32,
16    }
17
18    impl Accumulator {
19        /// Initializes the value to the initial value.
20        #[ink(constructor)]
21        pub fn new(init_value: i32) -> Self {
22            Self { value: init_value }
23        }
24
25        /// Mutates the internal value.
26        #[ink(message)]
27        pub fn inc(&mut self, by: i32) {
28            self.value += by;
29        }
30
31        /// Returns the current state.
32        #[ink(message)]
33        pub fn get(&self) -> i32 {
34            self.value
35        }
36    }
37}