Skip to content

Commit 2b4cb31

Browse files
authored
feat(athena): Create rbac-registration module (#552)
* feat: implement building reg chain logic Signed-off-by: bkioshn <[email protected]> * chore: change module name Signed-off-by: bkioshn <[email protected]> * fix: cleanup Signed-off-by: bkioshn <[email protected]> * fix: cleanup Signed-off-by: bkioshn <[email protected]> * fix: cleanup Signed-off-by: bkioshn <[email protected]> * fix: just build and cspell Signed-off-by: bkioshn <[email protected]> * fix: typo Signed-off-by: bkioshn <[email protected]> * fix: handle finalize Signed-off-by: bkioshn <[email protected]> * chore: grammar Signed-off-by: bkioshn <[email protected]> * fix: naming Signed-off-by: bkioshn <[email protected]> * chore: remove unused --------- Signed-off-by: bkioshn <[email protected]>
1 parent 2a05b72 commit 2b4cb31

26 files changed

+1701
-0
lines changed

hermes/apps/athena/manifest_app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"package": "modules/rbac-registration-indexer/lib/rbac_registration_indexer.hmod",
1313
"name": "rbac_registration_indexer"
14+
},
15+
{
16+
"package": "modules/rbac-registration/lib/rbac_registration.hmod",
17+
"name": "rbac_registration"
1418
}
1519
],
1620
"www": "modules/http-proxy/lib/www"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rbac-registration"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
wit-bindgen = "0.43.0"
11+
anyhow = "1.0.98"
12+
serde_json = "1.0.142"
13+
strum = "0.27.2"
14+
strum_macros = "0.27.2"
15+
16+
cardano-blockchain-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs", tag = "cardano-blockchain-types/v0.0.6" }
17+
rbac-registration = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs", tag = "rbac-registration/v0.0.9" }
18+
catalyst-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.6" }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
VERSION 0.8
2+
3+
IMPORT ../../../../ AS hermes
4+
IMPORT ../../../../../wasm/wasi AS wasi
5+
6+
build-rbac-registration:
7+
DO wasi+BUILD_RUST_COMPONENT --wasi-src-dir=../../../../../wasm/wasi --out=rbac_registration.wasm
8+
9+
local-build-rbac-registration:
10+
FROM scratch
11+
COPY +build-rbac-registration/rbac_registration.wasm .
12+
SAVE ARTIFACT rbac_registration.wasm AS LOCAL lib/rbac_registration.wasm
13+
14+
15+
rbac-registration-package-module:
16+
FROM hermes+build
17+
18+
COPY lib/ .
19+
COPY +build-rbac-registration/rbac_registration.wasm .
20+
21+
RUN ./target/release/hermes module package manifest_module.json
22+
SAVE ARTIFACT rbac_registration.hmod

hermes/apps/athena/modules/rbac-registration/blueprint.cue

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/input-output-hk/hermes/main/hermes/schemas/hermes_module_manifest.schema.json",
3+
"name": "rbac_registration",
4+
"metadata": "metadata.json",
5+
"component": "rbac_registration.wasm",
6+
"config": {
7+
"file": "config.json",
8+
"schema": "config.schema.json"
9+
},
10+
"settings": {
11+
"schema": "settings.schema.json"
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/input-output-hk/hermes/main/hermes/schemas/hermes_app_metadata.schema.json",
3+
"name": "RBAC registration service",
4+
"version": "V0.1.0",
5+
"description": "Catalyst Role based access control registration service",
6+
"src": [
7+
"https://github.com/input-output-hk/hermes",
8+
"https://github.com/input-output-hk/catalyst-voices"
9+
],
10+
"copyright": ["Copyright Ⓒ 2024, IOG Singapore."],
11+
"license": [
12+
{
13+
"spdx": "Apache-2.0",
14+
"file": "/srv/data/apache2.txt"
15+
},
16+
{
17+
"spdx": "MIT",
18+
"file": "/srv/data/mit.txt"
19+
}
20+
],
21+
"developer": {
22+
"name": "IOG Singapore",
23+
"contact": "[email protected]",
24+
"payment": "wallet address"
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//! Database access layer for RBAC registration.
2+
3+
pub(crate) mod operation;
4+
pub(crate) mod query_builder;
5+
pub(crate) mod select;
6+
pub(crate) mod statement;
7+
8+
use crate::{
9+
hermes::sqlite::api::{open, Sqlite},
10+
utils::log::log_error,
11+
};
12+
13+
/// RBAC registration persistent table name.
14+
pub(crate) const RBAC_REGISTRATION_PERSISTENT_TABLE_NAME: &str = "rbac_registration_persistent";
15+
/// RBAC registration volatile table name.
16+
pub(crate) const RBAC_REGISTRATION_VOLATILE_TABLE_NAME: &str = "rbac_registration_volatile";
17+
/// RBAC stake address persistent table name.
18+
pub(crate) const RBAC_STAKE_ADDRESS_PERSISTENT_TABLE_NAME: &str = "rbac_stake_address_persistent";
19+
/// RBAC stake address volatile table name.
20+
pub(crate) const RBAC_STAKE_ADDRESS_VOLATILE_TABLE_NAME: &str = "rbac_stake_address_volatile";
21+
22+
/// Open database connection.
23+
pub(crate) fn open_db_connection(is_mem: bool) -> anyhow::Result<Sqlite> {
24+
const FUNCTION_NAME: &str = "open_db_connection";
25+
match open(false, is_mem) {
26+
Ok(db) => Ok(db),
27+
Err(e) => {
28+
let error = "Failed to open database";
29+
log_error(
30+
file!(),
31+
FUNCTION_NAME,
32+
"hermes::sqlite::api::open",
33+
&format!("{error}: {e}"),
34+
None,
35+
);
36+
anyhow::bail!(error)
37+
},
38+
}
39+
}
40+
41+
/// Close database connection.
42+
pub(crate) fn close_db_connection(sqlite: Sqlite) {
43+
const FUNCTION_NAME: &str = "close_db_connection";
44+
if let Err(e) = sqlite.close() {
45+
log_error(
46+
file!(),
47+
FUNCTION_NAME,
48+
"hermes::sqlite::api::close",
49+
&format!("Failed to close database: {e}"),
50+
None,
51+
);
52+
}
53+
}
54+
55+
// --------------- Binding helper -------------------
56+
57+
/// A macro to bind parameters to a prepared statement.
58+
#[macro_export]
59+
macro_rules! bind_parameters {
60+
($stmt:expr, $func_name:expr, $($field:expr => $field_name:expr),*) => {
61+
{
62+
let mut idx = 1;
63+
$(
64+
let value: Value = $field.try_into()?;
65+
if let Err(e) = $stmt.bind(idx, &value) {
66+
log_error(
67+
file!(),
68+
$func_name,
69+
"hermes::sqlite::bind",
70+
&format!("Failed to bind: {e:?}"),
71+
Some(&serde_json::json!({ $field_name: format!("{value:?}") }).to_string()),
72+
);
73+
anyhow::bail!("Failed to bind {}", $field_name);
74+
}
75+
idx += 1;
76+
)*
77+
Ok::<(), anyhow::Error>(())
78+
}
79+
};
80+
}

0 commit comments

Comments
 (0)