Trait ink_lang::reflect::ContractEnv
source · [−]pub trait ContractEnv {
type Env: Environment;
}
Expand description
Stores the used host environment type of the ink! smart contract.
Note
The used host environment can be altered using the env
configuration
parameter in the #[ink::contract]
parameters. For example if the user
wanted to use an environment type definition called MyEnvironment
they
issue the ink! smart contract as follows:
#[ink::contract(env = MyEnvironment)]
Usage: Default Environment
use ink_lang as ink;
#[ink::contract]
pub mod contract {
#[ink(storage)]
pub struct Contract {}
impl Contract {
#[ink(constructor)]
pub fn constructor() -> Self { Self {} }
#[ink(message)]
pub fn message(&self) {}
}
}
use contract::Contract;
// The following line only compiles successfully if both
// `ink_env::DefaultEnvironment` and `<Contract as ContractEnv>::Env`
// are of the same type.
const _: IsSameType<<Contract as ContractEnv>::Env> =
<IsSameType<ink_env::DefaultEnvironment>>::new();
Usage: Custom Environment
use ink_lang as ink;
pub struct CustomEnvironment {}
impl Environment for CustomEnvironment {
const MAX_EVENT_TOPICS: usize = 4;
type AccountId = <DefaultEnvironment as Environment>::AccountId;
type Balance = u64;
type Hash = <DefaultEnvironment as Environment>::Hash;
type BlockNumber = u32;
type Timestamp = u64;
type ChainExtension = <DefaultEnvironment as Environment>::ChainExtension;
}
#[ink::contract(env = super::CustomEnvironment)]
pub mod contract {
#[ink(storage)]
pub struct Contract {}
impl Contract {
#[ink(constructor)]
pub fn constructor() -> Self { Self {} }
#[ink(message)]
pub fn message(&self) {}
}
}
use contract::Contract;
// The following line only compiles successfully if both
// `CustomEnvironment` and `<Contract as ContractEnv>::Env`
// are of the same type.
const _: IsSameType<<Contract as ContractEnv>::Env> =
<IsSameType<CustomEnvironment>>::new();
fn main() {}
Required Associated Types
sourcetype Env: Environment
type Env: Environment
The environment type.