Skip to content

Commit

Permalink
wip: skeleton code for indexing rbac registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Sep 24, 2024
1 parent a1675bb commit 7124987
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/db/index/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub(crate) mod certs;
pub(crate) mod cip36;
pub(crate) mod rbac509;
pub(crate) mod txi;
pub(crate) mod txo;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Index CIP-509 Registrations (Valid)
INSERT INTO cip509_registration (
chain_root,
transaction_id,
purpose,
slot_no,
txn,
prv_txn_id
) VALUES (
:chain_root,
:transaction_id,
:purpose,
:slot_no,
:txn,
:prv_txn_id
);
48 changes: 48 additions & 0 deletions catalyst-gateway/bin/src/db/index/block/rbac509/insert_rbac509.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Insert RBAC 509 Indexed D
//!
//! Note, there are multiple ways TXO Data is indexed and they all happen in here.

use std::sync::Arc;

use scylla::{SerializeRow, Session};

use crate::{db::index::queries::SizedBatch, settings::CassandraEnvVars};

/// RBAC Registration Indexing query
#[allow(dead_code)]
const INSERT_RBAC_QUERY: &str = include_str!("./cql/insert_rbac509.cql");

/// Insert RBAC Registration Query Parameters
#[derive(SerializeRow, Debug)]
pub(super) struct Params {
/// Chain Root Hash. 32 bytes.
chain_root: Vec<u8>,
/// Transaction ID Hash. 32 bytes.
transaction_id: Vec<u8>,
/// Purpose.`UUIDv4`. 16 bytes.
purpose: Vec<u8>,
/// Block Slot Number
slot_no: num_bigint::BigInt,
/// Transaction Offset inside the block.
txn: i16,
/// Hash of Previous Transaction. Is `None` for the first registration. 32 Bytes.
prv_txn_id: Option<Vec<u8>>,
}

#[allow(clippy::todo, dead_code, clippy::unused_async)]
impl Params {
/// Create a new record for this transaction.
pub(super) fn new(//
//stake_address: &[u8], slot_no: u64, txn: i16, txo: i16, address: &str, value: u64,
// txn_hash: &[u8],
) -> Self {
todo!();
}

/// Prepare Batch of RBAC Registration Index Data Queries
pub(super) async fn prepare_batch(
_session: &Arc<Session>, _cfg: &CassandraEnvVars,
) -> anyhow::Result<SizedBatch> {
todo!();
}
}
68 changes: 68 additions & 0 deletions catalyst-gateway/bin/src/db/index/block/rbac509/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Index Role-Based Access Control (RBAC) Registration.
#![allow(
unused_imports,
clippy::todo,
dead_code,
unused_variables,
clippy::unused_async
)]

mod insert_rbac509;

use std::sync::Arc;

use cardano_chain_follower::{Metadata, MultiEraBlock};
use scylla::Session;

use crate::{
db::index::{
queries::{FallibleQueryTasks, PreparedQuery, SizedBatch},
session::CassandraSession,
},
settings::CassandraEnvVars,
};

/// Index RBAC 509 Registration Query Parameters
pub(crate) struct Rbac509InsertQuery {
/// RBAC Registration Data captured during indexing.
registrations: Vec<insert_rbac509::Params>,
}

impl Rbac509InsertQuery {
/// Create new data set for CIP-36 Registrations Insert Query Batch.
pub(crate) fn new() -> Self {
Rbac509InsertQuery {
registrations: Vec::new(),
}
}

/// Prepare Batch of Insert Cip36 Registration Data Queries
pub(crate) async fn prepare_batch(
session: &Arc<Session>, cfg: &CassandraEnvVars,
) -> anyhow::Result<(SizedBatch, SizedBatch, SizedBatch)> {
todo!();
}

/// Index the CIP-36 registrations in a transaction.
pub(crate) fn index(
&mut self, txn: usize, txn_index: i16, slot_no: u64, block: &MultiEraBlock,
) {
todo!();
}

/// Execute the CIP-36 Registration Indexing Queries.
///
/// Consumes the `self` and returns a vector of futures.
pub(crate) fn execute(self, session: &Arc<CassandraSession>) -> FallibleQueryTasks {
let mut query_handles: FallibleQueryTasks = Vec::new();

if !self.registrations.is_empty() {
let inner_session = session.clone();
query_handles.push(tokio::spawn(async move {
todo!();
}));
}

query_handles
}
}

0 comments on commit 7124987

Please sign in to comment.