Example #1
0
 def handle_unlock_wallet(self, details: str):
     if details is None:
         return
     details = details.lower()
     # The Wallet Unlocker gRPC service disappears from LND's API
     # after the wallet is unlocked (or created/recovered)
     if 'unknown service lnrpc.walletunlocker' in details:
         pass
     # User needs to create a new wallet
     elif 'wallet not found' in details:
         new_wallet_password = get_random_password()
         keyring_service_name = keyring_user_name = f'lnd_wallet_password'
         log.info('create_wallet',
                  keyring_service_name=keyring_service_name,
                  keyring_user_name=keyring_user_name)
         keyring.set_password(service=keyring_service_name,
                              username=keyring_user_name,
                              password=new_wallet_password)
         seed = self.generate_seed(new_wallet_password)
         try:
             self.node_set.lnd_client.initialize_wallet(
                 wallet_password=new_wallet_password,
                 seed=seed,
                 seed_password=new_wallet_password)
         except _Rendezvous as e:
             log.error('initialize_wallet', exc_info=True)
             # noinspection PyProtectedMember
             self.error_message.showMessage(e._state.details)
             return
         keyring.set_password(
             service=f'lnd_{self.node_set.litecoin.network}_wallet_password',
             username=self.node_set.litecoin.file['rpcuser'],
             password=new_wallet_password)
     else:
         log.warning('unlock_wallet failed', details=details, exc_info=True)
Example #2
0
 def handle_unlock_wallet(self, details: str):
     if details is None:
         return
     details = details.lower()
     # The Wallet Unlocker gRPC service disappears from LND's API
     # after the wallet is unlocked (or created/recovered)
     if 'unknown service lnrpc.walletunlocker' in details:
         pass
     # User needs to create a new wallet
     elif 'wallet not found' in details:
         new_wallet_password = get_random_password()
         keyring_service_name = keyring_user_name = f'lnd_wallet_password'
         log.info('create_wallet',
                  keyring_service_name=keyring_service_name,
                  keyring_user_name=keyring_user_name)
         keyring.set_password(service=keyring_service_name,
                              username=keyring_user_name,
                              password=new_wallet_password)
         seed = self.generate_seed(new_wallet_password)
         try:
             self.lnd.client.initialize_wallet(
                 wallet_password=new_wallet_password,
                 seed=seed,
                 seed_password=new_wallet_password)
         except _Rendezvous:
             log.error('initialize_wallet error', exc_info=True)
             raise
         keyring.set_password(service=f'lnd_mainnet_wallet_password',
                              username=self.lnd.file['bitcoind.rpcuser'],
                              password=new_wallet_password)
     else:
         log.warning('unlock_wallet failed', details=details, exc_info=True)
    def __init__(self, configuration_file_path: str):
        self.hard_drives = HardDrives()
        self.software = LitecoinSoftware()
        self.file = ConfigurationFile(configuration_file_path)
        self.running = False
        self.process = None

        if self.file['datadir'] is None:
            self.autoconfigure_datadir()

        if 'litecoin.conf' in os.listdir(self.file['datadir']):
            actual_conf_file = os.path.join(self.file['datadir'], 'litecoin.conf')
            log.info(
                'datadir_redirect',
                configuration_file_path=configuration_file_path,
                actual_conf_file=actual_conf_file
            )
            self.file = ConfigurationFile(actual_conf_file)
            if self.file['datadir'] is None:
                self.autoconfigure_datadir()

        if os.path.exists(os.path.join(self.file['datadir'], 'blocks')):
            if self.file['prune'] is None:
                self.set_prune(False)

        self.wallet_paths = self.get_wallet_paths()

        if self.file['server'] is None:
            self.file['server'] = True

        if self.file['disablewallet'] is None and not self.wallet_paths:
            self.file['disablewallet'] = True
        elif self.file['disablewallet'] is None and self.wallet_paths:
            self.file['disablewallet'] = False

        if self.file['timeout'] is None:
            self.file['timeout'] = 6000

        if self.file['rpcuser'] is None:
            self.file['rpcuser'] = '******'

        if self.file['rpcpassword'] is None:
            self.file['rpcpassword'] = get_random_password()

        if self.file['prune'] is None:
            should_prune = self.hard_drives.should_prune(self.file['datadir'], has_litecoin=True)
            self.set_prune(should_prune)

        self.zmq_block_port = get_zmq_port()
        self.zmq_tx_port = get_zmq_port()

        self.file['zmqpubrawblock'] = f'tcp://127.0.0.1:{self.zmq_block_port}'
        self.file['zmqpubrawtx'] = f'tcp://127.0.0.1:{self.zmq_tx_port}'

        # noinspection PyBroadException
        try:
            memory = psutil.virtual_memory()
            free_mb = round(memory.available / 1000000)
            free_mb -= int(free_mb * .3)
            self.file['dbcache'] = free_mb
        except:
            log.warning(
                'dbcache psutil.virtual_memory',
                exc_info=True
            )
            self.file['dbcache'] = 1000

        self.config_snapshot = self.file.snapshot.copy()
        self.file.file_watcher.fileChanged.connect(self.config_file_changed)

        self.process = QProcess()
        self.process.setProgram(self.software.litecoind)
        self.process.setCurrentReadChannel(0)
        self.process.setArguments(self.args)
        self.process.start()
Example #4
0
    def __init__(self, configuration_file_path: str):
        self.hard_drives = HardDrives()
        self.software = BitcoinSoftware()
        self.file = ConfigurationFile(configuration_file_path)
        self.running = False
        self.process = None

        if self.file['datadir'] is None:
            self.autoconfigure_datadir()

        if 'bitcoin.conf' in os.listdir(self.file['datadir']):
            actual_conf_file = os.path.join(self.file['datadir'],
                                            'bitcoin.conf')
            log.info('datadir_redirect',
                     configuration_file_path=configuration_file_path,
                     actual_conf_file=actual_conf_file)
            self.file = ConfigurationFile(actual_conf_file)
            if self.file['datadir'] is None:
                self.autoconfigure_datadir()

        self.wallet_paths = self.get_wallet_paths()

        if self.file['server'] is None:
            self.file['server'] = True

        if self.file['disablewallet'] is None and not self.wallet_paths:
            self.file['disablewallet'] = True
        elif self.file['disablewallet'] is None and self.wallet_paths:
            self.file['disablewallet'] = False

        if self.file['timeout'] is None:
            self.file['timeout'] = 6000

        if self.file['rpcuser'] is None:
            self.file['rpcuser'] = '******'

        if self.file['rpcpassword'] is None:
            self.file['rpcpassword'] = get_random_password()

        if self.file['prune'] is None:
            should_prune = self.hard_drives.should_prune(self.file['datadir'],
                                                         has_bitcoin=True)
            self.set_prune(should_prune)

        if not self.detect_zmq_ports():
            self.zmq_block_port = get_zmq_port()
            self.zmq_tx_port = get_zmq_port()

        self.file['zmqpubrawblock'] = f'tcp://127.0.0.1:{self.zmq_block_port}'
        self.file['zmqpubrawtx'] = f'tcp://127.0.0.1:{self.zmq_tx_port}'

        # noinspection PyBroadException
        try:
            memory = psutil.virtual_memory()
            free_mb = round(memory.available / 1000000)
            free_mb -= int(free_mb * .3)
            self.file['dbcache'] = free_mb
        except:
            log.warning('dbcache psutil.virtual_memory', exc_info=True)
            self.file['dbcache'] = 1000

        self.check_process()