github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/hbar_unit.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 type HbarUnit string 24 25 // HbarUnits is a set of HbarUnit 26 var HbarUnits = struct { 27 Tinybar HbarUnit 28 Microbar HbarUnit 29 Millibar HbarUnit 30 Hbar HbarUnit 31 Kilobar HbarUnit 32 Megabar HbarUnit 33 Gigabar HbarUnit 34 }{ 35 Tinybar: HbarUnit("tinybar"), 36 Microbar: HbarUnit("microbar"), 37 Millibar: HbarUnit("millibar"), 38 Hbar: HbarUnit("hbar"), 39 Kilobar: HbarUnit("kilobar"), 40 Megabar: HbarUnit("megabar"), 41 Gigabar: HbarUnit("gigabar"), 42 } 43 44 // Symbol returns the symbol representation of the HbarUnit 45 func (unit HbarUnit) Symbol() string { 46 switch unit { 47 case HbarUnits.Tinybar: 48 return "tℏ" 49 case HbarUnits.Microbar: 50 return "μℏ" 51 case HbarUnits.Millibar: 52 return "mℏ" 53 case HbarUnits.Hbar: 54 return "ℏ" 55 case HbarUnits.Kilobar: 56 return "kℏ" 57 case HbarUnits.Megabar: 58 return "Mℏ" 59 case HbarUnits.Gigabar: 60 return "Gℏ" 61 } 62 63 panic("unreachable: HbarUnit.Symbol() switch statement is non-exhaustive") 64 } 65 66 // String returns a string representation of the HbarUnit 67 func (unit HbarUnit) String() string { 68 return string(unit) 69 } 70 71 func (unit HbarUnit) _NumberOfTinybar() int64 { 72 switch unit { 73 case HbarUnits.Tinybar: 74 return 1 75 case HbarUnits.Microbar: 76 return 100 77 case HbarUnits.Millibar: 78 return 100_000 79 case HbarUnits.Hbar: 80 return 100_000_000 81 case HbarUnits.Kilobar: 82 return 100_000_000_000 83 case HbarUnits.Megabar: 84 return 100_000_000_000_000 85 case HbarUnits.Gigabar: 86 return 100_000_000_000_000_000 87 } 88 89 panic("unreachable: HbarUnit.Symbol() switch statement is non-exhaustive") 90 }