Skip to content

Commit

Permalink
lazy example
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianStraszak committed Jun 15, 2023
1 parent 66c46a0 commit e1111a3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ink/lazytest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
27 changes: 27 additions & 0 deletions ink/lazytest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "lazytest"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink = { version = "4.2", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = "4.2"

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
e2e-tests = []
51 changes: 51 additions & 0 deletions ink/lazytest/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[ink::contract]
mod lazytest {
use ink::storage::{Lazy, traits::ManualKey};

/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[derive(Default)]
#[ink(storage)]
pub struct Lazytest {
/// Stores a single `bool` value on the storage.
value1: Lazy<u32>,
value2: Lazy<u32, ManualKey<123>>,
}

impl Lazytest {
/// Constructor that initializes the `bool` value to the given `init_value`.
#[ink(constructor)]
pub fn new() -> Self {
Lazytest::default()
}


/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
#[ink(message)]
pub fn set_1(&mut self, a: u32) {
self.value1.set(&a);
}

/// Simply returns the current value of our `bool`.
#[ink(message)]
pub fn get_1(&self) -> Option<u32> {
self.value1.get()
}

#[ink(message)]
pub fn set_2(&mut self, a: u32) {
self.value2.set(&a);
}

/// Simply returns the current value of our `bool`.
#[ink(message)]
pub fn get_2(&self) -> Option<u32> {
self.value2.get()
}
}
}
2 changes: 1 addition & 1 deletion ink/reentrancy-corrupt/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub mod my_flipper_guard {
#[ink(storage)]
#[derive(Default, Storage)]
pub struct MyFlipper {
value: u32,
#[storage_field]
guard: reentrancy_guard::Data,
value: u32,
}

impl MyFlipper {
Expand Down

0 comments on commit e1111a3

Please sign in to comment.