dpp/identity/accessors/v0/
mod.rs1use 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
8pub trait IdentityGettersV0 {
10 fn public_keys(&self) -> &BTreeMap<KeyID, IdentityPublicKey>;
12 fn public_keys_mut(&mut self) -> &mut BTreeMap<KeyID, IdentityPublicKey>;
18 fn public_keys_owned(self) -> BTreeMap<KeyID, IdentityPublicKey>;
24
25 fn balance(&self) -> u64;
27
28 fn revision(&self) -> Revision;
30
31 fn id(&self) -> Identifier;
33
34 fn get_public_key_by_id(&self, key_id: KeyID) -> Option<&IdentityPublicKey>;
36 fn get_public_key_by_id_mut(&mut self, key_id: KeyID) -> Option<&mut IdentityPublicKey>;
38 fn add_public_keys(&mut self, keys: impl IntoIterator<Item = IdentityPublicKey>);
40 fn get_public_key_max_id(&self) -> KeyID;
42 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 fn add_public_key(&mut self, key: IdentityPublicKey);
52}
53
54pub trait IdentitySettersV0 {
56 fn set_public_keys(&mut self, new_public_keys: BTreeMap<KeyID, IdentityPublicKey>);
58
59 fn set_balance(&mut self, new_balance: u64);
61
62 fn set_revision(&mut self, new_revision: Revision);
64 fn bump_revision(&mut self);
70
71 fn set_id(&mut self, new_id: Identifier);
73 fn increase_balance(&mut self, amount: u64) -> u64;
75 fn reduce_balance(&mut self, amount: u64) -> u64;
77 fn increment_revision(&mut self) -> Result<(), ProtocolError>;
79}