1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use ex3_node_error::{Error, OtherError};
use ex3_serde::cbor;

use crate::tx_type_dto::Withdrawal;
use crate::{PayloadDecoder, Result};

impl PayloadDecoder {
    /// Decode the payload to a withdrawal
    pub fn decode_to_withdrawal(payload: &[u8]) -> Result<ex3_node_types::transaction::Withdrawal> {
        let withdrawal = cbor::deserialize::<Withdrawal>(payload).map_err(|e| {
            <OtherError as Into<Error>>::into(OtherError::new(format!(
                "Failed to deserialize payload to Withdrawal: {}",
                e
            )))
        })?;
        Ok(withdrawal.into())
    }
}