use alloy_primitives::Address;
use std::str::FromStr;
use crate::error::WalletKitError;
#[allow(dead_code)]
pub trait ParseFromForeignBinding {
fn parse_from_ffi(s: &str, attr: &'static str) -> Result<Self, WalletKitError>
where
Self: Sized;
fn parse_from_ffi_optional(
s: Option<String>,
attr: &'static str,
) -> Result<Option<Self>, WalletKitError>
where
Self: Sized;
}
impl ParseFromForeignBinding for Address {
fn parse_from_ffi(s: &str, attr: &'static str) -> Result<Self, WalletKitError> {
Self::from_str(s).map_err(|e| WalletKitError::InvalidInput {
attribute: attr.to_string(),
reason: e.to_string(),
})
}
fn parse_from_ffi_optional(
s: Option<String>,
attr: &'static str,
) -> Result<Option<Self>, WalletKitError> {
if let Some(s) = s {
return Self::parse_from_ffi(s.as_str(), attr).map(Some);
}
Ok(None)
}
}