forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbar_unit.go
67 lines (60 loc) · 1.35 KB
/
hbar_unit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package hedera
type HbarUnit string
var HbarUnits = struct {
Tinybar HbarUnit
Microbar HbarUnit
Millibar HbarUnit
Hbar HbarUnit
Kilobar HbarUnit
Megabar HbarUnit
Gigabar HbarUnit
}{
Tinybar: HbarUnit("tinybar"),
Microbar: HbarUnit("microbar"),
Millibar: HbarUnit("millibar"),
Hbar: HbarUnit("hbar"),
Kilobar: HbarUnit("kilobar"),
Megabar: HbarUnit("megabar"),
Gigabar: HbarUnit("gigabar"),
}
func (unit HbarUnit) Symbol() string {
switch unit {
case HbarUnits.Tinybar:
return "tℏ"
case HbarUnits.Microbar:
return "μℏ"
case HbarUnits.Millibar:
return "mℏ"
case HbarUnits.Hbar:
return "ℏ"
case HbarUnits.Kilobar:
return "kℏ"
case HbarUnits.Megabar:
return "Mℏ"
case HbarUnits.Gigabar:
return "Gℏ"
}
panic("unreacahble: HbarUnit.Symbol() switch statement is non-exhaustive")
}
func (unit HbarUnit) String() string {
return string(unit)
}
func (unit HbarUnit) numberOfTinybar() int64 {
switch unit {
case HbarUnits.Tinybar:
return 1
case HbarUnits.Microbar:
return 100
case HbarUnits.Millibar:
return 100_000
case HbarUnits.Hbar:
return 100_000_000
case HbarUnits.Kilobar:
return 100_000_000_000
case HbarUnits.Megabar:
return 100_000_000_000_000
case HbarUnits.Gigabar:
return 100_000_000_000_000_000
}
panic("unreacahble: HbarUnit.Symbol() switch statement is non-exhaustive")
}