From af0bfc342cc25a5143c8e535028afda7d5dc3e6d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 1 Sep 2021 16:56:47 +0000 Subject: [PATCH] obj.py: new CoinAmt abstract class --- mmgen/altcoins/eth/obj.py | 9 ++++----- mmgen/obj.py | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mmgen/altcoins/eth/obj.py b/mmgen/altcoins/eth/obj.py index 0df201b5..ac260782 100755 --- a/mmgen/altcoins/eth/obj.py +++ b/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 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) diff --git a/mmgen/obj.py b/mmgen/obj.py index 47e17237..8a49b2a6 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -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