referrerpolicy=no-referrer-when-downgrade

Trait Ext

Source
pub trait Ext: Sealed {
    type T: Config;

Show 49 methods // Required methods fn call( &mut self, call_resources: &CallResources<Self::T>, to: &H160, value: U256, input_data: Vec<u8>, reentrancy: ReentrancyProtection, 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 caller_of_caller(&self) -> Origin<Self::T>; fn origin(&self) -> &Origin<Self::T>; fn to_account_id(&self, address: &H160) -> <Self::T as Config>::AccountId; fn code_hash(&self, address: &H160) -> H256; fn code_size(&self, address: &H160) -> u64; fn caller_is_origin(&self, use_caller_of_caller: bool) -> bool; fn caller_is_root(&self, use_caller_of_caller: bool) -> 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) -> H160; fn gas_limit(&self) -> u64; fn chain_id(&self) -> u64; fn gas_meter(&self) -> &FrameMeter<Self::T>; fn gas_meter_mut(&mut self) -> &mut FrameMeter<Self::T>; fn frame_meter(&self) -> &FrameMeter<Self::T>; fn frame_meter_mut(&mut self) -> &mut FrameMeter<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 is_delegate_call(&self) -> bool; fn last_frame_output(&self) -> &ExecReturnValue; fn last_frame_output_mut(&mut self) -> &mut ExecReturnValue; fn copy_code_slice( &mut self, buf: &mut [u8], address: &H160, code_offset: usize, ); fn terminate_caller( &mut self, beneficiary: &H160, ) -> Result<(), DispatchError>; fn effective_gas_price(&self) -> U256; fn gas_left(&self) -> u64; fn get_storage(&mut self, key: &Key) -> Option<Vec<u8>>; fn get_storage_size(&mut self, key: &Key) -> Option<u32>; fn set_storage( &mut self, key: &Key, value: Option<Vec<u8>>, take_old: bool, ) -> Result<WriteOutcome, DispatchError>; fn charge_storage(&mut self, diff: &Diff) -> DispatchResult; // Provided methods fn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError> { ... } fn adjust_gas(&mut self, charged: ChargedAmount, actual_weight: Weight) { ... } fn charge_or_halt<Tok: Token<Self::T>>( &mut self, token: Tok, ) -> ControlFlow<Halt, ChargedAmount> { ... } fn address(&self) -> H160 { ... }
}
Expand description

Environment functions which are available to all pre-compiles.

Required Associated Types§

Required Methods§

Source

fn call( &mut self, call_resources: &CallResources<Self::T>, to: &H160, value: U256, input_data: Vec<u8>, reentrancy: ReentrancyProtection, read_only: bool, ) -> Result<(), ExecError>

Call (possibly transferring some amount of funds) into the specified account.

Source

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.

Source

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.

Source

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.

Source

fn caller(&self) -> Origin<Self::T>

Returns the caller.

Source

fn caller_of_caller(&self) -> Origin<Self::T>

Returns the caller of the caller.

Source

fn origin(&self) -> &Origin<Self::T>

Return the origin of the whole call stack.

Source

fn to_account_id(&self, address: &H160) -> <Self::T as Config>::AccountId

Returns the account id for the given address.

Source

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.

Source

fn code_size(&self, address: &H160) -> u64

Returns the code size of the contract at the given address or zero.

Source

fn caller_is_origin(&self, use_caller_of_caller: bool) -> bool

Check if the caller of the current contract is the origin of the whole call stack.

Source

fn caller_is_root(&self, use_caller_of_caller: bool) -> bool

Check if the caller is origin, and this origin is root.

Source

fn account_id(&self) -> &<Self::T as Config>::AccountId

Returns a reference to the account id of the current contract.

Source

fn balance(&self) -> U256

Returns the balance of the current contract.

The value_transferred is already added.

Source

fn balance_of(&self, address: &H160) -> U256

Returns the balance of the supplied account.

The value_transferred is already added.

Source

fn value_transferred(&self) -> U256

Returns the value transferred along with this call.

Source

fn now(&self) -> U256

Returns the timestamp of the current block in seconds.

Source

fn minimum_balance(&self) -> U256

Returns the minimum balance that is required for creating an account.

Source

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.

Source

fn block_number(&self) -> U256

Returns the current block number.

Source

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.

Source

fn block_author(&self) -> H160

Returns the author of the current block.

Source

fn gas_limit(&self) -> u64

Returns the block gas limit.

Source

fn chain_id(&self) -> u64

Returns the chain id.

Source

fn gas_meter(&self) -> &FrameMeter<Self::T>

👎Deprecated: Renamed to frame_meter; this alias will be removed in future versions

Get an immutable reference to the nested resource meter of the frame.

Source

fn gas_meter_mut(&mut self) -> &mut FrameMeter<Self::T>

👎Deprecated: Renamed to frame_meter_mut; this alias will be removed in future versions

Get a mutable reference to the nested resource meter of the frame.

Source

fn frame_meter(&self) -> &FrameMeter<Self::T>

Get an immutable reference to the nested resource meter of the frame.

Source

fn frame_meter_mut(&mut self) -> &mut FrameMeter<Self::T>

Get a mutable reference to the nested resource meter of the frame.

Source

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.

Source

fn sr25519_verify( &self, signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32], ) -> bool

Verify a sr25519 signature.

Source

fn ecdsa_to_eth_address(&self, pk: &[u8; 33]) -> Result<[u8; 20], ()>

Returns Ethereum address from the ECDSA compressed public key.

Source

fn contract_info(&mut self) -> &mut ContractInfo<Self::T>

Tests sometimes need to modify and inspect the contract info directly.

Source

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.

Source

fn is_read_only(&self) -> bool

Check if running in read-only context.

Source

fn is_delegate_call(&self) -> bool

Check if running as a delegate call.

Source

fn last_frame_output(&self) -> &ExecReturnValue

Returns an immutable reference to the output of the last executed call frame.

Source

fn last_frame_output_mut(&mut self) -> &mut ExecReturnValue

Returns a mutable reference to the output of the last executed call frame.

Source

fn copy_code_slice( &mut self, buf: &mut [u8], address: &H160, code_offset: usize, )

Copies a slice of the contract’s code at address into the provided buffer.

EVM CODECOPY semantics:

  • If buf.len() = 0: Nothing happens
  • If code_offset >= code size: len bytes of zero are written to memory
  • If code_offset + buf.len() extends beyond code: Available code copied, remaining bytes are filled with zeros
Source

fn terminate_caller(&mut self, beneficiary: &H160) -> Result<(), DispatchError>

Register the caller of the current contract for destruction. Destruction happens at the end of the call stack. This is supposed to be used by the terminate precompile.

Transfer all funds to beneficiary. Contract is deleted at the end of the call stack.

This function will fail if called from constructor.

Source

fn effective_gas_price(&self) -> U256

Returns the effective gas price of this transaction.

Source

fn gas_left(&self) -> u64

The amount of gas left in eth gas units.

Source

fn get_storage(&mut self, key: &Key) -> Option<Vec<u8>>

Returns the storage entry of the executing account by the given key.

Returns None if the key wasn’t previously set by set_storage or was deleted.

Source

fn get_storage_size(&mut self, key: &Key) -> Option<u32>

Returns Some(len) (in bytes) if a storage item exists at key.

Returns None if the key wasn’t previously set by set_storage or was deleted.

Source

fn set_storage( &mut self, key: &Key, value: Option<Vec<u8>>, take_old: bool, ) -> Result<WriteOutcome, DispatchError>

Sets the storage entry by the given key to the specified value. If value is None then the storage entry is deleted.

Source

fn charge_storage(&mut self, diff: &Diff) -> DispatchResult

Charges diff from the meter.

Provided Methods§

Source

fn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError>

Charges the weight meter with the given weight.

Source

fn adjust_gas(&mut self, charged: ChargedAmount, actual_weight: Weight)

Reconcile an earlier gas charge with the actual weight consumed. This updates the current weight meter to reflect the real cost of the token.

Source

fn charge_or_halt<Tok: Token<Self::T>>( &mut self, token: Tok, ) -> ControlFlow<Halt, ChargedAmount>

Charges the weight meter with the given token or halts execution if not enough weight is left.

Source

fn address(&self) -> H160

Returns a reference to the H160 address of the current contract.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§