Trait pallet_revive::chain_extension::Ext
source · pub trait Ext: Sealed {
type T: Config;
Show 52 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,
gas_limit: Weight,
deposit_limit: U256,
address: H160,
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 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 origin(&self) -> &Origin<Self::T>;
fn is_contract(&self, address: &H160) -> bool;
fn code_hash(&self, address: &H160) -> H256;
fn code_size(&self, address: &H160) -> U256;
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 block_hash(&self, block_number: U256) -> Option<H256>;
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§
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 delegate_call(
&mut self,
gas_limit: Weight,
deposit_limit: U256,
address: H160,
input_data: Vec<u8>,
) -> Result<(), ExecError>
fn delegate_call( &mut self, gas_limit: Weight, deposit_limit: U256, address: H160, input_data: Vec<u8>, ) -> Result<(), ExecError>
Execute code in the current frame.
Returns the code size of the called contract.
sourcefn 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 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.
sourcefn terminate(&mut self, beneficiary: &H160) -> DispatchResult
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.
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 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 is_contract(&self, address: &H160) -> bool
fn is_contract(&self, address: &H160) -> bool
Check if a contract lives at the specified 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) -> U256
fn code_size(&self, address: &H160) -> U256
Returns the code size of the contract at the given address
or zero.
sourcefn own_code_hash(&mut self) -> &H256
fn own_code_hash(&mut self) -> &H256
Returns the code hash of the contract being executed.
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.
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.
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 get_immutable_data(
&mut self,
) -> Result<BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>, DispatchError>
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.
sourcefn set_immutable_data(
&mut self,
data: BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>,
) -> Result<(), DispatchError>
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.
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.
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 charge_storage(&mut self, diff: &Diff)
fn charge_storage(&mut self, diff: &Diff)
Charges diff
from the meter.
sourcefn append_debug_buffer(&mut self, msg: &str) -> bool
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.
sourcefn debug_buffer_enabled(&self) -> bool
fn debug_buffer_enabled(&self) -> bool
Returns true
if debug message recording is enabled. Otherwise false
is returned.
sourcefn call_runtime(
&self,
call: <Self::T as Config>::RuntimeCall,
) -> DispatchResultWithPostInfo
fn call_runtime( &self, call: <Self::T as Config>::RuntimeCall, ) -> DispatchResultWithPostInfo
Call some dispatchable and return the result.
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 set_code_hash(&mut self, hash: H256) -> DispatchResult
fn set_code_hash(&mut self, hash: H256) -> DispatchResult
Sets new code hash and immutable data for an existing contract.
sourcefn increment_refcount(code_hash: H256) -> DispatchResult
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
.
sourcefn decrement_refcount(code_hash: H256)
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.
sourcefn lock_delegate_dependency(&mut self, code_hash: H256) -> DispatchResult
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
sourcefn unlock_delegate_dependency(&mut self, code_hash: &H256) -> DispatchResult
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
sourcefn locked_delegate_dependencies_count(&mut self) -> usize
fn locked_delegate_dependencies_count(&mut self) -> usize
Returns the number of locked delegate dependencies.
Note: Requires &mut self to access the contract info.
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.