dpp/identity/accessors/v0/
mod.rs

1use crate::identity::{IdentityPublicKey, KeyID, KeyType, Purpose, SecurityLevel};
2
3use crate::prelude::Revision;
4use crate::ProtocolError;
5use platform_value::Identifier;
6use std::collections::{BTreeMap, HashSet};
7
8/// Trait for getters in Identity
9pub trait IdentityGettersV0 {
10    /// Returns a reference to the public keys of the identity.
11    fn public_keys(&self) -> &BTreeMap<KeyID, IdentityPublicKey>;
12    /// Returns a mutable reference to the public keys of the identity.
13    ///
14    /// # Returns
15    ///
16    /// A mutable reference to a `BTreeMap` containing the `KeyID` as keys and `IdentityPublicKey` as values.
17    fn public_keys_mut(&mut self) -> &mut BTreeMap<KeyID, IdentityPublicKey>;
18    /// Consumes the `Identity` and returns the owned public keys.
19    ///
20    /// # Returns
21    ///
22    /// A `BTreeMap` containing the `KeyID` as keys and `IdentityPublicKey` as values.
23    fn public_keys_owned(self) -> BTreeMap<KeyID, IdentityPublicKey>;
24
25    /// Returns the balance of the identity.
26    fn balance(&self) -> u64;
27
28    /// Returns the revision of the identity.
29    fn revision(&self) -> Revision;
30
31    /// Returns the identifier of the identity.
32    fn id(&self) -> Identifier;
33
34    /// Returns a public key for a given id
35    fn get_public_key_by_id(&self, key_id: KeyID) -> Option<&IdentityPublicKey>;
36    /// Returns a public key for a given id
37    fn get_public_key_by_id_mut(&mut self, key_id: KeyID) -> Option<&mut IdentityPublicKey>;
38    /// Add identity public keys
39    fn add_public_keys(&mut self, keys: impl IntoIterator<Item = IdentityPublicKey>);
40    /// Get the biggest public KeyID
41    fn get_public_key_max_id(&self) -> KeyID;
42    /// Get first public key matching a purpose, security levels or key types
43    fn get_first_public_key_matching(
44        &self,
45        purpose: Purpose,
46        security_levels: HashSet<SecurityLevel>,
47        key_types: HashSet<KeyType>,
48        allow_disabled: bool,
49    ) -> Option<&IdentityPublicKey>;
50    /// Add an identity public key
51    fn add_public_key(&mut self, key: IdentityPublicKey);
52}
53
54/// Trait for setters in Identity
55pub trait IdentitySettersV0 {
56    /// Sets the public keys of the identity.
57    fn set_public_keys(&mut self, new_public_keys: BTreeMap<KeyID, IdentityPublicKey>);
58
59    /// Sets the balance of the identity.
60    fn set_balance(&mut self, new_balance: u64);
61
62    /// Sets the revision of the identity.
63    fn set_revision(&mut self, new_revision: Revision);
64    /// Sets the revision of the identity.
65    ///
66    /// # Arguments
67    ///
68    /// * `new_revision` - The new revision as a `Revision`.
69    fn bump_revision(&mut self);
70
71    /// Sets the identifier of the identity.
72    fn set_id(&mut self, new_id: Identifier);
73    /// Increase Identity balance
74    fn increase_balance(&mut self, amount: u64) -> u64;
75    /// Reduce the Identity balance
76    fn reduce_balance(&mut self, amount: u64) -> u64;
77    /// Increment revision
78    fn increment_revision(&mut self) -> Result<(), ProtocolError>;
79}