pub trait Ext: Sealed {
    type T: Config;

Show 39 methods // Required methods fn call( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, to: <Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, input_data: Vec<u8>, allows_reentry: bool ) -> Result<ExecReturnValue, ExecError>; fn delegate_call( &mut self, code: <Self::T as Config>::Hash, input_data: Vec<u8> ) -> Result<ExecReturnValue, ExecError>; fn instantiate( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, code: <Self::T as Config>::Hash, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, input_data: Vec<u8>, salt: &[u8] ) -> Result<(<Self::T as Config>::AccountId, ExecReturnValue), ExecError>; fn terminate( &mut self, beneficiary: &<Self::T as Config>::AccountId ) -> Result<(), DispatchError>; fn transfer( &mut self, to: &<Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance ) -> DispatchResult; fn get_storage(&mut self, key: &Key<Self::T>) -> Option<Vec<u8>>; fn get_storage_size(&mut self, key: &Key<Self::T>) -> Option<u32>; fn set_storage( &mut self, key: &Key<Self::T>, value: Option<Vec<u8>>, take_old: bool ) -> Result<WriteOutcome, DispatchError>; fn caller(&self) -> Origin<Self::T>; fn is_contract(&self, address: &<Self::T as Config>::AccountId) -> bool; fn code_hash( &self, address: &<Self::T as Config>::AccountId ) -> Option<<Self::T as Config>::Hash>; fn own_code_hash(&mut self) -> &<Self::T as Config>::Hash; fn caller_is_origin(&self) -> bool; fn caller_is_root(&self) -> bool; fn address(&self) -> &<Self::T as Config>::AccountId; fn balance( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance; fn value_transferred( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance; fn now(&self) -> &<<Self::T as Config>::Time as Time>::Moment; fn minimum_balance( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance; fn random( &self, subject: &[u8] ) -> (<Self::T as Config>::Hash, BlockNumberFor<Self::T>); fn deposit_event( &mut self, topics: Vec<<Self::T as Config>::Hash>, data: Vec<u8> ); fn block_number(&self) -> BlockNumberFor<Self::T>; fn max_value_size(&self) -> u32; fn get_weight_price( &self, weight: Weight ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance; fn schedule(&self) -> &Schedule<Self::T>; fn gas_meter(&self) -> &GasMeter<Self::T>; fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>; fn charge_storage(&mut self, diff: &Diff); fn append_debug_buffer(&mut self, msg: &str) -> bool; fn call_runtime( &self, call: <Self::T as Config>::RuntimeCall ) -> DispatchResultWithPostInfo; 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 set_code_hash( &mut self, hash: <Self::T as Config>::Hash ) -> Result<(), DispatchError>; fn reentrance_count(&self) -> u32; fn account_reentrance_count( &self, account_id: &<Self::T as Config>::AccountId ) -> u32; fn nonce(&mut self) -> u64; fn add_delegate_dependency( &mut self, code_hash: <Self::T as Config>::Hash ) -> Result<(), DispatchError>; fn remove_delegate_dependency( &mut self, code_hash: &<Self::T as Config>::Hash ) -> Result<(), DispatchError>;
}
Expand description

An interface that provides access to the external environment in which the smart-contract is executed.

This interface is specialized to an account of the executing code, so all operations are implicitly performed on that account.

Note

This trait is sealed and cannot be implemented by downstream crates.

Required Associated Types§

Required Methods§

source

fn call( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, to: <Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, input_data: Vec<u8>, allows_reentry: bool ) -> Result<ExecReturnValue, ExecError>

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

Returns the code size of the called contract.

source

fn delegate_call( &mut self, code: <Self::T as Config>::Hash, input_data: Vec<u8> ) -> Result<ExecReturnValue, ExecError>

Execute code in the current frame.

Returns the code size of the called contract.

source

fn instantiate( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, code: <Self::T as Config>::Hash, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance, input_data: Vec<u8>, salt: &[u8] ) -> Result<(<Self::T as Config>::AccountId, ExecReturnValue), ExecError>

Instantiate a contract from the given code.

Returns the original code size of the called contract. The newly created account will be associated with code. value specifies the amount of value transferred from the caller to the newly created account.

source

fn terminate( &mut self, beneficiary: &<Self::T as Config>::AccountId ) -> Result<(), DispatchError>

Transfer all funds to beneficiary and delete the contract.

Since this function removes the self contract eagerly, if succeeded, no further actions should be performed on this Ext instance.

This function will fail if the same contract is present on the contract call stack.

source

fn transfer( &mut self, to: &<Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance ) -> DispatchResult

Transfer some amount of funds into the specified account.

source

fn get_storage(&mut self, key: &Key<Self::T>) -> 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<Self::T>) -> 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<Self::T>, 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 caller(&self) -> Origin<Self::T>

Returns the caller.

source

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

Check if a contract lives at the specified address.

source

fn code_hash( &self, address: &<Self::T as Config>::AccountId ) -> Option<<Self::T as Config>::Hash>

Returns the code hash of the contract for the given address.

Returns None if the address does not belong to a contract.

source

fn own_code_hash(&mut self) -> &<Self::T as Config>::Hash

Returns the code hash of the contract being executed.

source

fn caller_is_origin(&self) -> bool

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

This can be checked with is_contract(self.caller()) as well. However, this function does not require any storage lookup and therefore uses less weight.

source

fn caller_is_root(&self) -> bool

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

source

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

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

source

fn balance( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance

Returns the balance of the current contract.

The value_transferred is already added.

source

fn value_transferred( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance

Returns the value transferred along with this call.

source

fn now(&self) -> &<<Self::T as Config>::Time as Time>::Moment

Returns a reference to the timestamp of the current block

source

fn minimum_balance( &self ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance

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

source

fn random( &self, subject: &[u8] ) -> (<Self::T as Config>::Hash, BlockNumberFor<Self::T>)

Returns a random number for the current block with the given subject.

source

fn deposit_event( &mut self, topics: Vec<<Self::T as Config>::Hash>, data: Vec<u8> )

Deposit an event with the given topics.

There should not be any duplicates in topics.

source

fn block_number(&self) -> BlockNumberFor<Self::T>

Returns the current block number.

source

fn max_value_size(&self) -> u32

Returns the maximum allowed size of a storage item.

source

fn get_weight_price( &self, weight: Weight ) -> <<Self::T as Config>::Currency as Inspect<<Self::T as Config>::AccountId>>::Balance

Returns the price for the specified amount of weight.

source

fn schedule(&self) -> &Schedule<Self::T>

Get a reference to the schedule used by the current call.

source

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

Get an immutable reference to the nested gas meter.

source

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

Get a mutable reference to the nested gas meter.

source

fn charge_storage(&mut self, diff: &Diff)

Charges diff from the meter.

source

fn append_debug_buffer(&mut self, msg: &str) -> bool

Append a string to the debug buffer.

It is added as-is without any additional new line.

This is a no-op if debug message recording is disabled which is always the case when the code is executing on-chain.

Returns true if debug message recording is enabled. Otherwise false is returned.

source

fn call_runtime( &self, call: <Self::T as Config>::RuntimeCall ) -> DispatchResultWithPostInfo

Call some dispatchable and return the result.

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 set_code_hash( &mut self, hash: <Self::T as Config>::Hash ) -> Result<(), DispatchError>

Sets new code hash for existing contract.

source

fn reentrance_count(&self) -> u32

Returns the number of times the currently executing contract exists on the call stack in addition to the calling instance. A value of 0 means no reentrancy.

source

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

Returns the number of times the specified contract exists on the call stack. Delegated calls are not calculated as separate entrance. A value of 0 means it does not exist on the call stack.

source

fn nonce(&mut self) -> u64

Returns a nonce that is incremented for every instantiated contract.

source

fn add_delegate_dependency( &mut self, code_hash: <Self::T as Config>::Hash ) -> Result<(), DispatchError>

Adds a delegate dependency to [ContractInfo]’s delegate_dependencies field.

This ensures that the delegated contract is not removed while it is still in use. It increases the reference count of the code hash and charges a fraction (see Config::CodeHashLockupDepositPercent) of the code deposit.

Errors
source

fn remove_delegate_dependency( &mut self, code_hash: &<Self::T as Config>::Hash ) -> Result<(), DispatchError>

Removes a delegate dependency from [ContractInfo]’s delegate_dependencies field.

This is the counterpart of Self::add_delegate_dependency. It decreases the reference count and refunds the deposit that was charged by Self::add_delegate_dependency.

Errors

Implementors§