hiero_sdk/
custom_fixed_fee.rs1use hiero_sdk_proto::services;
4
5use crate::{
6 AccountId,
7 FixedFee,
8 FixedFeeData,
9 FromProtobuf,
10 ToProtobuf,
11 TokenId,
12};
13
14#[derive(Debug, Hash, PartialEq, Eq, Clone, Default)]
24pub struct CustomFixedFee {
25 pub amount: u64,
29
30 pub denominating_token_id: Option<TokenId>,
33
34 pub fee_collector_account_id: Option<AccountId>,
36}
37
38impl CustomFixedFee {
39 pub fn new(
41 amount: u64,
42 denominating_token_id: Option<TokenId>,
43 fee_collector_account_id: Option<AccountId>,
44 ) -> Self {
45 Self { amount, denominating_token_id, fee_collector_account_id }
46 }
47}
48
49impl CustomFixedFee {
50 pub(crate) fn to_fixed_fee_protobuf(&self) -> services::FixedFee {
51 services::FixedFee {
52 amount: self.amount as i64,
53 denominating_token_id: self.denominating_token_id.to_protobuf(),
54 }
55 }
56}
57
58impl From<CustomFixedFee> for FixedFee {
59 fn from(v: CustomFixedFee) -> Self {
60 Self {
61 fee: FixedFeeData {
62 amount: v.amount as i64,
63 denominating_token_id: v.denominating_token_id,
64 },
65 fee_collector_account_id: v.fee_collector_account_id,
66 all_collectors_are_exempt: false,
67 }
68 }
69}
70
71impl ToProtobuf for CustomFixedFee {
72 type Protobuf = services::FixedCustomFee;
73
74 fn to_protobuf(&self) -> Self::Protobuf {
75 Self::Protobuf {
76 fixed_fee: Some(services::FixedFee {
77 amount: self.amount as i64,
78 denominating_token_id: self.denominating_token_id.to_protobuf(),
79 }),
80 fee_collector_account_id: self.fee_collector_account_id.to_protobuf(),
81 }
82 }
83}
84
85impl FromProtobuf<services::FixedCustomFee> for CustomFixedFee {
86 fn from_protobuf(pb: services::FixedCustomFee) -> crate::Result<Self> {
87 let fee = FixedFeeData::from_protobuf(pb.fixed_fee.unwrap())?;
88
89 Ok(Self {
90 amount: fee.amount as u64,
91 denominating_token_id: fee.denominating_token_id,
92 fee_collector_account_id: Option::from_protobuf(pb.fee_collector_account_id)?,
93 })
94 }
95}
96
97impl FromProtobuf<services::FixedFee> for CustomFixedFee {
98 fn from_protobuf(pb: services::FixedFee) -> crate::Result<Self> {
99 let fee = FixedFeeData::from_protobuf(pb)?;
100
101 Ok(Self {
102 amount: fee.amount as u64,
103 denominating_token_id: fee.denominating_token_id,
104 fee_collector_account_id: None,
105 })
106 }
107}