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

Add --http-port to settings yaml #3796

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Settings {
first_inscription_height: Option<u32>,
height_limit: Option<u32>,
hidden: Option<HashSet<InscriptionId>>,
http_port: Option<u16>,
index: Option<PathBuf>,
index_addresses: bool,
index_cache_size: Option<usize>,
Expand Down Expand Up @@ -133,6 +134,7 @@ impl Settings {
.cloned()
.collect(),
),
http_port: self.http_port.or(source.http_port),
index: self.index.or(source.index),
index_addresses: self.index_addresses || source.index_addresses,
index_cache_size: self.index_cache_size.or(source.index_cache_size),
Expand Down Expand Up @@ -169,6 +171,7 @@ impl Settings {
first_inscription_height: options.first_inscription_height,
height_limit: options.height_limit,
hidden: None,
http_port: None,
index: options.index,
index_addresses: options.index_addresses,
index_cache_size: options.index_cache_size,
Expand Down Expand Up @@ -219,13 +222,22 @@ impl Settings {
})
};

let get_u16 = |key| {
env
.get(key)
.map(|int| int.parse::<u16>())
.transpose()
.with_context(|| format!("failed to parse environment variable ORD_{key} as u16"))
};

let get_u32 = |key| {
env
.get(key)
.map(|int| int.parse::<u32>())
.transpose()
.with_context(|| format!("failed to parse environment variable ORD_{key} as u32"))
};

let get_usize = |key| {
env
.get(key)
Expand All @@ -249,6 +261,7 @@ impl Settings {
first_inscription_height: get_u32("FIRST_INSCRIPTION_HEIGHT")?,
height_limit: get_u32("HEIGHT_LIMIT")?,
hidden: inscriptions("HIDDEN")?,
http_port: get_u16("HTTP_PORT")?,
index: get_path("INDEX"),
index_addresses: get_bool("INDEX_ADDRESSES"),
index_cache_size: get_usize("INDEX_CACHE_SIZE")?,
Expand Down Expand Up @@ -280,6 +293,7 @@ impl Settings {
first_inscription_height: None,
height_limit: None,
hidden: None,
http_port: None,
index: None,
index_addresses: true,
index_cache_size: None,
Expand Down Expand Up @@ -354,6 +368,7 @@ impl Settings {
}),
height_limit: self.height_limit,
hidden: self.hidden,
http_port: self.http_port,
index: Some(index),
index_addresses: self.index_addresses,
index_cache_size: Some(match self.index_cache_size {
Expand Down Expand Up @@ -1011,6 +1026,7 @@ mod tests {
("FIRST_INSCRIPTION_HEIGHT", "2"),
("HEIGHT_LIMIT", "3"),
("HIDDEN", "6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0"),
("HTTP_PORT", "8080"),
("INDEX", "index"),
("INDEX_CACHE_SIZE", "4"),
("INDEX_ADDRESSES", "1"),
Expand Down Expand Up @@ -1056,6 +1072,7 @@ mod tests {
.into_iter()
.collect()
),
http_port: Some(8080),
index: Some("index".into()),
index_addresses: true,
index_cache_size: Some(4),
Expand Down Expand Up @@ -1120,6 +1137,7 @@ mod tests {
first_inscription_height: Some(2),
height_limit: Some(3),
hidden: None,
http_port: None,
index: Some("index".into()),
index_addresses: true,
index_cache_size: Some(4),
Expand Down
1 change: 1 addition & 0 deletions tests/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn default() {
"first_inscription_height": 767430,
"height_limit": null,
"hidden": \[\],
"http_port": null,
"index": ".*index\.redb",
"index_addresses": false,
"index_cache_size": \d+,
Expand Down
Loading