This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* working util contract which can be shared between contracts * rename shared contract to "util" * add util to captcha contract * move err macros * refactor util contract to be named "util" * rlib captcha contract to mirror other contracts (don't believe it's needed, but hey) * pin to sr25519_verify ink pr * move lazy macro * rename util to common * try error in common * silence warning in proxy unused import for ink StorageLayout * mod_name() macro, move err macro / func * working * add module name into named functions macro * fmt * rename contract from Util to Common * rename ctor and func in common to avoid clippy warnings * move unit test account functions to common * move util testing functions to common * fix get_contract_account() method in testing * fmt * move get_contract() to common, add reset_caller() and reset_callee() * add common_dev to delineate common testing code from common contract code. Ink cannot handle the two together in one crate * skip common_dev contract when building (does not compile due to being dev/testing module) * fix skipping common_dev contract build in cli
- Loading branch information
Showing
13 changed files
with
518 additions
and
478 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,32 @@ | ||
[package] | ||
name = "common" | ||
version = "0.3.0" | ||
authors = ["Chris Taylor [email protected]", "George Oastler [email protected]", "Vincenzo Ferrara", "Siniša Čanak"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink = { git = "https://github.com/prosopo/ink", rev="9ca19c462d5f5d1572ddce595d2698207241fd4a", 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 } | ||
|
||
[lib] | ||
name = "common" | ||
path = "src/lib.rs" | ||
crate-type = [ | ||
# Used for normal contract Wasm blobs. | ||
"cdylib", | ||
"rlib", | ||
] | ||
|
||
# Needed until https://github.com/paritytech/ink/issues/364 is resolved. | ||
[profile.release] | ||
overflow-checks = false | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"scale/std", | ||
"scale-info/std", | ||
] | ||
ink-as-dependency = [] |
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 @@ | ||
This is a common library for contracts. This is the non-testing contract version which should be imported using dependency, not dev-dependency. All non-testing contract related common contract code should go in this library. Unfortunately, ink does not expose tests from dev-dependencies _and_ build a contract properly, so we are forced to put them in a separate crates: one for testing (common-dev) and one for building contracts (common). |
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,54 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
/// Print and return an error in ink | ||
#[macro_export] | ||
macro_rules! err { | ||
($e:expr) => {{ | ||
let self_ = get_self!(); | ||
ink::env::debug_println!( | ||
"'{:?}' error in {:?}() at block {:?} with caller {:?}", | ||
$e, | ||
function_name!(), | ||
self_.env().block_number(), | ||
self_.env().caller(), | ||
); | ||
Err($e) | ||
}}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! err_fn { | ||
($err:expr) => { | ||
|| get_self!().print_err($err, function_name!()) | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! lazy { | ||
($lazy:expr, $func:ident, $value:expr) => { | ||
let mut contents = $lazy.get_or_default(); | ||
contents.$func($value); | ||
$lazy.set(&contents); | ||
}; | ||
} | ||
|
||
/// An ink contract must be defined in order to import functions into another contract | ||
#[ink::contract] | ||
pub mod common { | ||
|
||
/// No fields are stored in the util contract as it's just filler | ||
#[ink(storage)] | ||
pub struct Common {} | ||
|
||
/// Implementation of the contract | ||
impl Common { | ||
#[ink(constructor)] | ||
pub fn noop_ctor() -> Self { | ||
Self {} | ||
} | ||
|
||
/// No-op function to fill the mandatory ink message requirement | ||
#[ink(message)] | ||
pub fn noop_func(&self) {} | ||
} | ||
} |
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,32 @@ | ||
[package] | ||
name = "common_dev" | ||
version = "0.3.0" | ||
authors = ["Chris Taylor [email protected]", "George Oastler [email protected]", "Vincenzo Ferrara", "Siniša Čanak"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink = { git = "https://github.com/prosopo/ink", rev="9ca19c462d5f5d1572ddce595d2698207241fd4a", 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 } | ||
|
||
[lib] | ||
name = "common_dev" | ||
path = "src/lib.rs" | ||
crate-type = [ | ||
# Used for normal contract Wasm blobs. | ||
"cdylib", | ||
"rlib", | ||
] | ||
|
||
# Needed until https://github.com/paritytech/ink/issues/364 is resolved. | ||
[profile.release] | ||
overflow-checks = false | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"scale/std", | ||
"scale-info/std", | ||
] | ||
ink-as-dependency = [] |
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 @@ | ||
This is a common library for contracts. This is the dev version which should be imported using dev-dependency. All test related common contract code should go in this library. Unfortunately, ink does not expose tests from dev-dependencies _and_ build a contract properly, so we are forced to put them in a separate crates: one for testing (common-dev) and one for building contracts (common). |
Oops, something went wrong.