use std::{
convert::{TryFrom, TryInto},
sync::Arc,
};
use crate::mempool::{StateResponse, proto::mempool::StateResponse as ProtoStateResponse};
impl TryFrom<ProtoStateResponse> for StateResponse {
type Error = String;
fn try_from(state: ProtoStateResponse) -> Result<Self, Self::Error> {
Ok(Self {
unconfirmed_pool: state
.unconfirmed_pool
.into_iter()
.map(|tx| tx.try_into().map(Arc::new))
.collect::<Result<Vec<_>, _>>()?,
reorg_pool: state
.reorg_pool
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()
.map_err(|_| "Malformed excess sig")?,
})
}
}
impl TryFrom<StateResponse> for ProtoStateResponse {
type Error = String;
fn try_from(state: StateResponse) -> Result<Self, Self::Error> {
Ok(Self {
unconfirmed_pool: state
.unconfirmed_pool
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
reorg_pool: state.reorg_pool.into_iter().map(Into::into).collect::<Vec<_>>(),
})
}
}