lib.rs 1.44 KB
Newer Older
Ricardo Rius's avatar
Ricardo Rius committed
1
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
2
//
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9 10 11 12 13
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
14 15 16

#![cfg_attr(not(feature = "std"), no_std)]

17
use ink_lang as ink;
18 19 20

#[ink::contract(version = "0.1.0")]
mod adder {
21 22 23 24
    #[cfg(not(feature = "ink-as-dependency"))]
    use ink_core::storage;
    use accumulator::Accumulator;

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    /// Increments the underlying accumulator's value.
    #[ink(storage)]
    struct Adder {
        /// The accumulator to store the value.
        accumulator: storage::Value<accumulator::Accumulator>,
    }

    impl Adder {
        /// Creates a new adder from the given accumulator.
        #[ink(constructor)]
        fn new(&mut self, accumulator: Accumulator) {
            self.accumulator.set(accumulator)
        }

        /// Increases the accumulator's value by some amount.
        #[ink(message)]
        fn inc(&mut self, by: i32) {
            self.accumulator.inc(by)
        }
    }
}

pub use crate::adder::Adder;