1010
1111class CurrencyFormat (Enum ):
1212 WHOLE = 1
13- MICRO = 2
13+ NANO = 2
1414
1515class CurrencyUnderflow (Exception ):
1616 pass
1717
1818class Currency ():
1919 @classmethod
20- def __microcodas_from_int (_cls , n ):
20+ def __nanocodas_from_int (_cls , n ):
2121 return n * 1000000000
2222
2323 @classmethod
24- def __microcodas_from_string (_cls , s ):
24+ def __nanocodas_from_string (_cls , s ):
2525 segments = s .split ('.' )
2626 if len (segments ) == 1 :
2727 return int (segments [0 ])
@@ -35,30 +35,30 @@ def __microcodas_from_string(_cls, s):
3535 def __init__ (self , value , format = CurrencyFormat .WHOLE ):
3636 if format == CurrencyFormat .WHOLE :
3737 if isinstance (value , int ):
38- self .__microcodas = Currency .__microcodas_from_int (value )
38+ self .__nanocodas = Currency .__nanocodas_from_int (value )
3939 elif isinstance (value , float ):
40- self .__microcodas = Currency .__microcodas_from_string (str (value ))
40+ self .__nanocodas = Currency .__nanocodas_from_string (str (value ))
4141 elif isinstance (value , str ):
42- self .__microcodas = Currency .__microcodas_from_string (value )
42+ self .__nanocodas = Currency .__nanocodas_from_string (value )
4343 else :
4444 raise Exception ('cannot construct whole Currency from %s' % type (value ))
45- elif format == CurrencyFormat .MICRO :
45+ elif format == CurrencyFormat .NANO :
4646 if isinstance (value , int ):
47- self .__microcodas = value
47+ self .__nanocodas = value
4848 else :
49- raise Exception ('cannot construct micro Currency from %s' % type (value ))
49+ raise Exception ('cannot construct nano Currency from %s' % type (value ))
5050 else :
5151 raise Exception ('invalid Currency format %s' % format )
5252
5353 def decimal_format (self ):
54- s = str (self .__microcodas )
54+ s = str (self .__nanocodas )
5555 if len (s ) > 9 :
5656 return s [:- 9 ] + '.' + s [- 9 :]
5757 else :
5858 return '0.' + ('0' * (9 - len (s ))) + s
5959
60- def microcodas (self ):
61- return self .__microcodas
60+ def nanocodas (self ):
61+ return self .__nanocodas
6262
6363 def __str__ (self ):
6464 return self .decimal_format ()
@@ -68,25 +68,25 @@ def __repr__(self):
6868
6969 def __add__ (self , other ):
7070 if isinstance (other , Currency ):
71- return Currency (self .microcodas () + other .microcodas (), format = CurrencyFormat .MICRO )
71+ return Currency (self .nanocodas () + other .nanocodas (), format = CurrencyFormat .NANO )
7272 else :
7373 raise Exception ('cannot add Currency and %s' % type (other ))
7474
7575 def __sub__ (self , other ):
7676 if isinstance (other , Currency ):
77- new_value = self .microcodas () - other .microcodas ()
77+ new_value = self .nanocodas () - other .nanocodas ()
7878 if new_value >= 0 :
79- return Currency (new_value , format = CurrencyFormat .MICRO )
79+ return Currency (new_value , format = CurrencyFormat .NANO )
8080 else :
8181 raise CurrencyUnderflow ()
8282 else :
8383 raise Exception ('cannot subtract Currency and %s' % type (other ))
8484
8585 def __mul__ (self , other ):
8686 if isinstance (other , int ):
87- return Currency (self .microcodas () * other , format = CurrencyFormat .MICRO )
87+ return Currency (self .nanocodas () * other , format = CurrencyFormat .NANO )
8888 elif isinstance (other , Currency ):
89- return Currency (self .microcodas () * other .microcodas (), format = CurrencyFormat .MICRO )
89+ return Currency (self .nanocodas () * other .nanocodas (), format = CurrencyFormat .NANO )
9090 else :
9191 raise Exception ('cannot multiply Currency and %s' % type (other ))
9292
@@ -507,8 +507,8 @@ def send_payment(self, to_pk: str, from_pk: str, amount: Currency, fee: Currency
507507 variables = {
508508 "from" : from_pk ,
509509 "to" : to_pk ,
510- "amount" : amount .microcodas (),
511- "fee" : fee .microcodas (),
510+ "amount" : amount .nanocodas (),
511+ "fee" : fee .nanocodas (),
512512 "memo" : memo
513513 }
514514 res = self ._send_mutation (query , variables )
0 commit comments