Skip to content

Commit 0e1b48f

Browse files
fix: Handle legacy networks
1 parent 88e7c31 commit 0e1b48f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ futures-util = "0.3.30"
1414
http-body-util = "0.1.0"
1515
hyper = { version = "1.1.0", features = ["full"] }
1616
hyper-util = { version = "0.1.3", features = ["full"] }
17+
lazy_static = "1.5.0"
1718
leaky-bucket = "1.0.1"
1819
prometheus = "0.13.3"
1920
regex = "1.10.3"

proxy/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use tiers::Tier;
1313
use tokio::sync::RwLock;
1414
use tracing::Level;
1515

16+
use crate::utils::handle_legacy_networks;
17+
1618
mod auth;
1719
mod config;
1820
mod health;
@@ -93,7 +95,7 @@ impl Display for Consumer {
9395
}
9496
impl From<&OgmiosPort> for Consumer {
9597
fn from(value: &OgmiosPort) -> Self {
96-
let network = value.spec.network.to_string();
98+
let network = handle_legacy_networks(&value.spec.network);
9799
let version = value.spec.version.to_string();
98100
let tier = value.spec.throughput_tier.to_string();
99101
let key = value.status.as_ref().unwrap().auth_token.clone();

proxy/src/utils.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
use bytes::Bytes;
22
use http_body_util::{combinators::BoxBody, BodyExt, Full};
33
use hyper::{body::Incoming, Request, Response};
4+
use lazy_static::lazy_static;
5+
use std::collections::HashMap;
46

57
pub const DMTR_API_KEY: &str = "dmtr-api-key";
6-
78
pub type Body = BoxBody<Bytes, hyper::Error>;
89
pub type ProxyResponse = Response<Body>;
910

11+
lazy_static! {
12+
static ref LEGACY_NETWORKS: HashMap<&'static str, String> = {
13+
let mut m = HashMap::new();
14+
m.insert("mainnet", "cardano-mainnet".into());
15+
m.insert("preprod", "cardano-preprod".into());
16+
m.insert("preview", "cardano-preview".into());
17+
m
18+
};
19+
}
20+
21+
pub fn handle_legacy_networks(network: &str) -> String {
22+
let default = network.to_string();
23+
LEGACY_NETWORKS.get(network).unwrap_or(&default).to_string()
24+
}
25+
1026
pub fn full<T: Into<Bytes>>(chunk: T) -> Body {
1127
Full::new(chunk.into())
1228
.map_err(|never| match never {})

0 commit comments

Comments
 (0)