Trait pallet_contracts::chain_extension::Ext
source · pub trait Ext: Sealed {
type T: Config;
Show 36 methods
// Required methods
fn call(
&mut self,
gas_limit: Weight,
deposit_limit: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance,
to: <Self::T as Config>::AccountId,
value: <<Self::T as Config>::Currency as Currency<<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 Currency<<Self::T as Config>::AccountId>>::Balance,
code: <Self::T as Config>::Hash,
value: <<Self::T as Config>::Currency as Currency<<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 Currency<<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 Currency<<Self::T as Config>::AccountId>>::Balance;
fn value_transferred(
&self
) -> <<Self::T as Config>::Currency as Currency<<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 Currency<<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 Currency<<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 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;
}
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: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance,
to: <Self::T as Config>::AccountId,
value: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance,
input_data: Vec<u8>,
allows_reentry: bool
) -> Result<ExecReturnValue, ExecError>
fn call( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance, to: <Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Currency<<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.
sourcefn delegate_call(
&mut self,
code: <Self::T as Config>::Hash,
input_data: Vec<u8>
) -> Result<ExecReturnValue, ExecError>
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.
sourcefn instantiate(
&mut self,
gas_limit: Weight,
deposit_limit: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance,
code: <Self::T as Config>::Hash,
value: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance,
input_data: Vec<u8>,
salt: &[u8]
) -> Result<(<Self::T as Config>::AccountId, ExecReturnValue), ExecError>
fn instantiate( &mut self, gas_limit: Weight, deposit_limit: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance, code: <Self::T as Config>::Hash, value: <<Self::T as Config>::Currency as Currency<<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.
sourcefn terminate(
&mut self,
beneficiary: &<Self::T as Config>::AccountId
) -> Result<(), DispatchError>
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.
sourcefn transfer(
&mut self,
to: &<Self::T as Config>::AccountId,
value: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
) -> DispatchResult
fn transfer( &mut self, to: &<Self::T as Config>::AccountId, value: <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance ) -> DispatchResult
Transfer some amount of funds into the specified account.
sourcefn get_storage(&mut self, key: &Key<Self::T>) -> Option<Vec<u8>>
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.
sourcefn get_storage_size(&mut self, key: &Key<Self::T>) -> Option<u32>
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.
sourcefn set_storage(
&mut self,
key: &Key<Self::T>,
value: Option<Vec<u8>>,
take_old: bool
) -> Result<WriteOutcome, DispatchError>
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.
sourcefn is_contract(&self, address: &<Self::T as Config>::AccountId) -> bool
fn is_contract(&self, address: &<Self::T as Config>::AccountId) -> bool
Check if a contract lives at the specified address
.
sourcefn code_hash(
&self,
address: &<Self::T as Config>::AccountId
) -> Option<<Self::T as Config>::Hash>
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.
sourcefn own_code_hash(&mut self) -> &<Self::T as Config>::Hash
fn own_code_hash(&mut self) -> &<Self::T as Config>::Hash
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 address(&self) -> &<Self::T as Config>::AccountId
fn address(&self) -> &<Self::T as Config>::AccountId
Returns a reference to the account id of the current contract.
sourcefn balance(
&self
) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
fn balance( &self ) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
Returns the balance of the current contract.
The value_transferred
is already added.
sourcefn value_transferred(
&self
) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
fn value_transferred( &self ) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
Returns the value transferred along with this call.
sourcefn now(&self) -> &<<Self::T as Config>::Time as Time>::Moment
fn now(&self) -> &<<Self::T as Config>::Time as Time>::Moment
Returns a reference to the timestamp of the current block
sourcefn minimum_balance(
&self
) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
fn minimum_balance( &self ) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
Returns the minimum balance that is required for creating an account.
sourcefn random(
&self,
subject: &[u8]
) -> (<Self::T as Config>::Hash, BlockNumberFor<Self::T>)
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.
sourcefn deposit_event(
&mut self,
topics: Vec<<Self::T as Config>::Hash>,
data: Vec<u8>
)
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
.
sourcefn block_number(&self) -> BlockNumberFor<Self::T>
fn block_number(&self) -> BlockNumberFor<Self::T>
Returns the current block number.
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
) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
fn get_weight_price( &self, weight: Weight ) -> <<Self::T as Config>::Currency as Currency<<Self::T as Config>::AccountId>>::Balance
Returns the price for the specified amount of weight.
sourcefn schedule(&self) -> &Schedule<Self::T>
fn schedule(&self) -> &Schedule<Self::T>
Get a reference to the schedule used by the current call.
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 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 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 set_code_hash(
&mut self,
hash: <Self::T as Config>::Hash
) -> Result<(), DispatchError>
fn set_code_hash( &mut self, hash: <Self::T as Config>::Hash ) -> Result<(), DispatchError>
Sets new code hash for existing contract.
sourcefn reentrance_count(&self) -> u32
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.