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

Rename EnvTypes -> Env (and many other renamings) (#513)

* [env] rename Env -> EnvBackend, TypedEnv -> TypedEnvBackend

* [env] rename EnvError -> Error

* [*] rename ink_env::EnvTypes -> Environment

Namely rename:
ink_env::EnvTypes -> Environment
ink_env::DefaultEnvTypes -> DefaultEnvironment

* [*] update cfg-if dependency 0.1 -> 1.0

* [alloc] rename ink_alloc -> ink_allocator

* [env] forgot to rename in lib.rs

* [env, lang] fix some bugs with ink_env::EnvError -> Error renaming

* [ci] adjust renaming of ink_alloc -> ink_allocator

* [env] apply rustfmt

* [lang/macro] re-enable disabled UI test

* [examples] DNS: apply rustfmt

* [examples] ERC-20, ERC-721: apply rustfmt
parent f197a986
Pipeline #109973 passed with stages
in 6 minutes and 8 seconds
...@@ -17,7 +17,7 @@ variables: ...@@ -17,7 +17,7 @@ variables:
CARGO_INCREMENTAL: 0 CARGO_INCREMENTAL: 0
CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}" 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}" CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
ALL_CRATES: "env storage storage/derive alloc prelude primitives lang lang/macro lang/ir" ALL_CRATES: "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
workflow: workflow:
rules: rules:
......
[workspace] [workspace]
members = [ members = [
"crates/metadata", "crates/metadata",
"crates/alloc", "crates/allocator",
"crates/lang", "crates/lang",
"crates/lang/macro", "crates/lang/macro",
"crates/lang/ir", "crates/lang/ir",
......
[package] [package]
name = "ink_alloc" name = "ink_allocator"
version = "3.0.0" version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
......
...@@ -16,14 +16,14 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] ...@@ -16,14 +16,14 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies] [dependencies]
ink_metadata = { version = "3.0.0", path = "../metadata/", default-features = false, features = ["derive"], optional = true } 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_allocator = { version = "3.0.0", path = "../allocator/", default-features = false }
ink_primitives = { version = "3.0.0", path = "../primitives/", default-features = false } ink_primitives = { version = "3.0.0", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0", path = "../prelude/", 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"] } 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"] } derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] } num-traits = { version = "0.2", default-features = false, features = ["i128"] }
cfg-if = "0.1" cfg-if = "1.0"
paste = "1.0" paste = "1.0"
arrayref = "0.3" arrayref = "0.3"
static_assertions = "1.1" static_assertions = "1.1"
...@@ -46,7 +46,7 @@ default = ["std"] ...@@ -46,7 +46,7 @@ default = ["std"]
std = [ std = [
"ink_metadata", "ink_metadata",
"ink_metadata/std", "ink_metadata/std",
"ink_alloc/std", "ink_allocator/std",
"ink_prelude/std", "ink_prelude/std",
"ink_primitives/std", "ink_primitives/std",
"scale/std", "scale/std",
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
use crate::{ use crate::{
backend::{ backend::{
Env, EnvBackend,
ReturnFlags, ReturnFlags,
TypedEnv, TypedEnvBackend,
}, },
call::{ call::{
utils::ReturnType, utils::ReturnType,
...@@ -34,7 +34,7 @@ use crate::{ ...@@ -34,7 +34,7 @@ use crate::{
HashOutput, HashOutput,
}, },
topics::Topics, topics::Topics,
EnvTypes, Environment,
Result, Result,
}; };
use ink_primitives::Key; use ink_primitives::Key;
...@@ -46,9 +46,11 @@ use ink_primitives::Key; ...@@ -46,9 +46,11 @@ use ink_primitives::Key;
/// If the returned caller cannot be properly decoded. /// If the returned caller cannot be properly decoded.
pub fn caller<T>() -> Result<T::AccountId> pub fn caller<T>() -> Result<T::AccountId>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| TypedEnv::caller::<T>(instance)) <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::caller::<T>(instance)
})
} }
/// Returns the transferred balance for the contract execution. /// Returns the transferred balance for the contract execution.
...@@ -58,10 +60,10 @@ where ...@@ -58,10 +60,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn transferred_balance<T>() -> Result<T::Balance> pub fn transferred_balance<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::transferred_balance::<T>(instance) TypedEnvBackend::transferred_balance::<T>(instance)
}) })
} }
...@@ -72,10 +74,10 @@ where ...@@ -72,10 +74,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn weight_to_fee<T>(gas: u64) -> Result<T::Balance> pub fn weight_to_fee<T>(gas: u64) -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::weight_to_fee::<T>(instance, gas) TypedEnvBackend::weight_to_fee::<T>(instance, gas)
}) })
} }
...@@ -86,9 +88,11 @@ where ...@@ -86,9 +88,11 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn gas_left<T>() -> Result<T::Balance> pub fn gas_left<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| TypedEnv::gas_left::<T>(instance)) <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::gas_left::<T>(instance)
})
} }
/// Returns the current block timestamp. /// Returns the current block timestamp.
...@@ -98,10 +102,10 @@ where ...@@ -98,10 +102,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn block_timestamp<T>() -> Result<T::Timestamp> pub fn block_timestamp<T>() -> Result<T::Timestamp>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::block_timestamp::<T>(instance) TypedEnvBackend::block_timestamp::<T>(instance)
}) })
} }
...@@ -116,10 +120,10 @@ where ...@@ -116,10 +120,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn account_id<T>() -> Result<T::AccountId> pub fn account_id<T>() -> Result<T::AccountId>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::account_id::<T>(instance) TypedEnvBackend::account_id::<T>(instance)
}) })
} }
...@@ -130,9 +134,11 @@ where ...@@ -130,9 +134,11 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn balance<T>() -> Result<T::Balance> pub fn balance<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| TypedEnv::balance::<T>(instance)) <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::balance::<T>(instance)
})
} }
/// Returns the current rent allowance for the executed contract. /// Returns the current rent allowance for the executed contract.
...@@ -142,10 +148,10 @@ where ...@@ -142,10 +148,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn rent_allowance<T>() -> Result<T::Balance> pub fn rent_allowance<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::rent_allowance::<T>(instance) TypedEnvBackend::rent_allowance::<T>(instance)
}) })
} }
...@@ -156,10 +162,10 @@ where ...@@ -156,10 +162,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn block_number<T>() -> Result<T::BlockNumber> pub fn block_number<T>() -> Result<T::BlockNumber>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::block_number::<T>(instance) TypedEnvBackend::block_number::<T>(instance)
}) })
} }
...@@ -170,10 +176,10 @@ where ...@@ -170,10 +176,10 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn minimum_balance<T>() -> Result<T::Balance> pub fn minimum_balance<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::minimum_balance::<T>(instance) TypedEnvBackend::minimum_balance::<T>(instance)
}) })
} }
...@@ -184,31 +190,31 @@ where ...@@ -184,31 +190,31 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn tombstone_deposit<T>() -> Result<T::Balance> pub fn tombstone_deposit<T>() -> Result<T::Balance>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::tombstone_deposit::<T>(instance) TypedEnvBackend::tombstone_deposit::<T>(instance)
}) })
} }
/// Emits an event with the given event data. /// Emits an event with the given event data.
pub fn emit_event<T, Event>(event: Event) pub fn emit_event<T, Event>(event: Event)
where where
T: EnvTypes, T: Environment,
Event: Topics + scale::Encode, Event: Topics + scale::Encode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::emit_event::<T, Event>(instance, event) TypedEnvBackend::emit_event::<T, Event>(instance, event)
}) })
} }
/// Sets the rent allowance of the executed contract to the new value. /// Sets the rent allowance of the executed contract to the new value.
pub fn set_rent_allowance<T>(new_value: T::Balance) pub fn set_rent_allowance<T>(new_value: T::Balance)
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::set_rent_allowance::<T>(instance, new_value) TypedEnvBackend::set_rent_allowance::<T>(instance, new_value)
}) })
} }
...@@ -222,7 +228,7 @@ where ...@@ -222,7 +228,7 @@ where
V: scale::Encode, V: scale::Encode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
Env::set_contract_storage::<V>(instance, key, value) EnvBackend::set_contract_storage::<V>(instance, key, value)
}) })
} }
...@@ -236,14 +242,14 @@ where ...@@ -236,14 +242,14 @@ where
R: scale::Decode, R: scale::Decode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
Env::get_contract_storage::<R>(instance, key) EnvBackend::get_contract_storage::<R>(instance, key)
}) })
} }
/// Clears the contract's storage key entry. /// Clears the contract's storage key entry.
pub fn clear_contract_storage(key: &Key) { pub fn clear_contract_storage(key: &Key) {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
Env::clear_contract_storage(instance, key) EnvBackend::clear_contract_storage(instance, key)
}) })
} }
...@@ -266,11 +272,11 @@ pub fn clear_contract_storage(key: &Key) { ...@@ -266,11 +272,11 @@ pub fn clear_contract_storage(key: &Key) {
/// - If the called contract ran out of gas upon execution. /// - If the called contract ran out of gas upon execution.
pub fn invoke_contract<T, Args>(params: &CallParams<T, Args, ()>) -> Result<()> pub fn invoke_contract<T, Args>(params: &CallParams<T, Args, ()>) -> Result<()>
where where
T: EnvTypes, T: Environment,
Args: scale::Encode, Args: scale::Encode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::invoke_contract::<T, Args>(instance, params) TypedEnvBackend::invoke_contract::<T, Args>(instance, params)
}) })
} }
...@@ -292,12 +298,12 @@ where ...@@ -292,12 +298,12 @@ where
/// - If the returned value failed to decode properly. /// - If the returned value failed to decode properly.
pub fn eval_contract<T, Args, R>(params: &CallParams<T, Args, ReturnType<R>>) -> Result<R> pub fn eval_contract<T, Args, R>(params: &CallParams<T, Args, ReturnType<R>>) -> Result<R>
where where
T: EnvTypes, T: Environment,
Args: scale::Encode, Args: scale::Encode,
R: scale::Decode, R: scale::Decode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::eval_contract::<T, Args, R>(instance, params) TypedEnvBackend::eval_contract::<T, Args, R>(instance, params)
}) })
} }
...@@ -320,11 +326,11 @@ pub fn instantiate_contract<T, Args, C>( ...@@ -320,11 +326,11 @@ pub fn instantiate_contract<T, Args, C>(
params: &CreateParams<T, Args, C>, params: &CreateParams<T, Args, C>,
) -> Result<T::AccountId> ) -> Result<T::AccountId>
where where
T: EnvTypes, T: Environment,
Args: scale::Encode, Args: scale::Encode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::instantiate_contract::<T, Args, C>(instance, params) TypedEnvBackend::instantiate_contract::<T, Args, C>(instance, params)
}) })
} }
...@@ -376,10 +382,10 @@ pub fn restore_contract<T>( ...@@ -376,10 +382,10 @@ pub fn restore_contract<T>(
rent_allowance: T::Balance, rent_allowance: T::Balance,
filtered_keys: &[Key], filtered_keys: &[Key],
) where ) where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::restore_contract::<T>( TypedEnvBackend::restore_contract::<T>(
instance, instance,
account_id, account_id,
code_hash, code_hash,
...@@ -401,10 +407,10 @@ pub fn restore_contract<T>( ...@@ -401,10 +407,10 @@ pub fn restore_contract<T>(
/// which is considered fatal and results in a trap + rollback. /// which is considered fatal and results in a trap + rollback.
pub fn terminate_contract<T>(beneficiary: T::AccountId) -> ! pub fn terminate_contract<T>(beneficiary: T::AccountId) -> !
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::terminate_contract::<T>(instance, beneficiary) TypedEnvBackend::terminate_contract::<T>(instance, beneficiary)
}) })
} }
...@@ -421,10 +427,10 @@ where ...@@ -421,10 +427,10 @@ where
/// If the contract doesn't have sufficient funds. /// If the contract doesn't have sufficient funds.
pub fn transfer<T>(destination: T::AccountId, value: T::Balance) -> Result<()> pub fn transfer<T>(destination: T::AccountId, value: T::Balance) -> Result<()>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::transfer::<T>(instance, destination, value) TypedEnvBackend::transfer::<T>(instance, destination, value)
}) })
} }
...@@ -445,7 +451,7 @@ where ...@@ -445,7 +451,7 @@ where
O: scale::Codec + 'static, O: scale::Codec + 'static,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
Env::call_chain_extension(instance, func_id, input) EnvBackend::call_chain_extension(instance, func_id, input)
}) })
} }
...@@ -476,7 +482,9 @@ pub fn decode_input<T>() -> Result<T> ...@@ -476,7 +482,9 @@ pub fn decode_input<T>() -> Result<T>
where where
T: scale::Decode, T: scale::Decode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| Env::decode_input::<T>(instance)) <EnvInstance as OnInstance>::on_instance(|instance| {
EnvBackend::decode_input::<T>(instance)
})
} }
/// Returns the value back to the caller of the executed contract. /// Returns the value back to the caller of the executed contract.
...@@ -489,7 +497,7 @@ where ...@@ -489,7 +497,7 @@ where
R: scale::Encode, R: scale::Encode,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
Env::return_value::<R>(instance, return_flags, return_value) EnvBackend::return_value::<R>(instance, return_flags, return_value)
}) })
} }
...@@ -505,16 +513,18 @@ where ...@@ -505,16 +513,18 @@ where
/// If the returned value cannot be properly decoded. /// If the returned value cannot be properly decoded.
pub fn random<T>(subject: &[u8]) -> Result<T::Hash> pub fn random<T>(subject: &[u8]) -> Result<T::Hash>
where where
T: EnvTypes, T: Environment,
{ {
<EnvInstance as OnInstance>::on_instance(|instance| { <EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::random::<T>(instance, subject) TypedEnvBackend::random::<T>(instance, subject)
}) })
} }
/// Prints the given contents to the environmental log. /// Prints the given contents to the environmental log.
pub fn debug_println(content: &str) { pub fn debug_println(content: &str) {
<EnvInstance as OnInstance>::on_instance(|instance| Env::println(instance, content)) <EnvInstance as OnInstance>::on_instance(|instance| {
EnvBackend::println(instance, content)
})
} }
/// Conducts the crypto hash of the given input and stores the result in `output`. /// Conducts the crypto hash of the given input and stores the result in `output`.
......
...@@ -23,7 +23,7 @@ use crate::{ ...@@ -23,7 +23,7 @@ use crate::{
HashOutput, HashOutput,
}, },
topics::Topics, topics::Topics,
EnvTypes, Environment,
Result, Result,
}; };
use ink_primitives::Key; use ink_primitives::Key;
...@@ -55,8 +55,8 @@ impl ReturnFlags { ...@@ -55,8 +55,8 @@ impl ReturnFlags {
} }
} }
/// Environmental contract functionality that does not require `EnvTypes`. /// Environmental contract functionality that does not require `Environment`.