use ex3_node_error::{Error, OtherError};
use ex3_serde::cbor;
use crate::tx_type_dto::{
ClaimSpotMarketRoyalty, ClaimSpotMarketTradingFee, SpotMarketRegistration,
UpdateSpotMarketFeeTo, UpdateSpotMarketInitialFeeTo, UpdateSpotMarketInitialTradingFee,
UpdateSpotMarketRoyalty, UpdateSpotMarketTradingFee, UpdateSpotMarketTradingSettings,
};
use crate::PayloadDecoder;
use crate::Result;
impl PayloadDecoder {
pub fn decode_to_register_spot_market(
payload: &[u8],
) -> Result<ex3_node_types::transaction::SpotMarketRegistration> {
let register_market =
cbor::deserialize::<SpotMarketRegistration>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to SpotMarketRegistration: {}",
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_spot_market_initial_fee_to(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketInitialFeeTo> {
let update_market_initial_fee_to =
cbor::deserialize::<UpdateSpotMarketInitialFeeTo>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateMarketInitialFeeTo: {}",
e
)))
})?;
Ok(update_market_initial_fee_to.into())
}
pub fn decode_to_update_spot_market_fee_to(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketFeeTo> {
let update_market_fee_to =
cbor::deserialize::<UpdateSpotMarketFeeTo>(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_spot_market_initial_trading_fee(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketInitialTradingFee> {
let update_market_initial_fee =
cbor::deserialize::<UpdateSpotMarketInitialTradingFee>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketInitialFee: {}",
e
)))
})?;
Ok(update_market_initial_fee.into())
}
pub fn decode_to_update_spot_market_trading_fee(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketTradingFee> {
let update_market_fee =
cbor::deserialize::<UpdateSpotMarketTradingFee>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketFee: {}",
e
)))
})?;
Ok(update_market_fee.into())
}
pub fn decode_to_update_spot_market_royalty(
payload: &[u8],
) -> Result<ex3_node_types::transaction::UpdateSpotMarketRoyalty> {
let update_market_royalty =
cbor::deserialize::<UpdateSpotMarketRoyalty>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to UpdateSpotMarketRoyalty: {}",
e
)))
})?;
Ok(update_market_royalty.into())
}
pub fn decode_to_claim_spot_market_royalty(
payload: &[u8],
) -> Result<ex3_node_types::transaction::ClaimSpotMarketRoyalty> {
let claim_market_royalty =
cbor::deserialize::<ClaimSpotMarketRoyalty>(payload).map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to ClaimSpotMarketRoyalty: {}",
e
)))
})?;
Ok(claim_market_royalty.into())
}
pub fn decode_to_claim_spot_market_trading_fee(
payload: &[u8],
) -> Result<ex3_node_types::transaction::ClaimSpotMarketTradingFee> {
let claim_market_trading_fee = cbor::deserialize::<ClaimSpotMarketTradingFee>(payload)
.map_err(|e| {
<OtherError as Into<Error>>::into(OtherError::new(format!(
"Failed to deserialize payload to ClaimSpotMarketTradingFee: {}",
e
)))
})?;
Ok(claim_market_trading_fee.into())
}
}