Skip to content

Commit

Permalink
more awaits
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Mar 2, 2024
1 parent 60468a0 commit e4d6a5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/encointer-api-client-extension/src/ceremonies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl CeremoniesApi for Api {
}

async fn get_meetup_time_offset(&self) -> Result<Option<MeetupTimeOffsetType>> {
self.get_storage(ENCOINTER_CEREMONIES, "MeetupTimeOffset", None)
self.get_storage(ENCOINTER_CEREMONIES, "MeetupTimeOffset", None).await
}

async fn get_meetup_time(&self, location: Location, one_day: Moment) -> Result<Moment> {
Expand All @@ -359,7 +359,7 @@ impl CeremoniesApi for Api {
// get stats of every meetup
for m in 1..=mcount {
let m_location = self.get_meetup_location(&community_ceremony, m).await?.unwrap();
let time = self.get_meetup_time(m_location, ONE_DAY).unwrap_or(0);
let time = self.get_meetup_time(m_location, ONE_DAY).await.unwrap_or(0);
let participants = self.get_meetup_participants(&community_ceremony, m).await?;

let mut registrations = vec![];
Expand Down
3 changes: 2 additions & 1 deletion client/encointer-api-client-extension/src/communities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ impl CommunitiesApi for Api {
async fn get_locations(&self, cid: CommunityIdentifier) -> Result<Vec<Location>> {
let locations = self
.client()
.request::<Vec<Location>>("encointer_getLocations", rpc_params![cid])?;
.request::<Vec<Location>>("encointer_getLocations", rpc_params![cid])
.await?;
Ok(locations)
}
}
14 changes: 9 additions & 5 deletions client/encointer-api-client-extension/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ pub trait SchedulerApi {

impl SchedulerApi for Api {
async fn get_current_phase(&self) -> Result<CeremonyPhaseType> {
self.get_storage("EncointerScheduler", "CurrentPhase", None)?
self.get_storage("EncointerScheduler", "CurrentPhase", None)
.await?
.ok_or_else(|| ApiClientError::Other("Couldn't get CurrentPhase".into()))
}

async fn get_next_phase_timestamp(&self) -> Result<Moment> {
self.get_storage("EncointerScheduler", "NextPhaseTimestamp", None)?
self.get_storage("EncointerScheduler", "NextPhaseTimestamp", None)
.await?
.ok_or_else(|| ApiClientError::Other("Couldn't get NextPhaseTimestamp".into()))
}

async fn get_phase_duration(&self, phase: CeremonyPhaseType) -> Result<Moment> {
self.get_storage_map("EncointerScheduler", "PhaseDurations", phase, None)?
self.get_storage_map("EncointerScheduler", "PhaseDurations", phase, None)
.await?
.ok_or_else(|| ApiClientError::Other("Couldn't get PhaseDuration".into()))
}

async fn get_start_of_attesting_phase(&self) -> Result<Moment> {
let next_phase_timestamp = self.get_next_phase_timestamp()?;
let next_phase_timestamp = self.get_next_phase_timestamp().await?;

match self.get_current_phase()? {
match self.get_current_phase().await? {
CeremonyPhaseType::Assigning => Ok(next_phase_timestamp), // - next_phase_timestamp.rem(ONE_DAY),
CeremonyPhaseType::Attesting => {
self.get_phase_duration(CeremonyPhaseType::Attesting)
.await
.map(|dur| next_phase_timestamp - dur) //- next_phase_timestamp.rem(ONE_DAY)
},
CeremonyPhaseType::Registering => Err(ApiClientError::Other(
Expand Down

0 comments on commit e4d6a5c

Please sign in to comment.