Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cat-gateway): Add autogenerated cassandra schema version and sync status tables. #889

Merged
merged 129 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
02c0595
fix(docs): Fix up docs issues
stevenj Jul 11, 2024
b3ba2f4
fix(backend): Huge refactor to prep for scylladb config management
stevenj Jul 11, 2024
94a3689
fix(backend): Clean up logging a little, and add build info logs as r…
stevenj Jul 12, 2024
8308f34
Refactor and setup cassandra config/session
stevenj Jul 15, 2024
98176bd
feat(backend): Index DB schema setup seems to work
stevenj Jul 17, 2024
042f5ed
WIP
stevenj Jul 21, 2024
b69c30f
fix(rust): Format fixes
stevenj Jul 24, 2024
209716d
fix(rust): Build fixes
stevenj Jul 24, 2024
82dabcf
Merge branch 'main' into feat/chain-sync-v2
stevenj Jul 24, 2024
c1d09ff
fix(rust): Adjust index DB so we can index without querying, and can …
stevenj Jul 24, 2024
bd4d73b
fix(rust): add more docs
stevenj Jul 25, 2024
c53b198
fix(rust): basic new follower integration
stevenj Jul 25, 2024
a9bb395
fix(rust): wip
stevenj Jul 25, 2024
d71c063
fix(ci): Bump rust compiler version to match CI
stevenj Jul 29, 2024
7deebc3
ci(backend): Bump rust version to match CI
stevenj Jul 29, 2024
63e0ac8
fix(backend): Fix code format and lints
stevenj Jul 29, 2024
0463d92
feat(backend): simple new block indexer just to test the logic works
stevenj Jul 29, 2024
9c5f21a
feat(gateway): Simple indexing with cassandra seems to work
stevenj Jul 30, 2024
316fdfd
refactor(backend): Remove lazy and once_cell in favor of new standard…
stevenj Jul 31, 2024
1c01aad
fix(backend): WIP indexing for stake addresses and unstaked ada
stevenj Aug 1, 2024
a3f47df
fix(backend): indexing WIP
stevenj Aug 6, 2024
22eb2bb
Merge branch 'main' into feat/chain-sync-v2
stevenj Aug 8, 2024
194d734
fix(backend): Add support for log control with env vars, default to m…
stevenj Aug 16, 2024
318060a
feat(backend): Make local test scylla db run with 4 nodes, not 1
stevenj Aug 19, 2024
2f7f893
fix(backend-lib): Add stop for cassandra db cluster
stevenj Aug 27, 2024
52ca260
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 5, 2024
def54ca
refactor(backend-lib): Remove c509-certificate because its moved to c…
stevenj Sep 5, 2024
a1f6557
fix(backend): Remove dependencies from Workspace, and move into project
stevenj Sep 6, 2024
67fe2eb
fix(backend): Use temporary cat-ci branch for rust builders
stevenj Sep 6, 2024
8cbe29b
fix(backend): Remove obsolete common crates subdirectory
stevenj Sep 6, 2024
de6e465
fix(backend): Don't use pre-packaged mithril snapshots in integration…
stevenj Sep 6, 2024
5df51b1
fix(backend): Fix code so it builds with latest chain follower code.
stevenj Sep 6, 2024
00d96b8
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 9, 2024
36634b9
fix(backend): Fix broken reference to catalyst libs
stevenj Sep 10, 2024
5578b24
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 10, 2024
a57ac80
ci(ci): Bump all earthfiles to latest WIP cat-ci branch
stevenj Sep 11, 2024
3c15ae2
fix(frontend-pkg): Ignore .dart_tool directory in frontend files chec…
stevenj Sep 11, 2024
004ff17
fix(ci): Fix spelling
stevenj Sep 11, 2024
98d53e7
fix(spelling): Add more project words and properly sort list
stevenj Sep 11, 2024
52a4a67
fix(backend): Sync rust configs and add target to make it easier in f…
stevenj Sep 11, 2024
841d8ce
fix(backend): Enable all features of Scylla for now.
stevenj Sep 11, 2024
12b93c6
fix(frontend-pkg): Fix markdown table having too many columns
stevenj Sep 11, 2024
6895162
ci(spelling): Fix spelling issues
stevenj Sep 11, 2024
8564ba6
fix(docs): Bump docs to latest WIP cat-ci version
stevenj Sep 11, 2024
4073cd9
feat(gateway): Add low resource scylla db instance for local testing
stevenj Sep 11, 2024
8242f61
feat(gateway): Add and update developer convenience functions for bac…
stevenj Sep 11, 2024
6de6084
fix(backend): Fix code format
stevenj Sep 11, 2024
9d5dbb7
fix(backend): Fix spelling issues in CQL files
stevenj Sep 11, 2024
306473a
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 11, 2024
0eef251
fix(spelling): Remove duplicates from the project words dictionary
stevenj Sep 11, 2024
08030a3
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 11, 2024
5074177
fix(backend): Get the backend building properly with earthly.
stevenj Sep 11, 2024
6f9192c
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 11, 2024
412a7b0
feat(backend): remove obsoleted postgres logic for chain indexing
stevenj Sep 12, 2024
47af540
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 12, 2024
9eba03d
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 12, 2024
704f5a2
revert(event-db): Revert extension changes to sql files after fixing …
stevenj Sep 12, 2024
273e15d
fix(frontend): Regenerate the dart api interface file, and add doing …
stevenj Sep 12, 2024
45848eb
fix(backend): temporarily disable API tests
stevenj Sep 12, 2024
c80008e
fix(backend): Also temporarily stop workflow consuming test reports t…
stevenj Sep 12, 2024
13b4968
fix(ci): Try and stop coveralls running for api-tests
stevenj Sep 12, 2024
000d129
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 12, 2024
e4a6939
ci(general): Replace temp CI branch with tagged release
stevenj Sep 13, 2024
d8bf390
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 13, 2024
38f8ee9
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 13, 2024
0789214
feat: Add Handler for Permissionless Auth (#825)
stevenj Sep 17, 2024
f2dee3e
feat: auth token (#723)
cong-or Sep 17, 2024
5213f64
feat: Update GET staked_ada endpoint to fetch from ScyllaDB (#728)
FelipeRosa Sep 17, 2024
138172d
feat: DB Indexing for CIP-36 registrations (#788)
saibatizoku Sep 18, 2024
3aae7c9
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 18, 2024
092fa4b
docs(general): Cleanup project dictionary
stevenj Sep 18, 2024
d2c65ba
docs(spelling): Fix spelling
stevenj Sep 18, 2024
dbd6f57
fix(backend): remove obsolete clippy lint cfg
stevenj Sep 18, 2024
8eee590
docs(backend): Improve field documentation so its not ambiguous.
stevenj Sep 18, 2024
1246b78
docs(backend): Fix comment
stevenj Sep 18, 2024
add69d8
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 18, 2024
3f069b3
docs(backend): Improve comment
stevenj Sep 19, 2024
5ed882e
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 19, 2024
8be3334
fix(backend): Vote Key index logic, and update comments
stevenj Sep 19, 2024
d779c5c
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 19, 2024
c8087a6
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 19, 2024
262d534
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 19, 2024
82676d1
fix(backend): Earthfile needs to be executed from root of repo, to pr…
stevenj Sep 19, 2024
3e8c76f
fix(backend): make generic saturating value converter and use it inst…
stevenj Sep 19, 2024
96b784d
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 19, 2024
c174601
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 19, 2024
b50a882
Merge branch 'main' into feat/chain-sync-v2
saibatizoku Sep 19, 2024
552508a
test(cat-gateway): Add tests for float conversion and better docs abo…
stevenj Sep 20, 2024
b7d25b4
fix(cat-gateway): Developer lints in release mode, and also refer to …
stevenj Sep 20, 2024
be0d3fc
fix(cat-gateway): CIP36 index schema error
stevenj Sep 20, 2024
43152e4
fix(cat-gateway): Cip36 indexing working, improve bad cassandra query…
stevenj Sep 20, 2024
4653142
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 20, 2024
ffa0b40
Merge branch 'main' into feat/chain-sync-v2
saibatizoku Sep 20, 2024
3e1bfd2
refactor(cat-gateway): Make settings a sub-module
stevenj Sep 24, 2024
7a2e14a
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 24, 2024
1b5c6ac
refactor(cat-gateway): Break up Envvar handling into multiple files
stevenj Sep 24, 2024
7617b7a
refactor(cat-gateway): Fix code format
stevenj Sep 24, 2024
2587d94
feat(cat-gateway): Add chain-sync downloader options to cat-gateway e…
stevenj Sep 24, 2024
beb2958
test(cat-gateway): Make debug logs visible in local testing
stevenj Sep 24, 2024
f457927
fix(cat-gateway): Minimum timeout for mithril downloads
stevenj Sep 24, 2024
343b77c
test(cat-gateway): Silence gratuitous debug log in cassandra queries
stevenj Sep 24, 2024
0bc72a4
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 24, 2024
0bc9238
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 24, 2024
2b68a4c
refactor(cat-gateway): Decrease verboseness of the string env var log…
stevenj Sep 24, 2024
31de465
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 24, 2024
bc92706
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 24, 2024
53da87b
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 25, 2024
3ad1460
fix(general): Bump alpine version and pin to fix missing upstream con…
stevenj Sep 25, 2024
c29c903
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 25, 2024
ead01c9
ci(general): Bump cat-ci to v3.2.07
stevenj Sep 25, 2024
d7eedf9
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 25, 2024
bedbe30
ci(general): fix docker in docker container image
stevenj Sep 25, 2024
9237d9c
feat(cat-gateway): Autogenerate the cassandra schema version and add …
stevenj Sep 26, 2024
caf05b7
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 26, 2024
89b0bfc
fix(cat-gateway): Bump rust library dependency versions
stevenj Sep 26, 2024
cc466b2
fix(cat-gateway): Make cassandra namespace compliant.
stevenj Sep 26, 2024
450e721
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 26, 2024
20cde28
refactor(cat-gateway): rename utilities to utils
stevenj Sep 26, 2024
02b84af
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 26, 2024
cf42b41
refactor(cat-gateway): use ensure! instead of if/bail
stevenj Sep 27, 2024
7eefdc8
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 27, 2024
68690c2
Merge branch 'main' into feat/chain-sync-v2
stevenj Sep 27, 2024
9f2498c
ci(general): Bump cat-ci version to latest
stevenj Sep 27, 2024
2adf600
Merge branch 'feat/chain-sync-v2' of github.com:input-output-hk/catal…
stevenj Sep 27, 2024
c2ad667
fix(flutter): Again, try and see if caching is working ok for flutter…
stevenj Sep 28, 2024
3bdd317
ci(general): Bump CI to latest version to try and fix docs build issues
stevenj Sep 28, 2024
044a102
docs(cat-gateway): Better document the generate_cql_schema_version fu…
stevenj Sep 28, 2024
d91540a
fix(cat-gateway): Use a string array reference rather than a vec of s…
stevenj Sep 28, 2024
d21f90d
refactor(cat-gateway): fix code format
stevenj Sep 28, 2024
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
1 change: 1 addition & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Precertificate
preprod
projectcatalyst
Prokhorenko
proptest
psql
Ptarget
pubkey
Expand Down
27 changes: 15 additions & 12 deletions catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalys
pallas-traverse = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
#pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }

clap = { version = "4.5.17", features = ["derive", "env"] }
clap = { version = "4.5.18", features = ["derive", "env"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = [
"fmt",
Expand All @@ -31,25 +31,25 @@ tracing-subscriber = { version = "0.3.18", features = [
"time",
"env-filter",
] }
serde = { version = "1.0.204", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
thiserror = "1.0.63"
thiserror = "1.0.64"
chrono = "0.4.38"
# async-trait = "0.1.82"
bb8 = "0.8.5"
bb8-postgres = "0.8.1"
tokio-postgres = { version = "0.7.11", features = [
tokio-postgres = { version = "0.7.12", features = [
"with-chrono-0_4",
"with-serde_json-1",
"with-time-0_3",
] }
tokio = { version = "1.39.2", features = ["rt", "macros", "rt-multi-thread"] }
tokio = { version = "1.40.0", features = ["rt", "macros", "rt-multi-thread"] }
dotenvy = "0.15.7"
local-ip-address = "0.6.2"
local-ip-address = "0.6.3"
gethostname = "0.5.0"
hex = "0.4.3"
handlebars = "6.0.0"
anyhow = "1.0.86"
handlebars = "6.1.0"
anyhow = "1.0.89"
#cddl = "0.9.4"
#ciborium = "0.2.2"
# stringzilla = "3.9.3"
Expand All @@ -69,8 +69,8 @@ rust_decimal = { version = "1.36.0", features = [
"serde-with-float",
"db-tokio-postgres",
] }
poem = { version = "3.0.4", features = ["embed", "prometheus", "compression"] }
poem-openapi = { version = "5.0.3", features = [
poem = { version = "3.1.0", features = ["embed", "prometheus", "compression"] }
poem-openapi = { version = "5.1.1", features = [
"openapi-explorer",
"rapidoc",
"redoc",
Expand All @@ -81,15 +81,18 @@ poem-openapi = { version = "5.0.3", features = [
] }
uuid = { version = "1.10.0", features = ["v4", "serde"] }
ulid = { version = "1.1.3", features = ["serde", "uuid"] }
cryptoxide = "0.4.4" # TODO: For blake2b replace with blake2b_simd.
blake2b_simd = "1.0.2"
url = "2.5.2"
panic-message = "0.3.0"
cpu-time = "1.0.0"
prometheus = "0.13.4"
rust-embed = "8.5.0"
num-traits = "0.2.19"
base64 = "0.22.1"
dashmap = "6.0.1"
dashmap = "6.1.0"

[dev-dependencies]
proptest = "1.5.0"

[build-dependencies]
build-info-build = "0.0.38"
16 changes: 0 additions & 16 deletions catalyst-gateway/bin/src/cardano/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Block stream parsing and filtering utils
use cryptoxide::{blake2b::Blake2b, digest::Digest};
use pallas::ledger::{
primitives::conway::StakeCredential,
traverse::{Era, MultiEraAsset, MultiEraCert, MultiEraPolicyAssets},
Expand All @@ -18,21 +17,6 @@ pub type StakeCredentialHash = String;
/// Correct stake credential key in hex
pub type StakeCredentialKey = String;

/// Hash size
#[allow(dead_code)]
pub(crate) const BLAKE_2B_256_HASH_SIZE: usize = 256 / 8;

/// Helper function to generate the `blake2b_256` hash of a byte slice
#[allow(dead_code)]
pub(crate) fn hash(bytes: &[u8]) -> [u8; BLAKE_2B_256_HASH_SIZE] {
let mut digest = [0u8; BLAKE_2B_256_HASH_SIZE];
let mut context = Blake2b::new(BLAKE_2B_256_HASH_SIZE);
context.input(bytes);
context.result(&mut digest);

digest
}

#[derive(Default, Debug, Serialize)]
/// Assets
pub struct Asset {
Expand Down
11 changes: 11 additions & 0 deletions catalyst-gateway/bin/src/db/index/schema/cql/sync_status.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Most recent completed
-- Can also be used to convert a known stake key hash back to a full stake address.
CREATE TABLE IF NOT EXISTS sync_status (
-- Primary Key Data
end_slot varint, -- The slot that has been indexed up-to (inclusive).
start_slot varint, -- The slot the sync block started at (inclusive).
sync_time timestamp, -- The time we finished the sync.
node_id uuid, -- The node that synced this data.

PRIMARY KEY (end_slot, start_slot, sync_time, node_id)
);
192 changes: 170 additions & 22 deletions catalyst-gateway/bin/src/db/index/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@

use std::sync::Arc;

use anyhow::Context;
use anyhow::{bail, Context};
use handlebars::Handlebars;
use scylla::Session;
use serde_json::json;
use tracing::error;

use crate::settings::cassandra_db;
use crate::{settings::cassandra_db, utilities::blake2b_hash::generate_uuid_string_from_data};

/// The version of the Index DB Schema we SHOULD BE using.
/// DO NOT change this unless you are intentionally changing the Schema.
///
/// This constant is ONLY used by Unit tests to identify when the schema version will
/// change accidentally, and is NOT to be used directly to set the schema version of the
/// table namespaces.
#[allow(dead_code)]
const SCHEMA_VERSION: &str = "a0e54866-1f30-8ad2-9ac7-df1cfaf9c634";

/// Keyspace Create (Templated)
const CREATE_NAMESPACE_CQL: &str = include_str!("./cql/namespace.cql");

/// The version of the Schema we are using.
/// Must be incremented if there is a breaking change in any schema tables below.
pub(crate) const SCHEMA_VERSION: u64 = 1;

/// All Schema Creation Statements
const SCHEMAS: &[(&str, &str)] = &[
(
// Sync Status Table Schema
include_str!("./cql/sync_status.cql"),
"Create Sync Status Table",
),
(
// TXO by Stake Address Table Schema
include_str!("./cql/txo_by_stake_table.cql"),
Expand Down Expand Up @@ -66,10 +76,72 @@ const SCHEMAS: &[(&str, &str)] = &[
),
];

/// Removes all comments from each line in the input query text and joins the remaining
/// lines into a single string, reducing consecutive whitespace characters to a single
/// space. Comments are defined as any text following `--` on a line.
///
/// # Arguments
///
/// * `text`: A string slice that holds the query to be cleaned.
///
/// # Returns
///
/// A new string with comments removed and whitespace reduced, where each remaining line
/// from the original text is separated by a newline character.
fn remove_comments_and_join_query_lines(text: &str) -> String {
// Split the input text into lines, removing any trailing empty lines
let raw_lines: Vec<&str> = text.lines().collect();
let mut clean_lines: Vec<String> = Vec::new();

// Filter out comments from each line
for line in raw_lines {
let mut clean_line = line.to_string();
if let Some(no_comment) = line.split_once("--") {
clean_line = no_comment.0.to_string();
}
clean_line = clean_line
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
.trim()
.to_string();
if !clean_line.is_empty() {
clean_lines.push(clean_line);
}
}
clean_lines.join("\n")
}

/// Comment
stevenj marked this conversation as resolved.
Show resolved Hide resolved
fn generate_cql_schema_version() -> String {
// Where we will actually store the bytes we derive the UUID from.
let mut clean_schemas: Vec<String> = Vec::new();

// Iterate through each CQL schema and add it to the list of clean schemas documents.
for (schema, _) in SCHEMAS {
let schema = remove_comments_and_join_query_lines(schema);
if !schema.is_empty() {
clean_schemas.push(schema);
}
}

// make sure any re-ordering of the schemas in the list does not effect the generated
// schema version
clean_schemas.sort();

// Generate a unique hash of the clean schemas,
// and use it to form a UUID to identify the schema version.
generate_uuid_string_from_data("Catalyst-Gateway Index Database Schema", clean_schemas)
}

/// Get the namespace for a particular db configuration
pub(crate) fn namespace(cfg: &cassandra_db::EnvVars) -> String {
// Build and set the Keyspace to use.
format!("{}_V{}", cfg.namespace.as_str(), SCHEMA_VERSION)
format!(
"{}_{}",
cfg.namespace.as_str(),
generate_cql_schema_version().replace('-', "_")
)
}

/// Create the namespace we will use for this session
Expand All @@ -83,11 +155,19 @@ async fn create_namespace(
// disable default `html_escape` function
// which transforms `<`, `>` symbols to `&lt`, `&gt`
reg.register_escape_fn(|s| s.into());
let query = reg.render_template(CREATE_NAMESPACE_CQL, &json!({"keyspace": keyspace}))?;
let query = reg
.render_template(CREATE_NAMESPACE_CQL, &json!({"keyspace": keyspace}))
.context(format!("Keyspace: {keyspace}"))?;

// Create the Keyspace if it doesn't exist already.
let stmt = session.prepare(query).await?;
session.execute_unpaged(&stmt, ()).await?;
let stmt = session
.prepare(query)
.await
.context(format!("Keyspace: {keyspace}"))?;
session
.execute_unpaged(&stmt, ())
.await
.context(format!("Keyspace: {keyspace}"))?;

// Wait for the Schema to be ready.
session.await_schema_agreement().await?;
Expand All @@ -104,22 +184,90 @@ async fn create_namespace(
pub(crate) async fn create_schema(
session: &mut Arc<Session>, cfg: &cassandra_db::EnvVars,
) -> anyhow::Result<()> {
create_namespace(session, cfg).await?;

for schema in SCHEMAS {
let stmt = session
.prepare(schema.0)
.await
.context(format!("{} : Prepared", schema.1))?;

session
.execute_unpaged(&stmt, ())
.await
.context(format!("{} : Executed", schema.1))?;
create_namespace(session, cfg)
.await
.context("Creating Namespace")?;

let mut failed = false;

for (schema, schema_name) in SCHEMAS {
match session.prepare(*schema).await {
Ok(stmt) => {
if let Err(err) = session.execute_unpaged(&stmt, ()).await {
failed = true;
error!(schema=schema_name, error=%err, "Failed to Execute Create Schema Query");
};
},
Err(err) => {
failed = true;
error!(schema=schema_name, error=%err, "Failed to Prepare Create Schema Query");
},
}
}

if failed {
stevenj marked this conversation as resolved.
Show resolved Hide resolved
bail!("Failed to Create Schema");
}

// Wait for the Schema to be ready.
session.await_schema_agreement().await?;

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
/// This test is designed to fail if the schema version has changed.
/// It is used to help detect inadvertent schema version changes.
/// If you did NOT intend to change the index db schema and this test fails,
/// then revert or fix your changes to the schema files.
fn check_schema_version_has_not_changed() {
let calculated_version = generate_cql_schema_version();
assert_eq!(SCHEMA_VERSION, calculated_version);
}

#[test]
fn test_no_comments() {
let input = "SELECT * FROM table1;";
let expected_output = "SELECT * FROM table1;";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}

#[test]
fn test_single_line_comment() {
let input = "SELECT -- some comment * FROM table1;";
let expected_output = "SELECT";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}

#[test]
fn test_multi_line_comment() {
let input = "SELECT -- some comment\n* FROM table1;";
let expected_output = "SELECT\n* FROM table1;";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}

#[test]
fn test_multiple_lines() {
let input = "SELECT * FROM table1;\n-- another comment\nSELECT * FROM table2;";
let expected_output = "SELECT * FROM table1;\nSELECT * FROM table2;";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}

#[test]
fn test_empty_lines() {
let input = "\n\nSELECT * FROM table1;\n-- comment here\n\n";
let expected_output = "SELECT * FROM table1;";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}

#[test]
fn test_whitespace_only() {
let input = " \n -- comment here\n ";
let expected_output = "";
assert_eq!(remove_comments_and_join_query_lines(input), expected_output);
}
}
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod db;
mod logger;
mod service;
mod settings;
mod utilities;
stevenj marked this conversation as resolved.
Show resolved Hide resolved

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
9 changes: 3 additions & 6 deletions catalyst-gateway/bin/src/service/api/cardano/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
//! Event DB logic for chain-sync. They should be replaced with proper types in a better
//! place.

use cryptoxide::{blake2b::Blake2b, digest::Digest};
use serde::{Deserialize, Serialize};

use crate::utilities::blake2b_hash::blake2b_224;

/// Pub key
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct PubKey(Vec<u8>);
Expand All @@ -15,11 +16,7 @@ impl PubKey {
/// Get credentials, a blake2b 28 bytes hash of the pub key
#[allow(dead_code)]
pub(crate) fn get_credentials(&self) -> [u8; 28] {
let mut digest = [0u8; 28];
let mut context = Blake2b::new(28);
context.input(&self.0);
context.result(&mut digest);
digest
blake2b_224(&self.0)
}

/// Get bytes
Expand Down
Loading
Loading