Skip to main content

dpp/identity/identity_public_key/accessors/v1/
mod.rs

1use crate::fee::Credits;
2use crate::identity::TimestampMillis;
3
4/// Trait for the getters added with `IdentityPublicKeyV1`. A V0 key answers `None` to both.
5pub trait IdentityPublicKeyGettersV1 {
6    /// The total credits that state transitions signed with this key may take from the
7    /// identity over its lifetime, `None` when the key has no budget. What is left of it is not
8    /// in the key: Drive tracks it.
9    fn total_budget(&self) -> Option<Credits>;
10
11    /// The block time, in milliseconds, from which the key can no longer sign, `None` when the
12    /// key does not expire.
13    fn expires_at(&self) -> Option<TimestampMillis>;
14
15    /// Has the key expired at the given block time. The expiry instant itself is already expired.
16    fn is_expired_at(&self, time_ms: TimestampMillis) -> bool {
17        self.expires_at()
18            .is_some_and(|expires_at| time_ms >= expires_at)
19    }
20
21    /// Does the key carry a budget or an expiry
22    fn has_limits(&self) -> bool {
23        self.total_budget().is_some() || self.expires_at().is_some()
24    }
25}