encapsulate funding_address_for_channel
This commit is contained in:
@@ -4,6 +4,7 @@ import binascii
|
|||||||
import json
|
import json
|
||||||
from .util import bfh, PrintError
|
from .util import bfh, PrintError
|
||||||
from .bitcoin import Hash
|
from .bitcoin import Hash
|
||||||
|
from .bitcoin import redeem_script_to_address
|
||||||
from .crypto import sha256
|
from .crypto import sha256
|
||||||
from . import ecc
|
from . import ecc
|
||||||
from .lnutil import Outpoint, ChannelConfig, LocalState, RemoteState, Keypair, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore
|
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 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 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 HTLC_TIMEOUT_WEIGHT, HTLC_SUCCESS_WEIGHT
|
||||||
|
from .lnutil import funding_output_script
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
SettleHtlc = namedtuple("SettleHtlc", ["htlc_id"])
|
SettleHtlc = namedtuple("SettleHtlc", ["htlc_id"])
|
||||||
@@ -141,6 +143,10 @@ class HTLCStateMachine(PrintError):
|
|||||||
|
|
||||||
self.state = 'DISCONNECTED'
|
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):
|
def add_htlc(self, htlc):
|
||||||
"""
|
"""
|
||||||
AddHTLC adds an HTLC to the state machine's local update log. This method
|
AddHTLC adds an HTLC to the state machine's local update log. This method
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
from .util import PrintError, bh2u, bfh, NoDynamicFeeEstimates
|
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,
|
get_per_commitment_secret_from_seed, derive_pubkey,
|
||||||
make_commitment_output_to_remote_address,
|
make_commitment_output_to_remote_address,
|
||||||
RevocationStore, UnableToDeriveSecret)
|
RevocationStore, UnableToDeriveSecret)
|
||||||
@@ -29,7 +29,7 @@ class LNWatcher(PrintError):
|
|||||||
return response['params'], response['result']
|
return response['params'], response['result']
|
||||||
|
|
||||||
def watch_channel(self, chan, callback):
|
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.watched_channels[funding_address] = chan, callback
|
||||||
self.network.subscribe_to_addresses([funding_address], self.on_address_status)
|
self.network.subscribe_to_addresses([funding_address], self.on_address_status)
|
||||||
|
|
||||||
@@ -51,9 +51,6 @@ class LNWatcher(PrintError):
|
|||||||
callback(chan, result)
|
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):
|
class LNChanCloseHandler(PrintError):
|
||||||
@@ -66,7 +63,7 @@ class LNChanCloseHandler(PrintError):
|
|||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.chan = chan
|
self.chan = chan
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.funding_address = funding_address_for_channel(chan)
|
self.funding_address = chan.get_funding_address()
|
||||||
self.watched_addresses = set()
|
self.watched_addresses = set()
|
||||||
network.register_callback(self.on_network_update, ['updated'])
|
network.register_callback(self.on_network_update, ['updated'])
|
||||||
self.watch_address(self.funding_address)
|
self.watch_address(self.funding_address)
|
||||||
|
|||||||
Reference in New Issue
Block a user