1

In a pallet I have used set_lock() with a own LockIdentifier for that pallet. Now I need to check the locked balance of an account with that LockIdentifier and not the global locked amount. how to do that?

1 Answer 1

1

You have to query the lock balance in the pallet_balances. On there you can see the identifier of the lock.

Query this storage (see code):

    #[pallet::storage]
    #[pallet::getter(fn locks)]
    pub type Locks<T: Config<I>, I: 'static = ()> = StorageMap<
        _,
        Blake2_128Concat,
        T::AccountId,
        WeakBoundedVec<BalanceLock<T::Balance>, T::MaxLocks>,
        ValueQuery,
    >;

And there you can filter using the LockIdentifier that you want with the field id.

/// A single lock on a balance. There can be many of these on an account and they "overlap", so the
/// same balance is frozen by multiple locks.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct BalanceLock<Balance> {
    /// An identifier for this lock. Only one lock may be in existence for each identifier.
    pub id: LockIdentifier,
    /// The amount which the free balance may not drop below when this lock is in effect.
    pub amount: Balance,
    /// If true, then the lock remains in effect even for payment of transaction fees.
    pub reasons: Reasons,
}
2
  • so for this we need to tightly couple pallet-balances to my pallet ? Sep 8, 2023 at 5:48
  • 1
    If you want this information inside your pallet you will have to query another pallet yes. Another option might be keep track (Adding a storage) in your pallet of all the funds you are locking
    – Alex Bean
    Sep 8, 2023 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.