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§
Sourcefn call(
&mut self,
call_resources: &CallResources<Self::T>,
to: &H160,
value: U256,
input_data: Vec<u8>,
reentrancy: ReentrancyProtection,
read_only: bool,
) -> Result<(), ExecError>
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.
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 caller_of_caller(&self) -> Origin<Self::T>
fn caller_of_caller(&self) -> Origin<Self::T>
Returns the caller of the caller.
Sourcefn to_account_id(&self, address: &H160) -> <Self::T as Config>::AccountId
fn to_account_id(&self, address: &H160) -> <Self::T as Config>::AccountId
Returns the account id for the given address.
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, use_caller_of_caller: bool) -> bool
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.
Sourcefn caller_is_root(&self, use_caller_of_caller: bool) -> bool
fn caller_is_root(&self, use_caller_of_caller: bool) -> 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 gas_meter(&self) -> &FrameMeter<Self::T>
👎Deprecated: Renamed to frame_meter; this alias will be removed in future versions
fn gas_meter(&self) -> &FrameMeter<Self::T>
frame_meter; this alias will be removed in future versionsGet an immutable reference to the nested resource meter of the frame.
Sourcefn gas_meter_mut(&mut self) -> &mut FrameMeter<Self::T>
👎Deprecated: Renamed to frame_meter_mut; this alias will be removed in future versions
fn gas_meter_mut(&mut self) -> &mut FrameMeter<Self::T>
frame_meter_mut; this alias will be removed in future versionsGet a mutable reference to the nested resource meter of the frame.
Sourcefn frame_meter(&self) -> &FrameMeter<Self::T>
fn frame_meter(&self) -> &FrameMeter<Self::T>
Get an immutable reference to the nested resource meter of the frame.
Sourcefn frame_meter_mut(&mut self) -> &mut FrameMeter<Self::T>
fn frame_meter_mut(&mut self) -> &mut FrameMeter<Self::T>
Get a mutable reference to the nested resource meter of the frame.
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 is_delegate_call(&self) -> bool
fn is_delegate_call(&self) -> bool
Check if running as a delegate call.
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.
Sourcefn copy_code_slice(
&mut self,
buf: &mut [u8],
address: &H160,
code_offset: usize,
)
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:lenbytes of zero are written to memory - If
code_offset + buf.len()extends beyond code: Available code copied, remaining bytes are filled with zeros
Sourcefn terminate_caller(&mut self, beneficiary: &H160) -> Result<(), DispatchError>
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.
Sourcefn effective_gas_price(&self) -> U256
fn effective_gas_price(&self) -> U256
Returns the effective gas price of this transaction.
Sourcefn get_storage(&mut self, key: &Key) -> Option<Vec<u8>>
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.
Sourcefn get_storage_size(&mut self, key: &Key) -> Option<u32>
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.
Sourcefn set_storage(
&mut self,
key: &Key,
value: Option<Vec<u8>>,
take_old: bool,
) -> Result<WriteOutcome, DispatchError>
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.
Sourcefn charge_storage(&mut self, diff: &Diff) -> DispatchResult
fn charge_storage(&mut self, diff: &Diff) -> DispatchResult
Charges diff from the meter.
Provided Methods§
Sourcefn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError>
fn charge(&mut self, weight: Weight) -> Result<ChargedAmount, DispatchError>
Charges the weight meter with the given weight.
Sourcefn adjust_gas(&mut self, charged: ChargedAmount, actual_weight: Weight)
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.
Sourcefn charge_or_halt<Tok: Token<Self::T>>(
&mut self,
token: Tok,
) -> ControlFlow<Halt, ChargedAmount>
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.
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.