-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b03dc3d
commit bdc857d
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package hedera | ||
|
||
type Hbar struct { | ||
tinybar int64 | ||
} | ||
|
||
const max = int64(^uint(0) >> 1) | ||
const min = -max - 1 | ||
|
||
var HbarMAX = Hbar{max} | ||
var HbarMIN = Hbar{min} | ||
var HbarZERO = Hbar{} | ||
|
||
func HbarFromTinybar(tinybar uint64) Hbar { | ||
return Hbar{tinybar: int64(tinybar)} | ||
} | ||
|
||
func HbarOf(tinybar float64) Hbar { | ||
return Hbar{tinybar: int64(tinybar * 100_000_000)} | ||
} | ||
|
||
func (hbar Hbar) AsTinybar() uint64 { | ||
return uint64(hbar.tinybar) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package hedera | ||
|
||
type HbarUnit string | ||
|
||
const ( | ||
Tinybar HbarUnit = "tinybar" | ||
Microbar HbarUnit = "microbar" | ||
Millibar HbarUnit = "millibar" | ||
// Hbar HbarUnit = "hbar" | ||
Kilobar HbarUnit = "kilobar" | ||
Megabar HbarUnit = "megabar" | ||
Gigabar HbarUnit = "gigabar" | ||
) | ||
|
||
func (unit HbarUnit) GetSymbol() string { | ||
switch unit { | ||
case Tinybar: | ||
return "tℏ" | ||
case Microbar: | ||
return "μℏ" | ||
case Millibar: | ||
return "mℏ" | ||
// case Hbar: | ||
// return "ℏ" | ||
case Kilobar: | ||
return "kℏ" | ||
case Megabar: | ||
return "Mℏ" | ||
case Gigabar: | ||
return "Gℏ" | ||
} | ||
|
||
// Unreachable | ||
return "" | ||
} | ||
|
||
func (unit HbarUnit) String() string { | ||
return string(unit) | ||
} |