WIP: feat-shamir (old) #103
@@ -6,6 +6,7 @@ use crate::{
|
||||
},
|
||||
db::{
|
||||
self,
|
||||
functions::unixepoch,
|
||||
models::{
|
||||
NewProposal, NewProposalVote, NewRecoveryProposalVote, NewRecoveryWakeupRequest,
|
||||
OperatorIdentityId, Proposal, ProposalId, ProposalStatus, RecoveryOperatorIdentityId,
|
||||
@@ -570,15 +571,13 @@ impl ProposalManager {
|
||||
|
||||
/// Returns true when an uncancelled wakeup request has passed the 14-day dispute window.
|
||||
async fn is_recovery_active_conn(conn: &mut db::DatabaseConnection) -> Result<bool, Error> {
|
||||
let cutoff = diesel::dsl::sql::<diesel::sql_types::Integer>(&format!(
|
||||
"unixepoch('now') - {}",
|
||||
Self::WAKEUP_DELAY_SECS
|
||||
));
|
||||
|
||||
select(exists(
|
||||
schema::recovery_wakeup_request::table
|
||||
.filter(schema::recovery_wakeup_request::cancelled_at.is_null())
|
||||
.filter(schema::recovery_wakeup_request::requested_at.le(cutoff)),
|
||||
.filter(
|
||||
schema::recovery_wakeup_request::requested_at
|
||||
.le(unixepoch("now") - Self::WAKEUP_DELAY_SECS),
|
||||
),
|
||||
))
|
||||
.get_result(conn)
|
||||
.await
|
||||
|
||||
12
server/crates/arbiter-server/src/db/functions.rs
Normal file
12
server/crates/arbiter-server/src/db/functions.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
//! Typed bindings for the SQLite scalar functions used in Diesel expressions.
|
||||
|
||||
use diesel::sql_types::{Integer, Text};
|
||||
|
||||
diesel::define_sql_function! {
|
||||
/// SQLite `unixepoch(modifier)` -- seconds since the Unix epoch.
|
||||
///
|
||||
/// Declared so timestamp comparisons are built by the query DSL instead of by
|
||||
/// `format!`-ing a SQL fragment: the argument becomes a bind parameter and the
|
||||
/// result type is checked against the column it is compared with.
|
||||
fn unixepoch(modifier: Text) -> Integer;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
|
||||
use thiserror::Error;
|
||||
use tracing::info;
|
||||
|
||||
pub mod functions;
|
||||
pub mod models;
|
||||
pub mod proposal;
|
||||
pub mod schema;
|
||||
|
||||
Reference in New Issue
Block a user