def test_set_rpcuser(bitcoind_configuration: BitcoindConfiguration): bitcoind_configuration.file['rpcuser'] = '******' changed = ConfigurationFile(bitcoind_configuration.file.path) assert changed['rpcuser'] == 'test_user' bitcoind_configuration.file['rpcuser'] = '******' changed_again = ConfigurationFile(bitcoind_configuration.file.path) assert changed_again['rpcuser'] == 'test_user_2'
def test_set_prune(bitcoind_configuration: BitcoindConfiguration): bitcoind_configuration.set_prune(True) pruned = ConfigurationFile(bitcoind_configuration.file.path) assert pruned['prune'] assert not pruned['txindex'] bitcoind_configuration.set_prune(False) unpruned = ConfigurationFile(bitcoind_configuration.file.path) assert not unpruned['prune'] assert unpruned['txindex']
def check(self): self.lnddir = LND_DIR_PATH[OPERATING_SYSTEM] # Previous versions of the launcher set lnddir in the config file, # but it is not a valid key so this helps old users upgrading if self.file['lnddir'] is not None: self.file['lnddir'] = None if self.file['debuglevel'] is None: self.file['debuglevel'] = 'info' self.file['bitcoin.active'] = True self.file['bitcoin.node'] = 'bitcoind' bitcoind_conf = BitcoindConfiguration() bitcoind_conf.load() self.file['bitcoind.rpchost'] = f'127.0.0.1:{bitcoind_conf.rpc_port}' self.file['bitcoind.rpcuser'] = bitcoind_conf.file['rpcuser'] self.file['bitcoind.rpcpass'] = bitcoind_conf.file['rpcpassword'] self.file['bitcoind.zmqpubrawblock'] = bitcoind_conf.file[ 'zmqpubrawblock'] self.file['bitcoind.zmqpubrawtx'] = bitcoind_conf.file['zmqpubrawtx'] if self.file['restlisten'] is None: self.rest_port = get_port(LND_DEFAULT_REST_PORT) self.file['restlisten'] = f'127.0.0.1:{self.rest_port}' else: self.rest_port = self.file['restlisten'].split(':')[-1] if not self.file['rpclisten']: self.grpc_port = get_port(LND_DEFAULT_GRPC_PORT) self.file['rpclisten'] = f'127.0.0.1:{self.grpc_port}' else: self.grpc_port = int(self.file['rpclisten'].split(':')[-1]) if not self.file['tlsextraip']: self.file['tlsextraip'] = '127.0.0.1' if self.file['color'] is None: self.file['color'] = '#000000' self.file['tor.active'] = True self.file['tor.v3'] = True self.file['tor.streamisolation'] = True self.macaroon_path = os.path.join(self.lnddir, 'data', 'chain', 'bitcoin', 'mainnet') self.config_snapshot = self.file.snapshot.copy() # self.file.file_watcher.fileChanged.connect(self.config_file_changed) # self.file.file_watcher.fileChanged.connect( # self.bitcoin_config_file_changed) hostname_file = os.path.join(TOR_SERVICE_PATH, 'hostname') with open(hostname_file, 'r') as f: self.file['externalip'] = f.readline().strip()
def bitcoin_config_file_changed(self): # Refresh config file self.file_watcher.blockSignals(True) self.populate_cache() self.file_watcher.blockSignals(False) bitcoind_conf = BitcoindConfiguration() bitcoind_conf.load() self['bitcoind.rpchost'] = f'127.0.0.1:{bitcoind_conf.rpc_port}' self['bitcoind.rpcuser'] = bitcoind_conf['rpcuser'] self['bitcoind.rpcpass'] = bitcoind_conf['rpcpassword'] self['bitcoind.zmqpubrawblock'] = bitcoind_conf['zmqpubrawblock'] self['bitcoind.zmqpubrawtx'] = bitcoind_conf['zmqpubrawtx']
def test_file_changed(self, bitcoind_configuration: BitcoindConfiguration): bitcoind_configuration.file['rpcport'] = 8338 bitcoind_configuration.config_file_changed() new_config = bitcoind_configuration.file.snapshot bitcoind_configuration.running = False assert bitcoind_configuration.rpc_port == new_config['rpcport'] == new_config['main.rpcport'] == 8338 assert bitcoind_configuration.restart_required == False bitcoind_configuration.running = True assert bitcoind_configuration.restart_required == True bitcoind_configuration.file['port'] = 8336 bitcoind_configuration.config_file_changed() new_config = bitcoind_configuration.file.snapshot bitcoind_configuration.running = False assert bitcoind_configuration.node_port == new_config['port'] == new_config['main.port'] == 8336 assert bitcoind_configuration.restart_required == False bitcoind_configuration.running = True assert bitcoind_configuration.restart_required == True
def bitcoind_configuration() -> BitcoindConfiguration: tmpdirname = mkdtemp() os.rmdir(tmpdirname) configuration_path = os.path.join(tmpdirname, 'bitcoin.conf') conf = BitcoindConfiguration() conf.file_path = configuration_path conf.load() conf.check() return conf