Move ETHAmt and ETHNonce to eth/obj.py
This commit is contained in:
parent
adef0b38c5
commit
57f7cfc0e9
3 changed files with 66 additions and 39 deletions
64
mmgen/altcoins/eth/obj.py
Executable file
64
mmgen/altcoins/eth/obj.py
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
||||
# Copyright (C)2013-2018 The MMGen Project <mmgen@tuta.io>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
obj.py: MMGen native classes for Ethereum
|
||||
"""
|
||||
|
||||
# Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18
|
||||
from decimal import Decimal
|
||||
from mmgen.color import *
|
||||
from mmgen.obj import *
|
||||
class ETHAmt(BTCAmt):
|
||||
max_prec = 18
|
||||
max_amt = 999999999 # TODO
|
||||
wei = Decimal('0.000000000000000001')
|
||||
Kwei = Decimal('0.000000000000001')
|
||||
Mwei = Decimal('0.000000000001')
|
||||
Gwei = Decimal('0.000000001')
|
||||
szabo = Decimal('0.000001')
|
||||
finney = Decimal('0.001')
|
||||
min_coin_unit = wei
|
||||
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)
|
||||
def toMwei(self): return int(Decimal(self) / self.Mwei)
|
||||
def toGwei(self): return int(Decimal(self) / self.Gwei)
|
||||
def toSzabo(self): return int(Decimal(self) / self.szabo)
|
||||
def toFinney(self): return int(Decimal(self) / self.finney)
|
||||
|
||||
class ETHNonce(int,Hilite,InitErrors): # WIP
|
||||
def __new__(cls,n,on_fail='die'):
|
||||
if type(n) == cls: return n
|
||||
cls.arg_chk(cls,on_fail)
|
||||
from mmgen.util import is_int
|
||||
try:
|
||||
assert is_int(n),"'{}': value is not an integer".format(n)
|
||||
me = int.__new__(cls,n)
|
||||
return me
|
||||
except Exception as e:
|
||||
m = "{!r}: value cannot be converted to ETH nonce ({})"
|
||||
return cls.init_fail(m.format(n,e[0]),on_fail)
|
||||
|
||||
@classmethod
|
||||
def colorize(cls,s,color=True):
|
||||
k = color if type(color) is str else cls.color # hack: override color with str value
|
||||
return globals()[k](str(s)) if (color or cls.color_always) else str(s)
|
||||
|
|
@ -22,7 +22,7 @@ altcoins.eth.tw: ETH tracking wallet functions and methods for the MMGen suite
|
|||
|
||||
import json
|
||||
from mmgen.common import *
|
||||
from mmgen.obj import *
|
||||
from mmgen.obj import ETHAmt,TwMMGenID,TwComment,TwLabel
|
||||
from mmgen.tw import TrackingWallet,TwAddrList,TwUnspentOutputs
|
||||
from mmgen.addr import AddrData
|
||||
|
||||
|
|
|
|||
39
mmgen/obj.py
39
mmgen/obj.py
|
|
@ -387,44 +387,7 @@ class BCHAmt(BTCAmt): pass
|
|||
class B2XAmt(BTCAmt): pass
|
||||
class LTCAmt(BTCAmt): max_amt = 84000000
|
||||
|
||||
# Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18
|
||||
class ETHAmt(BTCAmt):
|
||||
max_prec = 18
|
||||
max_amt = 999999999 # TODO
|
||||
wei = Decimal('0.000000000000000001')
|
||||
Kwei = Decimal('0.000000000000001')
|
||||
Mwei = Decimal('0.000000000001')
|
||||
Gwei = Decimal('0.000000001')
|
||||
szabo = Decimal('0.000001')
|
||||
finney = Decimal('0.001')
|
||||
min_coin_unit = wei
|
||||
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)
|
||||
def toMwei(self): return int(Decimal(self) / self.Mwei)
|
||||
def toGwei(self): return int(Decimal(self) / self.Gwei)
|
||||
def toSzabo(self): return int(Decimal(self) / self.szabo)
|
||||
def toFinney(self): return int(Decimal(self) / self.finney)
|
||||
|
||||
class ETHNonce(int,Hilite,InitErrors): # WIP
|
||||
def __new__(cls,n,on_fail='die'):
|
||||
if type(n) == cls: return n
|
||||
cls.arg_chk(cls,on_fail)
|
||||
from mmgen.util import is_int
|
||||
try:
|
||||
assert is_int(n),"'{}': value is not an integer".format(n)
|
||||
me = int.__new__(cls,n)
|
||||
return me
|
||||
except Exception as e:
|
||||
m = "{!r}: value cannot be converted to ETH nonce ({})"
|
||||
return cls.init_fail(m.format(n,e[0]),on_fail)
|
||||
|
||||
@classmethod
|
||||
def colorize(cls,s,color=True):
|
||||
k = color if type(color) is str else cls.color # hack: override color with str value
|
||||
return globals()[k](str(s)) if (color or cls.color_always) else str(s)
|
||||
from mmgen.altcoins.eth.obj import ETHAmt,ETHNonce
|
||||
|
||||
class CoinAddr(str,Hilite,InitErrors,MMGenObject):
|
||||
color = 'cyan'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue