Browse Source

instanciate LNWorker without Network

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
e6d680ec1b
  1. 12
      electrum/lnworker.py
  2. 5
      electrum/wallet.py

12
electrum/lnworker.py

@ -64,15 +64,12 @@ encoder = ChannelJsonEncoder()
class LNWorker(PrintError):
def __init__(self, wallet: 'Abstract_Wallet', network: 'Network'):
def __init__(self, wallet: 'Abstract_Wallet'):
self.wallet = wallet
# invoices we are currently trying to pay (might be pending HTLCs on a commitment transaction)
self.paying = self.wallet.storage.get('lightning_payments_inflight', {}) # type: Dict[bytes, Tuple[str, Optional[int], str]]
self.sweep_address = wallet.get_receiving_address()
self.network = network
self.channel_db = self.network.channel_db
self.lock = threading.RLock()
self.config = network.config
self.ln_keystore = self._read_ln_keystore()
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
@ -80,13 +77,18 @@ class LNWorker(PrintError):
self.channels = {} # type: Dict[bytes, Channel]
for x in wallet.storage.get("channels", []):
c = Channel(x, sweep_address=self.sweep_address, payment_completed=self.payment_completed)
c.lnwatcher = network.lnwatcher
c.get_preimage_and_invoice = self.get_invoice
self.channels[c.channel_id] = c
c.set_remote_commitment()
c.set_local_commitment(c.current_commitment(LOCAL))
def start_network(self, network: 'Network'):
self.network = network
self.config = network.config
self.channel_db = self.network.channel_db
for chan_id, chan in self.channels.items():
self.network.lnwatcher.watch_channel(chan.get_funding_address(), chan.funding_outpoint.to_str())
chan.lnwatcher = network.lnwatcher
self._last_tried_peer = {} # LNPeerAddr -> unix timestamp
self._add_peers_from_config()
# wait until we see confirmations

5
electrum/wallet.py

@ -229,10 +229,11 @@ class Abstract_Wallet(AddressSynchronizer):
if self.storage.get('wallet_type') is None:
self.storage.put('wallet_type', self.wallet_type)
# lightning
self.lnworker = LNWorker(self)
# invoices and contacts
self.invoices = InvoiceStore(self.storage)
self.contacts = Contacts(self.storage)
self._coin_price_cache = {}
def stop_threads(self):
@ -249,7 +250,7 @@ class Abstract_Wallet(AddressSynchronizer):
def start_network(self, network):
AddressSynchronizer.start_network(self, network)
self.lnworker = LNWorker(self, network)
self.lnworker.start_network(network)
def load_and_cleanup(self):
self.load_keystore()

Loading…
Cancel
Save