cat_gateway/db/index/queries/rbac/
get_chain_root.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_CHAIN_ROOT: &str = include_str!("../cql/get_chain_root.cql");
#[derive(SerializeRow)]
pub(crate) struct GetChainRootQueryParams {
pub(crate) stake_address: Vec<u8>,
}
#[derive(DeserializeRow)]
pub(crate) struct GetChainRootQuery {
pub(crate) chain_root: Vec<u8>,
}
impl GetChainRootQuery {
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> {
let get_chain_root_by_stake_address_query = PreparedQueries::prepare(
session,
GET_CHAIN_ROOT,
scylla::statement::Consistency::All,
true,
)
.await;
if let Err(ref error) = get_chain_root_by_stake_address_query {
error!(error=%error, "Failed to prepare get chain root by stake address query");
};
get_chain_root_by_stake_address_query
}
pub(crate) async fn execute(
session: &CassandraSession, params: GetChainRootQueryParams,
) -> anyhow::Result<TypedRowStream<GetChainRootQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::ChainRootByStakeAddress, params)
.await?
.rows_stream::<GetChainRootQuery>()?;
Ok(iter)
}
}