Documentation
¶
Index ¶
- Constants
- Variables
- type Amount
- func (a Amount) Format(opts ...FormatOption) string
- func (a Amount) MulF64(f float64) Amount
- func (a *Amount) Scan(src any) error
- func (a Amount) String() string
- func (a Amount) ToNanoPAC() int64
- func (a Amount) ToPAC() float64
- func (a Amount) ToUnit(u Unit) float64
- func (a Amount) Value() (driver.Value, error)
- type FormatOption
- type Unit
Constants ¶
const ( // NanoPACPerPAC is the number of NanoPAC in one PAC. NanoPACPerPAC = 1e9 // MaxNanoPAC is the maximum transaction amount allowed in NanoPAC. MaxNanoPAC = 42e6 * NanoPACPerPAC )
Variables ¶
var ErrInvalidSQLType = errors.New("invalid SQL type")
ErrInvalidSQLType is returned when the type of the data is not supported for SQL database operations.
Functions ¶
This section is empty.
Types ¶
type Amount ¶
type Amount int64
Amount represents the atomic unit in Pactus blockchain. Each unit equals 1e-9 of a PAC.
func FromString ¶
FromString parses a string representing a value in PAC. It then uses NewAmount to create an Amount based on the parsed floating-point value. If the parsing of the string fails, it returns an error. TODO: Parse Unit and remove delimiters...
func NewAmount ¶
NewAmount creates an Amount from a floating-point value representing an amount in PAC. NewAmount returns an error if f is NaN or +-Infinity, but it does not check whether the amount is within the total amount of PAC producible, as it may not refer to an amount at a single moment in time.
NewAmount is specifically for converting PAC to NanoPAC. For creating a new Amount with an int64 value which denotes a quantity of NanoPAC, do a simple type conversion from type int64 to Amount.
func (Amount) Format ¶
func (a Amount) Format(opts ...FormatOption) string
Format formats a monetary amount counted in Pactus base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formatted with an appended label describing the units with SI notation, and "NanoPAC" for the base unit.
Format accepts options:
- WithUnit(u Unit): sets the unit for formatting (defaults to no unit)
- WithDelimiters(): enables comma delimiters in the formatted number (defaults to false)
func (*Amount) Scan ¶ added in v1.11.0
Scan implements the sql.Scanner interface for SQL database operations. It accepts int64 values representing NanoPAC and converts them to Amount.
func (Amount) ToNanoPAC ¶
ToNanoPAC returns the amount of NanoPAC (atomic units) as a 64-bit integer.
type FormatOption ¶ added in v1.11.0
type FormatOption func(*formatOptions)
FormatOption is a function that configures formatting options.
func WithDelimiters ¶ added in v1.11.0
func WithDelimiters() FormatOption
WithDelimiters enables delimiter formatting (e.g., "1,234.56").
func WithUnit ¶ added in v1.11.0
func WithUnit(u Unit) FormatOption
WithUnit sets the unit for formatting.
type Unit ¶
type Unit int
Unit describes a method of converting an Amount to something other than the base unit of PAC. The value of the Unit is the exponent component of the decimal multiple to convert from an amount in PAC to an amount counted in units.