Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jan 15, 2024
1 parent c1e38ba commit f3717e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions iot_verifier/src/last_beacon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use chrono::{DateTime, Utc};
use file_store::traits::TimestampDecode;
use serde::{Deserialize, Serialize};

#[derive(sqlx::FromRow, Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -40,15 +39,15 @@ impl LastBeacon {
}

pub async fn get_all_since<'c, E>(
deadline: DateTime<Utc>,
executor: E,
timestamp: DateTime<Utc>,
) -> anyhow::Result<Vec<Self>>
where
E: sqlx::Executor<'c, Database = sqlx::Postgres> + 'c,
{
Ok(
sqlx::query_as::<_, Self>(r#" select * from last_beacon where timestamp >= $1; "#)
.bind(deadline)
.bind(timestamp)
.fetch_all(executor)
.await?,
)
Expand All @@ -61,20 +60,15 @@ impl LastBeacon {
where
E: sqlx::Executor<'c, Database = sqlx::Postgres>,
{
let height = sqlx::query_scalar::<_, String>(
let height = sqlx::query_scalar(
r#"
select timestamp from last_beacon
where id = $1
"#,
)
.bind(id)
.fetch_optional(executor)
.await?
.and_then(|v| {
v.parse::<u64>()
.map_or_else(|_| None, |secs| Some(secs.to_timestamp()))
})
.transpose()?;
.await?;
Ok(height)
}

Expand Down
2 changes: 1 addition & 1 deletion iot_verifier/src/tx_scaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Server {
) -> anyhow::Result<HashMap<Vec<u8>, DateTime<Utc>>> {
let interactivity_deadline = now - Duration::minutes(HIP_17_INTERACTIVITY_LIMIT);
Ok(
LastBeacon::get_all_since(interactivity_deadline, &self.pool)
LastBeacon::get_all_since(&self.pool, interactivity_deadline)
.await?
.into_iter()
.map(|beacon| (beacon.id, beacon.timestamp))
Expand Down

0 comments on commit f3717e2

Please sign in to comment.