ab_example_contract_flipper/
lib.rs1#![no_std]
2
3use ab_contracts_macros::contract;
4use ab_io_type::bool::Bool;
5use ab_io_type::trivial_type::TrivialType;
6
7#[derive(Debug, Copy, Clone, TrivialType)]
8#[repr(C)]
9pub struct Flipper {
10 pub value: Bool,
11}
12
13#[contract]
14impl Flipper {
15 #[init]
16 pub fn new(#[input] &init_value: &Bool) -> Self {
17 Self { value: init_value }
18 }
19
20 #[update]
21 pub fn flip(&mut self) {
22 self.value = !self.value;
23 }
24
25 #[view]
26 pub fn value(&self) -> Bool {
27 self.value
28 }
29}