|
@@ -701,6 +701,89 @@ class CoinInfo(object):
|
|
|
'bech32': { 'keyconv': True },
|
|
|
}
|
|
|
|
|
|
+def init_genonly_altcoins(usr_coin=None,testnet=False):
|
|
|
+ """
|
|
|
+ Initialize altcoin protocol class or classes for current network.
|
|
|
+ If usr_coin is a core coin, initialization is skipped.
|
|
|
+ If usr_coin has a trust level of -1, an exception is raised.
|
|
|
+ If usr_coin is None, initializes all coins for current network with trust level >-1.
|
|
|
+ Returns trust_level of usr_coin, or 0 (untrusted) if usr_coin is None.
|
|
|
+ """
|
|
|
+ data = { 'mainnet': (), 'testnet': () }
|
|
|
+ networks = ['mainnet'] + (['testnet'] if testnet else [])
|
|
|
+ network = 'testnet' if testnet else 'mainnet'
|
|
|
+
|
|
|
+ if usr_coin == None:
|
|
|
+ for network in networks:
|
|
|
+ data[network] = CoinInfo.get_supported_coins(network)
|
|
|
+ trust_level = 0
|
|
|
+ else:
|
|
|
+ from .globalvars import g
|
|
|
+ if usr_coin.lower() in g.core_coins: # core coin, so return immediately
|
|
|
+ from .protocol import CoinProtocol
|
|
|
+ return CoinProtocol.coins[usr_coin.lower()].trust_level
|
|
|
+ for network in networks:
|
|
|
+ data[network] = (CoinInfo.get_entry(usr_coin,network),)
|
|
|
+
|
|
|
+ cinfo = data[network][0]
|
|
|
+ if not cinfo:
|
|
|
+ raise ValueError(f'{usr_coin.upper()!r}: unrecognized coin for network {network.upper()}')
|
|
|
+ if cinfo.trust_level == -1:
|
|
|
+ raise ValueError(f'{usr_coin.upper()!r}: unsupported (disabled) coin for network {network.upper()}')
|
|
|
+
|
|
|
+ trust_level = cinfo.trust_level
|
|
|
+
|
|
|
+ create_altcoin_protos(data)
|
|
|
+
|
|
|
+ return trust_level
|
|
|
+
|
|
|
+def create_altcoin_protos(data):
|
|
|
+
|
|
|
+ from .protocol import CoinProtocol
|
|
|
+
|
|
|
+ def make_proto(e,testnet=False):
|
|
|
+
|
|
|
+ proto = ('X_' if e.name[0] in '0123456789' else '') + e.name + ('Testnet' if testnet else '')
|
|
|
+
|
|
|
+ if hasattr(CoinProtocol,proto):
|
|
|
+ return
|
|
|
+
|
|
|
+ def num2hexstr(n):
|
|
|
+ return '{:0{}x}'.format(n,(4,2)[n < 256])
|
|
|
+
|
|
|
+ setattr(
|
|
|
+ CoinProtocol,
|
|
|
+ proto,
|
|
|
+ type(
|
|
|
+ 'CoinProtocol.' + proto,
|
|
|
+ (CoinProtocol.Bitcoin,),
|
|
|
+ {
|
|
|
+ 'base_coin': e.symbol,
|
|
|
+ 'addr_ver_bytes': dict(
|
|
|
+ [( num2hexstr(e.p2pkh_info[0]), 'p2pkh' )] +
|
|
|
+ ([( num2hexstr(e.p2sh_info[0]), 'p2sh' )] if e.p2sh_info else [])
|
|
|
+ ),
|
|
|
+ 'wif_ver_num': { 'std': num2hexstr(e.wif_ver_num) },
|
|
|
+ 'mmtypes': ('L','C','S') if e.has_segwit else ('L','C'),
|
|
|
+ 'dfl_mmtype': 'L',
|
|
|
+ 'mmcaps': ('key','addr'),
|
|
|
+ },
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ for e in data['mainnet']:
|
|
|
+ make_proto(e)
|
|
|
+
|
|
|
+ for e in data['testnet']:
|
|
|
+ make_proto(e,testnet=True)
|
|
|
+
|
|
|
+ for e in data['mainnet']:
|
|
|
+ if e.symbol.lower() in CoinProtocol.coins:
|
|
|
+ continue
|
|
|
+ CoinProtocol.coins[e.symbol.lower()] = CoinProtocol.proto_info(
|
|
|
+ name = 'X_'+e.name if e.name[0] in '0123456789' else e.name,
|
|
|
+ trust_level = e.trust_level )
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
quiet = '--quiet' in sys.argv
|
|
|
verbose = '--verbose' in sys.argv
|