Unverified Commit cfe52e98 authored by Hero Bird's avatar Hero Bird Committed by GitHub
Browse files

Split ink_core crate into ink_env and ink_storage (#500)

* [*] split ink_core into ink_env and ink_storage

The workspace does not yet compile!

* [env] make compile again

* [env] fix doc tests

* [storage] make crate compile again

* [env] fix some doc comment links

* [README] flipper example: remove unused import

* [storage/derive] fix compilation of generated code

* [README] add ink_storage and ink_env doc links

* [env, primitives, storage] fix docs

* [lang] make compile again

* [lang/codegen] use absolute paths in #[ink::test] proc. macro

* [examples] make compile again

* [*] apply rustfmt

* [env] remove unneeded dependencies

* [storage] remove all unneeded dependencies and crate features

* [*] update outdated dependencies

* [env, lang] remove unused dependencies

* [*] fix comments

* [*] fix some intra doc links

* [ci] adjust to split ink_env and ink_storage crates

* [ci] forgot to handle split ink_env and ink_storage in docs

* [storage] fix fuzz tests

* [examples] apply rustfmt

* [examples] apply rustfmt (ERC-721)
parent 8c385f4d
Pipeline #109266 passed with stages
in 9 minutes and 48 seconds
......@@ -17,7 +17,7 @@ variables:
CARGO_INCREMENTAL: 0
CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}"
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
ALL_CRATES: "core core/derive alloc prelude primitives lang lang/macro lang/ir"
ALL_CRATES: "env storage storage/derive alloc prelude primitives lang lang/macro lang/ir"
workflow:
rules:
......@@ -270,7 +270,7 @@ publish-docs:
- git fetch origin gh-pages
# Generating Docs
- time cargo doc --no-deps --all-features
-p scale-info -p ink_metadata -p ink_core -p ink_core_derive
-p scale-info -p ink_metadata -p ink_env -p ink_storage -p ink_storage_derive
-p ink_primitives -p ink_prelude -p ink_lang -p ink_lang_macro
# saving README and docs
- mv target/doc/ /tmp/
......
......@@ -2,14 +2,15 @@
members = [
"crates/metadata",
"crates/alloc",
"crates/core",
"crates/core/derive",
"crates/lang",
"crates/lang/macro",
"crates/lang/ir",
"crates/lang/codegen",
"crates/prelude",
"crates/primitives",
"crates/env",
"crates/storage",
"crates/storage/derive",
]
exclude = [
"examples/",
......
......@@ -12,8 +12,10 @@
[d2]: https://coveralls.io/github/paritytech/ink?branch=master
[e1]: https://tokei.rs/b1/github/paritytech/ink?category=code
[e2]: https://github.com/Aaronepower/tokei#badges
[f1]: https://img.shields.io/badge/docs-core-blue.svg
[f2]: https://paritytech.github.io/ink/ink_core
[f1]: https://img.shields.io/badge/docs-storage-blue.svg
[f2]: https://paritytech.github.io/ink/ink_storage
[g1]: https://img.shields.io/badge/docs-env-blue.svg
[g2]: https://paritytech.github.io/ink/ink_env
[h1]: https://img.shields.io/badge/docs-metadata-blue.svg
[h2]: https://paritytech.github.io/ink/ink_metadata
[i1]: https://img.shields.io/badge/docs-prelude-blue.svg
......@@ -27,9 +29,9 @@ For more information please visit [the ink! tutorial](https://substrate.dev/subs
## Developer Documentation
| `ink_metadata` | `ink_core` | `ink_prelude` |
| ------------- | ------------- | ------------- |
| [![][h1]][h2] | [![][f1]][f2] | [![][i1]][i2] |
| `ink_metadata` | `ink_env` | `ink_storage` | `ink_prelude` |
| ------------- | ------------- | ------------- | ------------- |
| [![][h1]][h2] | [![][g1]][g2] | [![][f1]][f2] | [![][i1]][i2] |
### Interaction with Substrate
......@@ -88,8 +90,6 @@ use ink_lang as ink;
#[ink::contract]
mod flipper {
use ink_core::storage;
/// The storage of the flipper contract.
#[ink(storage)]
pub struct Flipper {
......
[package]
name = "ink_core"
name = "ink_env"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......@@ -18,16 +18,13 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
ink_metadata = { version = "3.0.0", path = "../metadata/", default-features = false, features = ["derive"], optional = true }
ink_alloc = { version = "3.0.0", path = "../alloc/", default-features = false }
ink_primitives = { version = "3.0.0", path = "../primitives/", default-features = false }
ink_core_derive = { version = "3.0.0", path = "derive", default-features = false }
ink_prelude = { version = "3.0.0", path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.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 = "0.1"
array-init = "0.1"
generic-array = "0.14.1"
paste = "0.1"
paste = "1.0"
arrayref = "0.3"
static_assertions = "1.1"
......@@ -43,21 +40,9 @@ blake2 = { version = "0.9", optional = true }
rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true }
# Workaround: we actually just need criterion as a dev-dependency, but
# there is an issue with a doubly included std lib when executing
# `cargo check --no-default-features --target wasm32-unknown-unknown`.
# We haven't found a better solution yet.
criterion = { version = "0.3", optional = true }
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.8"
itertools = "0.9"
[features]
default = ["std"]
std = [
"criterion",
"ink_metadata",
"ink_metadata/std",
"ink_alloc/std",
......@@ -74,25 +59,4 @@ std = [
"sha3",
"blake2",
]
ink-fuzz-tests = ["std"]
ink-unstable-chain-extensions = []
[[bench]]
name = "bench_lazy"
harness = false
[[bench]]
name = "bench_vec"
harness = false
[[bench]]
name = "bench_stash"
harness = false
[[bench]]
name = "bench_bitstash"
harness = false
[[bench]]
name = "bench_hashmap"
harness = false
......@@ -14,7 +14,7 @@
//! The public raw interface towards the host Wasm engine.
use crate::env::{
use crate::{
backend::{
Env,
ReturnFlags,
......@@ -532,14 +532,14 @@ where
/// # Example
///
/// ```
/// # use ink_core::env::hash::{Sha2x256, HashOutput};
/// # use ink_env::hash::{Sha2x256, HashOutput};
/// const EXPECTED: [u8; 32] = [
/// 243, 242, 58, 110, 205, 68, 100, 244, 187, 55, 188, 248, 29, 136, 145, 115,
/// 186, 134, 14, 175, 178, 99, 183, 21, 4, 94, 92, 69, 199, 207, 241, 179,
/// ];
/// let encodable = (42, "foo", true); // Implements `scale::Encode`
/// let mut output = <Sha2x256 as HashOutput>::Type::default(); // 256-bit buffer
/// ink_core::env::hash_encoded::<Sha2x256, _>(&encodable, &mut output);
/// ink_env::hash_encoded::<Sha2x256, _>(&encodable, &mut output);
/// assert_eq!(output, EXPECTED);
/// ```
pub fn hash_encoded<H, T>(input: &T, output: &mut <H as HashOutput>::Type)
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::env::{
use crate::{
call::{
utils::ReturnType,
CallParams,
......@@ -151,84 +151,84 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::caller`]
/// For more details visit: [`ink_env::caller`]
fn caller<T: EnvTypes>(&mut self) -> Result<T::AccountId>;
/// Returns the transferred balance for the contract execution.
///
/// # Note
///
/// For more details visit: [`ink_core::env::transferred_balance`]
/// For more details visit: [`ink_env::transferred_balance`]
fn transferred_balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Returns the price for the specified amount of gas.
///
/// # Note
///
/// For more details visit: [`ink_core::env::gas_price`]
/// For more details visit: [`ink_env::gas_price`]
fn weight_to_fee<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance>;
/// Returns the amount of gas left for the contract execution.
///
/// # Note
///
/// For more details visit: [`ink_core::env::gas_left`]
/// For more details visit: [`ink_env::gas_left`]
fn gas_left<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Returns the timestamp of the current block.
///
/// # Note
///
/// For more details visit: [`ink_core::env::block_timestamp`]
/// For more details visit: [`ink_env::block_timestamp`]
fn block_timestamp<T: EnvTypes>(&mut self) -> Result<T::Timestamp>;
/// Returns the address of the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_core::env::account_id`]
/// For more details visit: [`ink_env::account_id`]
fn account_id<T: EnvTypes>(&mut self) -> Result<T::AccountId>;
/// Returns the balance of the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_core::env::balance`]
/// For more details visit: [`ink_env::balance`]
fn balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Returns the current rent allowance for the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_core::env::rent_allowance`]
/// For more details visit: [`ink_env::rent_allowance`]
fn rent_allowance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Returns the current block number.
///
/// # Note
///
/// For more details visit: [`ink_core::env::block_number`]
/// For more details visit: [`ink_env::block_number`]
fn block_number<T: EnvTypes>(&mut self) -> Result<T::BlockNumber>;
/// Returns the minimum balance of the contracts chain.
///
/// # Note
///
/// For more details visit: [`ink_core::env::minimum_balance`]
/// For more details visit: [`ink_env::minimum_balance`]
fn minimum_balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Returns the tombstone deposit of the contract chain.
///
/// # Note
///
/// For more details visit: [`ink_core::env::tombstone_deposit`]
/// For more details visit: [`ink_env::tombstone_deposit`]
fn tombstone_deposit<T: EnvTypes>(&mut self) -> Result<T::Balance>;
/// Emits an event with the given event data.
///
/// # Note
///
/// For more details visit: [`ink_core::env::emit_event`]
/// For more details visit: [`ink_env::emit_event`]
fn emit_event<T, Event>(&mut self, event: Event)
where
T: EnvTypes,
......@@ -238,7 +238,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::set_rent_allowance`]
/// For more details visit: [`ink_env::set_rent_allowance`]
fn set_rent_allowance<T>(&mut self, new_value: T::Balance)
where
T: EnvTypes;
......@@ -247,7 +247,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::invoke_contract`]
/// For more details visit: [`ink_env::invoke_contract`]
fn invoke_contract<T, Args>(
&mut self,
call_data: &CallParams<T, Args, ()>,
......@@ -260,7 +260,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::eval_contract`]
/// For more details visit: [`ink_env::eval_contract`]
fn eval_contract<T, Args, R>(
&mut self,
call_data: &CallParams<T, Args, ReturnType<R>>,
......@@ -274,7 +274,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::instantiate_contract`]
/// For more details visit: [`ink_env::instantiate_contract`]
fn instantiate_contract<T, Args, C>(
&mut self,
params: &CreateParams<T, Args, C>,
......@@ -287,7 +287,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::restore_contract`]
/// For more details visit: [`ink_env::restore_contract`]
fn restore_contract<T>(
&mut self,
account_id: T::AccountId,
......@@ -301,7 +301,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::terminate_contract`]
/// For more details visit: [`ink_env::terminate_contract`]
fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> !
where
T: EnvTypes;
......@@ -310,7 +310,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::transfer`]
/// For more details visit: [`ink_env::transfer`]
fn transfer<T>(&mut self, destination: T::AccountId, value: T::Balance) -> Result<()>
where
T: EnvTypes;
......@@ -319,7 +319,7 @@ pub trait TypedEnv: Env {
///
/// # Note
///
/// For more details visit: [`ink_core::env::random`]
/// For more details visit: [`ink_env::random`]
fn random<T>(&mut self, subject: &[u8]) -> Result<T::Hash>
where
T: EnvTypes;
......
......@@ -13,21 +13,18 @@
// limitations under the License.
use crate::{
env,
env::{
call::{
utils::{
EmptyArgumentList,
ReturnType,
Set,
Unset,
Unwrap,
},
ExecutionInput,
call::{
utils::{
EmptyArgumentList,
ReturnType,
Set,
Unset,
Unwrap,
},
EnvError,
EnvTypes,
ExecutionInput,
},
EnvError,
EnvTypes,
};
use core::marker::PhantomData;
......@@ -95,8 +92,8 @@ where
///
/// Prefer [`invoke`](`Self::invoke`) over [`eval`](`Self::eval`) if the
/// called contract message does not return anything because it is more efficient.
pub fn invoke(&self) -> Result<(), env::EnvError> {
env::invoke_contract(self)
pub fn invoke(&self) -> Result<(), crate::EnvError> {
crate::invoke_contract(self)
}
}
......@@ -114,8 +111,8 @@ where
///
/// Prefer [`invoke`](`Self::invoke`) over [`eval`](`Self::eval`) if the
/// called contract message does not return anything because it is more efficient.
pub fn eval(&self) -> Result<R, env::EnvError> {
env::eval_contract(self)
pub fn eval(&self) -> Result<R, crate::EnvError> {
crate::eval_contract(self)
}
}
......@@ -141,7 +138,7 @@ where
/// 3. an array of 32 `u8` with value `0x10`
///
/// ```should_panic
/// # use ::ink_core::env::{
/// # use ::ink_env::{
/// # EnvTypes,
/// # DefaultEnvTypes,
/// # call::{build_call, Selector, ExecutionInput}
......@@ -176,7 +173,7 @@ where
/// 3. an array of 32 `u8` with value `0x10`
///
/// ```should_panic
/// # use ::ink_core::env::{
/// # use ::ink_env::{
/// # EnvTypes,
/// # DefaultEnvTypes,
/// # call::{build_call, Selector, ExecutionInput, utils::ReturnType},
......
......@@ -13,21 +13,18 @@
// limitations under the License.
use crate::{
env,
env::{
call::{
utils::{
EmptyArgumentList,
ReturnType,
Set,
Unset,
Unwrap,
},
ExecutionInput,
call::{
utils::{
EmptyArgumentList,
ReturnType,
Set,
Unset,
Unwrap,
},
EnvError,
EnvTypes,
ExecutionInput,
},
EnvError,
EnvTypes,
};
use core::marker::PhantomData;
......@@ -106,8 +103,8 @@ where
{
/// Instantiates the contract and returns its account ID back to the caller.
#[inline]
pub fn instantiate(&self) -> Result<R, env::EnvError> {
env::instantiate_contract(self).map(FromAccountId::from_account_id)
pub fn instantiate(&self) -> Result<R, crate::EnvError> {
crate::instantiate_contract(self).map(FromAccountId::from_account_id)
}
}
......@@ -141,7 +138,7 @@ where
/// 3. an array of 32 `u8` with value `0x10`
///
/// ```should_panic
/// # use ::ink_core::env::{
/// # use ::ink_env::{
/// # EnvTypes,
/// # DefaultEnvTypes,
/// # call::{build_create, Selector, ExecutionInput, FromAccountId}
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::env::call::Selector;
use crate::call::Selector;
/// The input data for a smart contract execution.
#[derive(Debug)]
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::env::backend::{
use crate::backend::{
Env,
TypedEnv,
};
......
use crate::env::call::Selector;
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::call::Selector;
use ink_prelude::{
vec,
vec::Vec,
......
......@@ -13,7 +13,7 @@
// limitations under the License.
use super::OffChainError;
use crate::env::Result;
use crate::Result;
use std::collections::HashMap;
type FuncId = u32;
......
......@@ -20,7 +20,7 @@ use super::{
OffAccountId,
OffBalance,
};
use crate::env::{
use crate::{
EnvError,
EnvTypes,
};
......
......@@ -21,7 +21,7 @@ use super::{
OffHash,
OffTimestamp,
};
use crate::env::EnvTypes;
use crate::EnvTypes;
/// An emulated block in the chain.
pub struct Block {
......@@ -34,7 +34,7 @@ pub struct Block {
/// # Note
///
/// - Can optionally be set for more control via
/// [`crate::env::set_block_randomization_hash`].
/// [`crate::set_block_randomization_hash`].
entropy: OffHash,
}
......@@ -44,7 +44,7 @@ impl Block {
where
T: EnvTypes,
{
use crate::env::Clear;
use crate::Clear;
use rand::Rng as _;
let mut entropy = <T as EnvTypes>::Hash::clear();
rand::thread_rng().fill(entropy.as_mut());
......@@ -75,7 +75,7 @@ impl Block {
///
/// # Note
///
/// This is mainly used to control what [`crate::env::random`] returns
/// This is mainly used to control what [`crate::random`] returns
/// in the off-chain environment.
pub fn set_entropy<T>(&mut self, new_entropy: T::Hash) -> Result<()>
where
......@@ -89,7 +89,7 @@ impl Block {
/// # Note
///
/// - This is the off-chain environment implementation of
/// [`crate::env::random`]. It provides the same behaviour in that it
/// [`crate::random`]. It provides the same behaviour in that it
/// will likely yield the same hash for the same subjects within the same
/// block (or execution context).
///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment