cat_gateway/db/index/queries/registrations/
get_all_invalids.rs

1//! Get all invalid registrations for snapshot
2
3use 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
16/// Get all invalid registrations
17const GET_ALL_INVALIDS: &str = include_str!("../cql/get_all_invalids.cql");
18
19/// Get all invalid registrations
20#[derive(SerializeRow)]
21pub(crate) struct GetAllInvalidRegistrationsParams {}
22
23/// Get all invalid registrations details for snapshot.
24#[derive(DeserializeRow)]
25pub(crate) struct GetAllInvalidRegistrationsQuery {
26    /// Error report
27    pub problem_report: String,
28    /// Full Stake Address (not hashed, 32 byte ED25519 Public key).
29    pub stake_public_key: Vec<u8>,
30    /// Slot Number
31    pub slot_no: num_bigint::BigInt,
32    /// Voting Public Key
33    pub vote_key: Vec<u8>,
34    /// Full Payment Address (not hashed, 32 byte ED25519 Public key).
35    pub payment_address: Vec<u8>,
36    /// Is the stake address a script or not.
37    pub is_payable: bool,
38    /// Is the Registration CIP36 format, or CIP15
39    pub cip36: bool,
40}
41
42impl GetAllInvalidRegistrationsQuery {
43    /// Prepares get all registrations
44    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    /// Executes get all registrations for snapshot
59    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}