Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,828 changes: 2,828 additions & 0 deletions hermes/apps/athena/Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions hermes/apps/athena/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["shared", "modules/*"]
18 changes: 1 addition & 17 deletions hermes/apps/athena/modules/Earthfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
VERSION 0.8

# External Build Dependencies
# ===========================
# Import pre-configured build environments and tools from external repositories.
# These provide standardized Rust toolchains, WASM compilation support, and CI/CD utilities.

# Catalyst CI Rust Environment - provides pre-configured Rust toolchain with WASM support
# This includes: rustc, cargo, wasm32-wasip2 target, optimization tools, and build utilities
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.5.14 AS rust-ci


# Alternative for local catalyst-ci debugging (uncomment when needed):
# IMPORT ../../../catalyst-ci/earthly/rust AS rust-ci

# WASI Bindings Generator - provides WebAssembly Interface Types (WIT) binding generation
# This generates Rust code from WIT files that define WebAssembly component interfaces
IMPORT ../../../../wasm/wasi AS wasi
Expand Down Expand Up @@ -89,10 +76,7 @@ gen-bindings:
#
# Duration: ~3-7 minutes total (depending on cache state and number of modules)
# Output: All build artifacts ready for packaging and deployment
build-all:
# Build the Hermes runtime engine
BUILD +get-local-hermes

build-all:
# Build all WASM modules (currently just HTTP proxy, more coming soon)
BUILD +build-http-proxy

Expand Down
2 changes: 1 addition & 1 deletion hermes/apps/athena/modules/http-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = "0.43.0"
shared = { path = "../../shared" }
serde = { version = "1.0", features = ["derive"] }
tracing = "0.1.41"
regex = "1.10"
1 change: 1 addition & 0 deletions hermes/apps/athena/modules/http-proxy/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMPORT ../../../../ AS hermes
IMPORT ../../../../../wasm/wasi AS wasi

build-http-proxy:
# TODO(no30bit): copy shared from workspace
DO wasi+BUILD_RUST_COMPONENT --wasi-src-dir=../../../../../wasm/wasi --out=http_proxy.wasm


Expand Down
12 changes: 5 additions & 7 deletions hermes/apps/athena/modules/http-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
use regex::RegexSet;
use std::sync::OnceLock;

use exports::hermes::http_gateway::event::{
Bstr, Guest as _, Headers, HttpGatewayResponse, HttpResponse,
};
use exports::hermes::http_gateway::event::{Bstr, Headers, HttpGatewayResponse, HttpResponse};

wit_bindgen::generate!({
shared::bindings_generate!({
world: "hermes:app/hermes",
path: "../../../wasi/wit",
path: "../../../../../wasm/wasi/wit",
inline: "
package hermes:app;

Expand All @@ -40,11 +38,11 @@ wit_bindgen::generate!({

}
",
generate_all,
share: ["hermes:logging"],
});
export!(HttpProxyComponent);

use hermes::logging::api::{log, Level};
use shared::bindings::hermes::logging::api::{log, Level};

/// What to do when a route pattern matches
#[derive(Debug, Clone, Copy)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = "0.43.0"
shared = { path = "../../shared" }
anyhow = "1.0.98"
serde_json = "1.0.142"
strum = "0.27.2"
strum_macros = "0.27.2"

cardano-blockchain-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs", tag = "cardano-blockchain-types/v0.0.6" }
rbac-registration = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs", tag = "rbac-registration/v0.0.9" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMPORT ../../../../ AS hermes
IMPORT ../../../../../wasm/wasi AS wasi

build-rbac-registration-indexer:
# TODO(no30bit): copy shared from workspace
DO wasi+BUILD_RUST_COMPONENT --wasi-src-dir=../../../../../wasm/wasi --out=rbac_registration_indexer.wasm

local-build-rbac-registration-indexer:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Create the database tables for RBAC registration.

use crate::{
database::{
operation::Operation, query_builder::QueryBuilder, statement::DatabaseStatement,
RBAC_REGISTRATION_PERSISTENT_TABLE_NAME, RBAC_REGISTRATION_VOLATILE_TABLE_NAME,
RBAC_STAKE_ADDRESS_PERSISTENT_TABLE_NAME, RBAC_STAKE_ADDRESS_VOLATILE_TABLE_NAME,
},
hermes::sqlite::api::Sqlite,
use shared::{
bindings::hermes::sqlite::api::Sqlite,
utils::sqlite::{operation::Operation, statement::DatabaseStatement},
};

use crate::database::{
query_builder::QueryBuilder, RBAC_REGISTRATION_PERSISTENT_TABLE_NAME,
RBAC_REGISTRATION_VOLATILE_TABLE_NAME, RBAC_STAKE_ADDRESS_PERSISTENT_TABLE_NAME,
RBAC_STAKE_ADDRESS_VOLATILE_TABLE_NAME,
};

/// Create a persistent `rbac_registration` and `rbac_stake_address` table.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Handle block rollback from volatile table.

use crate::{
database::{operation::Operation, query_builder::QueryBuilder, statement::DatabaseStatement},
hermes::sqlite::api::{Sqlite, Statement},
use shared::{
bindings::hermes::sqlite::api::{Sqlite, Statement},
utils::sqlite::{operation::Operation, statement::DatabaseStatement},
};

use crate::database::query_builder::QueryBuilder;

/// Prepare delete statement for deleting data when rollback happen from given volatile table.
pub(crate) fn prepare_roll_back_delete_from_volatile(
sqlite: &Sqlite,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Handle block forward from volatile table.

use crate::{
database::{operation::Operation, query_builder::QueryBuilder, statement::DatabaseStatement},
hermes::sqlite::api::{Sqlite, Statement},
use shared::{
bindings::hermes::sqlite::api::{Sqlite, Statement},
utils::sqlite::{operation::Operation, statement::DatabaseStatement},
};

use crate::database::query_builder::QueryBuilder;

/// Prepare delete statement for deleting data for roll forward from given volatile table.
pub(crate) fn prepare_roll_forward_delete_from_volatile(
sqlite: &Sqlite,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//! Insert data to `rbac_registration` table.
use crate::{
bind_parameters,
database::{
data::rbac_db::RbacDbData, operation::Operation, query_builder::QueryBuilder,
statement::DatabaseStatement,

use shared::{
bindings::hermes::sqlite::api::{Sqlite, Statement, Value},
sqlite_bind_parameters,
utils::{
log::log_error,
sqlite::{operation::Operation, statement::DatabaseStatement},
},
hermes::sqlite::api::{Sqlite, Statement, Value},
utils::log::log_error,
};

use crate::database::{data::rbac_db::RbacDbData, query_builder::QueryBuilder};

/// Prepare insert statement for `rbac_registration` table.
pub(crate) fn prepare_insert_rbac_registration(
sqlite: &Sqlite,
Expand All @@ -30,7 +32,7 @@ pub(crate) fn insert_rbac_registration(
data: RbacDbData,
) {
const FUNCTION_NAME: &str = "insert_rbac_registration";
DatabaseStatement::bind_step_reset_statement(
let _ = DatabaseStatement::bind_step_reset_statement(
stmt,
|stmt| bind_rbac_registration(stmt, data),
FUNCTION_NAME,
Expand All @@ -57,7 +59,7 @@ fn bind_rbac_registration(
anyhow::bail!("Failed to convert slot: {e}");
},
};
bind_parameters!(stmt, FUNCTION_NAME,
sqlite_bind_parameters!(stmt, FUNCTION_NAME,
data.txn_id => "txn_id",
slot => "slot_no",
data.txn_idx => "txn_idx",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! Insert data to `rbac_stake_address` table.

use crate::{
bind_parameters,
database::{
data::rbac_stake_db::RbacStakeDbData, operation::Operation, query_builder::QueryBuilder,
statement::DatabaseStatement,
use shared::{
bindings::hermes::sqlite::api::{Sqlite, Statement, Value},
sqlite_bind_parameters,
utils::{
log::log_error,
sqlite::{operation::Operation, statement::DatabaseStatement},
},
hermes::sqlite::api::{Sqlite, Statement, Value},
utils::log::log_error,
};

use crate::database::{data::rbac_stake_db::RbacStakeDbData, query_builder::QueryBuilder};

/// Prepare insert statement for `rbac_stake_address` table.
pub(crate) fn prepare_insert_rbac_stake_address(
sqlite: &Sqlite,
Expand All @@ -31,7 +32,7 @@ pub(crate) fn insert_rbac_stake_address(
data: RbacStakeDbData,
) {
const FUNCTION_NAME: &str = "insert_rbac_stake_address";
DatabaseStatement::bind_step_reset_statement(
let _ = DatabaseStatement::bind_step_reset_statement(
stmt,
|stmt| bind_rbac_stake_address(stmt, data),
FUNCTION_NAME,
Expand All @@ -58,7 +59,7 @@ fn bind_rbac_stake_address(
anyhow::bail!("Failed to convert slot: {e}");
},
};
bind_parameters!(stmt, FUNCTION_NAME,
sqlite_bind_parameters!(stmt, FUNCTION_NAME,
data.stake_address => "stake_address",
slot => "slot_no",
data.txn_idx => "txn_idx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ pub(crate) mod create;
pub(crate) mod data;
pub(crate) mod delete;
pub(crate) mod insert;
pub(crate) mod operation;
pub(crate) mod query_builder;
pub(crate) mod statement;

use crate::{
hermes::sqlite::api::{open, Sqlite},
utils::log::log_error,
};

/// RBAC registration persistent table name.
pub(crate) const RBAC_REGISTRATION_PERSISTENT_TABLE_NAME: &str = "rbac_registration_persistent";
Expand All @@ -21,63 +14,3 @@ pub(crate) const RBAC_REGISTRATION_VOLATILE_TABLE_NAME: &str = "rbac_registratio
pub(crate) const RBAC_STAKE_ADDRESS_PERSISTENT_TABLE_NAME: &str = "rbac_stake_address_persistent";
/// RBAC stake address volatile table name.
pub(crate) const RBAC_STAKE_ADDRESS_VOLATILE_TABLE_NAME: &str = "rbac_stake_address_volatile";

/// Open database connection.
pub(crate) fn open_db_connection(is_mem: bool) -> anyhow::Result<Sqlite> {
const FUNCTION_NAME: &str = "open_db_connection";
match open(false, is_mem) {
Ok(db) => Ok(db),
Err(e) => {
let error = "Failed to open database";
log_error(
file!(),
FUNCTION_NAME,
"hermes::sqlite::api::open",
&format!("{error}: {e}"),
None,
);
anyhow::bail!(error)
},
}
}

/// Close database connection.
pub(crate) fn close_db_connection(sqlite: Sqlite) {
const FUNCTION_NAME: &str = "close_db_connection";
if let Err(e) = sqlite.close() {
log_error(
file!(),
FUNCTION_NAME,
"hermes::sqlite::api::close",
&format!("Failed to close database: {e}"),
None,
);
}
}

// --------------- Binding helper -------------------

/// A macro to bind parameters to a prepared statement.
#[macro_export]
macro_rules! bind_parameters {
($stmt:expr, $func_name:expr, $($field:expr => $field_name:expr),*) => {
{
let mut idx = 1;
$(
let value: Value = $field.into();
if let Err(e) = $stmt.bind(idx, &value) {
log_error(
file!(),
$func_name,
"hermes::sqlite::bind",
&format!("Failed to bind: {e:?}"),
Some(&serde_json::json!({ $field_name: format!("{value:?}") }).to_string()),
);
anyhow::bail!("Failed to bind {}", $field_name);
}
idx += 1;
)*
Ok::<(), anyhow::Error>(())
}
};
}
Loading
Loading