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

migrating-chain.rs-to-snafu #3904

Merged
merged 6 commits into from
Aug 28, 2024
Merged
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
15 changes: 7 additions & 8 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ impl Chain {
}
}

pub(crate) fn address_from_script(
self,
script: &Script,
) -> Result<Address, bitcoin::address::Error> {
Address::from_script(script, self.network())
pub(crate) fn address_from_script(self, script: &Script) -> Result<Address, SnafuError> {
Address::from_script(script, self.network()).snafu_context(error::AddressConversion)
}

pub(crate) fn join_with_data_dir(self, data_dir: impl AsRef<Path>) -> PathBuf {
Expand Down Expand Up @@ -110,15 +107,17 @@ impl Display for Chain {
}

impl FromStr for Chain {
type Err = Error;
type Err = SnafuError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"mainnet" => Ok(Self::Mainnet),
"regtest" => Ok(Self::Regtest),
"signet" => Ok(Self::Signet),
"testnet" => Ok(Self::Testnet),
_ => bail!("invalid chain `{s}`"),
_ => Err(SnafuError::InvalidChain {
chain: s.to_string(),
}),
}
}
}
Expand All @@ -135,7 +134,7 @@ mod tests {
assert_eq!("testnet".parse::<Chain>().unwrap(), Chain::Testnet);
assert_eq!(
"foo".parse::<Chain>().unwrap_err().to_string(),
"invalid chain `foo`"
"Invalid chain `foo`"
);
}
}
Loading