instanciate LNWorker without Network
This commit is contained in:
@@ -64,15 +64,12 @@ encoder = ChannelJsonEncoder()
|
|||||||
|
|
||||||
class LNWorker(PrintError):
|
class LNWorker(PrintError):
|
||||||
|
|
||||||
def __init__(self, wallet: 'Abstract_Wallet', network: 'Network'):
|
def __init__(self, wallet: 'Abstract_Wallet'):
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
# invoices we are currently trying to pay (might be pending HTLCs on a commitment transaction)
|
# 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.paying = self.wallet.storage.get('lightning_payments_inflight', {}) # type: Dict[bytes, Tuple[str, Optional[int], str]]
|
||||||
self.sweep_address = wallet.get_receiving_address()
|
self.sweep_address = wallet.get_receiving_address()
|
||||||
self.network = network
|
|
||||||
self.channel_db = self.network.channel_db
|
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
self.config = network.config
|
|
||||||
self.ln_keystore = self._read_ln_keystore()
|
self.ln_keystore = self._read_ln_keystore()
|
||||||
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
|
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
|
||||||
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
||||||
@@ -80,13 +77,18 @@ class LNWorker(PrintError):
|
|||||||
self.channels = {} # type: Dict[bytes, Channel]
|
self.channels = {} # type: Dict[bytes, Channel]
|
||||||
for x in wallet.storage.get("channels", []):
|
for x in wallet.storage.get("channels", []):
|
||||||
c = Channel(x, sweep_address=self.sweep_address, payment_completed=self.payment_completed)
|
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
|
c.get_preimage_and_invoice = self.get_invoice
|
||||||
self.channels[c.channel_id] = c
|
self.channels[c.channel_id] = c
|
||||||
c.set_remote_commitment()
|
c.set_remote_commitment()
|
||||||
c.set_local_commitment(c.current_commitment(LOCAL))
|
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():
|
for chan_id, chan in self.channels.items():
|
||||||
self.network.lnwatcher.watch_channel(chan.get_funding_address(), chan.funding_outpoint.to_str())
|
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._last_tried_peer = {} # LNPeerAddr -> unix timestamp
|
||||||
self._add_peers_from_config()
|
self._add_peers_from_config()
|
||||||
# wait until we see confirmations
|
# wait until we see confirmations
|
||||||
|
|||||||
@@ -229,10 +229,11 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
if self.storage.get('wallet_type') is None:
|
if self.storage.get('wallet_type') is None:
|
||||||
self.storage.put('wallet_type', self.wallet_type)
|
self.storage.put('wallet_type', self.wallet_type)
|
||||||
|
|
||||||
|
# lightning
|
||||||
|
self.lnworker = LNWorker(self)
|
||||||
# invoices and contacts
|
# invoices and contacts
|
||||||
self.invoices = InvoiceStore(self.storage)
|
self.invoices = InvoiceStore(self.storage)
|
||||||
self.contacts = Contacts(self.storage)
|
self.contacts = Contacts(self.storage)
|
||||||
|
|
||||||
self._coin_price_cache = {}
|
self._coin_price_cache = {}
|
||||||
|
|
||||||
def stop_threads(self):
|
def stop_threads(self):
|
||||||
@@ -249,7 +250,7 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
|
|
||||||
def start_network(self, network):
|
def start_network(self, network):
|
||||||
AddressSynchronizer.start_network(self, network)
|
AddressSynchronizer.start_network(self, network)
|
||||||
self.lnworker = LNWorker(self, network)
|
self.lnworker.start_network(network)
|
||||||
|
|
||||||
def load_and_cleanup(self):
|
def load_and_cleanup(self):
|
||||||
self.load_keystore()
|
self.load_keystore()
|
||||||
|
|||||||
Reference in New Issue
Block a user