1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{PayloadDecoder, Result};
use ex3_node_error::{Error, OtherError};
use ex3_serde::cbor;

use crate::tx_type_dto::{AssetAccountBinding, AssetAccountUnbinding};

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

    /// Decode asset account unbinding
    pub fn decode_to_asset_account_unbinding(
        payload: &[u8],
    ) -> Result<ex3_node_types::transaction::AssetAccountUnbinding> {
        let asset_account_unbinding =
            cbor::deserialize::<AssetAccountUnbinding>(payload).map_err(|e| {
                <OtherError as Into<Error>>::into(OtherError::new(format!(
                    "Failed to deserialize payload to AssetAccountUnbinding: {}",
                    e
                )))
            })?;
        Ok(asset_account_unbinding.into())
    }
}