cat_gateway/db/index/queries/registrations/
get_all_registrations.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::{
12 index::{
13 queries::{PreparedQueries, PreparedSelectQuery},
14 session::CassandraSession,
15 },
16 types::DbTxnIndex,
17};
18
19const GET_ALL_REGISTRATIONS: &str = include_str!("../cql/get_all_registrations.cql");
21
22#[derive(SerializeRow)]
24pub(crate) struct GetAllRegistrationsParams {}
25
26#[derive(DeserializeRow)]
28pub(crate) struct GetAllRegistrationsQuery {
29 pub stake_public_key: Vec<u8>,
31 pub nonce: num_bigint::BigInt,
33 pub slot_no: num_bigint::BigInt,
35 pub txn_index: DbTxnIndex,
37 pub vote_key: Vec<u8>,
39 pub payment_address: Vec<u8>,
41 pub is_payable: bool,
43 pub cip36: bool,
45}
46
47impl GetAllRegistrationsQuery {
48 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 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}