Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into varg-delegate-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
VargSupercolony committed Feb 23, 2022
2 parents 5caf9a7 + 07a8ed9 commit 612de66
Show file tree
Hide file tree
Showing 65 changed files with 544 additions and 645 deletions.
53 changes: 52 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
# Version 3.0-rc9

This is the 9th release candidate for ink! 3.0.

## Breaking Changes
### We removed all data structures other than `Mapping` from the public ink! API

This is a drastic breaking change; it was no easy decision for us.
It affects `Lazy` and `Memory` as well. The rationale behind this change,
as well as some notes on migrating existing contracts, are explained
in [#1111](https://github.com/paritytech/ink/pull/1111) and
[#1137](https://github.com/paritytech/ink/pull/1137).

If you used `Memory` in your contract, you can achieve the same functionality
by passing this data via arguments. If you think there's a case to be
made for bringing it back, please get in contact with us.

If you use [`ink_storage::Mapping`](https://paritytech.github.io/ink/ink_storage/struct.Mapping.html)
in your contract, you need to initialize the data structure using the helper function
[`ink_lang::utils::initialize_contract(…)`](https://paritytech.github.io/ink/ink_lang/utils/fn.initialize_contract.html).
For more code examples you can take a look at our examples, e.g.
[`erc20`](https://github.com/paritytech/ink/blob/master/examples/erc20/lib.rs).

### Please upgrade `scale-info` and `parity-scale-codec` in your contract's dependencies

In this release candidate we upgraded `scale-info` and `parity-scale-codec`. You have to use a compatible
version in your contract's `Cargo.toml` as well; `cargo-contract` will throw an error otherwise.

The `Cargo.toml` should contain
```
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
```

## Added
- Export `ink_lang::utils::initialize_contract(…)` - [#1077](https://github.com/paritytech/ink/pull/1077).
- Add `get_owner()` function to `dns` example contract - [#1118](https://github.com/paritytech/ink/pull/1118) (thanks [@agryaznov](https://github.com/agryaznov)).
- Improved usage documentation of `ink_storage::Mapping` - [#1138](https://github.com/paritytech/ink/pull/1138).

## Changed
- Updated to `parity-scale-codec = "3"` and `scale-info = "2"` - [#1132](https://github.com/paritytech/ink/pull/1132).

## Removed
- Remove `collection` and `lazy` modules from public ink! API - [#1111](https://github.com/paritytech/ink/pull/1111).
- Remove `Memory` from public ink! API - [#1137](https://github.com/paritytech/ink/pull/1137).

## Fixed
- Fix bug with referencing two external trait definitions - [#1141](https://github.com/paritytech/ink/pull/1141).
- Explicitly specify trait in dispatching - [#1131](https://github.com/paritytech/ink/pull/1131) (thanks [@xgreenx](https://github.com/xgreenx)).
- Make `rust-analyzer` expand ink! macros without warning - [#1107](https://github.com/paritytech/ink/pull/1107).

# Version 3.0-rc8

This is the 8th release candidate for ink! 3.0.
Expand Down Expand Up @@ -44,7 +95,7 @@ The ink! PR which implemented this is [#1065](https://github.com/paritytech/ink/
metadata to V3 is [#1100](https://github.com/paritytech/ink/pull/1100), and for the `polkadot-js/api` it was [polkadot-js/api#4432](https://github.com/polkadot-js/api/pull/4432).

## Changed
- Update metadate to support payable constructors - [#1100](https://github.com/paritytech/ink/pull/1100).
- Update metadata to support payable constructors - [#1100](https://github.com/paritytech/ink/pull/1100).
- Make constructors non-payable by default, require specifying `payable` explicitly - [#1065](https://github.com/paritytech/ink/pull/1065).
- Renamed the error code `EcdsaRecoverFailed` to `EcdsaRecoveryFailed`[#1064](https://github.com/paritytech/ink/pull/1064).
- Renamed the `ink_env` function `transferred_balance()` to `transferred_value()`[#1063](https://github.com/paritytech/ink/pull/1063).
Expand Down
2 changes: 1 addition & 1 deletion crates/allocator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_allocator"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin@parity.io>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_engine"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Michael Müller <michi@parity.io>"]
edition = "2021"

Expand All @@ -15,7 +15,7 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[dependencies]
scale = { package = "parity-scale-codec", version = "2.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }

sha2 = { version = "0.10" }
Expand Down
19 changes: 8 additions & 11 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_env"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin@parity.io>"]
edition = "2021"

Expand All @@ -15,12 +15,12 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[dependencies]
ink_metadata = { version = "3.0.0-rc8", path = "../metadata/", default-features = false, features = ["derive"], optional = true }
ink_allocator = { version = "3.0.0-rc8", path = "../allocator/", default-features = false }
ink_primitives = { version = "3.0.0-rc8", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0-rc8", path = "../prelude/", default-features = false }
ink_metadata = { version = "3.0.0-rc9", path = "../metadata/", default-features = false, features = ["derive"], optional = true }
ink_allocator = { version = "3.0.0-rc9", path = "../allocator/", default-features = false }
ink_primitives = { version = "3.0.0-rc9", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0-rc9", path = "../prelude/", default-features = false }

scale = { package = "parity-scale-codec", version = "2.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
cfg-if = "1.0"
Expand All @@ -32,7 +32,7 @@ static_assertions = "1.1"
rlibc = "1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ink_engine = { version = "3.0.0-rc8", path = "../engine/", optional = true }
ink_engine = { version = "3.0.0-rc9", path = "../engine/", optional = true }

# Hashes for the off-chain environment.
sha2 = { version = "0.10", optional = true }
Expand All @@ -47,21 +47,18 @@ secp256k1 = { version = "0.21.2", features = ["recovery", "global-context"], opt
# Sadly couldn't be marked as dev-dependency.
# Never use this crate outside the off-chain environment!
rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

[features]
default = ["std"]
std = [
"ink_metadata",
"ink_metadata/std",
"ink_allocator/std",
"ink_prelude/std",
"ink_primitives/std",
"scale/std",
"scale-info",
"scale-info/std",
"secp256k1",
"rand",
"rand/std",
"rand/std_rng",
"num-traits/std",
Expand Down
4 changes: 2 additions & 2 deletions crates/eth_compatibility/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_eth_compatibility"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"

Expand All @@ -15,7 +15,7 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]

[dependencies]
ink_env = { version = "3.0.0-rc8", path = "../env", default-features = false }
ink_env = { version = "3.0.0-rc9", path = "../env", default-features = false }

[target.'cfg(not(target_os = "windows"))'.dependencies]
# We do not include `libsecp256k1` on Windows, since it's incompatible.
Expand Down
25 changes: 12 additions & 13 deletions crates/lang/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_lang"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin@parity.io>"]
edition = "2021"

Expand All @@ -15,29 +15,28 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[dependencies]
ink_env = { version = "3.0.0-rc8", path = "../env", default-features = false }
ink_storage = { version = "3.0.0-rc8", path = "../storage", default-features = false }
ink_primitives = { version = "3.0.0-rc8", path = "../primitives", default-features = false }
ink_metadata = { version = "3.0.0-rc8", path = "../metadata", default-features = false, optional = true }
ink_prelude = { version = "3.0.0-rc8", path = "../prelude", default-features = false }
ink_eth_compatibility = { version = "3.0.0-rc8", path = "../eth_compatibility", default-features = false }
ink_lang_macro = { version = "3.0.0-rc8", path = "macro", default-features = false }
ink_env = { version = "3.0.0-rc9", path = "../env", default-features = false }
ink_storage = { version = "3.0.0-rc9", path = "../storage", default-features = false }
ink_primitives = { version = "3.0.0-rc9", path = "../primitives", default-features = false }
ink_metadata = { version = "3.0.0-rc9", path = "../metadata", default-features = false, optional = true }
ink_prelude = { version = "3.0.0-rc9", path = "../prelude", default-features = false }
ink_eth_compatibility = { version = "3.0.0-rc9", path = "../eth_compatibility", default-features = false }
ink_lang_macro = { version = "3.0.0-rc9", path = "macro", default-features = false }

scale = { package = "parity-scale-codec", version = "2.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] }

[dev-dependencies]
ink_lang_ir = { version = "3.0.0-rc8", path = "ir" }
ink_metadata = { version = "3.0.0-rc8", default-features = false, path = "../metadata" }
ink_lang_ir = { version = "3.0.0-rc9", path = "ir" }
ink_metadata = { version = "3.0.0-rc9", default-features = false, path = "../metadata" }

trybuild = { version = "1.0.52", features = ["diff"] }
# Required for the doctest of `env_access::EnvAccess::instantiate_contract`
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }

[features]
default = ["std"]
std = [
"ink_metadata",
"ink_metadata/std",
"ink_prelude/std",
"ink_primitives/std",
Expand Down
6 changes: 3 additions & 3 deletions crates/lang/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_lang_codegen"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin@parity.io>"]
edition = "2021"

Expand All @@ -18,7 +18,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
name = "ink_lang_codegen"

[dependencies]
ir = { version = "3.0.0-rc8", package = "ink_lang_ir", path = "../ir", default-features = false }
ir = { version = "3.0.0-rc9", package = "ink_lang_ir", path = "../ir", default-features = false }
quote = "1"
syn = { version = "1.0", features = ["parsing", "full", "extra-traits"] }
proc-macro2 = "1.0"
Expand All @@ -27,7 +27,7 @@ itertools = "0.10"
either = { version = "1.5", default-features = false }
blake2 = "0.10"
heck = "0.4.0"
scale = { package = "parity-scale-codec", version = "2.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
impl-serde = "0.3.1"

[features]
Expand Down
4 changes: 2 additions & 2 deletions crates/lang/codegen/src/generator/arg_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn generate_reference_to_trait_info(
trait_path: &syn::Path,
) -> TokenStream2 {
quote_spanned!(span=>
<::ink_lang::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo
<<::ink_lang::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo as ::ink_lang::reflect::TraitInfo>::ID
)
}
14 changes: 7 additions & 7 deletions crates/lang/codegen/src/generator/as_dependency/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ impl CallBuilder<'_> {
) -> TokenStream2 {
let span = impl_block.span();
let cb_ident = Self::call_builder_ident();
let trait_info = generator::generate_reference_to_trait_info(span, trait_path);
let trait_info_id = generator::generate_reference_to_trait_info(span, trait_path);
quote_spanned!(span=>
#[doc(hidden)]
impl ::ink_lang::codegen::TraitCallForwarderFor<#trait_info> for #cb_ident {
impl ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}> for #cb_ident {
type Forwarder = <<Self as #trait_path>::__ink_TraitInfo as ::ink_lang::codegen::TraitCallForwarder>::Forwarder;

#[inline]
Expand Down Expand Up @@ -217,7 +217,7 @@ impl CallBuilder<'_> {
#[inline]
fn build(&self) -> &<Self::Forwarder as ::ink_lang::codegen::TraitCallBuilder>::Builder {
<_ as ::ink_lang::codegen::TraitCallBuilder>::call(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<#trait_info>>::forward(self)
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward(self)
)
}

Expand All @@ -226,7 +226,7 @@ impl CallBuilder<'_> {
-> &mut <Self::Forwarder as ::ink_lang::codegen::TraitCallBuilder>::Builder
{
<_ as ::ink_lang::codegen::TraitCallBuilder>::call_mut(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<#trait_info>>::forward_mut(self)
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward_mut(self)
)
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ impl CallBuilder<'_> {
let span = message.span();
let message_ident = message.ident();
let output_ident = generator::output_ident(message_ident);
let trait_info = generator::generate_reference_to_trait_info(span, trait_path);
let trait_info_id = generator::generate_reference_to_trait_info(span, trait_path);
let (input_bindings, input_types): (Vec<_>, Vec<_>) = message
.callable()
.inputs()
Expand All @@ -283,7 +283,7 @@ impl CallBuilder<'_> {
quote_spanned!(span=>
type #output_ident = <<<
Self
as ::ink_lang::codegen::TraitCallForwarderFor<#trait_info>>::Forwarder
as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::Forwarder
as ::ink_lang::codegen::TraitCallBuilder>::Builder
as #trait_path>::#output_ident;

Expand All @@ -294,7 +294,7 @@ impl CallBuilder<'_> {
#( , #input_bindings: #input_types )*
) -> Self::#output_ident {
<_ as #trait_path>::#message_ident(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<#trait_info>>::#build_cmd(self)
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::#build_cmd(self)
#( , #input_bindings )*
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl ContractRef<'_> {
) -> TokenStream2 {
use ir::Callable as _;
let span = message.span();
let trait_info = generator::generate_reference_to_trait_info(span, trait_path);
let trait_info_id = generator::generate_reference_to_trait_info(span, trait_path);
let message_ident = message.ident();
let output_ident = generator::output_ident(message_ident);
let call_operator = match message.receiver() {
Expand All @@ -266,7 +266,7 @@ impl ContractRef<'_> {
#( , #input_bindings : #input_types )*
) -> Self::#output_ident {
<_ as #trait_path>::#message_ident(
<_ as ::ink_lang::codegen::TraitCallForwarderFor<#trait_info>>::#forward_operator(
<_ as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::#forward_operator(
<Self as ::ink_lang::codegen::TraitCallBuilder>::#call_operator(self),
)
#( , #input_bindings )*
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/codegen/src/generator/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl Dispatch<'_> {

const CALLABLE: fn(&mut Self::Storage, Self::Input) -> Self::Output =
|storage, #input_tuple_bindings| {
#storage_ident::#message_ident( storage #( , #input_bindings )* )
<#storage_ident as #trait_path>::#message_ident( storage #( , #input_bindings )* )
};
const SELECTOR: [::core::primitive::u8; 4usize] = #selector;
const PAYABLE: ::core::primitive::bool = #payable;
Expand Down
24 changes: 23 additions & 1 deletion crates/lang/codegen/src/generator/trait_def/trait_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl TraitRegistry<'_> {
/// It is mainly used to access global information about the ink! trait.
fn generate_trait_info_object(&self) -> TokenStream2 {
let span = self.span();
let trait_id = self.generate_trait_id();
let trait_ident = self.trait_ident();
let trait_info_ident = self.trait_def.trait_info_ident();
let trait_call_forwarder = self.trait_def.call_forwarder_ident();
Expand All @@ -256,10 +257,12 @@ impl TraitRegistry<'_> {

#trait_message_info

impl<E> ::ink_lang::reflect::TraitModulePath for #trait_info_ident<E>
impl<E> ::ink_lang::reflect::TraitInfo for #trait_info_ident<E>
where
E: ::ink_env::Environment,
{
const ID: u32 = #trait_id;

const PATH: &'static ::core::primitive::str = ::core::module_path!();

const NAME: &'static ::core::primitive::str = ::core::stringify!(#trait_ident);
Expand All @@ -274,6 +277,25 @@ impl TraitRegistry<'_> {
)
}

/// Generates a unique id for the trait, as an XOR of the set of selectors.
fn generate_trait_id(&self) -> syn::LitInt {
let span = self.span();
let mut id = 0u32;
debug_assert!(
self.trait_def
.trait_def
.item()
.iter_items()
.next()
.is_some(),
"invalid empty ink! trait definition"
);
for (_, selector) in self.trait_def.trait_def.item().iter_items() {
id ^= selector.into_be_u32()
}
syn::LitInt::new(&format!("{}", id), span)
}

/// Generates the [`::ink_lang::reflect::TraitMessageInfo`] implementations for all
/// ink! messages defined by the ink! trait definition.
fn generate_info_for_trait_messages(&self) -> TokenStream2 {
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/ir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ink_lang_ir"
version = "3.0.0-rc8"
version = "3.0.0-rc9"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin@parity.io>"]
edition = "2021"

Expand Down
Loading

0 comments on commit 612de66

Please sign in to comment.