use ex3_node_error::{Error, OtherError};
use ex3_serde::cbor;
use crate::tx_type_dto::{
RegisterSpotMarket, UpdateMarketFee, UpdateMarketFeeTo, UpdateMarketGlobalFeeTo,
UpdateMarketTradingSettings, UpdateSpotMarketGlobalFee,
};
use crate::PayloadDecoder;
use crate::Result;
impl PayloadDecoder {
pub fn decode_to_register_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::<UpdateMarketTradingSettings>(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::UpdateMarketGlobalFeeTo> {
let update_market_global_fee_to = cbor::deserialize::<UpdateMarketGlobalFeeTo>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateMarketGlobalFeeTo: {}",
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::UpdateSpotMarketGlobalFee> {
let update_market_global_fee = cbor::deserialize::<UpdateSpotMarketGlobalFee>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketGlobalFee: {}",
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::<UpdateMarketFee>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketFee: {}",
e
)))
})?;
Ok(update_market_fee.into())
}
}