77 from hiero_sdk_python .tokens .custom_fixed_fee import CustomFixedFee
88 from hiero_sdk_python .hapi .services import custom_fees_pb2
99
10+ """Manages custom royalty fees for Non-Fungible Token (NFT) transactions.
11+
12+ This module defines the CustomRoyaltyFee class, which allows a percentage-based
13+ fee (with an optional fixed fee fallback) to be collected upon NFT transfer.
14+ """
15+
1016
1117class CustomRoyaltyFee (CustomFee ):
12- """
13- Represents a custom royalty fee.
18+ """Represents a custom royalty fee assessed during NFT transfers.
19+
20+ The royalty fee is defined by a fractional exchange value (numerator/denominator)
21+ and an optional fixed fee that applies if the NFT is exchanged for HBAR
22+ or a token not specified in the fee schedule.
23+
24+ Inherits common properties like fee_collector_account_id from CustomFee.
1425 """
1526
1627 def __init__ (
@@ -21,30 +32,77 @@ def __init__(
2132 fee_collector_account_id : typing .Optional ["AccountId" ] = None ,
2233 all_collectors_are_exempt : bool = False ,
2334 ):
35+ """Initializes the CustomRoyaltyFee.
36+
37+ Args:
38+ numerator (int): The numerator of the fraction defining the royalty amount.
39+ Defaults to 0.
40+ denominator (int): The denominator of the fraction defining the royalty
41+ amount. Defaults to 1.
42+ fallback_fee (typing.Optional[CustomFixedFee]): The fixed fee to be
43+ collected if the exchange is not in the token's unit (e.g., if sold
44+ for HBAR). Defaults to None.
45+ fee_collector_account_id (typing.Optional[AccountId]): The account ID of
46+ the fee collector. Inherited from CustomFee. Defaults to None.
47+ all_collectors_are_exempt (bool): If true, all collectors for this fee
48+ are exempt from custom fees. Inherited from CustomFee. Defaults to False.
49+ """
2450 super ().__init__ (fee_collector_account_id , all_collectors_are_exempt )
2551 self .numerator = numerator
2652 self .denominator = denominator
2753 self .fallback_fee = fallback_fee
2854
2955 def set_numerator (self , numerator : int ) -> "CustomRoyaltyFee" :
56+ """Sets the numerator of the royalty fraction.
57+
58+ Args:
59+ numerator (int): The numerator value (e.g., 5 for 5/100).
60+
61+ Returns:
62+ CustomRoyaltyFee: This CustomRoyaltyFee instance for chaining.
63+ """
3064 self .numerator = numerator
3165 return self
3266
3367 def set_denominator (self , denominator : int ) -> "CustomRoyaltyFee" :
68+ """Sets the denominator of the royalty fraction.
69+
70+ Args:
71+ denominator (int): The denominator value (e.g., 100 for 5/100).
72+
73+ Returns:
74+ CustomRoyaltyFee: This CustomRoyaltyFee instance for chaining.
75+ """
3476 self .denominator = denominator
3577 return self
3678
3779 def set_fallback_fee (self , fallback_fee : typing .Optional ["CustomFixedFee" ]) -> "CustomRoyaltyFee" :
80+ """Sets the optional fixed fee that applies if the royalty is paid in HBAR.
81+
82+ Args:
83+ fallback_fee (typing.Optional[CustomFixedFee]): A CustomFixedFee object
84+ to use as the fixed fallback fee, or None to remove it.
85+
86+ Returns:
87+ CustomRoyaltyFee: This CustomRoyaltyFee instance for chaining.
88+ """
3889 self .fallback_fee = fallback_fee
3990 return self
4091
4192 def _to_proto (self ) -> "custom_fees_pb2.CustomFee" :
93+ """Converts this CustomRoyaltyFee object to its protobuf representation.
94+
95+ Builds the RoyaltyFee message and integrates it with the common fields
96+ from the CustomFee parent class into a CustomFee protobuf message.
97+
98+ Returns:
99+ custom_fees_pb2.CustomFee: The protobuf CustomFee message.
100+ """
42101 from hiero_sdk_python .hapi .services import custom_fees_pb2
43102 from hiero_sdk_python .hapi .services .basic_types_pb2 import Fraction
44103
45104 fallback_fee_proto = None
46105 if self .fallback_fee :
47- # Use _to_proto instead of _to_protobuf
48106 fallback_fee_proto = self .fallback_fee ._to_proto ().fixed_fee
49107
50108 return custom_fees_pb2 .CustomFee (
@@ -61,19 +119,29 @@ def _to_proto(self) -> "custom_fees_pb2.CustomFee":
61119
62120 @classmethod
63121 def _from_proto (cls , proto_fee ) -> "CustomRoyaltyFee" :
64- """Create CustomRoyaltyFee from protobuf CustomFee message."""
122+ """Creates a CustomRoyaltyFee instance from a CustomFee protobuf message.
123+
124+ Extracts the royalty fee details, optional fallback fee, and common fee
125+ properties from the protobuf message.
126+
127+ Args:
128+ proto_fee: The protobuf CustomFee message. It is expected that the
129+ `royalty_fee` field is set.
130+
131+ Returns:
132+ CustomRoyaltyFee: The corresponding CustomRoyaltyFee object.
133+ """
65134 from hiero_sdk_python .account .account_id import AccountId
66135 from hiero_sdk_python .tokens .custom_fixed_fee import CustomFixedFee
67136
68137 royalty_fee_proto = proto_fee .royalty_fee
69138
70139 fallback_fee = None
71140 if royalty_fee_proto .HasField ("fallback_fee" ):
72- # Use the existing _from_fixed_fee_proto method
73141 fallback_fee = CustomFixedFee ._from_fixed_fee_proto (royalty_fee_proto .fallback_fee )
74142
75143 fee_collector_account_id = None
76- if proto_fee .HasField ("fee_collector_account_id" ): # Changed from WhichOneof
144+ if proto_fee .HasField ("fee_collector_account_id" ):
77145 fee_collector_account_id = AccountId ._from_proto (proto_fee .fee_collector_account_id )
78146
79147 return cls (
0 commit comments