-
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.
feat: RBAC chain root and registrations queries (#1024)
* feat: RBAC chain root and registrations queries * chore: PR changes * chore: fmt * chore: fix checks * chore: fix openapi lints * chore: fix types * chore: fix fmt * chore: fix openapi lints * chore: regenerate openapi sdk --------- Co-authored-by: Steven Johnson <stevenj@users.noreply.github.com> Co-authored-by: Oleksandr Prokhorenko <djminikin@gmail.com> Co-authored-by: Joaquín Rosales <joaquin.rosales@iohk.io>
- Loading branch information
1 parent
6fd3020
commit 5a14f87
Showing
17 changed files
with
883 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
catalyst-gateway/bin/src/db/index/queries/cql/get_chain_root.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,3 @@ | ||
SELECT chain_root | ||
FROM chain_root_for_stake_addr | ||
WHERE stake_addr = :stake_address |
3 changes: 3 additions & 0 deletions
3
catalyst-gateway/bin/src/db/index/queries/cql/get_registrations_by_chain_root.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,3 @@ | ||
SELECT transaction_id | ||
FROM RBAC509_registration | ||
WHERE chain_root = :chain_root |
3 changes: 3 additions & 0 deletions
3
catalyst-gateway/bin/src/db/index/queries/cql/get_role0_key_chain_root.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,3 @@ | ||
SELECT chain_root | ||
FROM chain_root_for_role0_key | ||
WHERE role0_key = :role0_key |
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
72 changes: 72 additions & 0 deletions
72
catalyst-gateway/bin/src/db/index/queries/rbac/get_chain_root.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,72 @@ | ||
//! Get chain root by stake address. | ||
use std::sync::Arc; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow, | ||
Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::db::index::{ | ||
queries::{PreparedQueries, PreparedSelectQuery}, | ||
session::CassandraSession, | ||
}; | ||
|
||
/// Get get chain root by stake address query string. | ||
const GET_CHAIN_ROOT: &str = include_str!("../cql/get_chain_root.cql"); | ||
|
||
/// Get chain root by stake address query params. | ||
#[derive(SerializeRow)] | ||
pub(crate) struct GetChainRootQueryParams { | ||
/// Stake address to get the chain root for. | ||
pub(crate) stake_address: Vec<u8>, | ||
} | ||
|
||
/// Get chain root by stake address query row result | ||
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828 | ||
// The macro uses expect to signal an error in deserializing values. | ||
#[allow(clippy::expect_used)] | ||
mod result { | ||
use scylla::FromRow; | ||
|
||
/// Get chain root query result. | ||
#[derive(FromRow)] | ||
pub(crate) struct GetChainRootQuery { | ||
/// Chain root for the queries stake address. | ||
pub(crate) chain_root: Vec<u8>, | ||
} | ||
} | ||
|
||
/// Get chain root by stake address query. | ||
pub(crate) struct GetChainRootQuery; | ||
|
||
impl GetChainRootQuery { | ||
/// Prepares a get chain root by stake address query. | ||
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let get_chain_root_by_stake_address_query = PreparedQueries::prepare( | ||
session, | ||
GET_CHAIN_ROOT, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
if let Err(ref error) = get_chain_root_by_stake_address_query { | ||
error!(error=%error, "Failed to prepare get chain root by stake address query"); | ||
}; | ||
|
||
get_chain_root_by_stake_address_query | ||
} | ||
|
||
/// Executes a get chain root by stake address query. | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: GetChainRootQueryParams, | ||
) -> anyhow::Result<TypedRowIterator<result::GetChainRootQuery>> { | ||
let iter = session | ||
.execute_iter(PreparedSelectQuery::ChainRootByStakeAddress, params) | ||
.await? | ||
.into_typed::<result::GetChainRootQuery>(); | ||
|
||
Ok(iter) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
catalyst-gateway/bin/src/db/index/queries/rbac/get_registrations.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,73 @@ | ||
//! Get registrations by chain root. | ||
use std::sync::Arc; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow, | ||
Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::db::index::{ | ||
queries::{PreparedQueries, PreparedSelectQuery}, | ||
session::CassandraSession, | ||
}; | ||
|
||
/// Get get chain root by stake address query string. | ||
const GET_REGISTRATIONS_BY_CHAIN_ROOT_CQL: &str = | ||
include_str!("../cql/get_registrations_by_chain_root.cql"); | ||
|
||
/// Get chain root by stake address query params. | ||
#[derive(SerializeRow)] | ||
pub(crate) struct GetRegistrationsByChainRootQueryParams { | ||
/// Chain root to get registrations for. | ||
pub(crate) chain_root: Vec<u8>, | ||
} | ||
|
||
/// Get registrations by chain root query row result | ||
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828 | ||
// The macro uses expect to signal an error in deserializing values. | ||
#[allow(clippy::expect_used)] | ||
mod result { | ||
use scylla::FromRow; | ||
|
||
/// Get chain root query result. | ||
#[derive(FromRow)] | ||
pub(crate) struct GetRegistrationsByChainRootQuery { | ||
/// Registration transaction id. | ||
pub(crate) transaction_id: Vec<u8>, | ||
} | ||
} | ||
|
||
/// Get chain root by stake address query. | ||
pub(crate) struct GetRegistrationsByChainRootQuery; | ||
|
||
impl GetRegistrationsByChainRootQuery { | ||
/// Prepares a get registrations by chain root query. | ||
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let get_registrations_by_chain_root_query = PreparedQueries::prepare( | ||
session, | ||
GET_REGISTRATIONS_BY_CHAIN_ROOT_CQL, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
if let Err(ref error) = get_registrations_by_chain_root_query { | ||
error!(error=%error, "Failed to prepare get registrations by chain root query"); | ||
}; | ||
|
||
get_registrations_by_chain_root_query | ||
} | ||
|
||
/// Executes a get registrations by chain root query. | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: GetRegistrationsByChainRootQueryParams, | ||
) -> anyhow::Result<TypedRowIterator<result::GetRegistrationsByChainRootQuery>> { | ||
let iter = session | ||
.execute_iter(PreparedSelectQuery::RegistrationsByChainRoot, params) | ||
.await? | ||
.into_typed::<result::GetRegistrationsByChainRootQuery>(); | ||
|
||
Ok(iter) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
catalyst-gateway/bin/src/db/index/queries/rbac/get_role0_chain_root.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,72 @@ | ||
//! Get chain root by role0 key. | ||
use std::sync::Arc; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow, | ||
Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::db::index::{ | ||
queries::{PreparedQueries, PreparedSelectQuery}, | ||
session::CassandraSession, | ||
}; | ||
|
||
/// Get chain root by role0 key query string. | ||
const GET_ROLE0_KEY_CHAIN_ROOT_CQL: &str = include_str!("../cql/get_role0_key_chain_root.cql"); | ||
|
||
/// Get chain root by role0 key query params. | ||
#[derive(SerializeRow)] | ||
pub(crate) struct GetRole0ChainRootQueryParams { | ||
/// Role0 key to get the chain root for. | ||
pub(crate) role0_key: Vec<u8>, | ||
} | ||
|
||
/// Get chain root by role0 key query row result | ||
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828 | ||
// The macro uses expect to signal an error in deserializing values. | ||
#[allow(clippy::expect_used)] | ||
mod result { | ||
use scylla::FromRow; | ||
|
||
/// Get role0 key chain root query result. | ||
#[derive(FromRow)] | ||
pub(crate) struct GetRole0ChainRootQuery { | ||
/// Chain root. | ||
pub(crate) chain_root: Vec<u8>, | ||
} | ||
} | ||
|
||
/// Get chain root by role0 key query. | ||
pub(crate) struct GetRole0ChainRootQuery; | ||
|
||
impl GetRole0ChainRootQuery { | ||
/// Prepares a get chain root by role0 key query. | ||
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let get_chain_root_by_role0_key_query = PreparedQueries::prepare( | ||
session, | ||
GET_ROLE0_KEY_CHAIN_ROOT_CQL, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
if let Err(ref error) = get_chain_root_by_role0_key_query { | ||
error!(error=%error, "Failed to prepare get chain root by role0 key query"); | ||
}; | ||
|
||
get_chain_root_by_role0_key_query | ||
} | ||
|
||
/// Executes a get chain root role0 key query. | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: GetRole0ChainRootQueryParams, | ||
) -> anyhow::Result<TypedRowIterator<result::GetRole0ChainRootQuery>> { | ||
let iter = session | ||
.execute_iter(PreparedSelectQuery::ChainRootByRole0Key, params) | ||
.await? | ||
.into_typed::<result::GetRole0ChainRootQuery>(); | ||
|
||
Ok(iter) | ||
} | ||
} |
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,4 @@ | ||
//! RBAC queries. | ||
pub(crate) mod get_chain_root; | ||
pub(crate) mod get_registrations; | ||
pub(crate) mod get_role0_chain_root; |
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
Oops, something went wrong.