-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Supercolony-net/bugfix/new-ink-and-target
Fixed bug with target folder and latest changes from ink
- Loading branch information
Showing
16 changed files
with
208 additions
and
176 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[package] | ||
name = "flipper" | ||
version = "1.4.0" | ||
authors = ["Supercolony <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink_primitives = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false } | ||
ink_metadata = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false, features = ["derive"], optional = true } | ||
ink_env = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false } | ||
ink_storage = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false } | ||
ink_lang = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false } | ||
ink_prelude = { branch = "master", git = "https://github.com/paritytech/ink", default-features = false } | ||
|
||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } | ||
|
||
# These dependencies | ||
brush = { path = "../..", default-features = false, features = ["reentrancy_guard"] } | ||
|
||
[lib] | ||
name = "flipper" | ||
path = "lib.rs" | ||
|
||
crate-type = [ | ||
"rlib", | ||
] | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink_primitives/std", | ||
"ink_metadata", | ||
"ink_metadata/std", | ||
"ink_env/std", | ||
"ink_storage/std", | ||
"ink_lang/std", | ||
"scale/std", | ||
"scale-info", | ||
"scale-info/std", | ||
|
||
# These dependencies | ||
"brush/std", | ||
] | ||
|
||
ink-as-dependency = [] | ||
|
||
[profile.dev] | ||
codegen-units = 16 | ||
overflow-checks = false | ||
|
||
[profile.release] | ||
overflow-checks = false |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[brush::contract] | ||
pub mod flip_on_me { | ||
use flipper::traits::flip_on_me::*; | ||
use ink_storage::traits::SpreadAllocate; | ||
|
||
#[ink(storage)] | ||
#[derive(Default, SpreadAllocate)] | ||
pub struct FlipOnMeContract {} | ||
|
||
impl FlipOnMeContract { | ||
#[ink(constructor)] | ||
pub fn new() -> Self { | ||
ink_lang::codegen::initialize_contract(|_instance: &mut Self| {}) | ||
} | ||
} | ||
|
||
impl FlipOnMe for FlipOnMeContract {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[brush::contract] | ||
pub mod my_flipper_guard { | ||
use flipper::traits::flipper::*; | ||
use ink_storage::traits::SpreadAllocate; | ||
|
||
#[ink(storage)] | ||
#[derive(Default, SpreadAllocate, ReentrancyGuardStorage)] | ||
pub struct MyFlipper { | ||
#[ReentrancyGuardStorageField] | ||
guard: ReentrancyGuardData, | ||
value: bool, | ||
} | ||
|
||
impl FlipperStorage for MyFlipper { | ||
fn value(&self) -> &bool { | ||
&self.value | ||
} | ||
|
||
fn value_mut(&mut self) -> &mut bool { | ||
&mut self.value | ||
} | ||
} | ||
|
||
impl MyFlipper { | ||
#[ink(constructor)] | ||
pub fn new() -> Self { | ||
ink_lang::codegen::initialize_contract(|_instance: &mut Self| {}) | ||
} | ||
} | ||
|
||
impl Flipper for MyFlipper {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub mod traits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pub use brush::contracts::reentrancy_guard::*; | ||
use brush::traits::{ | ||
AccountId, | ||
InkStorage, | ||
}; | ||
|
||
#[brush::wrapper] | ||
pub type FlipOnMeRef = dyn FlipOnMe; | ||
|
||
#[brush::trait_definition] | ||
pub trait FlipOnMe: InkStorage { | ||
#[ink(message)] | ||
fn flip_on_me(&mut self) -> Result<(), ReentrancyGuardError> { | ||
let caller = Self::env().caller(); | ||
self.flip_on_target(caller) | ||
} | ||
|
||
#[ink(message)] | ||
fn flip_on_target(&mut self, callee: AccountId) -> Result<(), ReentrancyGuardError> { | ||
// This method does a cross-contract call to caller contract and calls the `flip` method. | ||
crate::traits::flipper::FlipperRef::flip(&callee) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pub use brush::contracts::reentrancy_guard::*; | ||
use brush::{ | ||
modifiers, | ||
traits::AccountId, | ||
}; | ||
|
||
pub trait FlipperStorage { | ||
fn value(&self) -> &bool; | ||
fn value_mut(&mut self) -> &mut bool; | ||
} | ||
|
||
#[brush::wrapper] | ||
pub type FlipperRef = dyn Flipper; | ||
|
||
#[brush::trait_definition] | ||
pub trait Flipper: FlipperStorage + ReentrancyGuardStorage { | ||
#[ink(message)] | ||
fn get_value(&self) -> bool { | ||
self.value().clone() | ||
} | ||
|
||
#[ink(message)] | ||
#[brush::modifiers(non_reentrant)] | ||
fn flip(&mut self) -> Result<(), ReentrancyGuardError> { | ||
*self.value_mut() = !self.value().clone(); | ||
Ok(()) | ||
} | ||
|
||
#[ink(message)] | ||
#[modifiers(non_reentrant)] | ||
fn call_flip_on_me(&mut self, callee: AccountId) -> Result<(), ReentrancyGuardError> { | ||
// This method will do a cross-contract call to callee account. It calls method `flip_on_me`. | ||
// Callee contract during execution of `flip_on_me` will call `flip` of this contract. | ||
// `call_flip_on_me` and `flip` are marked with `non_reentrant` modifier. It means, | ||
// that call of `flip` after `call_flip_on_me` must fail. | ||
crate::traits::flip_on_me::FlipOnMeRef::flip_on_me(&callee) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod flip_on_me; | ||
pub mod flipper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.