use anyhow::{Context, Result};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Api};
#[cw_serde]
#[derive(Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct RawAddr(String);
impl RawAddr {
pub fn validate(&self, api: &dyn Api) -> Result<Addr> {
api.addr_validate(&self.0)
.with_context(|| format!("Could not parse address: {self}"))
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn into_string(self) -> String {
self.0
}
}
impl std::fmt::Display for RawAddr {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl From<String> for RawAddr {
fn from(s: String) -> Self {
RawAddr(s)
}
}
impl From<&str> for RawAddr {
fn from(s: &str) -> Self {
s.to_owned().into()
}
}
impl From<Addr> for RawAddr {
fn from(addr: Addr) -> Self {
addr.into_string().into()
}
}
impl From<&Addr> for RawAddr {
fn from(addr: &Addr) -> Self {
addr.to_string().into()
}
}
impl From<RawAddr> for String {
fn from(RawAddr(s): RawAddr) -> String {
s
}
}