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