Struct pallet_contracts::pallet::Pallet [−][src]
pub struct Pallet<T>(_);
Expand description
The pallet implementing the on-chain logic.
Implementations
Makes a call to an account, optionally transferring some balance.
- If the account is a smart-contract account, the associated code will be executed and any value will be transferred.
- If the account is a regular account, any value will be transferred.
- If no account exists and the call value is not less than
existential_deposit
, a regular account will be created and any value will be transferred.
Instantiates a new contract from the supplied code
optionally transferring
some balance.
This is the only function that can deploy new code to the chain.
Parameters
endowment
: The balance to transfer from theorigin
to the newly created contract.gas_limit
: The gas limit enforced when executing the constructor.code
: The contract code to deploy in raw bytes.data
: The input data to pass to the contract constructor.salt
: Used for the address derivation. SeePallet::contract_address
.
Instantiation is executed as follows:
- The supplied
code
is instrumented, deployed, and acode_hash
is created for that code. - If the
code_hash
already exists on the chain the underlyingcode
will be shared. - The destination address is computed based on the sender, code_hash and the salt.
- The smart-contract account is created at the computed address.
- The
endowment
is transferred to the new account. - The
deploy
function is executed in the context of the newly-created account.
Instantiates a contract from a previously deployed wasm binary.
This function is identical to Self::instantiate_with_code
but without the
code deployment step. Instead, the code_hash
of an on-chain deployed wasm binary
must be supplied.
pub fn claim_surcharge(
origin: OriginFor<T>,
dest: T::AccountId,
aux_sender: Option<T::AccountId>
) -> DispatchResultWithPostInfo
pub fn claim_surcharge(
origin: OriginFor<T>,
dest: T::AccountId,
aux_sender: Option<T::AccountId>
) -> DispatchResultWithPostInfo
Allows block producers to claim a small reward for evicting a contract. If a block producer fails to do so, a regular users will be allowed to claim the reward.
In case of a successful eviction no fees are charged from the sender. However, the reward is capped by the total amount of rent that was paid by the contract while it was alive.
If contract is not evicted as a result of this call, Error::ContractNotEvictable
is returned and the sender is not eligible for the reward.
Perform a call to a specified contract.
This function is similar to Self::call
, but doesn’t perform any address lookups
and better suitable for calling directly from Rust.
Note
debug
should only ever be set to true
when executing as an RPC because
it adds allocations and could be abused to drive the runtime into an OOM panic.
If set to true
it returns additional human readable debugging information.
It returns the execution result and the amount of used weight.
pub fn bare_instantiate(
origin: T::AccountId,
endowment: <<T as Config>::Currency as Currency<<T as Config>::AccountId>>::Balance,
gas_limit: Weight,
code: Code<<T as Config>::Hash>,
data: Vec<u8>,
salt: Vec<u8>,
compute_projection: bool,
debug: bool
) -> ContractInstantiateResult<T::AccountId, T::BlockNumber>
pub fn bare_instantiate(
origin: T::AccountId,
endowment: <<T as Config>::Currency as Currency<<T as Config>::AccountId>>::Balance,
gas_limit: Weight,
code: Code<<T as Config>::Hash>,
data: Vec<u8>,
salt: Vec<u8>,
compute_projection: bool,
debug: bool
) -> ContractInstantiateResult<T::AccountId, T::BlockNumber>
Instantiate a new contract.
This function is similar to Self::instantiate
, but doesn’t perform any address lookups
and better suitable for calling directly from Rust.
It returns the execution result, account id and the amount of used weight.
If compute_projection
is set to true
the result also contains the rent projection.
This is optional because some non trivial and stateful work is performed to compute
the projection. See Self::rent_projection
.
Note
debug
should only ever be set to true
when executing as an RPC because
it adds allocations and could be abused to drive the runtime into an OOM panic.
If set to true
it returns additional human readable debugging information.
Query storage of a specified contract under a specified key.
Query how many blocks the contract stays alive given that the amount endowment and consumed storage does not change.
Determine the address of a contract,
This is the address generation function used by contract instantiation. Its result is only dependend on its inputs. It can therefore be used to reliably predict the address of a contract. This is akin to the formular of eth’s CREATE2 opcode. There is no CREATE equivalent because CREATE2 is strictly more powerful.
Formula: hash(deploying_address ++ code_hash ++ salt)
Subsistence threshold is the extension of the minimum balance (aka existential deposit) by the tombstone deposit, required for leaving a tombstone.
Rent or any contract initiated balance transfer mechanism cannot make the balance lower than the subsistence threshold in order to guarantee that a tombstone is created.
The only way to completely kill a contract without a tombstone is calling seal_terminate
.
The in-memory size in bytes of the data structure associated with each contract.
The data structure is also put into storage for each contract. The in-storage size is never larger than the in-memory representation and usually smaller due to compact encoding and lack of padding.
Note
This returns the in-memory size because the in-storage size (SCALE encoded) cannot be efficiently determined. Treat this as an upper bound of the in-storage size.
Trait Implementations
impl<T: Config> Benchmarking<BenchmarkResults> for Pallet<T> where
T: Config,
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
impl<T: Config> Benchmarking<BenchmarkResults> for Pallet<T> where
T: Config,
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
Get the benchmarks available for this pallet. Generally there is one benchmark per extrinsic, so these are sometimes just called “extrinsics”. Read more
fn run_benchmark(
extrinsic: &[u8],
c: &[(BenchmarkParameter, u32)],
whitelist: &[TrackedStorageKey],
verify: bool,
internal_repeats: u32
) -> Result<Vec<BenchmarkResults>, &'static str>
fn run_benchmark(
extrinsic: &[u8],
c: &[(BenchmarkParameter, u32)],
whitelist: &[TrackedStorageKey],
verify: bool,
internal_repeats: u32
) -> Result<Vec<BenchmarkResults>, &'static str>
Run the benchmarks for this pallet.
Returns the current storage version as supported by the pallet.
Returns the on-chain storage version of the pallet as stored in the storage.
The block is being initialized. Implement to have something happen. Read more
Perform a module upgrade. Read more
The block is being finalized. Implement to have something happen.
This will be run when the block is being finalized (before on_finalize
).
Implement to have something happen using the remaining weight.
Will not fire if the remaining weight is 0.
Return the weight used, the hook will subtract it from current weight used
and pass the result to the next on_idle
hook if it exists. Read more
Execute some pre-checks prior to a runtime upgrade. Read more
Execute some post-checks after a runtime upgrade. Read more
Implementing this function on a module allows you to perform long-running tasks that make (by default) validators generate transactions that feed results of those long-running computations back on chain. Read more
Run integrity test. Read more
Run integrity test. Read more
impl<T: Config> OffchainWorker<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
impl<T: Config> OffchainWorker<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
This function is being called after every block import (when fully synced). Read more
impl<T: Config> OnFinalize<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
impl<T: Config> OnFinalize<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
The block is being finalized. Implement to have something happen. Read more
Something that should happen at genesis.
The block is being finalized.
Implement to have something happen in case there is leftover weight.
Check the passed remaining_weight
to make sure it is high enough to allow for
your pallet’s extra computation. Read more
impl<T: Config> OnInitialize<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
impl<T: Config> OnInitialize<<T as Config>::BlockNumber> for Pallet<T> where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
The block is being initialized. Implement to have something happen. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Pallet<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Pallet<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Generate a storage key unique to this runtime upgrade. Read more
Get temporary storage data written by Self::set_temp_storage
. Read more
Write some temporary data to a specific storage that can be read (potentially in
post-upgrade hook) via Self::get_temp_storage
. Read more
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
type Output = T
type Output = T
Should always be Self
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V
impl<T> MaybeDebug for T where
T: Debug,
impl<T> MaybeDebug for T where
T: Debug,