Put hbar unit values behind a namespace of HbarUnits
@@ -10,20 +10,22 @@ type Hbar struct {
const max = int64(^uint(0) >> 1)
const min = -max - 1
-var MaxHbar = Hbar{max, HBar}
-var MinHbar = Hbar{min, HBar}
-var ZeroHbar = Hbar{0, HBar}
+var MaxHbar = Hbar{max, HbarUnits.Hbar}
-func HbarFromDecimal(bars float64, unit HbarUnit) Hbar {
- return Hbar{int64(bars * float64(unit.toTinybarCount())), unit}
+var MinHbar = Hbar{min, HbarUnits.Hbar}
+
+var ZeroHbar = Hbar{0, HbarUnits.Hbar}
+
+func HbarFrom(bars float64, unit HbarUnit) Hbar {
+ return Hbar{int64(bars * float64(unit.numberOfTinybar())), unit}
}
func HbarFromTinybar(tinybar int64) Hbar {
- return Hbar{tinybar: tinybar, unit: Tinybar}
+ return Hbar{tinybar: tinybar, unit: HbarUnits.Tinybar}
}
func HbarOf(hbar float64) Hbar {
- return Hbar{tinybar: int64(hbar * 100_000_000), unit: HBar}
+ return Hbar{tinybar: int64(hbar * 100_000_000), unit: HbarUnits.Hbar}
}
func (hbar Hbar) AsTinybar() uint64 {
@@ -31,13 +33,13 @@ func (hbar Hbar) AsTinybar() uint64 {
}
func (hbar Hbar) As(unit HbarUnit) int64 {
- return hbar.tinybar * hbar.unit.toTinybarCount()
+ return hbar.tinybar * hbar.unit.numberOfTinybar()
}
func (hbar Hbar) String() string {
- if hbar.unit == Tinybar {
+ if hbar.unit == HbarUnits.Tinybar {
return fmt.Sprintf("%v %v", hbar.tinybar, hbar.unit.String())
- } else {
- return fmt.Sprintf("%v %v (%v tinybar)", hbar.tinybar, hbar.unit.String(), hbar.As(Tinybar))
}
+
+ return fmt.Sprintf("%v %v (%v tinybar)", hbar.tinybar, hbar.unit.String(), hbar.AsTinybar())
}
