Skip to content

Commit 707fbc8

Browse files
authored
Merge branch 'master' into addcall
2 parents 0cb51fe + 5c5d17d commit 707fbc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2618
-972
lines changed

.travis.yml

Lines changed: 12 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust:
77
# - stable
88
# - beta
99
- nightly
10-
- nightly-2019-07-19
10+
- nightly-2019-08-13
1111

1212
matrix:
1313
allow_failures:
@@ -35,6 +35,7 @@ install:
3535
# Print rustc and cargo versions
3636
- rustc -vV
3737
- cargo -vV
38+
- bash --version
3839
# Install cargo-kcov Cargo plugin
3940
- cargo install --force cargo-kcov
4041
- cargo kcov -vV
@@ -61,91 +62,21 @@ before_script:
6162

6263
script:
6364
- |
64-
cargo check --verbose --all --all-features
65-
check_all_features=$?
65+
./scripts/check-workspace.sh
66+
check_workspace=$?
6667
67-
cargo check --verbose --all --no-default-features
68-
check_no_default=$?
69-
70-
cargo fmt --verbose --all -- --check
71-
fmt=$?
72-
73-
cargo clippy --verbose --all --all-features -- -D warnings
74-
clippy_all_features=$?
75-
76-
cargo clippy --verbose --all --no-default-features -- -D warnings
77-
clippy_no_default=$?
78-
79-
cargo test --verbose --all --all-features
80-
test=$?
81-
82-
cargo kcov --verbose --coveralls --all --no-clean-rebuild
83-
kcov=$?
84-
bash <(curl -s https://codecov.io/bash)
85-
86-
cargo build --verbose --all --no-default-features --release --target=wasm32-unknown-unknown
87-
build_wasm=$?
88-
89-
echo "CI Summary"
90-
echo "=========="
91-
echo ""
92-
if [ $check_all_features -eq 0 ]
93-
then
94-
echo "compile (all-features): ok"
95-
else
96-
echo "compile (all-features): ERROR"
97-
fi
98-
99-
if [ $check_no_default -eq 0 ]
68+
if [ $check_workspace -eq 0 ]
10069
then
101-
echo "compile (no-default-features): ok"
102-
else
103-
echo "compile (no-default-features): ERROR"
70+
# Execute and upload kcov results
71+
cargo kcov --verbose --coveralls --all --no-clean-rebuild
72+
kcov=$?
73+
bash <(curl -s https://codecov.io/bash)
10474
fi
10575
106-
if [ $fmt -eq 0 ]
107-
then
108-
echo "formatting: ok"
109-
else
110-
echo "formatting: ERROR"
111-
fi
112-
113-
if [ $clippy_all_features -eq 0 ]
114-
then
115-
echo "clippy (all-features): ok"
116-
else
117-
echo "clippy (all-features): ERROR"
118-
fi
119-
120-
if [ $clippy_no_default -eq 0 ]
121-
then
122-
echo "clippy (no-default-features): ok"
123-
else
124-
echo "clippy (no-default-features): ERROR"
125-
fi
126-
127-
if [ $test -eq 0 ]
128-
then
129-
echo "test (all-features): ok"
130-
else
131-
echo "test (all-features): ERROR"
132-
fi
133-
134-
if [ $build_wasm -eq 0 ]
135-
then
136-
echo "build Wasm: ok"
137-
else
138-
echo "build Wasm: ERROR"
139-
fi
140-
141-
if [ $kcov -eq 0 ]
142-
then
143-
echo "coverage analysis: ok"
144-
else
145-
echo "coverage analysis: ERROR"
146-
fi
76+
./scripts/check-examples.sh
77+
check_examples=$?
14778
148-
if [ $check_all_features -eq 0 ] && [ $check_no_default -eq 0 ] && [ $fmt -eq 0 ] && [ $clippy_all_features -eq 0 ] && [ $clippy_no_default -eq 0 ] && [ $test -eq 0 ] && [ $build_wasm -eq 0 ]
79+
if [ $check_examples -eq 0 ] && [ $check_workspace -eq 0 ]
14980
then
15081
echo "All checks have passed!"
15182
exit 0

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ members = [
66
"model",
77
"lang",
88
"cli",
9+
"abi",
910
]
1011
exclude = [
1112
"examples/",
13+
"cli/template/",
1214
]
1315

1416
[profile.release]

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ink! - Parity's ink to write smart contracts
22

3-
| Linux | Codecov | Coveralls | LoC | Docs (Core) | Docs (Model) |
4-
|:------------------:|:--------------------:|:----------------------:|:----------------:|:-----------------:|:-----------------:|
5-
| [![linux][A1]][A2] | [![codecov][C1]][C2] | [![coveralls][D1]][D2] | [![loc][E1]][E2] | [![docs][F1]][F2] | [![docs][G1]][G2] |
3+
| Linux | Codecov | Coveralls | LoC |
4+
|:------------------:|:--------------------:|:----------------------:|:----------------:|
5+
| [![linux][A1]][A2] | [![codecov][C1]][C2] | [![coveralls][D1]][D2] | [![loc][E1]][E2] |
66

77
[A1]: https://travis-ci.org/paritytech/ink.svg?branch=master
88
[A2]: https://travis-ci.org/paritytech/ink
@@ -16,26 +16,44 @@
1616
[E1]: https://tokei.rs/b1/github/paritytech/ink?category=code
1717
[E2]: https://github.com/Aaronepower/tokei#badges
1818

19-
[F1]: https://img.shields.io/badge/docs-nightly-black.svg
20-
[F2]: https://paritytech.github.io/ink/ink_core/index.html
19+
[F1]: https://img.shields.io/badge/docs-core-blue.svg
20+
[F2]: https://paritytech.github.io/ink/ink_core
2121

22-
[G1]: https://img.shields.io/badge/docs-nightly-purple.svg
23-
[G2]: https://paritytech.github.io/ink/ink_model/index.html
22+
[G1]: https://img.shields.io/badge/docs-model-blue.svg
23+
[G2]: https://paritytech.github.io/ink/ink_model
24+
25+
[H1]: https://img.shields.io/badge/docs-abi-blue.svg
26+
[H2]: https://paritytech.github.io/ink/ink_abi
2427

2528
**IMPORTANT NOTE:** WORK IN PROGRESS! Do not expect this to be working.
2629

27-
ink is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to write WebAssembly based smart contracts using the Rust programming language.
30+
ink! is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to write WebAssembly based smart contracts using the Rust programming language targeting Substrate blockchains.
31+
32+
## Developer Documentation
33+
34+
| `ink_abi` | `ink_core` | `ink_model` |
35+
|-----------|------------|-------------|
36+
| [![][H1]][H2] | [![][F1]][F2] | [![][G1]][G2] |
37+
38+
### Scripts
39+
40+
Use the scripts provided under `scripts` directory in order to run checks on either the workspace or all examples. Please do this before pushing work in a PR.
41+
42+
### Testing
43+
44+
Off-chain testing is done by `cargo test`.
45+
If you want to test all workspace crates, do `cargo test --all`.
2846

2947
## Example
3048

31-
Below is an example using the eDSL demonstrating a simple Flipper smart contract
49+
Below is an example using ink! demonstrating a simple Flipper smart contract
3250
that has a boolean state that can be flipped or returned.
3351

3452
```rust
3553
contract! {
3654
/// Specify concrete implementation of contract environment types
3755
#![env = ink_core::env::DefaultSrmlTypes]
38-
56+
3957
/// Flips its state between `true` and `false`.
4058
struct Flipper {
4159
/// The current state of our flag.

abi/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "ink_abi"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
7+
license = "GPL-3.0"
8+
readme = "README.md"
9+
10+
description = "Rust based eDSL for writing smart contracts for Substrate"
11+
keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"]
12+
categories = ["no-std", "embedded"]
13+
14+
include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]
15+
16+
[dependencies]
17+
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
18+
derive_more = { version = "0.14", features = ["no_std"] }
19+
ink_abi_derive = { version = "0.1.0", path = "derive", default-features = false, optional = true }
20+
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"] }
21+
22+
[features]
23+
default = [
24+
"std",
25+
"derive",
26+
]
27+
derive = [
28+
"ink_abi_derive"
29+
]
30+
std = [
31+
"ink_abi_derive/std",
32+
"serde/std",
33+
"type-metadata/std",
34+
]

abi/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

abi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

abi/derive/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "ink_abi_derive"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
7+
license = "Apache-2.0"
8+
readme = "../README.md"
9+
10+
[lib]
11+
proc-macro = true
12+
13+
[dependencies]
14+
quote = "0.6"
15+
syn = { version = "0.15", features = ["full"] }
16+
proc-macro2 = "0.4"
17+
18+
[features]
19+
default = ["std"]
20+
std = []

abi/derive/src/error.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
2+
// This file is part of ink!.
3+
//
4+
// ink! is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// ink! is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
16+
17+
macro_rules! bail {
18+
($($args:tt)*) => {
19+
return Err(format_err!($($args)*).into())
20+
}
21+
}
22+
23+
macro_rules! format_err {
24+
($tokens:expr, $($msg:tt)*) => {
25+
match &$tokens {
26+
t => {
27+
syn::parse::Error::new_spanned(t, format_args!($($msg)*))
28+
}
29+
}
30+
}
31+
}

abi/derive/src/has_layout.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
2+
// This file is part of ink!.
3+
//
4+
// ink! is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// ink! is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
16+
17+
use crate::impl_wrapper::wrap;
18+
use proc_macro2::TokenStream as TokenStream2;
19+
use quote::quote;
20+
use syn::{
21+
self,
22+
parse::Result,
23+
parse_quote,
24+
punctuated::Punctuated,
25+
Data,
26+
DataStruct,
27+
DeriveInput,
28+
Field,
29+
Fields,
30+
Token,
31+
};
32+
33+
pub fn generate(input: TokenStream2) -> TokenStream2 {
34+
match generate_impl(input.into()) {
35+
Ok(output) => output.into(),
36+
Err(err) => err.to_compile_error().into(),
37+
}
38+
}
39+
40+
pub fn generate_impl(input: TokenStream2) -> Result<TokenStream2> {
41+
let mut ast: DeriveInput = syn::parse2(input)?;
42+
43+
ast.generics.type_params_mut().for_each(|p| {
44+
p.bounds.push(parse_quote!(_ink_abi::HasLayout));
45+
});
46+
47+
let ident = &ast.ident;
48+
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
49+
50+
let layout = match &ast.data {
51+
Data::Struct(ref s) => generate_struct_layout(s),
52+
Data::Enum(ref _e) => bail!(&ast, "enums are not supported"),
53+
Data::Union(ref _u) => bail!(&ast, "unions are not supported"),
54+
};
55+
56+
let has_layout_impl = quote! {
57+
impl #impl_generics _ink_abi::HasLayout for #ident #ty_generics #where_clause {
58+
fn layout(&self) -> _ink_abi::StorageLayout {
59+
#layout.into()
60+
}
61+
}
62+
};
63+
64+
Ok(wrap(ident, "HAS_LAYOUT", has_layout_impl).into())
65+
}
66+
67+
fn generate_fields_layout<'a>(
68+
fields: &'a Punctuated<Field, Token![,]>,
69+
) -> impl Iterator<Item = TokenStream2> + 'a {
70+
fields.iter().enumerate().map(|(n, field)| {
71+
let ident = &field.ident;
72+
if let Some(ident) = ident {
73+
quote! {
74+
_ink_abi::LayoutField::new(stringify!(#ident), self.#ident.layout())
75+
}
76+
} else {
77+
quote! {
78+
_ink_abi::LayoutField::new(stringify!(#n), self.#n.layout())
79+
}
80+
}
81+
})
82+
}
83+
84+
fn generate_struct_fields_layout(fields: &Punctuated<Field, Token![,]>) -> TokenStream2 {
85+
let fields_layout = generate_fields_layout(fields);
86+
quote! {
87+
use type_metadata::Metadata as _;
88+
_ink_abi::LayoutStruct::new(Self::meta_type(), __core::vec![
89+
#( #fields_layout, )*
90+
])
91+
}
92+
}
93+
94+
fn generate_struct_layout(data_struct: &DataStruct) -> TokenStream2 {
95+
match data_struct.fields {
96+
Fields::Named(ref fs) => generate_struct_fields_layout(&fs.named),
97+
Fields::Unnamed(ref fs) => generate_struct_fields_layout(&fs.unnamed),
98+
Fields::Unit => {
99+
quote! {
100+
use type_metadata::Metadata as _;
101+
_ink_abi::LayoutStruct::new(Self::meta_type(), __core::vec![])
102+
}
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)