init_proto(): remove testnet and regtest params
This commit is contained in:
parent
99b9081640
commit
1356325bf4
10 changed files with 16 additions and 25 deletions
|
|
@ -288,7 +288,7 @@ def make_proto(e, *, testnet=False):
|
|||
'dfl_mmtype': 'L',
|
||||
'mmcaps': ()}))
|
||||
|
||||
def init_genonly_altcoins(usr_coin=None, *, testnet=False):
|
||||
def init_genonly_altcoins(usr_coin=None, *, network=None):
|
||||
"""
|
||||
Initialize altcoin protocol class or classes for current network.
|
||||
If usr_coin is a core coin, initialization is skipped.
|
||||
|
|
@ -298,8 +298,8 @@ def init_genonly_altcoins(usr_coin=None, *, testnet=False):
|
|||
"""
|
||||
|
||||
data = {'mainnet': (), 'testnet': ()}
|
||||
networks = ['mainnet'] + (['testnet'] if testnet else [])
|
||||
network = 'testnet' if testnet else 'mainnet'
|
||||
network = 'testnet' if network in ('testnet', 'regtest') else 'mainnet'
|
||||
networks = ['mainnet'] + (['testnet'] if network == 'testnet' else [])
|
||||
|
||||
if usr_coin is None:
|
||||
for network in networks:
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class Autosign:
|
|||
async def check_daemons_running(self):
|
||||
from ..protocol import init_proto
|
||||
for coin in self.coins:
|
||||
proto = init_proto(self.cfg, coin, network=self.cfg.network, need_amt=True)
|
||||
proto = init_proto(self.cfg, coin, need_amt=True)
|
||||
if proto.sign_mode == 'daemon':
|
||||
self.cfg._util.vmsg(f'Checking {coin} daemon')
|
||||
from ..rpc import rpc_init
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class MMGenRegtest(MMGenObject):
|
|||
|
||||
assert self.coin in self.coins, f'{coin!r}: invalid coin for regtest'
|
||||
|
||||
self.proto = init_proto(cfg, self.coin, regtest=True, need_amt=True)
|
||||
self.proto = init_proto(cfg, self.coin, network='regtest', need_amt=True)
|
||||
self.d = CoinDaemon(
|
||||
cfg,
|
||||
network_id = self.coin + '_rt',
|
||||
|
|
@ -305,7 +305,7 @@ class MMGenRegtest(MMGenObject):
|
|||
|
||||
async def fork(self, coin): # currently disabled
|
||||
|
||||
proto = init_proto(self.cfg, coin, testnet=False)
|
||||
proto = init_proto(self.cfg, coin)
|
||||
if not [f for f in proto.forks if f[2] == proto.coin.lower() and f[3] is True]:
|
||||
die(1, f'Coin {proto.coin} is not a replayable fork of coin {coin}')
|
||||
|
||||
|
|
|
|||
|
|
@ -301,33 +301,27 @@ def init_proto(
|
|||
cfg,
|
||||
coin = None,
|
||||
*,
|
||||
testnet = False,
|
||||
regtest = False,
|
||||
network = None,
|
||||
network_id = None,
|
||||
tokensym = None,
|
||||
need_amt = False,
|
||||
return_cls = False):
|
||||
|
||||
assert type(testnet) is bool, 'init_proto_chk1'
|
||||
assert type(regtest) is bool, 'init_proto_chk2'
|
||||
assert coin or network_id, 'init_proto_chk3'
|
||||
assert not (coin and network_id), 'init_proto_chk4'
|
||||
assert coin or network_id, 'init_proto_chk1'
|
||||
assert not (coin and network_id), 'init_proto_chk2'
|
||||
|
||||
if network_id:
|
||||
coin, network = CoinProtocol.Base.parse_network_id(network_id)
|
||||
elif network:
|
||||
assert network in CoinProtocol.Base.networks, f'init_proto_chk5 - {network!r}: invalid network'
|
||||
assert testnet is False, 'init_proto_chk6'
|
||||
assert regtest is False, 'init_proto_chk7'
|
||||
assert network in CoinProtocol.Base.networks, f'init_proto_chk3 - {network!r}: invalid network'
|
||||
else:
|
||||
network = 'regtest' if regtest else 'testnet' if testnet else 'mainnet'
|
||||
network = cfg.network
|
||||
|
||||
coin = coin.lower()
|
||||
|
||||
if coin not in CoinProtocol.coins:
|
||||
from .altcoin.params import init_genonly_altcoins
|
||||
init_genonly_altcoins(coin, testnet=testnet) # raises exception on failure
|
||||
init_genonly_altcoins(coin, network=network) # raises exception on failure
|
||||
|
||||
name = CoinProtocol.coins[coin].name
|
||||
proto_name = name + ('' if network == 'mainnet' else network.capitalize())
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ class Thornode:
|
|||
def __init__(self, tx, amt):
|
||||
self.tx = tx
|
||||
self.in_amt = UniAmt(f'{amt:.8f}')
|
||||
proto = init_proto(tx.cfg, 'rune', network=tx.cfg._proto.network)
|
||||
self.rpc = ThornodeSwapClient(tx.cfg, proto)
|
||||
self.rpc = ThornodeSwapClient(tx.cfg, init_proto(tx.cfg, 'rune'))
|
||||
|
||||
def get_quote(self, swap_cfg):
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,5 @@ def init_swap_proto(cfg, asset):
|
|||
return init_proto(
|
||||
cfg,
|
||||
asset.coin,
|
||||
network = cfg._proto.network,
|
||||
tokensym = asset.tokensym,
|
||||
need_amt = True)
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ class Base(MMGenObject):
|
|||
async def check_swap_network(self):
|
||||
from ..protocol import init_proto
|
||||
from ..rpc import rpc_init
|
||||
proto = init_proto(self.cfg, self.swap_proto_mod.coin, network=self.cfg.network)
|
||||
proto = init_proto(self.cfg, self.swap_proto_mod.coin)
|
||||
rpc = await rpc_init(self.cfg, proto)
|
||||
data = rpc.inbound_addrs()
|
||||
for asset in (self.send_asset, self.recv_asset):
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ class Completed(Base):
|
|||
proto = init_proto(
|
||||
self.cfg,
|
||||
r.coin,
|
||||
network = self.cfg.network,
|
||||
tokensym = r.tokensym,
|
||||
need_amt = True)
|
||||
if mmid := getattr(self, 'swap_recv_addr_mmid', None):
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class OpBase:
|
|||
|
||||
hdr_addr_width = 95 if self.cfg.full_address else short_addr_width
|
||||
|
||||
self.proto = init_proto(cfg, 'xmr', network=self.cfg.network, need_amt=True)
|
||||
self.proto = init_proto(cfg, 'xmr', need_amt=True)
|
||||
|
||||
id_cur = None
|
||||
for cls in classes:
|
||||
|
|
|
|||
|
|
@ -476,12 +476,12 @@ def dump_test(proto, kg, ag, filename):
|
|||
|
||||
def get_protos(proto, addr_type, toolname):
|
||||
|
||||
init_genonly_altcoins(testnet=proto.testnet)
|
||||
init_genonly_altcoins(network=proto.network)
|
||||
|
||||
for coin in cinfo.external_tests[proto.network][toolname]:
|
||||
if coin.lower() not in CoinProtocol.coins:
|
||||
continue
|
||||
ret = init_proto(cfg, coin, testnet=proto.testnet)
|
||||
ret = init_proto(cfg, coin, network=proto.network)
|
||||
if addr_type not in ret.mmtypes:
|
||||
continue
|
||||
yield ret
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue