Skip to content

Commit

Permalink
merge Snapshot and NewSnapshotEntry diesel structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed May 3, 2022
1 parent bf82e2a commit e619833
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
10 changes: 2 additions & 8 deletions vit-servicing-station-lib/src/db/models/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use super::super::schema::snapshot;
use diesel::Queryable;

#[derive(Queryable)]
pub struct Snapshot {
pub voting_key: String,
pub voting_power: i64,
}

#[derive(Insertable)]
#[derive(Queryable, Insertable)]
#[table_name = "snapshot"]
pub struct NewSnapshotEntry {
pub struct SnapshotEntry {
pub voting_key: String,
pub voting_power: i64,
}
4 changes: 2 additions & 2 deletions vit-servicing-station-lib/src/server/snapshot_watcher.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
db::{models::snapshot::NewSnapshotEntry, schema, DbConnectionPool},
db::{models::snapshot::SnapshotEntry, schema, DbConnectionPool},
v0::context::SharedContext,
};
use diesel::{Connection, RunQueryDsl};
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn load_snapshot_table_from_file(path: PathBuf, pool: DbConnectionPool) ->
.values(
snapshot
.iter()
.map(|(vk, vp)| NewSnapshotEntry {
.map(|(vk, vp)| SnapshotEntry {
voting_key: vk.clone(),
voting_power: vp.parse::<u64>().unwrap() as i64,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
db::{models::snapshot::Snapshot, schema::snapshot},
db::{models::snapshot::SnapshotEntry, schema::snapshot},
v0::{context::SharedContext, errors::HandleError, result::HandlerResult},
};
use diesel::prelude::*;
Expand All @@ -16,7 +16,7 @@ pub async fn get_voting_power(
let db_conn = pool.get().map_err(HandleError::DatabaseError)?;
crate::db::schema::snapshot::table
.filter(snapshot::voting_key.eq(&voting_key))
.first::<Snapshot>(&db_conn)
.first::<SnapshotEntry>(&db_conn)
.map_err(|_e| HandleError::NotFound(voting_key))
})
.await
Expand Down

0 comments on commit e619833

Please sign in to comment.