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:
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: "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:
rules:
......
[workspace]
members = [
"crates/metadata",
"crates/alloc",
"crates/allocator",
"crates/lang",
"crates/lang/macro",
"crates/lang/ir",
......
[package]
name = "ink_alloc"
name = "ink_allocator"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......
......@@ -16,14 +16,14 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
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_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"
cfg-if = "1.0"
paste = "1.0"
arrayref = "0.3"
static_assertions = "1.1"
......@@ -46,7 +46,7 @@ default = ["std"]
std = [
"ink_metadata",
"ink_metadata/std",
"ink_alloc/std",
"ink_allocator/std",
"ink_prelude/std",
"ink_primitives/std",
"scale/std",
......
......@@ -16,9 +16,9 @@
use crate::{
backend::{
Env,
EnvBackend,
ReturnFlags,
TypedEnv,
TypedEnvBackend,
},
call::{
utils::ReturnType,
......@@ -34,7 +34,7 @@ use crate::{
HashOutput,
},
topics::Topics,
EnvTypes,
Environment,
Result,
};
use ink_primitives::Key;
......@@ -46,9 +46,11 @@ use ink_primitives::Key;
/// If the returned caller cannot be properly decoded.
pub fn caller<T>() -> Result<T::AccountId>
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.
......@@ -58,10 +60,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn transferred_balance<T>() -> Result<T::Balance>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::transferred_balance::<T>(instance)
TypedEnvBackend::transferred_balance::<T>(instance)
})
}
......@@ -72,10 +74,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn weight_to_fee<T>(gas: u64) -> Result<T::Balance>
where
T: EnvTypes,
T: Environment,
{
<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
/// If the returned value cannot be properly decoded.
pub fn gas_left<T>() -> Result<T::Balance>
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.
......@@ -98,10 +102,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn block_timestamp<T>() -> Result<T::Timestamp>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::block_timestamp::<T>(instance)
TypedEnvBackend::block_timestamp::<T>(instance)
})
}
......@@ -116,10 +120,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn account_id<T>() -> Result<T::AccountId>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::account_id::<T>(instance)
TypedEnvBackend::account_id::<T>(instance)
})
}
......@@ -130,9 +134,11 @@ where
/// If the returned value cannot be properly decoded.
pub fn balance<T>() -> Result<T::Balance>
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.
......@@ -142,10 +148,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn rent_allowance<T>() -> Result<T::Balance>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::rent_allowance::<T>(instance)
TypedEnvBackend::rent_allowance::<T>(instance)
})
}
......@@ -156,10 +162,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn block_number<T>() -> Result<T::BlockNumber>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::block_number::<T>(instance)
TypedEnvBackend::block_number::<T>(instance)
})
}
......@@ -170,10 +176,10 @@ where
/// If the returned value cannot be properly decoded.
pub fn minimum_balance<T>() -> Result<T::Balance>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::minimum_balance::<T>(instance)
TypedEnvBackend::minimum_balance::<T>(instance)
})
}
......@@ -184,31 +190,31 @@ where
/// If the returned value cannot be properly decoded.
pub fn tombstone_deposit<T>() -> Result<T::Balance>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::tombstone_deposit::<T>(instance)
TypedEnvBackend::tombstone_deposit::<T>(instance)
})
}
/// Emits an event with the given event data.
pub fn emit_event<T, Event>(event: Event)
where
T: EnvTypes,
T: Environment,
Event: Topics + scale::Encode,
{
<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.
pub fn set_rent_allowance<T>(new_value: T::Balance)
where
T: EnvTypes,
T: Environment,
{
<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
V: scale::Encode,
{
<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
R: scale::Decode,
{
<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.
pub fn clear_contract_storage(key: &Key) {
<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) {
/// - If the called contract ran out of gas upon execution.
pub fn invoke_contract<T, Args>(params: &CallParams<T, Args, ()>) -> Result<()>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode,
{
<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
/// - If the returned value failed to decode properly.
pub fn eval_contract<T, Args, R>(params: &CallParams<T, Args, ReturnType<R>>) -> Result<R>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode,
R: scale::Decode,
{
<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>(
params: &CreateParams<T, Args, C>,
) -> Result<T::AccountId>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode,
{
<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>(
rent_allowance: T::Balance,
filtered_keys: &[Key],
) where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::restore_contract::<T>(
TypedEnvBackend::restore_contract::<T>(
instance,
account_id,
code_hash,
......@@ -401,10 +407,10 @@ pub fn restore_contract<T>(
/// which is considered fatal and results in a trap + rollback.
pub fn terminate_contract<T>(beneficiary: T::AccountId) -> !
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::terminate_contract::<T>(instance, beneficiary)
TypedEnvBackend::terminate_contract::<T>(instance, beneficiary)
})
}
......@@ -421,10 +427,10 @@ where
/// If the contract doesn't have sufficient funds.
pub fn transfer<T>(destination: T::AccountId, value: T::Balance) -> Result<()>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::transfer::<T>(instance, destination, value)
TypedEnvBackend::transfer::<T>(instance, destination, value)
})
}
......@@ -445,7 +451,7 @@ where
O: scale::Codec + 'static,
{
<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>
where
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.
......@@ -489,7 +497,7 @@ where
R: scale::Encode,
{
<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
/// If the returned value cannot be properly decoded.
pub fn random<T>(subject: &[u8]) -> Result<T::Hash>
where
T: EnvTypes,
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::random::<T>(instance, subject)
TypedEnvBackend::random::<T>(instance, subject)
})
}
/// Prints the given contents to the environmental log.
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`.
......
......@@ -23,7 +23,7 @@ use crate::{
HashOutput,
},
topics::Topics,
EnvTypes,
Environment,
Result,
};
use ink_primitives::Key;
......@@ -55,8 +55,8 @@ impl ReturnFlags {
}
}
/// Environmental contract functionality that does not require `EnvTypes`.
pub trait Env {
/// Environmental contract functionality that does not require `Environment`.
pub trait EnvBackend {
/// Writes the value to the contract storage under the given key.
fn set_contract_storage<V>(&mut self, key: &Key, value: &V)
where
......@@ -146,83 +146,83 @@ pub trait Env {
}
/// Environmental contract functionality.
pub trait TypedEnv: Env {
pub trait TypedEnvBackend: EnvBackend {
/// Returns the address of the caller of the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_env::caller`]
fn caller<T: EnvTypes>(&mut self) -> Result<T::AccountId>;
fn caller<T: Environment>(&mut self) -> Result<T::AccountId>;
/// Returns the transferred balance for the contract execution.
///
/// # Note
///
/// For more details visit: [`ink_env::transferred_balance`]
fn transferred_balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn transferred_balance<T: Environment>(&mut self) -> Result<T::Balance>;
/// Returns the price for the specified amount of gas.
///
/// # Note
///
/// For more details visit: [`ink_env::gas_price`]
fn weight_to_fee<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance>;
fn weight_to_fee<T: Environment>(&mut self, gas: u64) -> Result<T::Balance>;
/// Returns the amount of gas left for the contract execution.
///
/// # Note
///
/// For more details visit: [`ink_env::gas_left`]
fn gas_left<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn gas_left<T: Environment>(&mut self) -> Result<T::Balance>;
/// Returns the timestamp of the current block.
///
/// # Note
///
/// For more details visit: [`ink_env::block_timestamp`]
fn block_timestamp<T: EnvTypes>(&mut self) -> Result<T::Timestamp>;
fn block_timestamp<T: Environment>(&mut self) -> Result<T::Timestamp>;
/// Returns the address of the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_env::account_id`]
fn account_id<T: EnvTypes>(&mut self) -> Result<T::AccountId>;
fn account_id<T: Environment>(&mut self) -> Result<T::AccountId>;
/// Returns the balance of the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_env::balance`]
fn balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn balance<T: Environment>(&mut self) -> Result<T::Balance>;
/// Returns the current rent allowance for the executed contract.
///
/// # Note
///
/// For more details visit: [`ink_env::rent_allowance`]
fn rent_allowance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn rent_allowance<T: Environment>(&mut self) -> Result<T::Balance>;
/// Returns the current block number.
///
/// # Note
///
/// For more details visit: [`ink_env::block_number`]
fn block_number<T: EnvTypes>(&mut self) -> Result<T::BlockNumber>;
fn block_number<T: Environment>(&mut self) -> Result<T::BlockNumber>;
/// Returns the minimum balance of the contracts chain.
///
/// # Note
///
/// For more details visit: [`ink_env::minimum_balance`]
fn minimum_balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn minimum_balance<T: Environment>(&mut self) -> Result<T::Balance>;
/// Returns the tombstone deposit of the contract chain.
///
/// # Note
///
/// For more details visit: [`ink_env::tombstone_deposit`]
fn tombstone_deposit<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn tombstone_deposit<T: Environment>(&mut self) -> Result<T::Balance>;
/// Emits an event with the given event data.
///
......@@ -231,7 +231,7 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_env::emit_event`]
fn emit_event<T, Event>(&mut self, event: Event)
where
T: EnvTypes,
T: Environment,
Event: Topics + scale::Encode;
/// Sets the rent allowance of the executed contract to the new value.
......@@ -241,7 +241,7 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_env::set_rent_allowance`]
fn set_rent_allowance<T>(&mut self, new_value: T::Balance)
where
T: EnvTypes;
T: Environment;
/// Invokes a contract message.
///
......@@ -253,7 +253,7 @@ pub trait TypedEnv: Env {
call_data: &CallParams<T, Args, ()>,
) -> Result<()>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode;
/// Evaluates a contract message and returns its result.
......@@ -266,7 +266,7 @@ pub trait TypedEnv: Env {
call_data: &CallParams<T, Args, ReturnType<R>>,
) -> Result<R>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode,
R: scale::Decode;
......@@ -280,7 +280,7 @@ pub trait TypedEnv: Env {
params: &CreateParams<T, Args, C>,
) -> Result<T::AccountId>
where
T: EnvTypes,
T: Environment,
Args: scale::Encode;
/// Restores a smart contract tombstone.
......@@ -295,7 +295,7 @@ pub trait TypedEnv: Env {
rent_allowance: T::Balance,
filtered_keys: &[Key],
) where
T: EnvTypes;
T: Environment;
/// Terminates a smart contract.
///
......@@ -304,7 +304,7 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_env::terminate_contract`]
fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> !
where
T: EnvTypes;
T: Environment;
/// Transfers value from the contract to the destination account ID.
///
......@@ -313,7 +313,7 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_env::transfer`]
fn transfer<T>(&mut self, destination: T::AccountId, value: T::Balance) -> Result<()>
where
T: EnvTypes;
T: Environment;
/// Returns a random hash seed.
///
......@@ -322,5 +322,5 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_env::random`]
fn random<T>(&mut self, subject: &[u8]) -> Result<T::Hash>
where
T: EnvTypes;
T: Environment;
}
......@@ -23,8 +23,8 @@ use crate::{
},
ExecutionInput,
},
EnvError,
EnvTypes,
Environment,
Error,
};
use core::marker::PhantomData;
......@@ -32,7 +32,7 @@ use core::marker::PhantomData;
#[derive(Debug)]
pub struct CallParams<E, Args, R>
where
E: EnvTypes,
E: Environment,
{
/// The account ID of the to-be-called smart contract.
callee: E::AccountId,
......@@ -54,7 +54,7 @@ where
)]
impl<E, Args, R> CallParams<E, Args, R>
where
E: EnvTypes,
E: Environment,
{
/// Returns the account ID of the called contract instance.
#[inline]
......@@ -83,7 +83,7 @@ where