Skip to content

Commit 85d50cc

Browse files
committed
Merge branch 'main' into 2091-map-proposal-elements-for-testing
2 parents 0285070 + f5a1130 commit 85d50cc

File tree

292 files changed

+5040
-3970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+5040
-3970
lines changed

.github/workflows/flutter-publish-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: subosito/flutter-action@v2
2121
with:
2222
channel: stable
23-
flutter-version: 3.29.0
23+
flutter-version: 3.29.3
2424
- uses: bluefireteam/melos-action@v3
2525
with:
2626
run-versioning: true

Earthfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
VERSION 0.8
22

3-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/mdlint:v3.3.3 AS mdlint-ci
4-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/cspell:v3.3.3 AS cspell-ci
5-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/postgresql:v3.3.3 AS postgresql-ci
3+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/mdlint:v3.4.0 AS mdlint-ci
4+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/cspell:v3.4.0 AS cspell-ci
5+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/postgresql:v3.4.0 AS postgresql-ci
66

77
FROM debian:stable-slim
88

catalyst-gateway/Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
VERSION 0.8
22

3-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.3.3 AS rust-ci
3+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.4.0 AS rust-ci
44
IMPORT ../ AS repo-ci
55

66
#cspell: words rustfmt toolsets USERARCH stdcfgs

catalyst-gateway/bin/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ repository.workspace = true
1515
workspace = true
1616

1717
[dependencies]
18-
cardano-chain-follower = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
19-
rbac-registration = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
20-
catalyst-types = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
21-
cardano-blockchain-types = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
22-
catalyst-signed-doc = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
23-
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250425-00" }
18+
cardano-chain-follower = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
19+
rbac-registration = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
20+
catalyst-types = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
21+
cardano-blockchain-types = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
22+
catalyst-signed-doc = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
23+
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250428-00" }
2424

2525
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
2626
pallas-traverse = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
@@ -87,7 +87,6 @@ rust-embed = "8.5.0"
8787
num-traits = "0.2.19"
8888
base64 = "0.22.1"
8989
dashmap = { version = "6.1.0", features = ["rayon"] }
90-
jsonschema = "0.26.1"
9190
bech32 = "0.11.0"
9291
const_format = "0.2.33"
9392
regex = "1.11.1"

catalyst-gateway/bin/src/db/event/config/default/frontend.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

catalyst-gateway/bin/src/db/event/config/default/frontend_ip.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
//! Configuration Key
22
3-
use std::{fmt::Display, net::IpAddr, sync::LazyLock};
4-
5-
use jsonschema::{BasicOutput, Validator};
6-
use serde_json::{json, Value};
7-
use tracing::error;
8-
9-
use crate::{
10-
service::utilities::json::load_json,
11-
utils::schema::{extract_json_schema_for, SCHEMA_VERSION},
12-
};
3+
use std::{fmt::Display, net::IpAddr};
134

145
/// Configuration key
156
#[derive(Debug, Clone, PartialEq)]
@@ -29,50 +20,6 @@ impl Display for ConfigKey {
2920
}
3021
}
3122

32-
/// Frontend schema from API specification.
33-
pub(crate) static FRONTEND_SCHEMA: LazyLock<Value> =
34-
LazyLock::new(|| extract_json_schema_for("FrontendConfig"));
35-
36-
/// Frontend schema validator.
37-
static FRONTEND_SCHEMA_VALIDATOR: LazyLock<Validator> =
38-
LazyLock::new(|| schema_validator(&FRONTEND_SCHEMA));
39-
40-
/// Frontend default configuration.
41-
static FRONTEND_DEFAULT: LazyLock<Value> =
42-
LazyLock::new(|| load_json(include_str!("default/frontend.json")));
43-
44-
/// Frontend specific configuration.
45-
static FRONTEND_IP_DEFAULT: LazyLock<Value> =
46-
LazyLock::new(|| load_json(include_str!("default/frontend_ip.json")));
47-
48-
/// Helper function to create a JSON validator from a JSON schema.
49-
/// If the schema is invalid, a default JSON validator is created.
50-
fn schema_validator(schema: &Value) -> Validator {
51-
Validator::options()
52-
.with_draft(jsonschema::Draft::Draft202012)
53-
.build(schema)
54-
.unwrap_or_else(|err| {
55-
error!(
56-
id="schema_validator",
57-
error=?err,
58-
"Error creating JSON validator"
59-
);
60-
61-
default_validator()
62-
})
63-
}
64-
65-
/// Create a default JSON validator as a fallback
66-
/// This should not fail since it is hard coded
67-
fn default_validator() -> Validator {
68-
#[allow(clippy::expect_used)]
69-
Validator::new(&json!({
70-
"$schema": SCHEMA_VERSION,
71-
"type": "object"
72-
}))
73-
.expect("Failed to create default JSON validator")
74-
}
75-
7623
impl ConfigKey {
7724
/// Convert a `ConfigKey` to its corresponding IDs.
7825
pub(super) fn to_id(&self) -> (String, String, String) {
@@ -83,106 +30,4 @@ impl ConfigKey {
8330
},
8431
}
8532
}
86-
87-
/// Validate the provided value against the JSON schema.
88-
pub(super) fn validate(&self, value: &Value) -> BasicOutput<'static> {
89-
// Retrieve the validator based on ConfigKey
90-
let validator = match self {
91-
ConfigKey::Frontend | ConfigKey::FrontendForIp(_) => &*FRONTEND_SCHEMA_VALIDATOR,
92-
};
93-
94-
// Validate the value against the schema
95-
validator.apply(value).basic()
96-
}
97-
98-
/// Retrieve the default configuration value.
99-
pub(super) fn default(&self) -> Value {
100-
// Retrieve the default value based on the ConfigKey
101-
match self {
102-
ConfigKey::Frontend => FRONTEND_DEFAULT.clone(),
103-
ConfigKey::FrontendForIp(_) => FRONTEND_IP_DEFAULT.clone(),
104-
}
105-
}
106-
107-
/// Retrieve the JSON schema.
108-
pub(crate) fn schema(&self) -> &Value {
109-
match self {
110-
ConfigKey::Frontend | ConfigKey::FrontendForIp(_) => &FRONTEND_SCHEMA,
111-
}
112-
}
113-
}
114-
115-
#[cfg(test)]
116-
mod tests {
117-
use serde_json::json;
118-
119-
use super::*;
120-
121-
#[test]
122-
fn test_schema_for_schema() {
123-
// Invalid schema
124-
let invalid_schema = json!({
125-
"title": "Invalid Example Schema",
126-
"type": "object",
127-
128-
"properties": {
129-
"invalidProperty": {
130-
"type": "unknownType"
131-
}
132-
},
133-
134-
});
135-
// This should not fail
136-
schema_validator(&invalid_schema);
137-
}
138-
139-
#[test]
140-
fn test_valid_validate_1() {
141-
let value = json!({
142-
"sentry": {
143-
"dsn": "https://test.com"
144-
}
145-
});
146-
let result = ConfigKey::Frontend.validate(&value);
147-
assert!(result.is_valid());
148-
println!("{:?}", serde_json::to_value(result).unwrap());
149-
}
150-
151-
#[test]
152-
fn test_valid_validate_2() {
153-
let value = json!({});
154-
let result = ConfigKey::Frontend.validate(&value);
155-
assert!(result.is_valid());
156-
println!("{:?}", serde_json::to_value(result).unwrap());
157-
}
158-
159-
#[test]
160-
fn test_invalid_validate() {
161-
let value = json!([]);
162-
let result = ConfigKey::Frontend.validate(&value);
163-
assert!(!result.is_valid());
164-
println!("{:?}", serde_json::to_value(result).unwrap());
165-
}
166-
167-
#[test]
168-
fn test_default() {
169-
let result = ConfigKey::Frontend.default();
170-
assert!(result.is_object());
171-
}
172-
173-
#[test]
174-
fn test_default_validator() {
175-
let result = std::panic::catch_unwind(|| {
176-
default_validator();
177-
});
178-
// Assert that no panic occurred
179-
assert!(result.is_ok(), "default_validator panicked");
180-
}
181-
182-
// Since load_json return an empty object for invalid JSON,
183-
// Add test for default file to ensure it is not empty object.
184-
#[test]
185-
fn test_default_files() {
186-
assert!(!FRONTEND_DEFAULT.as_object().unwrap().is_empty());
187-
}
18833
}
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Configuration query
22
3-
use jsonschema::BasicOutput;
43
use key::ConfigKey;
54
use serde_json::Value;
6-
use tracing::error;
75

86
use crate::db::event::EventDB;
97

@@ -27,20 +25,10 @@ impl Config {
2725
/// - Error if the query fails.
2826
pub(crate) async fn get(id: ConfigKey) -> anyhow::Result<Value> {
2927
let (id1, id2, id3) = id.to_id();
30-
let rows = EventDB::query(GET_CONFIG, &[&id1, &id2, &id3]).await?;
28+
let row = EventDB::query_one(GET_CONFIG, &[&id1, &id2, &id3]).await?;
3129

32-
if let Some(row) = rows.first() {
33-
let value: Value = row.get(0);
34-
match id.validate(&value) {
35-
BasicOutput::Valid(_) => return Ok(value),
36-
BasicOutput::Invalid(errors) => {
37-
// This should not happen, expecting the schema to be valid
38-
error!(id=%id, error=?errors, "Get Config, schema validation failed, defaulting.");
39-
},
40-
}
41-
}
42-
// Return the default config value as a fallback
43-
Ok(id.default())
30+
let value = row.get(0);
31+
Ok(value)
4432
}
4533

4634
/// Set the configuration for the given `ConfigKey`.
@@ -49,16 +37,9 @@ impl Config {
4937
///
5038
/// - A `BasicOutput` of the validation result, which can be valid or invalid.
5139
/// - Error if the query fails.
52-
pub(crate) async fn set(id: ConfigKey, value: Value) -> anyhow::Result<BasicOutput<'static>> {
53-
let validate = id.validate(&value);
54-
// Validate schema failed, return immediately with JSON schema error
55-
if !validate.is_valid() {
56-
return Ok(validate);
57-
}
58-
40+
pub(crate) async fn set(id: ConfigKey, value: Value) -> anyhow::Result<()> {
5941
let (id1, id2, id3) = id.to_id();
6042
EventDB::query(UPSERT_CONFIG, &[&id1, &id2, &id3, &value]).await?;
61-
62-
Ok(validate)
43+
Ok(())
6344
}
6445
}

0 commit comments

Comments
 (0)