traits.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #![cfg_attr(not(feature = "std"), no_std)]
  2. use crate::storage::{data_directory, data_object_storage_registry, data_object_type_registry};
  3. use parity_codec::Codec;
  4. use runtime_primitives::traits::{As, MaybeSerializeDebug, Member, SimpleArithmetic};
  5. use srml_support::Parameter;
  6. use system;
  7. // Members
  8. pub trait Members<T: system::Trait> {
  9. type Id: Parameter
  10. + Member
  11. + SimpleArithmetic
  12. + Codec
  13. + Default
  14. + Copy
  15. + As<usize>
  16. + As<u64>
  17. + MaybeSerializeDebug
  18. + PartialEq;
  19. fn is_active_member(account_id: &T::AccountId) -> bool;
  20. fn lookup_member_id(account_id: &T::AccountId) -> Result<Self::Id, &'static str>;
  21. fn lookup_account_by_member_id(member_id: Self::Id) -> Result<T::AccountId, &'static str>;
  22. }
  23. impl<T: system::Trait> Members<T> for () {
  24. type Id = u32;
  25. fn is_active_member(_account_id: &T::AccountId) -> bool {
  26. false
  27. }
  28. fn lookup_member_id(_account_id: &T::AccountId) -> Result<Self::Id, &'static str> {
  29. Err("member not found")
  30. }
  31. fn lookup_account_by_member_id(_member_id: Self::Id) -> Result<T::AccountId, &'static str> {
  32. Err("account not found")
  33. }
  34. }
  35. // Roles
  36. pub trait Roles<T: system::Trait> {
  37. fn is_role_account(account_id: &T::AccountId) -> bool;
  38. }
  39. impl<T: system::Trait> Roles<T> for () {
  40. fn is_role_account(_who: &T::AccountId) -> bool {
  41. false
  42. }
  43. }
  44. // Storage
  45. pub trait IsActiveDataObjectType<T: data_object_type_registry::Trait> {
  46. fn is_active_data_object_type(_which: &T::DataObjectTypeId) -> bool;
  47. }
  48. pub trait ContentIdExists<T: data_directory::Trait> {
  49. fn has_content(_which: &T::ContentId) -> bool;
  50. fn get_data_object(
  51. _which: &T::ContentId,
  52. ) -> Result<data_directory::DataObject<T>, &'static str>;
  53. }
  54. pub trait ContentHasStorage<T: data_object_storage_registry::Trait> {
  55. fn has_storage_provider(_which: &T::ContentId) -> bool;
  56. fn is_ready_at_storage_provider(_which: &T::ContentId, _provider: &T::AccountId) -> bool;
  57. }