credentials.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use codec::{Decode, Encode};
  2. use sp_std::collections::btree_set::BTreeSet;
  3. use sp_std::vec::Vec;
  4. #[cfg(feature = "std")]
  5. use serde::{Deserialize, Serialize};
  6. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  7. #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
  8. pub struct CredentialSet<Credential: Ord>(BTreeSet<Credential>);
  9. impl<Credential> From<Vec<Credential>> for CredentialSet<Credential>
  10. where
  11. Credential: Ord,
  12. {
  13. fn from(v: Vec<Credential>) -> CredentialSet<Credential> {
  14. let mut set = CredentialSet(BTreeSet::new());
  15. for credential in v.into_iter() {
  16. set.insert(credential);
  17. }
  18. set
  19. }
  20. }
  21. /// Default CredentialSet set is just an empty set.
  22. impl<Credential: Ord> Default for CredentialSet<Credential> {
  23. fn default() -> Self {
  24. CredentialSet(BTreeSet::new())
  25. }
  26. }
  27. impl<Credential: Ord> CredentialSet<Credential> {
  28. pub fn new() -> Self {
  29. Self(BTreeSet::new())
  30. }
  31. pub fn insert(&mut self, value: Credential) -> bool {
  32. self.0.insert(value)
  33. }
  34. pub fn contains(&self, value: &Credential) -> bool {
  35. self.0.contains(value)
  36. }
  37. pub fn is_empty(&self) -> bool {
  38. self.0.is_empty()
  39. }
  40. }
  41. /// Type, derived from dispatchable call, identifies the caller
  42. #[derive(Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Clone, Debug)]
  43. pub enum AccessLevel<Credential> {
  44. /// ROOT origin
  45. System,
  46. /// Caller identified as the entity maintainer
  47. EntityMaintainer, // Maybe enclose EntityId?
  48. /// Verified Credential
  49. Credential(Credential),
  50. /// In cases where a signed extrinsic doesn't provide a Credential
  51. Unspecified,
  52. }