cat_gateway/db/index/queries/registrations/
get_invalid.rsuse std::sync::Arc;
use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;
use crate::db::index::{
queries::{PreparedQueries, PreparedSelectQuery},
session::CassandraSession,
};
const GET_INVALID_REGISTRATIONS_FROM_STAKE_ADDR_QUERY: &str =
include_str!("../cql/get_invalid_registration_w_stake_addr.cql");
#[derive(SerializeRow)]
pub(crate) struct GetInvalidRegistrationParams {
pub stake_address: Vec<u8>,
slot_no: num_bigint::BigInt,
}
impl GetInvalidRegistrationParams {
pub(crate) fn new(
stake_address: Vec<u8>, slot_no: num_bigint::BigInt,
) -> GetInvalidRegistrationParams {
Self {
stake_address,
slot_no,
}
}
}
#[derive(DeserializeRow)]
pub(crate) struct GetInvalidRegistrationQuery {
pub error_report: Vec<String>,
pub stake_address: Vec<u8>,
pub vote_key: Vec<u8>,
pub payment_address: Vec<u8>,
pub is_payable: bool,
pub cip36: bool,
}
impl GetInvalidRegistrationQuery {
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> {
let get_invalid_registration_query = PreparedQueries::prepare(
session,
GET_INVALID_REGISTRATIONS_FROM_STAKE_ADDR_QUERY,
scylla::statement::Consistency::All,
true,
)
.await;
if let Err(ref error) = get_invalid_registration_query {
error!(error=%error, "Failed to prepare get registration query.");
};
get_invalid_registration_query
}
pub(crate) async fn execute(
session: &CassandraSession, params: GetInvalidRegistrationParams,
) -> anyhow::Result<TypedRowStream<GetInvalidRegistrationQuery>> {
let iter = session
.execute_iter(
PreparedSelectQuery::InvalidRegistrationsFromStakeAddr,
params,
)
.await?
.rows_stream::<GetInvalidRegistrationQuery>()?;
Ok(iter)
}
}