pub(crate) mod chain_root_for_role0_key;
pub(crate) mod chain_root_for_stake_address;
pub(crate) mod chain_root_for_txn_id;
pub(crate) mod cip36_registration;
pub(crate) mod cip36_registration_for_vote_key;
pub(crate) mod cip36_registration_invalid;
pub(crate) mod rbac509_registration;
pub(crate) mod stake_registration;
pub(crate) mod txi_by_hash;
pub(crate) mod txo_ada;
pub(crate) mod txo_assets;
pub(crate) mod unstaked_txo_ada;
pub(crate) mod unstaked_txo_assets;
use std::{fmt::Debug, sync::Arc};
use scylla::{
prepared_statement::PreparedStatement, serialize::row::SerializeRow,
transport::iterator::QueryPager, Session,
};
use super::{FallibleQueryResults, SizedBatch};
use crate::settings::cassandra_db;
const NO_PARAMS: () = ();
#[derive(strum_macros::Display)]
pub(crate) enum PreparedDeleteQuery {
TxoAda,
TxoAssets,
UnstakedTxoAda,
UnstakedTxoAsset,
Txi,
StakeRegistration,
Cip36Registration,
Cip36RegistrationInvalid,
Cip36RegistrationForVoteKey,
Rbac509,
ChainRootForTxnId,
ChainRootForRole0Key,
ChainRootForStakeAddress,
}
#[derive(strum_macros::Display)]
pub(crate) enum PreparedSelectQuery {
TxoAda,
TxoAssets,
UnstakedTxoAda,
UnstakedTxoAsset,
Txi,
StakeRegistration,
Cip36Registration,
Cip36RegistrationInvalid,
Cip36RegistrationForVoteKey,
Rbac509,
ChainRootForTxnId,
ChainRootForRole0Key,
ChainRootForStakeAddress,
}
#[allow(dead_code)]
pub(crate) struct PreparedQueries {
select_txo_ada: PreparedStatement,
delete_txo_ada: SizedBatch,
select_txo_assets: PreparedStatement,
delete_txo_assets: SizedBatch,
select_unstaked_txo_ada: PreparedStatement,
delete_unstaked_txo_ada: SizedBatch,
select_unstaked_txo_assets: PreparedStatement,
delete_unstaked_txo_assets: SizedBatch,
select_txi_by_hash: PreparedStatement,
delete_txi_by_hash: SizedBatch,
select_stake_registration: PreparedStatement,
delete_stake_registration: SizedBatch,
select_cip36_registration: PreparedStatement,
delete_cip36_registration: SizedBatch,
select_cip36_registration_invalid: PreparedStatement,
delete_cip36_registration_invalid: SizedBatch,
select_cip36_registration_for_vote_key: PreparedStatement,
delete_cip36_registration_for_vote_key: SizedBatch,
select_rbac509_registration: PreparedStatement,
delete_rbac509_registration: SizedBatch,
select_chain_root_for_txn_id: PreparedStatement,
delete_chain_root_for_txn_id: SizedBatch,
select_chain_root_for_role0_key: PreparedStatement,
delete_chain_root_for_role0_key: SizedBatch,
select_chain_root_for_stake_address: PreparedStatement,
delete_chain_root_for_stake_address: SizedBatch,
}
impl PreparedQueries {
pub(crate) async fn new(
session: Arc<Session>, cfg: &cassandra_db::EnvVars,
) -> anyhow::Result<Self> {
Ok(Self {
select_txo_ada: txo_ada::PrimaryKeyQuery::prepare(&session).await?,
delete_txo_ada: txo_ada::DeleteQuery::prepare_batch(&session, cfg).await?,
select_txo_assets: txo_assets::PrimaryKeyQuery::prepare(&session).await?,
delete_txo_assets: txo_assets::DeleteQuery::prepare_batch(&session, cfg).await?,
select_unstaked_txo_ada: unstaked_txo_ada::PrimaryKeyQuery::prepare(&session).await?,
delete_unstaked_txo_ada: unstaked_txo_ada::DeleteQuery::prepare_batch(&session, cfg)
.await?,
select_unstaked_txo_assets: unstaked_txo_assets::PrimaryKeyQuery::prepare(&session)
.await?,
delete_unstaked_txo_assets: unstaked_txo_assets::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_txi_by_hash: txi_by_hash::PrimaryKeyQuery::prepare(&session).await?,
delete_txi_by_hash: txi_by_hash::DeleteQuery::prepare_batch(&session, cfg).await?,
select_stake_registration: stake_registration::PrimaryKeyQuery::prepare(&session)
.await?,
delete_stake_registration: stake_registration::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_cip36_registration: cip36_registration::PrimaryKeyQuery::prepare(&session)
.await?,
delete_cip36_registration: cip36_registration::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_cip36_registration_invalid:
cip36_registration_invalid::PrimaryKeyQuery::prepare(&session).await?,
delete_cip36_registration_invalid:
cip36_registration_invalid::DeleteQuery::prepare_batch(&session, cfg).await?,
select_cip36_registration_for_vote_key:
cip36_registration_for_vote_key::PrimaryKeyQuery::prepare(&session).await?,
delete_cip36_registration_for_vote_key:
cip36_registration_for_vote_key::DeleteQuery::prepare_batch(&session, cfg).await?,
select_rbac509_registration: rbac509_registration::PrimaryKeyQuery::prepare(&session)
.await?,
delete_rbac509_registration: rbac509_registration::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_chain_root_for_role0_key: chain_root_for_role0_key::PrimaryKeyQuery::prepare(
&session,
)
.await?,
delete_chain_root_for_role0_key: chain_root_for_role0_key::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_chain_root_for_txn_id: chain_root_for_txn_id::PrimaryKeyQuery::prepare(&session)
.await?,
delete_chain_root_for_txn_id: chain_root_for_txn_id::DeleteQuery::prepare_batch(
&session, cfg,
)
.await?,
select_chain_root_for_stake_address:
chain_root_for_stake_address::PrimaryKeyQuery::prepare(&session).await?,
delete_chain_root_for_stake_address:
chain_root_for_stake_address::DeleteQuery::prepare_batch(&session, cfg).await?,
})
}
pub(crate) async fn prepare(
session: Arc<Session>, query: &str, consistency: scylla::statement::Consistency,
idempotent: bool,
) -> anyhow::Result<PreparedStatement> {
super::PreparedQueries::prepare(session, query, consistency, idempotent).await
}
pub(crate) async fn prepare_batch(
session: Arc<Session>, query: &str, cfg: &cassandra_db::EnvVars,
consistency: scylla::statement::Consistency, idempotent: bool, logged: bool,
) -> anyhow::Result<SizedBatch> {
super::PreparedQueries::prepare_batch(session, query, cfg, consistency, idempotent, logged)
.await
}
pub(crate) async fn execute_iter(
&self, session: Arc<Session>, select_query: PreparedSelectQuery,
) -> anyhow::Result<QueryPager> {
let prepared_stmt = match select_query {
PreparedSelectQuery::TxoAda => &self.select_txo_ada,
PreparedSelectQuery::TxoAssets => &self.select_txo_assets,
PreparedSelectQuery::UnstakedTxoAda => &self.select_unstaked_txo_ada,
PreparedSelectQuery::UnstakedTxoAsset => &self.select_unstaked_txo_assets,
PreparedSelectQuery::Txi => &self.select_txi_by_hash,
PreparedSelectQuery::StakeRegistration => &self.select_stake_registration,
PreparedSelectQuery::Cip36Registration => &self.select_cip36_registration,
PreparedSelectQuery::Cip36RegistrationInvalid => {
&self.select_cip36_registration_invalid
},
PreparedSelectQuery::Cip36RegistrationForVoteKey => {
&self.select_cip36_registration_for_vote_key
},
PreparedSelectQuery::Rbac509 => &self.select_rbac509_registration,
PreparedSelectQuery::ChainRootForTxnId => &self.select_chain_root_for_txn_id,
PreparedSelectQuery::ChainRootForRole0Key => &self.select_chain_root_for_role0_key,
PreparedSelectQuery::ChainRootForStakeAddress => {
&self.select_chain_root_for_stake_address
},
};
super::session_execute_iter(session, prepared_stmt, NO_PARAMS).await
}
pub(crate) async fn execute_batch<T: SerializeRow + Debug>(
&self, session: Arc<Session>, cfg: Arc<cassandra_db::EnvVars>, query: PreparedDeleteQuery,
values: Vec<T>,
) -> FallibleQueryResults {
let query_map = match query {
PreparedDeleteQuery::TxoAda => &self.delete_txo_ada,
PreparedDeleteQuery::TxoAssets => &self.delete_txo_assets,
PreparedDeleteQuery::UnstakedTxoAda => &self.delete_unstaked_txo_ada,
PreparedDeleteQuery::UnstakedTxoAsset => &self.delete_unstaked_txo_assets,
PreparedDeleteQuery::Txi => &self.delete_txi_by_hash,
PreparedDeleteQuery::StakeRegistration => &self.delete_stake_registration,
PreparedDeleteQuery::Cip36Registration => &self.delete_cip36_registration,
PreparedDeleteQuery::Cip36RegistrationInvalid => {
&self.delete_cip36_registration_invalid
},
PreparedDeleteQuery::Cip36RegistrationForVoteKey => {
&self.delete_cip36_registration_for_vote_key
},
PreparedDeleteQuery::Rbac509 => &self.delete_rbac509_registration,
PreparedDeleteQuery::ChainRootForTxnId => &self.delete_chain_root_for_txn_id,
PreparedDeleteQuery::ChainRootForRole0Key => &self.delete_chain_root_for_role0_key,
PreparedDeleteQuery::ChainRootForStakeAddress => {
&self.delete_chain_root_for_stake_address
},
};
super::session_execute_batch(session, query_map, cfg, query, values).await
}
}