-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: skeleton code for indexing rbac registrations
- Loading branch information
1 parent
a1675bb
commit 7124987
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
catalyst-gateway/bin/src/db/index/block/rbac509/cql/insert_rbac509.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
catalyst-gateway/bin/src/db/index/block/rbac509/insert_rbac509.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |