Struct Pallet

Source
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
Expand description

Primary Marker type for the XP pallet.

This pallet provides implementations for traits from:

§Fungible Trait Implementations

The pallet implements the following fungible-related traits:

§XP Trait Implementations

Pallet implements the core XP system traits:

§Helper Traits

Additional supporting traits:

Tuple Fields§

§0: PhantomData<(T, I)>

Implementations§

Source§

impl<T: Config<I>, I: 'static> Pallet<T, I>

XP Pallet Extrinsics includes major state mutation functions with origin authentication. Some read only functions are given for

Source

pub fn call( origin: OriginFor<T>, xp_id: XpId<T>, call: Box<<T as Config<I>>::RuntimeCall>, ) -> DispatchResult

Executes a runtime call using an XP identity as the origin.

Origin: Signed (must be the owner of the XP identity)

This extrinsic allows the owner of an XP identity to dispatch a call on its behalf. While an XP identity is not a native account, it can act as a logical origin for execution through owner authorization.

The caller must be the registered owner of the given xp_id. Upon successful verification, the provided call is dispatched with the XP identity as the signed origin.

Source

pub fn handover( origin: OriginFor<T>, xp_id: XpId<T>, new_owner: T::AccountId, ) -> DispatchResult

Transfer or handover ownership of an XP key to another account.

Origin: Signed user (must be the current XP key owner)

This extrinsic allows the current owner of an XP key to transfer ownership to another account. The call will fail if the destination account is already the owner or if the caller does not own the XP key.

On success, ownership of the XP key is transferred to the target account and an event is emitted.

Emits Event::XpOwner with the XP key and new owner.

Source

pub fn dispose( origin: OriginFor<T>, owner: T::AccountId, xp_id: XpId<T>, ) -> DispatchResult

Dispose (Reap) an XP key.

Origin: Signed user

This extrinsic allows any signed account to finalize and remove XP entries that are no longer valid.

For an XP key, it checks:

  • The key exists in storage,
  • The key is considered “dead” (does not meet minimum timestamp requirements),
  • The key has no active locks.

If all checks pass, the XP entry is reaped (removed from storage and blacklisted).

Emits Event::XpReap with each successfully reaped XP key.

Source

pub fn force_handover( origin: OriginFor<T>, owner: T::AccountId, xp_id: XpId<T>, new_owner: T::AccountId, ) -> DispatchResult

Force transfer/handover ownership of an XP key to another account.

Origin: Root only

This extrinsic allows the current owner of an XP key to transfer ownership to another account. The call will fail if the destination account is already the owner or if the caller does not own the XP key.

On success, ownership of the XP key is transferred to the target account and an event is emitted.

Emits Event::XpOwner with the XP key and new owner.

Source

pub fn force_genesis_config( origin: OriginFor<T>, field: ForceGenesisConfig<T, I>, ) -> DispatchResult

Force-update a selected genesis configuration parameter.

Origin: Root only.

This extrinsic allows privileged modification of runtime parameters that were originally defined at genesis.

The parameter to update is specified via the ForceGenesisConfig enum:

  • MinPulse - Updates the minimum pulse required for reputation effects.
  • InitXp - Updates the initial XP assigned to newly created XP entries.
  • PulseFactor - Updates the pulse stepping configuration (threshold and per_count).
  • MinTimeStamp - Updated the minimum blocks required for an XP entry to be considered alive.

For PulseFactor, the call fails with Error::LowPulseThreshold if per_count > threshold, as this would invalidate the stepping logic.

This call directly overwrites storage and emits an event containing the updated configuration variant.

Source§

impl<T: Config<I>, I: 'static> Pallet<T, I>

Public read-only functions for inspecting XP balances, reputation, and pulse progression state.

This interface exposes non-mutating functions that allow external consumers (e.g. off-chain clients, RPC layers, other pallets, UI layers, and gamification engines) to inspect XP ownership, multiplier status, reputation progress, and simulate earn_xp outcomes without modifying on-chain state.

Source

pub fn xp_state(key: &XpId<T>) -> Result<XpState<T, I>, DispatchError>

Returns the current XP state snapshot for an identity.

Combines balances, XP eligibility, and effective multiplier.

Intended for RPC responses and UI views.

Source

pub fn xp(key: &XpId<T>) -> Result<T::Xp, DispatchError>

Returns the current liquid (free, spendable) XP of the given xp_id.

This excludes reserved and locked balances.

Source

pub fn xp_keys(owner: &T::AccountId) -> Result<Vec<XpId<T>>, DispatchError>

Returns all XP IDs owned by the given owner.

Source

pub fn is_disposable(key: &XpId<T>) -> DispatchResult

Checks whether the given XP key can be safely disposed (finalized).

Source

pub fn xp_eligibility( key: &XpId<T>, ) -> Result<XpEligibility<T, I>, DispatchError>

Returns the XP eligibility state of an identity.

If XP is already active (pulse.value >= MinPulse), returns Earning.

Otherwise, computes how many additional blocks with at least one earn_xp call are required before XP starts being counted.

This calculation accounts for:

  • Current partial progression toward the next pulse increment
  • Pulse threshold
  • Progress gained per block (via earn_xp)

Note: Multiple earn_xp calls within the same block are treated as a single progression step.

Intended for RPC queries, previews, and UI interactions.

Source

pub fn xp_multiplier(key: &XpId<T>) -> Result<Option<T::Pulse>, DispatchError>

Returns the applicable XP multiplier for an identity.

Once XP is active, the multiplier is derived from the current pulse value. The multiplier can be applied at most once per block.

Returns:

  • Some(multiplier) if a multiplier is available for the next earn_xp call
  • None if no multiplier applies, which occurs when:
    • XP is not valid or active (see Self::xp_eligibility), or
    • A multiplier has already been applied in the current block

Note:

  • Subsequent earn_xp calls within the same block are unscaled.

Intended for RPC queries, previews, and UI interactions.

Source

pub fn xp_progress(key: &XpId<T>) -> Result<XpProgress<T, I>, DispatchError>

Returns the current XP progression details.

Includes the current multiplier level, progress toward the next level, and the configuration that defines how progression advances.

Intended for UI progress bars and gamified displays.

Source

pub fn earn_preview( key: &XpId<T>, raw: T::Xp, ) -> Result<XpState<T, I>, DispatchError>

Simulates an earn_xp action and returns the resulting XP state.

Executes the same logic as earn_xp without mutating storage, allowing callers to preview how an action would affect balances, XP activation, and multiplier.

Behavior:

  • If XP is not yet active, the action contributes only toward activation (no reward scaling is applied).
  • If XP is active, the input is scaled by the current multiplier (if any).
  • Progression toward the next multiplier level is updated accordingly.

The returned XpState reflects the post-action state as if the operation had been applied.

Intended for RPC queries, previews, and UI interactions.

Source

pub fn xp_last_earn(key: &XpId<T>) -> Result<BlockNumberFor<T>, DispatchError>

Returns the block number of the last earn_xp execution.

This value is used to enforce per-block rules, such as:

  • Allowing at most one multiplier application per block
  • Preventing multiple progression steps within the same block

Intended for RPC queries, previews, and UI interactions.

Source§

impl<T: Config<I>, I: 'static> Pallet<T, I>

Source

pub(crate) fn deposit_event(event: Event<T, I>)

Trait Implementations§

Source§

impl<T: Config<I>, I: 'static> BeforeAllRuntimeMigrations for Pallet<T, I>

Source§

fn before_all_runtime_migrations() -> Weight

Something that should happen before runtime migrations are executed.
Source§

impl<T: Config<I>, I: 'static> Callable<T> for Pallet<T, I>

Source§

impl<T, I> Clone for Pallet<T, I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, I> Debug for Pallet<T, I>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Config<I>, I: 'static> DiscreteAccumulator for Pallet<T, I>

Implementation of the DiscreteAccumulator trait for the XP pallet.

This trait provides an abstraction for accumulator data structures that can be incremented or decremented by discrete steps, while maintaining an internal state that can be revealed as a readable value.

The accumulator increases its value when enough fractional steps have been collected to reach the threshold. Similarly, it decreases its value when enough steps are removed, handling underflow and overflow gracefully.

Source§

type Value = <T as Config<I>>::Pulse

The value type being accumulated.

Source§

type Step = <T as Config<I>>::Pulse

The step type representing fractional progress.

Source§

type Accumulator = Accumulator<T, I>

The accumulator structure holding the current value and step count.

Source§

type Stepper = Stepper<T, I>

The stepper configuration, defining the threshold and per-step increment.

Source§

fn increment(accum: &mut Self::Accumulator, stepper: &Self::Stepper)

Increments the accumulator by the stepper’s per-count value.

When the accumulated step reaches or exceeds the threshold, the value is increased by one and the step is reduced accordingly. Handles overflow gracefully using saturating arithmetic.

Source§

fn decrement(accum: &mut Self::Accumulator, stepper: &Self::Stepper)

Decrements the accumulator by the stepper’s per-count value.

If the current step is greater than or equal to the per-count, it simply subtracts per-count from the step. Otherwise, it calculates the deficit needed to maintain a non-negative step.

If the value is > 0, subtract 1, and set step to deficit, else set step to 0.

Source§

fn reveal(accum: &Self::Accumulator) -> Self::Value

Reveals the current accumulated value from the internal state.

Returns the main value of the accumulator, ignoring the fractional step.

Source§

impl<T: Config<I>, I: 'static> DispatchViewFunction for Pallet<T, I>

Source§

fn dispatch_view_function<O: Output>( id: &ViewFunctionId, input: &mut &[u8], output: &mut O, ) -> Result<(), ViewFunctionDispatchError>

Source§

impl<T: Config<I>, I: 'static> GetStorageVersion for Pallet<T, I>

Source§

type InCodeStorageVersion = NoStorageVersionSet

This type is generated by the pallet macro. Read more
Source§

fn in_code_storage_version() -> Self::InCodeStorageVersion

Returns the in-code storage version as specified in the storage_version attribute, or [NoStorageVersionSet] if the attribute is missing.
Source§

fn on_chain_storage_version() -> StorageVersion

Returns the storage version of the pallet as last set in the actual on-chain storage.
§

fn current_storage_version() -> Self::InCodeStorageVersion

👎Deprecated: This method has been renamed to in_code_storage_version and will be removed after March 2024.
DEPRECATED: Use [Self::current_storage_version] instead. Read more
Source§

impl<T: Config<I>, I: 'static> Hooks<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

§

fn on_initialize(_n: BlockNumber) -> Weight

Block initialization hook. This is called at the very beginning of block execution. Read more
§

fn on_finalize(_n: BlockNumber)

Block finalization hook. This is called at the very end of block execution. Read more
§

fn on_idle(_n: BlockNumber, _remaining_weight: Weight) -> Weight

Hook to consume a block’s idle time. This will run when the block is being finalized (before [Hooks::on_finalize]). Read more
§

fn on_poll(_n: BlockNumber, _weight: &mut WeightMeter)

A hook to run logic after inherent application. Read more
§

fn on_runtime_upgrade() -> Weight

Hook executed when a code change (aka. a “runtime upgrade”) is detected by the FRAME Executive pallet. Read more
§

fn offchain_worker(_n: BlockNumber)

Implementing this function on a pallet allows you to perform long-running tasks that are dispatched as separate threads, and entirely independent of the main blockchain execution. Read more
§

fn integrity_test()

Check the integrity of this pallet’s configuration. Read more
Source§

impl<T: Config<I>, I: 'static> Inspect<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn total_issuance() -> Self::Balance

Always panics!. XP does not support total issuance.

XP does not track total issuance since it is earned based on work or intent-specific contributions.

There is no inflation model, as each XP point has individual meaning tied to context.

While XP units may be comparable numerically, they are not issued under the assumption of fungibility. XP providers define how XP is earned, not through a global issuance mechanism.

For runtime intents or abstractions which intend to operate on Fungible implementations such as pallet_balances and pallet_xp, callers should treat this as a no-op and utilize other trait extensions such as [Unbalanced]

Source§

fn minimum_balance() -> Self::Balance

Returns the minimum balance required for an XP to be considered alive.

XP reaping is not solely determined by balance. An XP entry may still be valid even if fully consumed, since XP can be re-earned through further work or actions.

Therefore, we assume no minimum balance is necessary to keep an XP alive.

Instead, XP lifecycle management (e.g., determining dead XP) should rely on other runtime mechanisms, such as timestamps crate::MinTimeStamp.

Consumers of this trait may implement automated reaping by integrating with functions like xp_exists or by analyzing XP activity rather than static balances.

This value is deliberately zero to support such flexible lifecycle handling.

Source§

fn total_balance(who: &XpId<T>) -> Self::Balance

Returns the total usable XP balance for the given key.

If the XP entry does not exist, this function returns zero as a fallback.

Unlike liquid XP, which refers only to the free portion, the usable XP includes both free and reserved portions - making this function more suited for systems that consider total accessible XP rather than just transferable XP.

This method relies on XpSystem::get_usable_xp.

Note:

  • This is provided to conform to the Fungible trait expectations.
  • While XP is not inherently fungible, total_balance allows integration in systems assuming that a balance-like arithmetic abstraction is available.
Source§

fn balance(who: &XpId<T>) -> Self::Balance

Returns the liquid XP balance for the given key.

If the XP does not exist, this returns zero.

Liquid XP represents the freely accessible portion of XP - that is, XP that is not locked or reserved and is available for immediate use.

This method relies on XpSystem::get_liquid_xp.

Note:

  • This method aligns with the Fungible trait’s balance expectation, even though XP is not strictly fungible.
  • It provides the free XP as a proxy for the “spendable” amount.
Source§

fn reducible_balance( who: &XpId<T>, _preservation: Preservation, _force: Fortitude, ) -> Self::Balance

Returns the amount of XP that can be reduced (i.e., slashed or withdrawn) for the given Xp key.

XP is not subject to existential deposit or minimum balance preservation like standard fungible assets.

If the XP does not exist, this returns zero.

This method relies on XpSystem::get_liquid_xp.

The _preservation and _force parameter is ignored as XP does not implement minimum balance enforcement.

Source§

fn can_deposit( who: &XpId<T>, amount: Self::Balance, provenance: Provenance, ) -> DepositConsequence

Determines whether XP can be deposited into the account of the given XP key.

Returns a DepositConsequence indicating whether the XP deposit is allowed.

§Rules
  • XP cannot be minted arbitrarily. Only providers with internal logic may assign new XP using XpMutate::earn_xp.
  • If the provenance is [Provenance::Minted], the deposit is always blocked.
  • While direct deposit minting is blocked, it is always preferable to allow minting in XP and balance systems using the safe Balanced trait to issue new balance and increase the balance of an account.
  • If the XP does not exist for the given key (XpSystem::xp_exists returns false), the deposit is blocked, because creating a new XP key should only be done via the Xp Trait XpMutate::new_xp or via genesis-config xp-accounts.
  • A zero-amount deposit is a success (considered a no-op).
  • Deposits are allowed only if the new liquid XP will not overflow.
Source§

fn can_withdraw( who: &XpId<T>, amount: Self::Balance, ) -> WithdrawConsequence<Self::Balance>

Determines whether a given amount of XP can be withdrawn from the given XP key.

Returns a WithdrawConsequence indicating whether the amount of XP can be withdrawn.

§Behavior
  • If the amount is zero, the withdrawal is trivially allowed.
  • If the XP key does not exist, returns UnknownAsset.
  • Checks whether the amount can be covered using the liquid/free XP balance. If the balance is insufficient, returns BalanceLow. Otherwise, returns Success.
Source§

fn active_issuance() -> Self::Balance

Always panics!. XP does not maintain an active issuance count.

Similar to total_issuance, XP is not issued in a globally managed or inflating manner.

The amount of XP granted is determined by the provider, and the XP system only defines how such points are added or interpreted.

Since XP is only numerically comparable (pseudo-fungible) but not truly fungible, no active issuance is tracked to prevent any notion of inflation or global supply.

Callers expecting issuance metrics (e.g., for fungible traits) should treat this as a no-op and utilize other trait extensions such as Fungible::Balanced or Fungible::Unbalanced.

Source§

type Balance = <Pallet<T, I> as XpSystem>::Points

Scalar type for representing balance of an account.
Source§

impl<T: Config<I>, I: 'static> Inspect<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn balance_frozen(id: &Self::Id, who: &XpId<T>) -> Self::Balance

Returns the locked (frozen) XP of the given lock id of XP Key.

Returns zero if no lock is found.

Source§

fn can_freeze(id: &Self::Id, who: &XpId<T>) -> bool

Checks if XP can be locked (frozen) for the given lock id and XP key.

Returns true if:

  • The XP key exists.
  • No lock currently exists for the given id.

Returns false otherwise.

Source§

type Id = <Pallet<T, I> as XpLock>::LockReason

An identifier for a freeze.
§

fn balance_freezable(who: &AccountId) -> Self::Balance

The amount of the balance which can become frozen. Defaults to total_balance().
Source§

impl<T: Config<I>, I: 'static> Inspect<<T as Config>::AccountId> for Pallet<T, I>

Source§

type Reason = <Pallet<T, I> as XpReserve>::ReserveReason

The reserve reason identifier used to categorize reserved XP points.

Source§

fn total_balance_on_hold(who: &XpId<T>) -> Self::Balance

Returns the total reserved XP for the given XP key.

  • If the XP does not exist, returns zero.

Note: This function cannot definitively determine whether an XP exists solely based on the returned value, since inactive or uninitialized reserves on an active XP will also return zero.

Source§

fn balance_on_hold(reason: &Self::Reason, who: &XpId<T>) -> Self::Balance

Returns the reserved XP held for the given reason by the specified XP key.

  • Returns zero if the XP key does not have an active reserve for the given reason, or if the reserve exists but has been fully reduced (i.e., balance is zero).

Note: Due to the design of the Fungible Traits, a reserve may still technically exist even if its balance is zero. Therefore, this method does not distinguish between a fully depleted reserve and a non-existent one.

§

fn reducible_total_balance_on_hold( who: &AccountId, _force: Fortitude, ) -> Self::Balance

Get the maximum amount that the total_balance_on_hold of who can be reduced successfully based on whether we are willing to force the reduction and potentially go below user-level restrictions on the minimum amount of the account. Note: This cannot bring the account into an inconsistent state with regards any required existential deposit. Read more
§

fn hold_available(_reason: &Self::Reason, _who: &AccountId) -> bool

Returns true if it’s possible to place (additional) funds under a hold of a given reason. This may fail if the account has exhausted a limited number of concurrent holds or if it cannot be made to exist (e.g. there is no provider reference). Read more
§

fn ensure_can_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> Result<(), DispatchError>

Check to see if some amount of funds of who may be placed on hold with the given reason. Reasons why this may not be true: Read more
§

fn can_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> bool

Check to see if some amount of funds of who may be placed on hold for the given reason. Reasons why this may not be true: Read more
Source§

impl<T: Config<I>, I: 'static> IntegrityTest for Pallet<T, I>

Source§

fn integrity_test()

See [Hooks::integrity_test].
Source§

impl<T: Config<I>, I: 'static> Mutate<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn mint_into( who: &XpId<T>, amount: Self::Balance, ) -> Result<Self::Balance, DispatchError>

Mints (adds) amount XP to the given XP key.

  • Fails if the XP key does not exist.
  • Fails on overflow.
  • Calls done_mint_into after successful mint.
  • Returns the actual amount minted (the imbalance).
Source§

fn burn_from( who: &XpId<T>, amount: Self::Balance, preservation: Preservation, precision: Precision, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Burns (removes) up to amount XP from the given XP key.

  • Fails if the XP key does not exist.
  • Fails if funds are unavailable and precision is Exact.
  • Calls done_burn_from after successful burn.
  • Returns the actual amount burned (the imbalance).
Source§

fn shelve( who: &XpId<T>, amount: Self::Balance, ) -> Result<Self::Balance, DispatchError>

Shelves (removes) up to amount XP from the given XP key.

  • Fails if funds are unavailable.
  • Returns the actual amount shelved (the imbalance).
Source§

fn restore( who: &XpId<T>, amount: Self::Balance, ) -> Result<Self::Balance, DispatchError>

Restores (adds) amount XP to the given XP key.

  • Fails if the XP key does not exist.
  • Fails on overflow.
  • Returns the actual amount restored (the imbalance).
Source§

fn transfer( _source: &XpId<T>, _dest: &XpId<T>, _amount: Self::Balance, _preservation: Preservation, ) -> Result<Self::Balance, DispatchError>

Transfers XP between keys is not supported.

Always returns Error::CannotTransferXp.

Source§

fn set_balance(who: &XpId<T>, amount: Self::Balance) -> Self::Balance

Sets the free XP balance for the given XP key.

  • Returns zero if the XP key does not exist.
  • Otherwise, sets the free balance and returns the new balance.
Source§

fn done_burn_from(who: &XpId<T>, amount: Self::Balance)

Called after a successful burn operation.

Triggers XP update hook.

Source§

fn done_mint_into(who: &XpId<T>, amount: Self::Balance)

Called after a successful mint operation.

Triggers XP update hook.

Source§

fn done_restore(who: &XpId<T>, amount: Self::Balance)

Called after a successful restore operation.

Triggers XP update hook.

Source§

fn done_shelve(who: &XpId<T>, amount: Self::Balance)

Called after a successful shelve operation.

Triggers XP update hook.

Source§

fn done_transfer(_source: &XpId<T>, _dest: &XpId<T>, _amount: Self::Balance)

This implementation is a no-op.

Source§

impl<T: Config<I>, I: 'static> Mutate<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn set_freeze( id: &Self::Id, who: &XpId<T>, amount: Self::Balance, ) -> DispatchResult

Sets or updates the locked XP (freeze) for the given id and XP Key.

  • If amount is zero and lock exists for the given key and id this operation is treated as a thaw (i.e., burn/remove the lock).
  • If the lock exists, XpLock::can_lock_mutate must return Ok(()) to allow the update.
  • If the lock does not exist, XpLock::can_lock_new must return Ok(()) to allow creating a new lock.

Returns Ok(()) on success, or an error if the operation fails.

Source§

fn extend_freeze( id: &Self::Id, who: &XpId<T>, amount: Self::Balance, ) -> DispatchResult

Extends (or sets) a lock (freeze) for the given lock id of the specified XP key.

  • If the lock exists, increases the locked amount to the greater of the current or requested value.
  • If the lock does not exist, returns an error (XpLockNotFound).
  • If amount is zero, this is a no-op and returns Ok(()).
Source§

fn thaw(id: &Self::Id, who: &XpId<T>) -> DispatchResult

Thaws (removes) the XP lock for the given lock id of the specified XP key.

This is effectively a lock burn as it permanently removes the lock.

  • Fails if the XP key does not exist.
  • Fails if the lock does not exist.
Source§

fn increase_frozen( id: &Self::Id, who: &XpId<T>, amount: Self::Balance, ) -> DispatchResult

Increase the amount which is being frozen for a particular freeze, failing in the case that too little balance is available for being frozen.

§

fn set_frozen( id: &Self::Id, who: &AccountId, amount: Self::Balance, fortitude: Fortitude, ) -> Result<(), DispatchError>

Attempt to alter the amount frozen under the given id to amount. Read more
§

fn ensure_frozen( id: &Self::Id, who: &AccountId, amount: Self::Balance, fortitude: Fortitude, ) -> Result<(), DispatchError>

Attempt to set the amount frozen under the given id to amount, iff this would increase the amount frozen under id. Do nothing otherwise. Read more
§

fn decrease_frozen( id: &Self::Id, who: &AccountId, amount: Self::Balance, ) -> Result<(), DispatchError>

Decrease the amount which is being frozen for a particular freeze, failing in the case of underflow.
Source§

impl<T: Config<I>, I: 'static> Mutate<<T as Config>::AccountId> for Pallet<T, I>

§

fn hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> Result<(), DispatchError>

Hold some funds in an account. If a hold for reason is already in place, then this will increase it.
§

fn release( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Release up to amount held funds in an account. Read more
§

fn set_on_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> Result<(), DispatchError>

Hold or release funds in the account of who to bring the balance on hold for reason to exactly amount.
§

fn release_all( reason: &Self::Reason, who: &AccountId, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Release all funds in the account of who on hold for reason. Read more
§

fn burn_held( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Attempt to decrease the balance of who which is held for the given reason by amount. Read more
§

fn burn_all_held( reason: &Self::Reason, who: &AccountId, precision: Precision, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Attempt to decrease the balance of who which is held for the given reason to zero. Read more
§

fn transfer_on_hold( reason: &Self::Reason, source: &AccountId, dest: &AccountId, amount: Self::Balance, precision: Precision, mode: Restriction, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Transfer held funds into a destination account. Read more
§

fn transfer_and_hold( reason: &Self::Reason, source: &AccountId, dest: &AccountId, amount: Self::Balance, precision: Precision, expendability: Preservation, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Transfer some amount of free balance from source to become owned by dest but on hold for reason. Read more
§

fn done_hold(_reason: &Self::Reason, _who: &AccountId, _amount: Self::Balance)

§

fn done_release( _reason: &Self::Reason, _who: &AccountId, _amount: Self::Balance, )

§

fn done_burn_held( _reason: &Self::Reason, _who: &AccountId, _amount: Self::Balance, )

§

fn done_transfer_on_hold( _reason: &Self::Reason, _source: &AccountId, _dest: &AccountId, _amount: Self::Balance, )

§

fn done_transfer_and_hold( _reason: &Self::Reason, _source: &AccountId, _dest: &AccountId, _transferred: Self::Balance, )

Source§

impl<T: Config<I>, I: 'static> OffchainWorker<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

Source§

fn offchain_worker(n: BlockNumberFor<T>)

This function is being called after every block import (when fully synced). Read more
Source§

impl<T: Config<I>, I: 'static> OnFinalize<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

Source§

fn on_finalize(n: BlockNumberFor<T>)

See [Hooks::on_finalize].
Source§

impl<T: Config<I>, I: 'static> OnGenesis for Pallet<T, I>

Source§

fn on_genesis()

Something that should happen at genesis.
Source§

impl<T: Config<I>, I: 'static> OnIdle<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

Source§

fn on_idle(n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight

See [Hooks::on_idle].
Source§

impl<T: Config<I>, I: 'static> OnInitialize<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

Source§

fn on_initialize(n: BlockNumberFor<T>) -> Weight

See [Hooks::on_initialize].
Source§

impl<T: Config<I>, I: 'static> OnPoll<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T, I>

Source§

fn on_poll(n: BlockNumberFor<T>, weight: &mut WeightMeter)

Code to execute every now and then at the beginning of the block after inherent application. Read more
Source§

impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Pallet<T, I>

Source§

fn on_runtime_upgrade() -> Weight

See [Hooks::on_runtime_upgrade].
Source§

impl<T: Config<I>, I: 'static> PalletInfoAccess for Pallet<T, I>

Source§

fn index() -> usize

Index of the pallet as configured in the runtime.
Source§

fn name() -> &'static str

Name of the pallet as configured in the runtime.
Source§

fn name_hash() -> [u8; 16]

Two128 hash of name.
Source§

fn module_name() -> &'static str

Name of the Rust module containing the pallet.
Source§

fn crate_version() -> CrateVersion

Version of the crate containing the pallet.
Source§

impl<T: Config<I>, I: 'static> PalletsInfoAccess for Pallet<T, I>

Source§

fn count() -> usize

The number of pallets’ information that this type represents. Read more
Source§

fn infos() -> Vec<PalletInfoData>

All of the pallets’ information that this type represents.
Source§

impl<T, I> PartialEq for Pallet<T, I>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Config<I>, I: 'static> StorageInfoTrait for Pallet<T, I>

Source§

fn storage_info() -> Vec<StorageInfo>

Source§

impl<T: Config<I>, I: 'static> Unbalanced<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn handle_dust(_dust: Dust<XpId<T>, Self>)

XP operations may generate imprecise or saturating side-effects (e.g., dust due to overflow control), which are handled internally by the XP system. XP accounts can exist at zero points, so it is assumed no such dust will be created.

Therefore, this implementation is a no-op.

Source§

fn write_balance( who: &XpId<T>, amount: Self::Balance, ) -> Result<Option<Self::Balance>, DispatchError>

Writes the free XP balance for the given key.

This bypasses XP earning mechanisms and directly sets the XP to the specified value.

We return None intentionally to indicate no dust may exist.

Source§

fn set_total_issuance(_amount: Self::Balance)

The XP system does not support active or total issuance.

Therefore, this implementation is a no-op.

Source§

fn handle_raw_dust(_amount: Self::Balance)

This implementation is a no-op.

Source§

fn increase_balance( who: &XpId<T>, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Increases the balance of who by amount.

If the balance cannot be increased by that amount for any reason, returns Err and does not increase it at all.

If successful, returns the amount by which the balance was increased (the imbalance).

Source§

fn decrease_balance( who: &XpId<T>, amount: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result<Self::Balance, DispatchError>

Decreases the balance of who by amount.

  • If precision is Exact and the balance cannot be reduced by that amount, returns Err and does not reduce it at all.
  • If precision is BestEffort, reduces the balance by as much as possible, up to amount.

In either case, if Ok is returned, the inner value is the amount by which the balance was reduced.

Source§

fn deactivate(_: Self::Balance)

This implementation is a no-op.

Source§

fn reactivate(_: Self::Balance)

This implementation is a no-op.

Source§

impl<T: Config<I>, I: 'static> Unbalanced<<T as Config>::AccountId> for Pallet<T, I>

Source§

fn set_balance_on_hold( reason: &Self::Reason, who: &XpId<T>, amount: Self::Balance, ) -> DispatchResult

Sets or updates the reserved XP (balance_on_hold) for a given reason of XP key.

  • If amount is zero, the function does not create or modify any reserve.
  • If the reserve exists, XpReserve::can_reserve_mutate must return Ok(()) to allow the update.
  • If the reserve does not exist, XpReserve::can_reserve_new must return Ok(()) to allow creating a new reserve.

Returns Ok(()) on success, or an error if the operation fails.

§

fn decrease_balance_on_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Reduce the balance on hold of who by amount. Read more
§

fn increase_balance_on_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Increase the balance on hold of who by amount. Read more
Source§

impl<T: Config<I>, I: 'static> ViewFunctionIdPrefix for Pallet<T, I>

Source§

fn prefix() -> [u8; 16]

Source§

impl<T: Config<I>, I: 'static> WhitelistedStorageKeys for Pallet<T, I>

Source§

fn whitelisted_storage_keys() -> Vec<TrackedStorageKey>

Returns a Vec<TrackedStorageKey> indicating the storage keys that should be whitelisted during benchmarking. This means that those keys will be excluded from the benchmarking performance calculation.
Source§

impl<T: Config<I>, I: 'static> XpErrorHandler for Pallet<T, I>

Source§

type Error = Error<T, I>

Concrete error type produced by the handler. Read more
Source§

fn from_xp_error(e: XpError) -> Self::Error

Converts a generic XpError into the handler’s concrete error type which implements Into<DispatchError>. Read more
Source§

impl<T: Config<I>, I: 'static> XpLock for Pallet<T, I>

Implementation of the XpLock trait for the XP pallet.

This provides the interface for issuing, managing, and burning XP locks, as well as querying lock state. All methods are implemented in terms of the pallet’s storage items and types.

Source§

type Lock = IdXp<<T as Config<I>>::LockReason, <T as Config<I>>::Xp>

The structure representing lock metadata (reason and locked XP amount).

Source§

type LockReason = <T as Config<I>>::LockReason

The lock reason identifier used to categorize locked XP points.

Source§

fn has_lock(key: &Self::XpKey) -> DispatchResult

Checks if the given XP key has at least one active lock.

This function verifies that the XP key has one or more active locks by checking if the locks vector is non-empty.

§Returns
  • Ok(()) if the XP key has at least one active lock
  • Err(DispatchError) if no locks exist for the XP key
Source§

fn lock_exists(key: &Self::XpKey, reason: &Self::LockReason) -> DispatchResult

Checks if a lock exists for the given XP key and lock reason.

§Returns
  • Ok(()) if the lock exists for the given key and reason
  • Err(DispatchError) if the lock does not exist
Source§

fn get_lock_xp( key: &Self::XpKey, reason: &Self::LockReason, ) -> Result<Self::Points, DispatchError>

Retrieves the XP points locked under the specified lock reason.

This function returns the amount of XP points currently locked for a specific reason on the given XP key.

§Returns
  • Ok(Points) containing the locked XP points if found
  • Err(DispatchError) if the XP key or lock reason does not exist
Source§

fn total_locked(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Retrieves the total XP points actively locked for the given key.

This function returns the sum of all locked XP across all lock reasons for the specified XP key.

§Returns
  • Ok(Points) containing the total locked XP points if found
  • Err(DispatchError) if the XP key does not exist
Source§

fn get_all_locks( key: &Self::XpKey, ) -> Result<Vec<Self::LockReason>, DispatchError>

Retrieves all active lock reasons associated with the XP key.

This function returns a list of all lock reason identifiers currently active for the specified XP key.

§Returns
  • Ok(Vec<Self::LockReason>) containing all active lock reasons
  • Empty vector if no locks exist for the XP key
Source§

fn burn_lock(key: &Self::XpKey, reason: &Self::LockReason) -> DispatchResult

Burns a lock and permanently removes the associated XP.

This function removes both the lock entry and destroys the locked XP points. Used in scenarios like forfeiture, decay, or permanent commitment where the XP should be permanently removed from circulation.

§Returns
  • Ok(()) if the lock was successfully burned
  • Err(DispatchError) for the respected error.
Source§

fn set_lock( key: &Self::XpKey, reason: &Self::LockReason, points: Self::Points, ) -> DispatchResult

Forcefully sets the locked XP for a specific lock reason.

This function bypasses typical XP flow and permission checks, directly modifying lock state without enforcing invariants.

Creates a new lock if none exists for the given reason, or updates an existing lock.

Use with caution as this is intended for internal runtime operations such as migrations, resets, or exceptional administrative flows.

§Returns
  • Ok(()) if the lock was successfully set
  • Err(DispatchError) if operation fails due to overflow or other constraints
Source§

fn on_lock_update( key: &Self::XpKey, reason: &Self::LockReason, lock_points: Self::Points, )

Hook invoked after a new XP lock is successfully created or mutated.

Emits an XpLock event with the XP key, lock reason, and lock points if Config::EmitEvents is true.

Source§

fn on_lock_burn(key: &Self::XpKey, reason: &Self::LockReason)

Hook invoked after an XP lock is burned and permanently removed.

Emits an XpLockBurn event with the XP key and lock reason if Config::EmitEvents is true.

Source§

fn on_lock_slash( key: &Self::XpKey, reason: &Self::LockReason, slashed_points: Self::Points, )

Hook invoked after locked XP points are slashed.

Emits an XpLockSlash event with the XP key, lock reason, and slashed points if Config::EmitEvents is true.

Source§

fn can_lock_xp( key: &Self::XpKey, points: Self::Points, ) -> Result<(), DispatchError>

Checks if the specified points of XP can be locked for the given key. Read more
Source§

fn can_lock_mutate( key: &Self::XpKey, reason: &Self::LockReason, points: Self::Points, ) -> Result<(), DispatchError>

Checks if an existing lock can be mutated to the new value. Read more
Source§

fn can_lock_new( key: &Self::XpKey, points: Self::Points, ) -> Result<(), DispatchError>

Determines if a new XP lock can be created for the given key and points. Read more
Source§

fn maximum_locks() -> usize

Returns the maximum number of concurrent locks allowed per XP key. Read more
Source§

fn lock_xp( key: &Self::XpKey, reason: &Self::LockReason, points: Self::Points, ) -> Result<(), DispatchError>

Lock’s the specified points of XP under the given lock reason. Read more
Source§

fn withdraw_lock( key: &Self::XpKey, reason: &Self::LockReason, ) -> Result<(), DispatchError>

Withdraws the specified lock, returning the locked XP to the liquid balance. Read more
Source§

fn slash_lock( key: &Self::XpKey, reason: &Self::LockReason, points: Self::Points, ) -> Result<Self::Points, DispatchError>

Reduces or slashes locked XP under the given lock reason. Read more
Source§

impl<T: Config<I>, I: 'static> XpMutate for Pallet<T, I>

Implementation of the XpMutate trait for the XP pallet.

This provides the interface for mutating XP entries, including creation, earning (with reputation effects), direct setting, and lifecycle hooks for XP changes.

All methods are implemented in terms of the pallet’s storage items and types.

Source§

fn init_xp() -> Self::Points

Returns the configured initial XP value for new entries.

This value is retrieved from runtime storage (InitXp) and is used during Self::create_xp to initialize newly created XP records.

Source§

fn new_xp(owner: &Self::Owner, key: &Self::XpKey)

Creates and initializes a new XP entry for the given key and owner.

Use with caution! as this bypasses typical XP flow and permission checks. Overwrites any existing XP entry without validation.

For absolute safety, utilize frame_suite::xp::BeginXp::begin_xp

Source§

fn set_xp(key: &Self::XpKey, points: Self::Points) -> DispatchResult

Use with caution! This function bypasses typical XP flow and permission checks.

Directly sets the liquid XP (free) for the given key.

Unlike Self::earn_xp, this method does not compute or validate the provided points. It simply overwrites the current liquid XP value.

Intended for low-level runtime intents (e.g., migrations or internal resets).

§Returns
  • Ok(()) if the XP was successfully set
  • Err(DispatchError) if the XP entry does not exist
Source§

fn earn_xp( key: &Self::XpKey, points: Self::Points, ) -> Result<Self::Points, DispatchError>

Increments the liquid XP of a given key, applying pulse-based reputation mechanics.

This function is the primary entry point for awarding XP from user-driven runtime actions such as task completion, participation events, or other domain-specific intents.

Instead of directly crediting raw XP on every call, this method integrates a pulse-based reputation system that:

  • Prevents inflation from repeated calls within the same block
  • Gradually builds reputation (pulse) before scaling XP rewards
  • Multiplies earned XP once sufficient reputation is achieved
  • Provides accelerated reputation growth for locked (committed/staked) accounts
§Core Mechanics
  1. Same-block protection

    • If XP is earned multiple times within the same block and the pulse is already above the minimum threshold, only raw XP is added.
    • Pulse is intentionally NOT incremented to discourage rapid intra-block spamming.
  2. Pulse warm-up phase

    • If the pulse reputation is below MinPulse, XP is not granted yet.
    • Instead, the pulse accumulator is incremented, encouraging consistent long-term participation rather than burst activity.
  3. Scaled XP phase

    • Once MinPulse is reached, earned XP is multiplied by the current pulse value, rewarding reputable accounts with higher returns.
  4. Lock-based acceleration

    • If a lock exists on the XP key (e.g., staking or commitment), the pulse is incremented again to accelerate future reputation growth.
§Note

MinPulse is dynamic-storage value to support a live, gamified XP economy. As the ecosystem evolves, the required reputation tier can be adjusted to maintain fair progression, prevent early-stage farming, and keep long-term engagement meaningful without resetting user progress.

§Returns
  • Ok(Points) containing the actual XP credited after pulse scaling
  • Err(DispatchError) if computation or storage mutation fails
Source§

fn quote_earn_xp( key: &Self::XpKey, points: Self::Points, ) -> Result<Self::Points, DispatchError>

Determines the effective XP that would be earned for a given key, applying pulse-based reputation mechanics.

This method mirrors the logic of XpMutate::earn_xp but does not mutate state.

§Returns
  • Ok(Points) containing the actual XP that would be credited after pulse scaling
  • Err(DispatchError) if computation fails or the XP key does not exist
Source§

fn on_xp_update(key: &Self::XpKey, points: Self::Points)

Hook invoked after an XP entry is updated reflecting currently available XP Points.

Emits an Xp event with the XP key and liquid points if Config::EmitEvents is true.

Source§

fn on_xp_earn(key: &Self::XpKey, points: Self::Points)

Hook invoked after a XP is earned.

Emits an XpEarn event with the XP key and earned points if Config::EmitEvents is true.

Source§

fn on_xp_create(key: &Self::XpKey, owner: &Self::Owner)

Hook invoked after a new XP entry is created.

Emits an XpCreate event with the XP key and owner if Config::EmitEvents is true.

Source§

fn on_xp_slash(key: &Self::XpKey, slashed_points: Self::Points)

Hook invoked after XP points are slashed.

Emits an XpSlash event with the XP key and slashed points if Config::EmitEvents is true.

Source§

fn create_xp( owner: &Self::Owner, key: &Self::XpKey, ) -> Result<(), DispatchError>

Creates and initializes a new XP entry under the given key and owner. Read more
Source§

fn slash_xp( key: &Self::XpKey, points: Self::Points, ) -> Result<Self::Points, DispatchError>

Reduces the liquid XP for the given key by the specified points. Read more
Source§

fn reset_xp(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Resets (burns) all liquid XP for the given key, returning the points burned. Read more
Source§

impl<T: Config<I>, I: 'static> XpOwner for Pallet<T, I>

Implementation of the XpOwner trait for the XP pallet.

This provides the interface for XP ownership and access control, including checking ownership, enumerating all XP keys owned by an account, transferring ownership, and emitting ownership events.

All methods are implemented in terms of the pallet’s storage items and types.

Source§

type Owner = <T as Config>::AccountId

The account ID type representing the owner of an XP entry.

Source§

fn is_owner(owner: &Self::Owner, key: &Self::XpKey) -> DispatchResult

Checks if the given owner possesses ownership of the specified XP key.

This function verifies ownership by checking if the owner-key pair exists in the XpOwners storage map.

§Returns
  • Ok(()) if the owner possesses ownership of the XP key
  • Err(DispatchError) if the owner does not have ownership rights
Source§

fn xp_of_owner(owner: &Self::Owner) -> Result<Vec<Self::XpKey>, DispatchError>

Retrieves all XP keys currently owned by the given owner.

§Returns
  • Ok(Vec<XpKey>) containing all valid XP keys owned by the account
  • Err(DispatchError) if there are issues accessing storage
Source§

fn set_owner( owner: &Self::Owner, key: &Self::XpKey, new_owner: &Self::Owner, ) -> DispatchResult

Sets the owner of the given XP key.

§Note

This is a low-level primitive that directly mutates storage without performing access control checks.

It should generally only be used internally. Prefer higher-level APIs such as Self::transfer_owner for safe ownership transitions.

§Returns
  • Ok(()) if the owner is successfully updated
  • Err(DispatchError) if the operation fails
Source§

fn xp_key_gen( owner: &Self::Owner, xp: &Self::Xp, ) -> Result<Self::XpKey, DispatchError>

Generates a deterministic XP key from the provided owner and XP data.

This function creates a unique XP key using the owner’s account ID, the XP struct, and the owner’s current nonce as salt to ensure uniqueness and prevent collisions. The key generation is deterministic for the same inputs and state-variables.

§Returns
  • Ok(XpKey) containing the generated XP key if successful
  • Err(DispatchError) if the key generation process fails
Source§

fn on_xp_transfer(key: &Self::XpKey, new_owner: &Self::Owner)

Hook invoked after a successful XP ownership transfer.

Emits an XpOwner event with the new owner and XP key.

Source§

fn transfer_owner( owner: &Self::Owner, key: &Self::XpKey, new_owner: &Self::Owner, ) -> Result<(), DispatchError>

Transfers ownership of the given XP key from the current owner to a new owner. Read more
Source§

impl<T: Config<I>, I: 'static> XpReap for Pallet<T, I>

Implementation of the XpReap trait for the XP pallet.

This provides the interface for finalizing (reaping) XP entries, checking reaped status, and emitting reaping events. All methods are implemented in terms of the pallet’s storage items and types.

Source§

fn reap_xp(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Reaps the given XP key, removing all associated data from storage.

This irreversibly deletes the XP entry from XpOf and ReservedXpOf, and marks the key in ReapedXp to prevent accidental recreation.

Returns the total usable (liquid + reserved) XP points, which may be imprecise in edge cases involving overflow or ignored dust, since the system does not track total issuance.

Reaping forcibly removes reserves regardless of their presence.

§Returns
  • Ok(Points) containing the total usable (liquid + reserved) XP points that were reaped, which may be imprecise in edge cases involving overflow or ignored dust, since the system does not track total issuance.
  • Err(DispatchError) if XP locks exist or the entry does not exist
Source§

fn is_reaped(key: &Self::XpKey) -> DispatchResult

Checks if the given XP key has been reaped.

Used as a guard against accidental recreation or mutation of finalized XP entries.

§Returns
  • Ok(()) if the XP key has been reaped
  • Err(DispatchError) if the XP key has not been reaped
Source§

fn on_xp_reap(key: &Self::XpKey)

Hook invoked after an XP entry has been reaped.

Source§

fn can_reap(key: &Self::XpKey) -> Result<(), DispatchError>

Checks whether the given XP key can be safely reaped (finalized). Read more
Source§

fn try_reap(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Attempts to reap (finalize) the given XP entry if all conditions are met. Read more
Source§

impl<T: Config<I>, I: 'static> XpReserve for Pallet<T, I>

Implementation of the XpReserve trait for the XP pallet.

This provides the interface for managing XP reserves, including creation, mutation, querying, and event emission for reserved XP. All methods are implemented in terms of the pallet’s storage items and types.

Source§

type Reserve = IdXp<<T as Config<I>>::ReserveReason, <T as Config<I>>::Xp>

The structure representing reserve metadata (reason and reserved XP amount).

Source§

type ReserveReason = <T as Config<I>>::ReserveReason

The lock reason identifier used to categorize locked XP points.

Source§

fn reserve_exists( key: &Self::XpKey, reason: &Self::ReserveReason, ) -> DispatchResult

Checks if a reserve exists for the given XP key and reserve reason.

§Returns
  • Ok(()) if the reserve exists for the given key and reason
  • Err(DispatchError) if the reserve does not exist
Source§

fn get_reserve_xp( key: &Self::XpKey, reason: &Self::ReserveReason, ) -> Result<Self::Points, DispatchError>

Retrieves the XP points reserved under the specified reserve reason.

This function returns the amount of XP points currently reserved for a specific reason on the given XP key.

§Returns
  • Ok(Points) containing the reserved XP points if found
  • Err(DispatchError) if the XP key or reserve reason does not exist
Source§

fn total_reserved(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Retrieves the total XP points actively reserved for the given key.

This function returns the sum of all reserved XP across all reserve reasons for the specified XP key.

§Returns
  • Ok(Points) containing the total reserved XP points if found
  • Err(DispatchError) if the XP key does not exist
Source§

fn has_reserve(key: &Self::XpKey) -> DispatchResult

Checks if the given XP key has at least one active reserve.

This function verifies that the XP key has one or more active reserves by checking if the reserves vector is non-empty.

§Returns
  • Ok(()) if the XP key has at least one active reserve
  • Err(DispatchError) if no reserves exist for the XP key
Source§

fn get_all_reserves( key: &Self::XpKey, ) -> Result<Vec<Self::ReserveReason>, DispatchError>

Retrieves all active reserve reasons associated with the XP key.

This function returns a list of all reserve reason identifiers currently active for the specified XP key.

§Returns
  • Ok(Vec<Self::ReserveReason>) containing all active reserve reasons
  • Empty vector if no reserves exist for the XP key
Source§

fn set_reserve( key: &Self::XpKey, reason: &Self::ReserveReason, points: Self::Points, ) -> DispatchResult

Forcefully sets the reserved XP for a specific reserve reason.

This function bypasses typical XP flow and permission checks, directly modifying reserve state without enforcing invariants.

Creates a new reserve if none exists for the given reason, or updates an existing reserve.

Use with caution as this is intended for internal runtime operations such as migrations, resets, or exceptional administrative flows.

§Returns
  • Ok(()) if the reserve was successfully set
  • Err(DispatchError) if operation fails due to overflow or other constraints
Source§

fn on_reserve_update( key: &Self::XpKey, reason: &Self::ReserveReason, reserve_points: Self::Points, )

Hook invoked after a new reservation is created or mutated.

Emits an XpReserve event with the XP key, reserve reason, and reserve points if Config::EmitEvents is true.

Source§

fn on_reserve_slash( key: &Self::XpKey, reason: &Self::ReserveReason, slashed_points: Self::Points, )

Hook invoked after reserved XP points are slashed.

Emits an XpReserveSlash event with the XP key, reserve reason, and slashed points if Config::EmitEvents is true.

Source§

fn can_reserve_xp( key: &Self::XpKey, points: Self::Points, ) -> Result<(), DispatchError>

Checks if the specified points of XP can be reserved for the given key. Read more
Source§

fn can_reserve_mutate( key: &Self::XpKey, reason: &Self::ReserveReason, points: Self::Points, ) -> Result<(), DispatchError>

Checks if an existing reserve can be mutated to the new value. Read more
Source§

fn can_reserve_new( key: &Self::XpKey, points: Self::Points, ) -> Result<(), DispatchError>

Determines if a new XP reserve can be created for the given key and points. Read more
Source§

fn maximum_reserves() -> usize

Returns the maximum number of concurrent reserves allowed per XP key. Read more
Source§

fn reserve_xp( key: &Self::XpKey, reason: &Self::ReserveReason, points: Self::Points, ) -> Result<(), DispatchError>

Reserve’s the specified points of XP under the given reserve reason. Read more
Source§

fn withdraw_reserve( key: &Self::XpKey, reason: &Self::ReserveReason, ) -> Result<(), DispatchError>

Withdraws the specified reserve, returning the reserved XP to the liquid balance. Read more
Source§

fn reset_reserve( key: &Self::XpKey, reason: &Self::ReserveReason, ) -> Result<Self::Points, DispatchError>

Resets (permanently burns) all reserved XP points for the given reason. Read more
Source§

fn slash_reserve( key: &Self::XpKey, reason: &Self::ReserveReason, points: Self::Points, ) -> Result<Self::Points, DispatchError>

Reduces or burns reserved XP under the given reserve reason. Read more
Source§

fn withdraw_reserve_partial( key: &Self::XpKey, reason: &Self::ReserveReason, points: Self::Points, precision: Precision, ) -> Result<(), DispatchError>

Withdraws a specified amount of reserved XP, returning it to the liquid balance. Read more
Source§

impl<T: Config<I>, I: 'static> XpSystem for Pallet<T, I>

Implementation of the XpSystem trait for the XP pallet.

This provides the core, read-only interface for querying XP state, metadata, and key management. All methods are implemented in terms of the pallet’s storage items and types.

Source§

type Xp = Xp<T, I>

The primary data structure for XP accounts in this pallet.

It encapsulates all metadata information for an XP entry, including liquid, reserved, and locked XP, as well as reputation pulse and timestamp.

Source§

type Points = <T as Config<I>>::Xp

The scalar type representing XP points (the main XP balance unit).

Source§

type XpKey = <T as Config>::AccountId

The unique key type for XP entries (distinct from the owner).

Same as [frame_system::Config::AccountId]

Source§

type TimeStamp = <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number

The type representing the timestamp (block number) for XP lifecycle tracking.

Source§

type Extension = <T as Config<I>>::Extensions

Pallet Extensions includes external listeners and their triggers.

Source§

fn xp_exists(key: &Self::XpKey) -> DispatchResult

Checks if an XP entry exists for the given key.

This function verifies the existence of an XP entry in storage by checking if the provided key exists in the XpOf storage map.

§Returns
  • Ok(()) if the XP entry exists for the given key
  • Err(DispatchError) if the entry does not exist
Source§

fn get_xp(key: &Self::XpKey) -> Result<Self::Xp, DispatchError>

Retrieves the complete XP struct for the given key.

This function fetches the full XP data structure from storage, containing all metadata including liquid, reserved, locked XP, reputation pulse, and timestamp.

§Returns
  • Ok(Xp) containing the complete XP struct if found
  • Err(DispatchError) if the entry does not exist
Source§

fn has_minimum_xp(key: &Self::XpKey) -> DispatchResult

Validates if the XP entry meets the minimum timestamp threshold.

This function checks whether an XP entry’s timestamp satisfies the minimum timestamp requirement, which is used for XP liveness validation and reaping logic.

§Returns
  • Ok(()) if the XP entry meets the minimum timestamp threshold
  • Err(DispatchError) if the timestamp is below the minimum
Source§

fn get_liquid_xp(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Retrieves the liquid (free) XP balance for the given key.

This function returns liquid XP points, which represents the freely spendable XP balance that is not reserved or locked for any specific purpose.

§Returns
  • Ok(Points) containing the liquid XP balance if found
  • Err(DispatchError) if the entry does not exist
Source§

fn get_usable_xp(key: &Self::XpKey) -> Result<Self::Points, DispatchError>

Retrieves the total usable XP (liquid + reserved) for the given key.

This function calculates and returns the sum of liquid and reserved XP, representing the total amount of XP that can be utilized by the account. Locked XP is excluded as it cannot be spent or transferred.

§Returns
  • Ok(Points) containing the total usable XP balance if found
  • Err(DispatchError) if the entry does not exist
Source§

impl<T, I> Eq for Pallet<T, I>

Auto Trait Implementations§

§

impl<T, I> Freeze for Pallet<T, I>

§

impl<T, I> RefUnwindSafe for Pallet<T, I>

§

impl<T, I> Send for Pallet<T, I>
where T: Send, I: Send,

§

impl<T, I> Sync for Pallet<T, I>
where T: Sync, I: Sync,

§

impl<T, I> Unpin for Pallet<T, I>
where T: Unpin, I: Unpin,

§

impl<T, I> UnwindSafe for Pallet<T, I>
where T: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CheckedConversion for T

§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> IntoKey<U> for T
where U: FromKey<T>,

§

fn into_key(self) -> U

Source§

impl<T, U, Tag> IntoTag<U, Tag> for T
where U: FromTag<T, Tag>, Tag: DiscriminantTag,

Source§

fn into_tag(self) -> U

§

impl<Src, Dest> IntoTuple<Dest> for Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

§

impl<T> IsType<T> for T

§

fn from_ref(t: &T) -> &T

Cast reference.
§

fn into_ref(&self) -> &T

Cast reference.
§

fn from_mut(t: &mut T) -> &mut T

Cast mutable reference.
§

fn into_mut(&mut self) -> &mut T

Cast mutable reference.
§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

Source§

impl<T, Time> Logging<Time> for T
where Time: Time,

Source§

const FALLBACK_TARGET: &'static str = "routine"

Default logging target if none is provided.

Most routines, especially offchain workers or background tasks, use this target for simplicity.

It allows a consistent place to look for routine logs without requiring every call to specify a target.

Note: This target is only a conveninence and may be somewhat vague. To ensure errors can still be traced accurately, the logged messages should include additional metadata (e.g., module name, error index, or contextual info) so that the source of the error can be identified even if the target is generic.

Source§

type Logger = DispatchError

The type taken and returned for logging.

We simply return the same [DispatchError] that was logged, so logging does not change control flow or error propagation.

DispatchError is used because in Substrate it encompasses all runtime errors - including module errors, token errors, arithmetic issues, and transactional boundaries - making it the universal substrate-side error representation.

Source§

type Level = LogLevel

The log level type.

We use the LogLevel enum to standardize severity levels (Info, Warn, Error, Debug) across all routine logs.

Source§

fn log( level: <T as Logging<Time>>::Level, err: &<T as Logging<Time>>::Logger, timestamp: Time, target: Option<&str>, fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>, ) -> <T as Logging<Time>>::Logger

Core logging function that all helpers delegate to. Read more
Source§

fn info( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs an info-level message. Read more
Source§

fn warn( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs a warning-level message. Read more
Source§

fn error( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs an error-level message. Read more
Source§

fn debug( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs a debug-level message. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SaturatedConversion for T

§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T, U> TryIntoKey<U> for T
where U: TryFromKey<T>,

§

type Error = <U as TryFromKey<T>>::Error

§

fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>

§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<Provider, Discriminant, T> DelegateVirtualDynBound<Provider, Discriminant> for T
where Provider: VirtualDynBound<Discriminant>, Discriminant: DiscriminantTag,

Source§

impl<Provider, Discriminant, T> DelegateVirtualStaticBound<Provider, Discriminant> for T
where Provider: VirtualStaticBound<Discriminant>, Discriminant: DiscriminantTag,

§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeDebug for T
where T: Debug,

§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,

§

impl<T> Member for T
where T: Send + Sync + Debug + Eq + PartialEq + Clone + 'static,