示例#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)
         self.keyring.set_password(service=keyring_service_name,
                                   username=keyring_user_name,
                                   password=new_wallet_password)
         seed = self.generate_seed(new_wallet_password)
         try:
             self.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
         self.keyring.set_password(
             service=f'lnd_mainnet_wallet_password',
             username=self.configuration['bitcoind.rpcuser'],
             password=new_wallet_password)
     else:
         log.warning('unlock_wallet failed', details=details, exc_info=True)
    def check(self):
        log.debug('datadir', datadir=self['datadir'])

        if (self['datadir'] is None or not os.path.exists(self['datadir'])):
            self.autoconfigure_datadir()

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

        self.wallet_paths = self.get_wallet_paths()

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

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

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

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

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

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

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

        self['proxy'] = '127.0.0.1:9050'
        self['listen'] = True
        self['bind'] = '127.0.0.1'
        self['debug'] = 'tor'
        self['discover'] = True

        # noinspection PyBroadException
        try:
            memory = psutil.virtual_memory()
            free_mb = round(memory.available / 1000000)
            free_mb -= int(free_mb * .3)
            if 'dbcache' in self:
                del self['dbcache']
            self['dbcache'] = min(free_mb, 10000)
            self['maxmempool'] = 500
            self['mempoolexpiry'] = 2000
        except:
            log.warning('dbcache psutil.virtual_memory', exc_info=True)
            self['dbcache'] = 1000
    def check(self):
        log.debug('datadir', datadir=self.file['datadir'])

        if (self.file['datadir'] is None
                or not os.path.exists(self.file['datadir'])):
            self.autoconfigure_datadir()

        if 'bitcoin.conf' in os.listdir(self.file['datadir']):
            actual_conf_file = os.path.join(self.file['datadir'],
                                            'bitcoin.conf')
            if self.file_path != actual_conf_file:
                log.info('datadir_redirect',
                         configuration_file_path=self.file_path,
                         actual_conf_file=actual_conf_file)
                self.file = ConfigurationFile(actual_conf_file)
                if (self.file['datadir'] is None
                        or not os.path.exists(self.file['datadir'])):
                    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_bitcoin=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}'

        self.file['proxy'] = '127.0.0.1:9050'
        self.file['listen'] = True
        self.file['bind'] = '127.0.0.1'
        self.file['debug'] = 'tor'
        self.file['discover'] = True

        # 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()