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

Handle 0x prefix str for Address #227

Merged
merged 4 commits into from
Oct 14, 2021
Merged
Changes from 2 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
4 changes: 2 additions & 2 deletions sewup/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl<'de> Deserialize<'de> for AddressType {
impl AddressType {
#[cfg(target_arch = "wasm32")]
pub fn from_str(s: &str) -> anyhow::Result<Self> {
// TODO: handle str starts with 0x
let byte20: [u8; 20] = hex::decode(s)?
let hex_s: &str = if s.starts_with("0x"){ &s[2..s.len()] } else { s };
let byte20: [u8; 20] = hex::decode(hex_s)?
.try_into()
.map_err(|_| anyhow::anyhow!("hex str can not convert to [u8; 20]"))?;
Ok(Self {
Expand Down