obj.py: new CoinAmt abstract class

This commit is contained in:
The MMGen Project 2021-09-01 16:56:47 +00:00
commit af0bfc342c
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 20 additions and 12 deletions

View file

@ -21,20 +21,19 @@ altcoins.eth.obj: Ethereum data type classes for the MMGen suite
"""
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
class ETHAmt(BTCAmt):
class ETHAmt(CoinAmt):
max_prec = 18
max_amt = None
wei = Decimal('0.000000000000000001')
Kwei = Decimal('0.000000000000001')
Mwei = Decimal('0.000000000001')
Gwei = Decimal('0.000000001')
szabo = Decimal('0.000001')
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 toKwei(self): return int(Decimal(self) // self.Kwei)

View file

@ -451,15 +451,15 @@ class SubSeedIdxRange(MMGenRange):
class UnknownCoinAmt(Decimal): pass
class BTCAmt(Decimal,Hilite,InitErrors):
class CoinAmt(Decimal,Hilite,InitErrors): # abstract class
color = 'yellow'
max_prec = 8
max_amt = 21000000
satoshi = Decimal('0.00000001')
amt_fs = '4.8'
units = ('satoshi',)
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):
if type(num) == cls:
return num
@ -540,13 +540,22 @@ class BTCAmt(Decimal,Hilite,InitErrors):
def __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 B2XAmt(BTCAmt): pass
class LTCAmt(BTCAmt): max_amt = 84000000
class XMRAmt(BTCAmt):
class XMRAmt(CoinAmt):
max_prec = 12
atomic = Decimal('0.000000000001')
units = ('atomic',)
amt_fs = '4.12'
from .altcoins.eth.obj import ETHAmt,ETHNonce