cat_gateway/db/index/queries/registrations/
get_all_invalids.rs1use std::sync::Arc;
4
5use scylla::{
6 prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
7 SerializeRow, Session,
8};
9use tracing::error;
10
11use crate::db::index::{
12 queries::{PreparedQueries, PreparedSelectQuery},
13 session::CassandraSession,
14};
15
16const GET_ALL_INVALIDS: &str = include_str!("../cql/get_all_invalids.cql");
18
19#[derive(SerializeRow)]
21pub(crate) struct GetAllInvalidRegistrationsParams {}
22
23#[derive(DeserializeRow)]
25pub(crate) struct GetAllInvalidRegistrationsQuery {
26 pub problem_report: String,
28 pub stake_public_key: Vec<u8>,
30 pub slot_no: num_bigint::BigInt,
32 pub vote_key: Vec<u8>,
34 pub payment_address: Vec<u8>,
36 pub is_payable: bool,
38 pub cip36: bool,
40}
41
42impl GetAllInvalidRegistrationsQuery {
43 pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> {
45 PreparedQueries::prepare(
46 session,
47 GET_ALL_INVALIDS,
48 scylla::statement::Consistency::All,
49 true,
50 )
51 .await
52 .inspect_err(
53 |error| error!(error=%error, "Failed to prepare get all invalid registrations"),
54 )
55 .map_err(|error| anyhow::anyhow!("{error}\n--\n{GET_ALL_INVALIDS}"))
56 }
57
58 pub(crate) async fn execute(
60 session: &CassandraSession, params: GetAllInvalidRegistrationsParams,
61 ) -> anyhow::Result<TypedRowStream<GetAllInvalidRegistrationsQuery>> {
62 let iter = session
63 .execute_iter(PreparedSelectQuery::GetAllInvalidRegistrations, params)
64 .await?
65 .rows_stream::<GetAllInvalidRegistrationsQuery>()?;
66
67 Ok(iter)
68 }
69}