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::Deposit;
use crate::{PayloadDecoder, Result};

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