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

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

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