Skip to content

Commit

Permalink
Merge pull request #39 from fpco/optional-config-file
Browse files Browse the repository at this point in the history
Optional config file support
  • Loading branch information
snoyberg authored Aug 1, 2024
2 parents e638976 + 300bd45 commit b35723b
Show file tree
Hide file tree
Showing 7 changed files with 478 additions and 9 deletions.
188 changes: 188 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cosmos-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
clap = { version = "4.5.4", features = ["derive", "env"] }
clap_complete = "4.5.2"
anyhow = { version = "1.0.82", features = ["backtrace"] }
cosmos = { path = "../cosmos", features = ["clap", "compression", "rustls-tls"], default-features = false }
cosmos = { path = "../cosmos", features = ["clap", "compression", "rustls-tls", "config"], default-features = false }
tokio = { version = "1.37.0", features = ["full"] }
chrono = { version = "0.4.38", features = ["serde"] }
serde = { version = "1.0.199", features = ["derive"] }
Expand Down
4 changes: 4 additions & 0 deletions packages/cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ flate2 = { version = "1.0.30", features = ["zlib"] }
strum = "0.26.2"
strum_macros = "0.26.2"
tendermint-proto = "0.35.0"
figment = { version = "0.10.19", features = ["env", "toml"], optional = true }
directories = { version = "5.0.1", optional = true }

[features]
clap = ["dep:clap"]
config = ["dep:figment", "dep:directories"]
default = ["rustls-tls", "compression"]
compression = ["reqwest/gzip", "reqwest/brotli"]
rustls-tls = ["reqwest/rustls-tls"]
native-tls = ["reqwest/native-tls"]
directories = ["dep:directories"]

[dev-dependencies]
quickcheck = "1"
31 changes: 28 additions & 3 deletions packages/cosmos/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ impl<T: HasAddress> HasAddress for &T {
/// This library internally shares multiple copies of the same HRP for both
/// efficiency and ease of use of this library: it allows both this data type,
/// as well as [Address], to be [Copy].
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, serde::Serialize, serde::Deserialize,
)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, serde::Serialize)]
pub struct AddressHrp(&'static str);

impl FromStr for AddressHrp {
Expand All @@ -237,6 +235,33 @@ impl FromStr for AddressHrp {
}
}

impl<'de> serde::Deserialize<'de> for AddressHrp {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(AddressHrpVisitor)
}
}

struct AddressHrpVisitor;

impl<'de> Visitor<'de> for AddressHrpVisitor {
type Value = AddressHrp;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("AddressHrp")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
v.parse::<AddressHrp>()
.map_err(|e| E::custom(e.to_string()))
}
}

impl AddressHrp {
/// The default [DerivationPath] for this HRP.
///
Expand Down
Loading

0 comments on commit b35723b

Please sign in to comment.