use hedera_proto::services;
use crate::protobuf::{
FromProtobuf,
ToProtobuf,
};
use crate::{
AccountId,
TokenId,
};
#[derive(Debug, Eq, PartialEq, Clone)]
#[cfg_attr(feature = "ffi", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ffi", serde(rename_all = "camelCase"))]
pub struct AssessedCustomFee {
pub amount: i64,
pub token_id: Option<TokenId>,
pub fee_collector_account_id: Option<AccountId>,
pub payer_account_id_list: Vec<AccountId>,
}
impl AssessedCustomFee {
pub fn from_bytes(bytes: &[u8]) -> crate::Result<Self> {
FromProtobuf::from_bytes(bytes)
}
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
ToProtobuf::to_bytes(self)
}
}
impl FromProtobuf<services::AssessedCustomFee> for AssessedCustomFee {
fn from_protobuf(pb: services::AssessedCustomFee) -> crate::Result<Self>
where
Self: Sized,
{
Ok(Self {
amount: pb.amount,
token_id: Option::from_protobuf(pb.token_id)?,
fee_collector_account_id: Option::from_protobuf(pb.fee_collector_account_id)?,
payer_account_id_list: Vec::from_protobuf(pb.effective_payer_account_id)?,
})
}
}
impl ToProtobuf for AssessedCustomFee {
type Protobuf = services::AssessedCustomFee;
fn to_protobuf(&self) -> Self::Protobuf {
services::AssessedCustomFee {
amount: self.amount,
token_id: self.token_id.to_protobuf(),
fee_collector_account_id: self.fee_collector_account_id.to_protobuf(),
effective_payer_account_id: self.payer_account_id_list.to_protobuf(),
}
}
}