Struct frame_system::pallet::Pallet
source · [−]pub struct Pallet<T>(_);
Expand description
The pallet implementing the on-chain logic.
Implementations
A dispatch that will fill the block weight up to the given ratio.
Set the number of pages in the WebAssembly environment’s heap.
Set the new runtime code.
O(C + S)
whereC
length ofcode
andS
complexity ofcan_set_code
- 1 call to
can_set_code
:O(S)
(callssp_io::misc::runtime_version
which is expensive). - 1 storage write (codec
O(C)
). - 1 digest item.
- 1 event. The weight of this function is dependent on the runtime, but generally this is very expensive. We will treat this as a full block.
pub fn set_code_without_checks(
origin: OriginFor<T>,
code: Vec<u8>
) -> DispatchResultWithPostInfo
pub fn set_code_without_checks(
origin: OriginFor<T>,
code: Vec<u8>
) -> DispatchResultWithPostInfo
Set some items of storage.
Kill some items from storage.
pub fn kill_prefix(
origin: OriginFor<T>,
prefix: Key,
_subkeys: u32
) -> DispatchResultWithPostInfo
pub fn kill_prefix(
origin: OriginFor<T>,
prefix: Key,
_subkeys: u32
) -> DispatchResultWithPostInfo
Kill all storage items with a key that starts with the given prefix.
NOTE: We rely on the Root origin to provide us the number of subkeys under the prefix we are removing to accurately calculate the weight of this function.
pub fn remark_with_event(
origin: OriginFor<T>,
remark: Vec<u8>
) -> DispatchResultWithPostInfo
pub fn remark_with_event(
origin: OriginFor<T>,
remark: Vec<u8>
) -> DispatchResultWithPostInfo
pub fn account<KArg>(k: KArg) -> AccountInfo<T::Index, T::AccountData> where
KArg: EncodeLike<T::AccountId>,
pub fn account<KArg>(k: KArg) -> AccountInfo<T::Index, T::AccountData> where
KArg: EncodeLike<T::AccountId>,
The full account information for a particular account ID.
The current weight for the block.
Map of block numbers to block hashes.
The current block number being processed. Set by execute_block
.
The number of events in the Events<T>
list.
pub fn event_topics<KArg>(k: KArg) -> Vec<(T::BlockNumber, u32)>ⓘ where
KArg: EncodeLike<T::Hash>,
pub fn event_topics<KArg>(k: KArg) -> Vec<(T::BlockNumber, u32)>ⓘ where
KArg: EncodeLike<T::Hash>,
Mapping between a topic (represented by T::Hash) and a vector of indexes
of events in the <Events<T>>
list.
All topic vectors have deterministic storage locations depending on the topic. This allows light-clients to leverage the changes trie storage tracking mechanism and in case of changes fetch the list of events of interest.
The value has the type (T::BlockNumber, EventIndex)
because if we used only just
the EventIndex
then in case if the topic has the same contents on the next block
no notification will be triggered thus the event might be lost.
Write code to the storage and emit related events and digest items.
Note this function almost never should be used directly. It is exposed
for OnSetCode
implementations that defer actual code being written to
the storage (for instance in case of parachains).
👎 Deprecated: Use inc_consumers
instead
Use inc_consumers
instead
Increment the reference counter on an account.
👎 Deprecated: Use dec_consumers
instead
Use dec_consumers
instead
Decrement the reference counter on an account. This MUST only be done once for every time
you called inc_consumers
on who
.
👎 Deprecated: Use consumers
instead
Use consumers
instead
The number of outstanding references for the account who
.
👎 Deprecated: Use !is_provider_required
instead
Use !is_provider_required
instead
True if the account has no outstanding references.
Increment the provider reference counter on an account.
Decrement the provider reference counter on an account.
This MUST only be done once for every time you called inc_providers
on who
.
Increment the self-sufficient reference counter on an account.
Decrement the sufficients reference counter on an account.
This MUST only be done once for every time you called inc_sufficients
on who
.
The number of outstanding provider references for the account who
.
The number of outstanding sufficient references for the account who
.
The number of outstanding provider and sufficient references for the account who
.
Increment the reference counter on an account.
The account who
’s providers
must be non-zero or this will return an error.
Decrement the reference counter on an account. This MUST only be done once for every time
you called inc_consumers
on who
.
The number of outstanding references for the account who
.
True if the account has some outstanding consumer references.
True if the account has no outstanding consumer references or more than one provider.
True if the account has at least one provider reference.
Deposits an event into this block’s event record.
Deposits an event into this block’s event record adding this event to the corresponding topic indexes.
This will update storage entries that correspond to the specified topics. It is expected that light-clients could subscribe to this topics.
Gets the index of extrinsic that is currently executing.
Gets extrinsics count.
Inform the system pallet of some additional weight that should be accounted for, in the current block.
NOTE: use with extra care; this function is made public only be used for certain pallets
that need it. A runtime that does not have dynamic calls should never need this and should
stick to static weights. A typical use case for this is inner calls or smart contract calls.
Furthermore, it only makes sense to use this when it is presumably cheap to provide the
argument weight
; In other words, if this function is to be used to account for some
unknown, user provided call’s weight, it would only make sense to use it if you are sure you
can rapidly compute the weight of the inner call.
Even more dangerous is to note that this function does NOT take any action, if the new sum of block weight is more than the block weight limit. This is what the unchecked.
Another potential use-case could be for the on_initialize
and on_finalize
hooks.
pub fn initialize(
number: &T::BlockNumber,
parent_hash: &T::Hash,
digest: &Digest,
kind: InitKind
)
pub fn initialize(
number: &T::BlockNumber,
parent_hash: &T::Hash,
digest: &Digest,
kind: InitKind
)
Start the execution of a particular block.
Remove temporary “environment” entries in storage, compute the storage root and return the resulting header for this block.
Get the basic externalities for this pallet, useful for tests.
Get the current events deposited by the runtime.
NOTE: This should only be used in tests. Reading events from the runtime can have a large impact on the PoV size of a block. Users should use alternative and well bounded storage items for any behavior like this.
Get the current events deposited by the runtime.
Should only be called if you know what you are doing and outside of the runtime block execution else it can have a large impact on the PoV size of a block.
Set the block number to something in particular. Can be used as an alternative to
initialize
for tests that don’t need to bother with the other environment entries.
Sets the index of extrinsic that is currently executing.
Set the parent hash number to something in particular. Can be used as an alternative to
initialize
for tests that don’t need to bother with the other environment entries.
Set the current block weight. This should only be used in some integration tests.
Reset events. Can be used as an alternative to
initialize
for tests that don’t need to bother with the other environment entries.
Assert the given event
exists.
Assert the last event equal to the given event
.
Return the chain’s current runtime version.
Retrieve the account transaction counter from storage.
Increment a particular account’s nonce by 1.
Note what the extrinsic data of the current extrinsic index is.
This is required to be called before applying an extrinsic. The data will used
in Self::finalize
to calculate the correct extrinsics root.
To be called immediately after an extrinsic has been applied.
To be called immediately after note_applied_extrinsic
of the last extrinsic of the block
has been called.
To be called immediately after finishing the initialization of the block
(e.g., called on_initialize
for all pallets).
An account is being created.
Determine whether or not it is possible to update the code.
Checks the given code if it is a valid runtime wasm blob by instantianting it and extracting the runtime version of it. It checks that the runtime version of the old and new runtime has the same spec name and that the spec version is increasing.
Trait Implementations
type BlockNumber = <T as Config>::BlockNumber
type BlockNumber = <T as Config>::BlockNumber
Type of BlockNumber
to provide.
Returns the current block number. Read more
Returns the current storage version as supported by the pallet.
Returns the on-chain storage version of the pallet as stored in the storage.
Perform a module upgrade. Read more
Run integrity test. 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
The block is being initialized. Implement to have something happen. 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
This function is being called after every block import (when fully synced). Read more
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
The block is being initialized. Implement to have something happen. Read more
Perform a module upgrade. Read more
Name of the Rust module containing the pallet.
Version of the crate containing the pallet.
Extend the given vector by all of the pallets’ information that this type represents. Read more
fn storage_info() -> Vec<StorageInfo>ⓘ
Implement StoredMap for a simple single-item, provide-when-not-default system. This works fine for storing a single item which allows the account to continue existing as long as it’s not empty/default.
Anything more complex will need more sophisticated logic.
Get the item, or its default if it doesn’t yet exist; we make no distinction between the two. Read more
fn try_mutate_exists<R, E: From<DispatchError>>(
k: &T::AccountId,
f: impl FnOnce(&mut Option<T::AccountData>) -> Result<R, E>
) -> Result<R, E>
fn try_mutate_exists<R, E: From<DispatchError>>(
k: &T::AccountId,
f: impl FnOnce(&mut Option<T::AccountData>) -> Result<R, E>
) -> Result<R, E>
Maybe mutate the item only if an Ok
value is returned from f
. Do nothing if an Err
is
returned. It is removed or reset to default value if it has been mutated to None
Read more
Mutate the item, removing or resetting to default value if it has been mutated to None
. 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
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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
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
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
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more