use ex3_node_error::{Error, OtherError};
use ex3_serde::cbor;
use crate::tx_type_dto::{
RegisterSpotMarket, UpdateMarketFeeTo, UpdateMarketInitialFeeTo, UpdateSpotMarketFee,
UpdateSpotMarketInitialFee, UpdateSpotMarketTradingSettings,
};
use crate::PayloadDecoder;
use crate::Result;
impl PayloadDecoder {
pub fn decode_to_register_spot_market(
payload: &[u8],
) -> Result<ex3_node_types::transaction::RegisterSpotMarket> {
let register_market = cbor::deserialize::<RegisterSpotMarket>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to RegisterSpotMarket: {}",
e
)))
})?;
Ok(register_market.into())
}
pub fn decode_to_update_spot_market_trading_settings(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketTradingSettings> {
let update_market_settings = cbor::deserialize::<UpdateSpotMarketTradingSettings>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketTradingSettings: {}",
e
)))
})?;
Ok(update_market_settings.into())
}
pub fn decode_to_update_market_global_fee_to(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateMarketInitialFeeTo> {
let update_market_global_fee_to = cbor::deserialize::<UpdateMarketInitialFeeTo>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateMarketInitialFeeTo: {}",
e
)))
})?;
Ok(update_market_global_fee_to.into())
}
pub fn decode_to_update_spot_market_fee_to(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateMarketFeeTo> {
let update_market_fee_to =
cbor::deserialize::<UpdateMarketFeeTo>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateMarketFeeTo: {}",
e
)))
})?;
Ok(update_market_fee_to.into())
}
pub fn decode_to_update_market_global_fee(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketInitialFee> {
let update_market_global_fee = cbor::deserialize::<UpdateSpotMarketInitialFee>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketInitialFee: {}",
e
)))
})?;
Ok(update_market_global_fee.into())
}
pub fn decode_to_update_spot_market_fee(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketFee> {
let update_market_fee = cbor::deserialize::<UpdateSpotMarketFee>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketFee: {}",
e
)))
})?;
Ok(update_market_fee.into())
}
}