Skip to content

Commit c0c6ef8

Browse files
committed
Balance update.
1 parent 097a6fb commit c0c6ef8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bittensor_cli/src/bittensor/balances.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# DEALINGS IN THE SOFTWARE.
1919

2020
from typing import Union
21+
from bittensor_cli.src import UNITS
2122

2223

2324
class Balance:
@@ -279,3 +280,21 @@ def from_rao(amount: int):
279280
:return: A Balance object representing the given amount.
280281
"""
281282
return Balance(amount)
283+
284+
@staticmethod
285+
def get_unit(netuid: int):
286+
units = UNITS
287+
base = len(units)
288+
if netuid < base:
289+
return units[netuid]
290+
else:
291+
result = ""
292+
while netuid > 0:
293+
result = units[netuid % base] + result
294+
netuid //= base
295+
return result
296+
297+
def set_unit(self, netuid: int):
298+
self.unit = Balance.get_unit(netuid)
299+
self.rao_unit = Balance.get_unit(netuid)
300+
return self

0 commit comments

Comments
 (0)