blueprint_client_core/
lib.rs1pub mod error;
2use error::Error;
3
4use blueprint_std::hash::Hash;
5
6pub type OperatorSet<K, V> = std::collections::BTreeMap<K, V>;
7
8#[auto_impl::auto_impl(&, Arc)]
9pub trait BlueprintServicesClient: Send + Sync + 'static {
10 type PublicApplicationIdentity: Eq + PartialEq + Hash + Ord + PartialOrd + Send + Sync + 'static;
13 type PublicAccountIdentity: Send + Sync + 'static;
16 type Id: Send + Sync + 'static;
18 type Error: core::error::Error + From<Error> + Send + Sync + 'static;
19
20 async fn get_operators(
22 &self,
23 ) -> Result<
24 OperatorSet<Self::PublicAccountIdentity, Self::PublicApplicationIdentity>,
25 Self::Error,
26 >;
27 async fn operator_id(&self) -> Result<Self::PublicApplicationIdentity, Self::Error>;
29 async fn blueprint_id(&self) -> Result<Self::Id, Self::Error>;
31
32 async fn get_operators_and_operator_id(
34 &self,
35 ) -> Result<(OperatorSet<usize, Self::PublicApplicationIdentity>, usize), Self::Error> {
36 let operators = self
37 .get_operators()
38 .await
39 .map_err(|e| Error::GetOperatorsAndOperatorId(e.to_string()))?;
40 let my_id = self
41 .operator_id()
42 .await
43 .map_err(|e| Error::GetOperatorsAndOperatorId(e.to_string()))?;
44 let mut ret = OperatorSet::new();
45 let mut ret_id = None;
46 for (id, op) in operators.into_values().enumerate() {
47 if my_id == op {
48 ret_id = Some(id);
49 }
50
51 ret.insert(id, op);
52 }
53
54 let ret_id = ret_id.ok_or_else(|| {
55 Error::GetOperatorsAndOperatorId("Operator index not found".to_string())
56 })?;
57 Ok((ret, ret_id))
58 }
59
60 async fn get_operator_index(&self) -> Result<usize, Self::Error> {
62 let (_, index) = self
63 .get_operators_and_operator_id()
64 .await
65 .map_err(|err| Error::GetOperatorIndex(err.to_string()))?;
66 Ok(index)
67 }
68}