Browse Source

encapsulate funding_address_for_channel

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 7 years ago
parent
commit
bc28edf178
  1. 6
      electrum/lnhtlc.py
  2. 9
      electrum/lnwatcher.py

6
electrum/lnhtlc.py

@ -4,6 +4,7 @@ import binascii
import json
from .util import bfh, PrintError
from .bitcoin import Hash
from .bitcoin import redeem_script_to_address
from .crypto import sha256
from . import ecc
from .lnutil import Outpoint, ChannelConfig, LocalState, RemoteState, Keypair, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore
@ -12,6 +13,7 @@ from .lnutil import secret_to_pubkey, derive_privkey, derive_pubkey, derive_blin
from .lnutil import sign_and_get_sig_string
from .lnutil import make_htlc_tx_with_open_channel, make_commitment, make_received_htlc, make_offered_htlc
from .lnutil import HTLC_TIMEOUT_WEIGHT, HTLC_SUCCESS_WEIGHT
from .lnutil import funding_output_script
from contextlib import contextmanager
SettleHtlc = namedtuple("SettleHtlc", ["htlc_id"])
@ -141,6 +143,10 @@ class HTLCStateMachine(PrintError):
self.state = 'DISCONNECTED'
def get_funding_addres(self):
script = funding_output_script(self.local_config, self.remote_config)
return redeem_script_to_address('p2wsh', script)
def add_htlc(self, htlc):
"""
AddHTLC adds an HTLC to the state machine's local update log. This method

9
electrum/lnwatcher.py

@ -1,7 +1,7 @@
import threading
from .util import PrintError, bh2u, bfh, NoDynamicFeeEstimates
from .lnutil import (funding_output_script, extract_ctn_from_tx, derive_privkey,
from .lnutil import (extract_ctn_from_tx, derive_privkey,
get_per_commitment_secret_from_seed, derive_pubkey,
make_commitment_output_to_remote_address,
RevocationStore, UnableToDeriveSecret)
@ -29,7 +29,7 @@ class LNWatcher(PrintError):
return response['params'], response['result']
def watch_channel(self, chan, callback):
funding_address = funding_address_for_channel(chan)
funding_address = chan.get_funding_address()
self.watched_channels[funding_address] = chan, callback
self.network.subscribe_to_addresses([funding_address], self.on_address_status)
@ -51,9 +51,6 @@ class LNWatcher(PrintError):
callback(chan, result)
def funding_address_for_channel(chan):
script = funding_output_script(chan.local_config, chan.remote_config)
return redeem_script_to_address('p2wsh', script)
class LNChanCloseHandler(PrintError):
@ -66,7 +63,7 @@ class LNChanCloseHandler(PrintError):
self.wallet = wallet
self.chan = chan
self.lock = threading.Lock()
self.funding_address = funding_address_for_channel(chan)
self.funding_address = chan.get_funding_address()
self.watched_addresses = set()
network.register_callback(self.on_network_update, ['updated'])
self.watch_address(self.funding_address)

Loading…
Cancel
Save