Browse Source

obj.py: new CoinAmt abstract class

The MMGen Project 3 years ago
parent
commit
af0bfc342c
2 changed files with 20 additions and 12 deletions
  1. 4 5
      mmgen/altcoins/eth/obj.py
  2. 16 7
      mmgen/obj.py

+ 4 - 5
mmgen/altcoins/eth/obj.py

@@ -21,20 +21,19 @@ altcoins.eth.obj: Ethereum data type classes for the MMGen suite
 """
 """
 
 
 from decimal import Decimal
 from decimal import Decimal
-from mmgen.obj import BTCAmt,Int
+from mmgen.obj import CoinAmt,Int
 
 
 # Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18
 # Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18
-class ETHAmt(BTCAmt):
+class ETHAmt(CoinAmt):
 	max_prec = 18
 	max_prec = 18
-	max_amt = None
 	wei     = Decimal('0.000000000000000001')
 	wei     = Decimal('0.000000000000000001')
 	Kwei    = Decimal('0.000000000000001')
 	Kwei    = Decimal('0.000000000000001')
 	Mwei    = Decimal('0.000000000001')
 	Mwei    = Decimal('0.000000000001')
 	Gwei    = Decimal('0.000000001')
 	Gwei    = Decimal('0.000000001')
 	szabo   = Decimal('0.000001')
 	szabo   = Decimal('0.000001')
 	finney  = Decimal('0.001')
 	finney  = Decimal('0.001')
-	units = ('wei','Kwei','Mwei','Gwei','szabo','finney')
-	amt_fs = '4.18'
+	units   = ('wei','Kwei','Mwei','Gwei','szabo','finney')
+	amt_fs  = '4.18'
 
 
 	def toWei(self):    return int(Decimal(self) // self.wei)
 	def toWei(self):    return int(Decimal(self) // self.wei)
 	def toKwei(self):   return int(Decimal(self) // self.Kwei)
 	def toKwei(self):   return int(Decimal(self) // self.Kwei)

+ 16 - 7
mmgen/obj.py

@@ -451,15 +451,15 @@ class SubSeedIdxRange(MMGenRange):
 
 
 class UnknownCoinAmt(Decimal): pass
 class UnknownCoinAmt(Decimal): pass
 
 
-class BTCAmt(Decimal,Hilite,InitErrors):
+class CoinAmt(Decimal,Hilite,InitErrors): # abstract class
 	color = 'yellow'
 	color = 'yellow'
-	max_prec = 8
-	max_amt = 21000000
-	satoshi = Decimal('0.00000001')
-	amt_fs = '4.8'
-	units = ('satoshi',)
 	forbidden_types = (float,int)
 	forbidden_types = (float,int)
 
 
+	max_prec = 0      # number of decimal places for this coin
+	max_amt  = None   # coin supply if known, otherwise None
+	units    = ()     # defined unit names, e.g. ('satoshi',...)
+	amt_fs   = '0.0'  # format string for the fmt() method
+
 	def __new__(cls,num,from_unit=None,from_decimal=False):
 	def __new__(cls,num,from_unit=None,from_decimal=False):
 		if type(num) == cls:
 		if type(num) == cls:
 			return num
 			return num
@@ -540,13 +540,22 @@ class BTCAmt(Decimal,Hilite,InitErrors):
 	def __neg__(self,other):
 	def __neg__(self,other):
 		return type(self)(Decimal.__neg__(self,other))
 		return type(self)(Decimal.__neg__(self,other))
 
 
+class BTCAmt(CoinAmt):
+	max_prec = 8
+	max_amt = 21000000
+	satoshi = Decimal('0.00000001')
+	units = ('satoshi',)
+	amt_fs = '4.8'
+
 class BCHAmt(BTCAmt): pass
 class BCHAmt(BTCAmt): pass
 class B2XAmt(BTCAmt): pass
 class B2XAmt(BTCAmt): pass
 class LTCAmt(BTCAmt): max_amt = 84000000
 class LTCAmt(BTCAmt): max_amt = 84000000
-class XMRAmt(BTCAmt):
+
+class XMRAmt(CoinAmt):
 	max_prec = 12
 	max_prec = 12
 	atomic = Decimal('0.000000000001')
 	atomic = Decimal('0.000000000001')
 	units = ('atomic',)
 	units = ('atomic',)
+	amt_fs = '4.12'
 
 
 from .altcoins.eth.obj import ETHAmt,ETHNonce
 from .altcoins.eth.obj import ETHAmt,ETHNonce