Skip to content

Commit

Permalink
wip: index rbac registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Sep 25, 2024
1 parent 092ff4b commit 4960a60
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
5 changes: 3 additions & 2 deletions catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ repository.workspace = true
workspace = true

[dependencies]
cardano-chain-follower = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.2" }
cardano-chain-follower = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", branch = "main" }
#cardano-chain-follower = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.2" }

pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
pallas-traverse = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
Expand Down Expand Up @@ -92,4 +93,4 @@ base64 = "0.22.1"
dashmap = "6.0.1"

[build-dependencies]
build-info-build = "0.0.38"
build-info-build = "0.0.38"
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/src/db/index/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) async fn index_block(block: &MultiEraBlock) -> anyhow::Result<()> {
txo_index.index(txs, slot_no, &txn_hash, txn);

// Index RBAC 509 inside the transaction.
rbac509_index.index(txn_index, txn, slot_no, block);
rbac509_index.index(&txn_hash, txn_index, txn, slot_no, block);
}

// We then execute each batch of data from the block.
Expand Down
37 changes: 29 additions & 8 deletions catalyst-gateway/bin/src/db/index/block/rbac509/insert_rbac509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
//!
//! Note, there are multiple ways TXO Data is indexed and they all happen in here.

use std::sync::Arc;
use std::{fmt::Debug, sync::Arc};

use scylla::{SerializeRow, Session};
use cardano_chain_follower::Metadata::cip509::Cip509;
use scylla::{frame::value::MaybeUnset, SerializeRow, Session};
use tracing::error;

use crate::{
Expand All @@ -17,7 +18,7 @@ use crate::{
const INSERT_RBAC509_QUERY: &str = include_str!("./cql/insert_rbac509.cql");

/// Insert RBAC Registration Query Parameters
#[derive(SerializeRow, Debug)]
#[derive(SerializeRow)]
pub(super) struct Params {
/// Chain Root Hash. 32 bytes.
chain_root: Vec<u8>,
Expand All @@ -30,23 +31,43 @@ pub(super) struct Params {
/// 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>>,
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()
}
}

#[allow(clippy::todo, dead_code, clippy::unused_async)]
impl Params {
/// Create a new record for this transaction.
pub(super) fn new(
chain_root: Vec<u8>, transaction_id: Vec<u8>, purpose: Vec<u8>, slot_no: u64, txn: i16,
prv_txn_id: Option<Vec<u8>>,
chain_root: Vec<u8>, transaction_id: Vec<u8>, slot_no: u64, txn: i16, cip509: &Cip509,
) -> Self {
Params {
chain_root,
transaction_id,
purpose,
purpose: cip509.purpose.to_vec(),
slot_no: num_bigint::BigInt::from(slot_no),
txn,
prv_txn_id,
prv_txn_id: if let Some(tx_id) = cip509.prv_tx_id {
MaybeUnset::Set(tx_id.to_vec())
} else {
MaybeUnset::Unset
},
}
}

Expand Down
28 changes: 19 additions & 9 deletions catalyst-gateway/bin/src/db/index/block/rbac509/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
//! Index Role-Based Access Control (RBAC) Registration.
#![allow(
unused_imports,
clippy::todo,
dead_code,
unused_variables,
clippy::unused_async
)]

mod insert_rbac509;

Expand Down Expand Up @@ -44,10 +37,27 @@ impl Rbac509InsertQuery {
}

/// Index the RBAC 509 registrations in a transaction.
#[allow(clippy::todo, unused_variables)]
pub(crate) fn index(
&mut self, txn: usize, txn_index: i16, slot_no: u64, block: &MultiEraBlock,
&mut self, txn_hash: &[u8], txn: usize, txn_index: i16, slot_no: u64, block: &MultiEraBlock,
) {
todo!();
if let Some(decoded_metadata) = block.txn_metadata(txn, Metadata::cip509::LABEL) {
#[allow(irrefutable_let_patterns)]
if let Metadata::DecodedMetadataValues::Cip509(rbac) = &decoded_metadata.value {
if let Some(tx_id) = rbac.prv_tx_id {
// WIP: fetch chain_root from cache or DB
} else {
let chain_root = txn_hash.to_vec();
self.registrations.push(insert_rbac509::Params::new(
chain_root,
txn_hash.to_vec(),
slot_no,
txn_index,
rbac,
));
}
}
}
}

/// Execute the RBAC 509 Registration Indexing Queries.
Expand Down

0 comments on commit 4960a60

Please sign in to comment.