1
0

constants: rm set_testnet/set_mainnet fns with AbstractNet.set_as_network

This commit is contained in:
SomberNight
2024-09-16 15:27:45 +00:00
parent 778aea340e
commit 1257f21b1b
11 changed files with 28 additions and 47 deletions

View File

@@ -76,6 +76,11 @@ class AbstractNet:
def rev_genesis_bytes(cls) -> bytes:
return bytes.fromhex(cls.GENESIS)[::-1]
@classmethod
def set_as_network(cls) -> None:
global net
net = cls
class BitcoinMainnet(AbstractNet):
@@ -203,27 +208,3 @@ NETS_LIST = tuple(all_subclasses(AbstractNet))
# don't import net directly, import the module instead (so that net is singleton)
net = BitcoinMainnet # type: Type[AbstractNet]
def set_signet():
global net
net = BitcoinSignet
def set_simnet():
global net
net = BitcoinSimnet
def set_mainnet():
global net
net = BitcoinMainnet
def set_testnet():
global net
net = BitcoinTestnet
def set_testnet4():
global net
net = BitcoinTestnet4
def set_regtest():
global net
net = BitcoinRegtest

View File

@@ -39,7 +39,7 @@ loop, stopping_fut, loop_thread = create_and_start_event_loop()
time.sleep(2)
if IS_TESTNET:
constants.set_testnet()
constants.BitcoinTestnet.set_as_network()
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

View File

@@ -16,7 +16,7 @@ from electrum.util import create_and_start_event_loop, log_exceptions
loop, stopping_fut, loop_thread = create_and_start_event_loop()
config = SimpleConfig({"testnet": True}) # to use ~/.electrum/testnet as datadir
constants.set_testnet() # to set testnet magic bytes
constants.BitcoinTestnet.set_as_network() # to set testnet magic bytes
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

View File

@@ -8,7 +8,7 @@ from electrum.util import create_and_start_event_loop, log_exceptions
from electrum import constants
# testnet?
#constants.set_testnet()
#constants.BitcoinTestnet.set_as_network()
config = SimpleConfig({'testnet': False})
loop, stopping_fut, loop_thread = create_and_start_event_loop()

View File

@@ -37,7 +37,7 @@ def get_newly_added_servers(fname1, fname2=None):
# testnet?
#constants.set_testnet()
#constants.BitcoinTestnet.set_as_network()
config = SimpleConfig({'testnet': False})
loop, stopping_fut, loop_thread = create_and_start_event_loop()