33NANO_PAC_PER_PAC = 1e9
44MAX_NANO_PAC = 42e6 * NANO_PAC_PER_PAC
55
6-
76class Amount :
87 """
9- The Amount class represents a quantity in NanoPAC.
8+ Amount represents the atomic unit in the Pactus blockchain.
9+ Each unit is equal to 1e-9 of a PAC.
1010
11- The `from_NanoPAC ` method creates an Amount from a floating-point value
11+ The `from_pac ` method creates an Amount from a floating-point value
1212 representing an amount in PAC. It raises an error if the value is NaN or
13- +- Infinity, but it does not check whether the amount exceeds the total
13+ ± Infinity, but it does not check whether the amount exceeds the total
1414 amount of PAC producible. This method is specifically for converting PAC
15- to NanoPAC. For creating a new Amount with an integer value representing
16- NanoPAC, you can initialize the Amount directly with an integer .
15+ to NanoPAC. To create a new Amount with an integer value representing
16+ NanoPAC, you can use the `from_nano_pac` method .
1717 """
1818
1919 def __init__ (self , amt : int = 0 ) -> None :
@@ -26,18 +26,23 @@ def __eq__(self, other: "Amount") -> bool:
2626 return False
2727
2828 @classmethod
29- def from_nano_pac (cls , f : float ) -> "Amount" :
29+ def from_nano_pac (cls , a : int ) -> "Amount" :
30+ """Store the value as NanoPAC in the Amount instance."""
31+ return cls (a )
32+
33+ @classmethod
34+ def from_pac (cls , f : float ) -> "Amount" :
3035 """
31- Convert a floating-point value in PAC to NanoPAC and stores it in the Amount instance.
36+ Convert a floating-point value in PAC to NanoPAC and store it in the Amount instance.
3237
33- The conversion is invalid if the floating-point value is NaN or +- Infinity,
38+ The conversion is invalid if the floating-point value is NaN or ± Infinity,
3439 in which case a ValueError is raised.
3540 """
3641 if math .isinf (f ) or math .isnan (f ):
3742 msg = f"invalid PAC amount: { f } "
3843 raise ValueError (msg )
3944
40- return cls (int (cls .round (f * NANO_PAC_PER_PAC )))
45+ return cls . from_nano_pac (int (cls .round (f * NANO_PAC_PER_PAC )))
4146
4247 @classmethod
4348 def from_string (cls , s : str ) -> "Amount" :
@@ -53,7 +58,7 @@ def from_string(cls, s: str) -> "Amount":
5358 msg = "invalid PAC amount"
5459 raise ValueError (msg ) from e
5560
56- return cls .from_nano_pac (f )
61+ return cls .from_pac (f )
5762
5863 def round (self : float ) -> float :
5964 """
0 commit comments