#[cfg(feature = "unstable-hostfn")]
use crate::call::{
ConstructorReturnType,
CreateParams,
FromAddr,
LimitParamsV2,
};
use crate::{
call::{
utils::DecodeMessageResult,
Call,
CallParams,
DelegateCall,
},
event::Event,
hash::{
CryptoHash,
HashOutput,
},
DecodeDispatch,
DispatchError,
Result,
};
#[cfg(feature = "unstable-hostfn")]
use ink_primitives::reflect::ScaleEncoding;
use ink_primitives::{
reflect::{
AbiDecodeWith,
AbiEncodeWith,
},
types::Environment,
Address,
SolEncode,
H256,
U256,
};
use ink_storage_traits::Storable;
pub use pallet_revive_uapi::ReturnFlags;
pub trait EnvBackend {
fn set_contract_storage<K, V>(&mut self, key: &K, value: &V) -> Option<u32>
where
K: scale::Encode,
V: Storable;
fn get_contract_storage<K, R>(&mut self, key: &K) -> Result<Option<R>>
where
K: scale::Encode,
R: Storable;
#[cfg(feature = "unstable-hostfn")]
fn take_contract_storage<K, R>(&mut self, key: &K) -> Result<Option<R>>
where
K: scale::Encode,
R: Storable;
#[cfg(feature = "unstable-hostfn")]
fn contains_contract_storage<K>(&mut self, key: &K) -> Option<u32>
where
K: scale::Encode;
#[cfg(feature = "unstable-hostfn")]
fn clear_contract_storage<K>(&mut self, key: &K) -> Option<u32>
where
K: scale::Encode;
fn decode_input<T>(&mut self) -> core::result::Result<T, DispatchError>
where
T: DecodeDispatch;
#[cfg(not(feature = "std"))]
fn return_value<R>(&mut self, flags: ReturnFlags, return_value: &R) -> !
where
R: scale::Encode;
#[cfg(feature = "std")]
fn return_value<R>(&mut self, flags: ReturnFlags, return_value: &R)
where
R: scale::Encode;
fn return_value_solidity<R>(&mut self, flags: ReturnFlags, return_value: &R) -> !
where
R: for<'a> SolEncode<'a>;
fn hash_bytes<H>(&mut self, input: &[u8], output: &mut <H as HashOutput>::Type)
where
H: CryptoHash;
fn hash_encoded<H, T>(&mut self, input: &T, output: &mut <H as HashOutput>::Type)
where
H: CryptoHash,
T: scale::Encode;
fn ecdsa_recover(
&mut self,
signature: &[u8; 65],
message_hash: &[u8; 32],
output: &mut [u8; 33],
) -> Result<()>;
#[cfg(feature = "unstable-hostfn")]
fn ecdsa_to_eth_address(
&mut self,
pubkey: &[u8; 33],
output: &mut [u8; 20],
) -> Result<()>;
#[cfg(feature = "unstable-hostfn")]
fn sr25519_verify(
&mut self,
signature: &[u8; 64],
message: &[u8],
pub_key: &[u8; 32],
) -> Result<()>;
#[cfg(feature = "unstable-hostfn")]
fn call_chain_extension<I, T, E, ErrorCode, F, D>(
&mut self,
id: u32,
input: &I,
status_to_result: F,
decode_to_result: D,
) -> ::core::result::Result<T, E>
where
I: scale::Encode,
T: scale::Decode,
E: From<ErrorCode>,
F: FnOnce(u32) -> ::core::result::Result<(), ErrorCode>,
D: FnOnce(&[u8]) -> ::core::result::Result<T, E>;
#[cfg(feature = "unstable-hostfn")]
fn set_code_hash(&mut self, code_hash: &H256) -> Result<()>;
}
pub trait TypedEnvBackend: EnvBackend {
fn caller(&mut self) -> Address;
fn transferred_value(&mut self) -> U256;
fn weight_to_fee<E: Environment>(&mut self, gas: u64) -> E::Balance;
fn block_timestamp<E: Environment>(&mut self) -> E::Timestamp;
#[cfg(feature = "unstable-hostfn")]
fn account_id<E: Environment>(&mut self) -> E::AccountId;
fn address(&mut self) -> Address;
fn balance(&mut self) -> U256;
fn block_number<E: Environment>(&mut self) -> E::BlockNumber;
#[cfg(feature = "unstable-hostfn")]
fn minimum_balance<E: Environment>(&mut self) -> E::Balance;
fn emit_event<E, Evt>(&mut self, event: Evt)
where
E: Environment,
Evt: Event;
fn invoke_contract<E, Args, R, Abi>(
&mut self,
call_data: &CallParams<E, Call, Args, R, Abi>,
) -> Result<ink_primitives::MessageResult<R>>
where
E: Environment,
Args: AbiEncodeWith<Abi>,
R: AbiDecodeWith<Abi> + DecodeMessageResult<Abi>;
fn invoke_contract_delegate<E, Args, R, Abi>(
&mut self,
call_data: &CallParams<E, DelegateCall, Args, R, Abi>,
) -> Result<ink_primitives::MessageResult<R>>
where
E: Environment,
Args: AbiEncodeWith<Abi>,
R: AbiDecodeWith<Abi> + DecodeMessageResult<Abi>;
#[cfg(feature = "unstable-hostfn")]
fn instantiate_contract<E, ContractRef, Args, R>(
&mut self,
params: &CreateParams<E, ContractRef, LimitParamsV2, Args, R>,
) -> Result<
ink_primitives::ConstructorResult<
<R as ConstructorReturnType<ContractRef>>::Output,
>,
>
where
E: Environment,
ContractRef: FromAddr + crate::ContractReverseReference,
<ContractRef as crate::ContractReverseReference>::Type:
crate::reflect::ContractConstructorDecoder,
Args: AbiEncodeWith<ScaleEncoding>,
R: ConstructorReturnType<ContractRef>;
#[cfg(feature = "unstable-hostfn")]
fn terminate_contract(&mut self, beneficiary: Address) -> !;
fn transfer<E>(&mut self, destination: Address, value: U256) -> Result<()>
where
E: Environment;
#[allow(clippy::wrong_self_convention)]
#[cfg(feature = "unstable-hostfn")]
fn is_contract(&mut self, account: &Address) -> bool;
#[cfg(feature = "unstable-hostfn")]
fn caller_is_origin<E>(&mut self) -> bool
where
E: Environment;
#[cfg(feature = "unstable-hostfn")]
fn caller_is_root<E>(&mut self) -> bool
where
E: Environment;
fn code_hash(&mut self, account: &Address) -> Result<H256>;
#[cfg(feature = "unstable-hostfn")]
fn own_code_hash(&mut self) -> Result<H256>;
#[cfg(feature = "unstable-hostfn")]
fn call_runtime<E, Call>(&mut self, call: &Call) -> Result<()>
where
E: Environment,
Call: scale::Encode;
#[cfg(feature = "unstable-hostfn")]
fn xcm_execute<E, Call>(&mut self, msg: &xcm::VersionedXcm<Call>) -> Result<()>
where
E: Environment,
Call: scale::Encode;
#[cfg(feature = "unstable-hostfn")]
fn xcm_send<E, Call>(
&mut self,
dest: &xcm::VersionedLocation,
msg: &xcm::VersionedXcm<Call>,
) -> Result<xcm::v4::XcmHash>
where
E: Environment,
Call: scale::Encode;
}