Improve coin selection logic, allow coin disabling
This commit is contained in:
parent
91ac2effb3
commit
279e8872ef
5 changed files with 53 additions and 35 deletions
|
|
@ -38,10 +38,12 @@ class CoinInfo(object):
|
||||||
coin_constants = {}
|
coin_constants = {}
|
||||||
coin_constants['mainnet'] = (
|
coin_constants['mainnet'] = (
|
||||||
# NAME SYM WIF P2PKH P2SH SEGWIT TRUST
|
# NAME SYM WIF P2PKH P2SH SEGWIT TRUST
|
||||||
# trust levels: 0=untested 1=low 2=med 3=high
|
# trust levels: 0=untested 1=low 2=med 3=high -1=disable
|
||||||
('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, 3),
|
# Fork coins must be disabled here to prevent generation from incorrect sub-seed
|
||||||
('BitcoinSegwit2X', 'B2X', 0x80, (0x00,'1'), (0x05,'3'), True, 2),
|
('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, -1),
|
||||||
('Bcash', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False, 3),
|
('BitcoinSegwit2X', 'B2X', 0x80, (0x00,'1'), (0x05,'3'), True, -1),
|
||||||
|
('BitcoinGold', 'BCG', 0x80, (0x00,'1'), (0x05,'3'), True, -1),
|
||||||
|
('Bcash', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False,-1),
|
||||||
('2GiveCoin', '2GIVE', 0xa7, (0x27,('G','H')), None, False, 0),
|
('2GiveCoin', '2GIVE', 0xa7, (0x27,('G','H')), None, False, 0),
|
||||||
('42Coin', '42', 0x88, (0x08,'4'), None, False, 1),
|
('42Coin', '42', 0x88, (0x08,'4'), None, False, 1),
|
||||||
('ACoin', 'ACOIN', 0xe6, (0x17,'A'), None, False, 0),
|
('ACoin', 'ACOIN', 0xe6, (0x17,'A'), None, False, 0),
|
||||||
|
|
@ -432,6 +434,7 @@ class CoinInfo(object):
|
||||||
from mmgen.util import pmsg,pdie
|
from mmgen.util import pmsg,pdie
|
||||||
# pmsg(sym)
|
# pmsg(sym)
|
||||||
# pdie(tt)
|
# pdie(tt)
|
||||||
|
if trust != -1:
|
||||||
if sym in tt:
|
if sym in tt:
|
||||||
src = tt[sym]
|
src = tt[sym]
|
||||||
if src != trust:
|
if src != trust:
|
||||||
|
|
|
||||||
|
|
@ -55,5 +55,7 @@ def launch(what):
|
||||||
if os.getenv('MMGEN_TRACEBACK'):
|
if os.getenv('MMGEN_TRACEBACK'):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
sys.stderr.write('{!r}\n'.format(e[0]))
|
try: m = u'{}\n'.format(e[0])
|
||||||
|
except: m = u'{!r}\n'.format(e[0])
|
||||||
|
sys.stderr.write(m)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
|
||||||
|
|
@ -326,22 +326,29 @@ class ZcashTestnetProtocol(ZcashProtocol):
|
||||||
|
|
||||||
class CoinProtocol(MMGenObject):
|
class CoinProtocol(MMGenObject):
|
||||||
coins = {
|
coins = {
|
||||||
'btc': (BitcoinProtocol,BitcoinTestnetProtocol),
|
# mainnet testnet trustlevel (None == skip)
|
||||||
'bch': (BitcoinCashProtocol,BitcoinCashTestnetProtocol),
|
'btc': (BitcoinProtocol,BitcoinTestnetProtocol,None),
|
||||||
'ltc': (LitecoinProtocol,LitecoinTestnetProtocol),
|
'bch': (BitcoinCashProtocol,BitcoinCashTestnetProtocol,None),
|
||||||
'eth': (EthereumProtocol,EthereumTestnetProtocol),
|
'ltc': (LitecoinProtocol,LitecoinTestnetProtocol,None),
|
||||||
'etc': (EthereumClassicProtocol,EthereumClassicTestnetProtocol),
|
'eth': (EthereumProtocol,EthereumTestnetProtocol,2),
|
||||||
'zec': (ZcashProtocol,ZcashTestnetProtocol),
|
'etc': (EthereumClassicProtocol,EthereumClassicTestnetProtocol,2),
|
||||||
|
'zec': (ZcashProtocol,ZcashTestnetProtocol,2),
|
||||||
}
|
}
|
||||||
def __new__(cls,coin,testnet):
|
def __new__(cls,coin,testnet):
|
||||||
coin = coin.lower()
|
coin = coin.lower()
|
||||||
assert type(testnet) == bool
|
assert type(testnet) == bool
|
||||||
from mmgen.altcoin import CoinInfo as ci
|
|
||||||
all_coins = sorted(set([e[1].lower() for e in ci.coin_constants['mainnet']] + cls.coins.keys()))
|
|
||||||
m = "'{}': not a valid coin. Valid choices are {}"
|
m = "'{}': not a valid coin. Valid choices are {}"
|
||||||
assert coin in cls.coins,m.format(coin,','.join(all_coins))
|
assert coin in cls.coins,m.format(coin,','.join(cls.get_valid_coins()))
|
||||||
return cls.coins[coin][testnet]
|
return cls.coins[coin][testnet]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_valid_coins(cls,upcase=False):
|
||||||
|
from mmgen.altcoin import CoinInfo as ci
|
||||||
|
ret = sorted(set(
|
||||||
|
[e[1] for e in ci.coin_constants['mainnet'] if e[6] != -1]
|
||||||
|
+ cls.coins.keys()))
|
||||||
|
return [getattr(e,('lower','upper')[upcase])() for e in ret]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_base_coin_from_name(cls,name):
|
def get_base_coin_from_name(cls,name):
|
||||||
for proto,foo in cls.coins.values():
|
for proto,foo in cls.coins.values():
|
||||||
|
|
@ -352,9 +359,11 @@ class CoinProtocol(MMGenObject):
|
||||||
def init_genonly_altcoins(usr_coin,trust_level=None):
|
def init_genonly_altcoins(usr_coin,trust_level=None):
|
||||||
from mmgen.altcoin import CoinInfo as ci
|
from mmgen.altcoin import CoinInfo as ci
|
||||||
if trust_level is None:
|
if trust_level is None:
|
||||||
if not usr_coin or usr_coin.lower() in CoinProtocol.coins: return None
|
if not usr_coin: return None # BTC
|
||||||
|
if usr_coin.lower() in CoinProtocol.coins:
|
||||||
|
return CoinProtocol.coins[usr_coin.lower()][2]
|
||||||
usr_coin = usr_coin.upper()
|
usr_coin = usr_coin.upper()
|
||||||
mn_coins = [e[1] for e in ci.coin_constants['mainnet']]
|
mn_coins = [e[1] for e in ci.coin_constants['mainnet'] if e[6] != -1]
|
||||||
if usr_coin not in mn_coins: return None
|
if usr_coin not in mn_coins: return None
|
||||||
trust_level = ci.coin_constants['mainnet'][mn_coins.index(usr_coin)][6]
|
trust_level = ci.coin_constants['mainnet'][mn_coins.index(usr_coin)][6]
|
||||||
data = {}
|
data = {}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ t_alts=(
|
||||||
|
|
||||||
"test/gentest.py --all 2:pycoin $ROUNDS_LOW"
|
"test/gentest.py --all 2:pycoin $ROUNDS_LOW"
|
||||||
"test/gentest.py --all 2:pyethereum $ROUNDS_LOW"
|
"test/gentest.py --all 2:pyethereum $ROUNDS_LOW"
|
||||||
"test/gentest.py --all 2:keyconv $ROUNDS_LOW")
|
"test/gentest.py --all 2:keyconv $ROUNDS_LOW"
|
||||||
|
"test/gentest.py --all 2:zcash_mini $ROUNDS_LOW")
|
||||||
|
|
||||||
f_alts='Gen-only altcoin tests completed'
|
f_alts='Gen-only altcoin tests completed'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ def pycoin_sec2addr(sec):
|
||||||
|
|
||||||
# pycoin/networks/all.py pycoin/networks/legacy_networks.py
|
# pycoin/networks/all.py pycoin/networks/legacy_networks.py
|
||||||
def init_external_prog():
|
def init_external_prog():
|
||||||
global b,b_desc,ext_lib,ext_sec2addr,sp,eth,pcku,PREFIX_TRANSFORMS
|
global b,b_desc,ext_lib,ext_sec2addr,sp,eth,pcku,PREFIX_TRANSFORMS,addr_type
|
||||||
def test_support(k):
|
def test_support(k):
|
||||||
if b == k: return True
|
if b == k: return True
|
||||||
if b != 'ext' and b != k: return False
|
if b != 'ext' and b != k: return False
|
||||||
|
|
@ -116,8 +116,11 @@ def init_external_prog():
|
||||||
return False
|
return False
|
||||||
if b == 'zcash_mini' or addr_type.name == 'zcash_z':
|
if b == 'zcash_mini' or addr_type.name == 'zcash_z':
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
from mmgen.protocol import init_coin
|
||||||
ext_sec2addr = zcash_mini_sec2addr
|
ext_sec2addr = zcash_mini_sec2addr
|
||||||
ext_lib = 'zcash_mini'
|
ext_lib = 'zcash_mini'
|
||||||
|
init_coin('zec')
|
||||||
|
addr_type = MMGenAddrType('Z')
|
||||||
elif test_support('pyethereum'):
|
elif test_support('pyethereum'):
|
||||||
try:
|
try:
|
||||||
import ethereum.utils as eth
|
import ethereum.utils as eth
|
||||||
|
|
@ -277,11 +280,11 @@ ag = AddrGenerator(addr_type)
|
||||||
|
|
||||||
if a and b:
|
if a and b:
|
||||||
if opt.all:
|
if opt.all:
|
||||||
from mmgen.protocol import init_coin,init_genonly_altcoins
|
from mmgen.protocol import init_coin,init_genonly_altcoins,CoinProtocol
|
||||||
init_genonly_altcoins('btc',trust_level=0)
|
init_genonly_altcoins('btc',trust_level=0)
|
||||||
mmgen_supported = [e[1] for e in ci.coin_constants['mainnet']]
|
mmgen_supported = CoinProtocol.get_valid_coins(upcase=True)
|
||||||
for coin in ci.external_tests[('mainnet','testnet')[g.testnet]][ext_lib]:
|
for coin in ci.external_tests[('mainnet','testnet')[g.testnet]][ext_lib]:
|
||||||
if coin not in mmgen_supported and ext_lib != 'pyethereum': continue
|
if coin not in mmgen_supported: continue
|
||||||
init_coin(coin)
|
init_coin(coin)
|
||||||
tmp_addr_type = addr_type if addr_type in g.proto.mmtypes else MMGenAddrType(g.proto.dfl_mmtype)
|
tmp_addr_type = addr_type if addr_type in g.proto.mmtypes else MMGenAddrType(g.proto.dfl_mmtype)
|
||||||
kg_a = KeyGenerator(tmp_addr_type,a)
|
kg_a = KeyGenerator(tmp_addr_type,a)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue