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

1//! Get all 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::{
12    index::{
13        queries::{PreparedQueries, PreparedSelectQuery},
14        session::CassandraSession,
15    },
16    types::DbTxnIndex,
17};
18
19/// Get all registrations
20const GET_ALL_REGISTRATIONS: &str = include_str!("../cql/get_all_registrations.cql");
21
22/// Get all registrations
23#[derive(SerializeRow)]
24pub(crate) struct GetAllRegistrationsParams {}
25
26/// Get all registration details for snapshot.
27#[derive(DeserializeRow)]
28pub(crate) struct GetAllRegistrationsQuery {
29    /// Full Stake Address (not hashed, 32 byte ED25519 Public key).
30    pub stake_public_key: Vec<u8>,
31    /// Nonce value after normalization.
32    pub nonce: num_bigint::BigInt,
33    /// Slot Number the cert is in.
34    pub slot_no: num_bigint::BigInt,
35    /// Transaction Index.
36    pub txn_index: DbTxnIndex,
37    /// Voting Public Key
38    pub vote_key: Vec<u8>,
39    /// Full Payment Address (not hashed, 32 byte ED25519 Public key).
40    pub payment_address: Vec<u8>,
41    /// Is the stake address a script or not.
42    pub is_payable: bool,
43    /// Is the Registration CIP36 format, or CIP15
44    pub cip36: bool,
45}
46
47impl GetAllRegistrationsQuery {
48    /// Prepares get all registrations
49    pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> {
50        PreparedQueries::prepare(
51            session,
52            GET_ALL_REGISTRATIONS,
53            scylla::statement::Consistency::All,
54            true,
55        )
56        .await
57        .inspect_err(|error| error!(error=%error, "Failed to prepare get all registrations"))
58        .map_err(|error| anyhow::anyhow!("{error}\n--\n{GET_ALL_REGISTRATIONS}"))
59    }
60
61    /// Executes get all registrations for snapshot
62    pub(crate) async fn execute(
63        session: &CassandraSession, params: GetAllRegistrationsParams,
64    ) -> anyhow::Result<TypedRowStream<GetAllRegistrationsQuery>> {
65        let iter = session
66            .execute_iter(PreparedSelectQuery::GetAllRegistrations, params)
67            .await?
68            .rows_stream::<GetAllRegistrationsQuery>()?;
69
70        Ok(iter)
71    }
72}