pub trait Ext: Sealed {
type T: Config;
Show 37 methods
// Required methods
fn call(
&mut self,
gas_limit: Weight,
deposit_limit: U256,
to: &H160,
value: U256,
input_data: Vec<u8>,
allows_reentry: bool,
read_only: bool,
) -> Result<(), ExecError>;
fn get_transient_storage(&self, key: &Key) -> Option<Vec<u8>>;
fn get_transient_storage_size(&self, key: &Key) -> Option<u32>;
fn set_transient_storage(
&mut self,
key: &Key,
value: Option<Vec<u8>>,
take_old: bool,
) -> Result<WriteOutcome, DispatchError>;
fn caller(&self) -> Origin<Self::T>;
fn origin(&self) -> &Origin<Self::T>;
fn code_hash(&self, address: &H160) -> H256;
fn code_size(&self, address: &H160) -> u64;
fn caller_is_origin(&self) -> bool;
fn caller_is_root(&self) -> bool;
fn account_id(&self) -> &<Self::T as Config>::AccountId;
fn balance(&self) -> U256;
fn balance_of(&self, address: &H160) -> U256;
fn value_transferred(&self) -> U256;
fn now(&self) -> U256;
fn minimum_balance(&self) -> U256;
fn deposit_event(&mut self, topics: Vec<H256>, data: Vec<u8>);
fn block_number(&self) -> U256;
fn block_hash(&self, block_number: U256) -> Option<H256>;
fn block_author(&self) -> Option<H160>;
fn gas_limit(&self) -> u64;
fn chain_id(&self) -> u64;
fn max_value_size(&self) -> u32;
fn get_weight_price(&self, weight: Weight) -> U256;
fn gas_meter(&self) -> &GasMeter<Self::T>;
fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>;
fn ecdsa_recover(
&self,
signature: &[u8; 65],
message_hash: &[u8; 32],
) -> Result<[u8; 33], ()>;
fn sr25519_verify(
&self,
signature: &[u8; 64],
message: &[u8],
pub_key: &[u8; 32],
) -> bool;
fn ecdsa_to_eth_address(&self, pk: &[u8; 33]) -> Result<[u8; 20], ()>;
fn contract_info(&mut self) -> &mut ContractInfo<Self::T>;
fn transient_storage(&mut self) -> &mut TransientStorage<Self::T>;
fn is_read_only(&self) -> bool;
fn last_frame_output(&self) -> &ExecReturnValue;
fn last_frame_output_mut(&mut self) -> &mut ExecReturnValue;
// Provided methods
fn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError> { ... }
fn adjust_gas(&mut self, charged: ChargedAmount, actual_weight: Weight) { ... }
fn address(&self) -> H160 { ... }
}
Expand description
Environment functions which are available to all pre-compiles.
Required Associated Types§
Required Methods§
Sourcefn call(
&mut self,
gas_limit: Weight,
deposit_limit: U256,
to: &H160,
value: U256,
input_data: Vec<u8>,
allows_reentry: bool,
read_only: bool,
) -> Result<(), ExecError>
fn call( &mut self, gas_limit: Weight, deposit_limit: U256, to: &H160, value: U256, input_data: Vec<u8>, allows_reentry: bool, read_only: bool, ) -> Result<(), ExecError>
Call (possibly transferring some amount of funds) into the specified account.
Returns the code size of the called contract.
Sourcefn get_transient_storage(&self, key: &Key) -> Option<Vec<u8>>
fn get_transient_storage(&self, key: &Key) -> Option<Vec<u8>>
Returns the transient storage entry of the executing account for the given key
.
Returns None
if the key
wasn’t previously set by set_transient_storage
or
was deleted.
Sourcefn get_transient_storage_size(&self, key: &Key) -> Option<u32>
fn get_transient_storage_size(&self, key: &Key) -> Option<u32>
Returns Some(len)
(in bytes) if a transient storage item exists at key
.
Returns None
if the key
wasn’t previously set by set_transient_storage
or
was deleted.
Sourcefn set_transient_storage(
&mut self,
key: &Key,
value: Option<Vec<u8>>,
take_old: bool,
) -> Result<WriteOutcome, DispatchError>
fn set_transient_storage( &mut self, key: &Key, value: Option<Vec<u8>>, take_old: bool, ) -> Result<WriteOutcome, DispatchError>
Sets the transient storage entry for the given key to the specified value. If value
is
None
then the storage entry is deleted.
Sourcefn code_hash(&self, address: &H160) -> H256
fn code_hash(&self, address: &H160) -> H256
Returns the code hash of the contract for the given address
.
If not a contract but account exists then keccak_256([])
is returned, otherwise zero
.
Sourcefn code_size(&self, address: &H160) -> u64
fn code_size(&self, address: &H160) -> u64
Returns the code size of the contract at the given address
or zero.
Sourcefn caller_is_origin(&self) -> bool
fn caller_is_origin(&self) -> bool
Check if the caller of the current contract is the origin of the whole call stack.
Sourcefn caller_is_root(&self) -> bool
fn caller_is_root(&self) -> bool
Check if the caller is origin, and this origin is root.
Sourcefn account_id(&self) -> &<Self::T as Config>::AccountId
fn account_id(&self) -> &<Self::T as Config>::AccountId
Returns a reference to the account id of the current contract.
Sourcefn balance(&self) -> U256
fn balance(&self) -> U256
Returns the balance of the current contract.
The value_transferred
is already added.
Sourcefn balance_of(&self, address: &H160) -> U256
fn balance_of(&self, address: &H160) -> U256
Returns the balance of the supplied account.
The value_transferred
is already added.
Sourcefn value_transferred(&self) -> U256
fn value_transferred(&self) -> U256
Returns the value transferred along with this call.
Sourcefn minimum_balance(&self) -> U256
fn minimum_balance(&self) -> U256
Returns the minimum balance that is required for creating an account.
Sourcefn deposit_event(&mut self, topics: Vec<H256>, data: Vec<u8>)
fn deposit_event(&mut self, topics: Vec<H256>, data: Vec<u8>)
Deposit an event with the given topics.
There should not be any duplicates in topics
.
Sourcefn block_number(&self) -> U256
fn block_number(&self) -> U256
Returns the current block number.
Sourcefn block_hash(&self, block_number: U256) -> Option<H256>
fn block_hash(&self, block_number: U256) -> Option<H256>
Returns the block hash at the given block_number
or None
if
block_number
isn’t within the range of the previous 256 blocks.
Returns the author of the current block.
Sourcefn max_value_size(&self) -> u32
fn max_value_size(&self) -> u32
Returns the maximum allowed size of a storage item.
Sourcefn get_weight_price(&self, weight: Weight) -> U256
fn get_weight_price(&self, weight: Weight) -> U256
Returns the price for the specified amount of weight.
Sourcefn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>
fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>
Get a mutable reference to the nested gas meter.
Sourcefn ecdsa_recover(
&self,
signature: &[u8; 65],
message_hash: &[u8; 32],
) -> Result<[u8; 33], ()>
fn ecdsa_recover( &self, signature: &[u8; 65], message_hash: &[u8; 32], ) -> Result<[u8; 33], ()>
Recovers ECDSA compressed public key based on signature and message hash.
Sourcefn sr25519_verify(
&self,
signature: &[u8; 64],
message: &[u8],
pub_key: &[u8; 32],
) -> bool
fn sr25519_verify( &self, signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32], ) -> bool
Verify a sr25519 signature.
Sourcefn ecdsa_to_eth_address(&self, pk: &[u8; 33]) -> Result<[u8; 20], ()>
fn ecdsa_to_eth_address(&self, pk: &[u8; 33]) -> Result<[u8; 20], ()>
Returns Ethereum address from the ECDSA compressed public key.
Sourcefn contract_info(&mut self) -> &mut ContractInfo<Self::T>
fn contract_info(&mut self) -> &mut ContractInfo<Self::T>
Tests sometimes need to modify and inspect the contract info directly.
Sourcefn transient_storage(&mut self) -> &mut TransientStorage<Self::T>
fn transient_storage(&mut self) -> &mut TransientStorage<Self::T>
Get a mutable reference to the transient storage. Useful in benchmarks when it is sometimes necessary to modify and inspect the transient storage directly.
Sourcefn is_read_only(&self) -> bool
fn is_read_only(&self) -> bool
Check if running in read-only context.
Sourcefn last_frame_output(&self) -> &ExecReturnValue
fn last_frame_output(&self) -> &ExecReturnValue
Returns an immutable reference to the output of the last executed call frame.
Sourcefn last_frame_output_mut(&mut self) -> &mut ExecReturnValue
fn last_frame_output_mut(&mut self) -> &mut ExecReturnValue
Returns a mutable reference to the output of the last executed call frame.
Provided Methods§
Sourcefn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError>
fn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError>
Charges the gas meter with the given weight.