referrerpolicy=no-referrer-when-downgrade

Trait pallet_revive::chain_extension::Ext

source ·
pub trait Ext: Sealed {
    type T: Config;

Show 50 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 delegate_call( &mut self, code: H256, input_data: Vec<u8>, ) -> Result<(), ExecError>; fn instantiate( &mut self, gas_limit: Weight, deposit_limit: U256, code: H256, value: U256, input_data: Vec<u8>, salt: Option<&[u8; 32]>, ) -> Result<H160, ExecError>; fn terminate(&mut self, beneficiary: &H160) -> DispatchResult; fn transfer(&mut self, to: &H160, value: U256) -> DispatchResult; 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 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 is_contract(&self, address: &H160) -> bool; fn code_hash(&self, address: &H160) -> H256; fn own_code_hash(&mut self) -> &H256; fn caller_is_origin(&self) -> bool; fn caller_is_root(&self) -> bool; fn account_id(&self) -> &<Self::T as Config>::AccountId; fn get_immutable_data( &mut self, ) -> Result<BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>, DispatchError>; fn set_immutable_data( &mut self, data: BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>, ) -> Result<(), DispatchError>; 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 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 charge_storage(&mut self, diff: &Diff); fn append_debug_buffer(&mut self, msg: &str) -> bool; fn debug_buffer_enabled(&self) -> 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 contract_info(&mut self) -> &mut ContractInfo<Self::T>; fn transient_storage(&mut self) -> &mut TransientStorage<Self::T>; fn set_code_hash(&mut self, hash: H256) -> DispatchResult; fn increment_refcount(code_hash: H256) -> DispatchResult; fn decrement_refcount(code_hash: H256); fn lock_delegate_dependency(&mut self, code_hash: H256) -> DispatchResult; fn unlock_delegate_dependency(&mut self, code_hash: &H256) -> DispatchResult; fn locked_delegate_dependencies_count(&mut self) -> usize; fn is_read_only(&self) -> bool; fn last_frame_output(&self) -> &ExecReturnValue; fn last_frame_output_mut(&mut self) -> &mut ExecReturnValue; // Provided method fn address(&self) -> H160 { ... }
}
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: 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.

source

fn delegate_call( &mut self, code: H256, input_data: Vec<u8>, ) -> Result<(), 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: U256, code: H256, value: U256, input_data: Vec<u8>, salt: Option<&[u8; 32]>, ) -> Result<H160, 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: &H160) -> DispatchResult

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: &H160, value: U256) -> DispatchResult

Transfer some amount of funds into the specified account.

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 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 is_contract(&self, address: &H160) -> bool

Check if a contract lives at the specified 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 own_code_hash(&mut self) -> &H256

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 account_id(&self) -> &<Self::T as Config>::AccountId

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

source

fn get_immutable_data( &mut self, ) -> Result<BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>, DispatchError>

Returns the immutable data of the current contract.

Returns Err(InvalidImmutableAccess) if called from a constructor.

source

fn set_immutable_data( &mut self, data: BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>, ) -> Result<(), DispatchError>

Set the the immutable data of the current contract.

Returns Err(InvalidImmutableAccess) if not called from a constructor.

Note: Requires &mut self to access the contract info.

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

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 max_value_size(&self) -> u32

Returns the maximum allowed size of a storage item.

source

fn get_weight_price(&self, weight: Weight) -> U256

Returns the price for the specified amount of weight.

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 debug_buffer_enabled(&self) -> bool

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 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 set_code_hash(&mut self, hash: H256) -> DispatchResult

Sets new code hash and immutable data for an existing contract.

source

fn increment_refcount(code_hash: H256) -> DispatchResult

Returns the number of times the specified contract exists on the call stack. Delegated calls Increment the reference count of a of a stored code by one.

§Errors

Error::CodeNotFound is returned if no stored code found having the specified code_hash.

source

fn decrement_refcount(code_hash: H256)

Decrement the reference count of a stored code by one.

§Note

A contract whose reference count dropped to zero isn’t automatically removed. A remove_code transaction must be submitted by the original uploader to do so.

source

fn lock_delegate_dependency(&mut self, code_hash: H256) -> DispatchResult

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 unlock_delegate_dependency(&mut self, code_hash: &H256) -> DispatchResult

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

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

§Errors
source

fn locked_delegate_dependencies_count(&mut self) -> usize

Returns the number of locked delegate dependencies.

Note: Requires &mut self to access the contract info.

source

fn is_read_only(&self) -> bool

Check if running in read-only context.

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.

Provided Methods§

source

fn address(&self) -> H160

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

Object Safety§

This trait is not object safe.

Implementors§