cat_gateway/db/index/block/rbac509/
insert_rbac509.rsuse std::{fmt::Debug, sync::Arc};
use rbac_registration::cardano::cip509::Cip509;
use scylla::{frame::value::MaybeUnset, SerializeRow, Session};
use tracing::error;
use crate::{
db::index::queries::{PreparedQueries, SizedBatch},
settings::cassandra_db::EnvVars,
};
const INSERT_RBAC509_QUERY: &str = include_str!("./cql/insert_rbac509.cql");
#[derive(SerializeRow)]
pub(super) struct Params {
chain_root: Vec<u8>,
transaction_id: Vec<u8>,
purpose: Vec<u8>,
slot_no: num_bigint::BigInt,
txn: i16,
prv_txn_id: MaybeUnset<Vec<u8>>,
}
impl Debug for Params {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let prv_txn_id = match self.prv_txn_id {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(ref v) => &hex::encode(v),
};
f.debug_struct("Params")
.field("chain_root", &self.chain_root)
.field("transaction_id", &self.transaction_id)
.field("purpose", &self.purpose)
.field("slot_no", &self.slot_no)
.field("txn", &self.txn)
.field("prv_txn_id", &prv_txn_id)
.finish()
}
}
impl Params {
pub(super) fn new(
chain_root: &[u8], transaction_id: &[u8], slot_no: u64, txn: i16, cip509: &Cip509,
) -> Self {
Params {
chain_root: chain_root.to_vec(),
transaction_id: transaction_id.to_vec(),
purpose: cip509.purpose.into(),
slot_no: num_bigint::BigInt::from(slot_no),
txn,
prv_txn_id: if let Some(tx_id) = cip509.prv_tx_id {
MaybeUnset::Set(tx_id.to_vec())
} else {
MaybeUnset::Unset
},
}
}
pub(super) async fn prepare_batch(
session: &Arc<Session>, cfg: &EnvVars,
) -> anyhow::Result<SizedBatch> {
let insert_queries = PreparedQueries::prepare_batch(
session.clone(),
INSERT_RBAC509_QUERY,
cfg,
scylla::statement::Consistency::Any,
true,
false,
)
.await;
if let Err(ref error) = insert_queries {
error!(error=%error,"Failed to prepare Insert RBAC 509 Registration Query.");
};
insert_queries
}
}