Browse Source

lnbase: when opening channel, test if we have enough balance first

and make sure we don't try to create the funding txn from local UTXOs
regtest_lnd
SomberNight 6 years ago
parent
commit
383897c42e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 6
      electrum/lnbase.py

6
electrum/lnbase.py

@ -394,6 +394,10 @@ class Peer(PrintError):
@log_exceptions @log_exceptions
async def channel_establishment_flow(self, password, funding_sat, push_msat, temp_channel_id): async def channel_establishment_flow(self, password, funding_sat, push_msat, temp_channel_id):
wallet = self.lnworker.wallet
# dry run creating funding tx to see if we even have enough funds
funding_tx_test = wallet.mktx([TxOutput(bitcoin.TYPE_ADDRESS, wallet.dummy_address(), funding_sat)],
password, self.lnworker.config, nonlocal_only=True)
await self.initialized await self.initialized
feerate = self.current_feerate_per_kw() feerate = self.current_feerate_per_kw()
local_config, per_commitment_secret_seed = self.make_local_config(funding_sat, push_msat, LOCAL) local_config, per_commitment_secret_seed = self.make_local_config(funding_sat, push_msat, LOCAL)
@ -454,7 +458,7 @@ class Peer(PrintError):
redeem_script = funding_output_script(local_config, remote_config) redeem_script = funding_output_script(local_config, remote_config)
funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script) funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script)
funding_output = TxOutput(bitcoin.TYPE_ADDRESS, funding_address, funding_sat) funding_output = TxOutput(bitcoin.TYPE_ADDRESS, funding_address, funding_sat)
funding_tx = self.lnworker.wallet.mktx([funding_output], password, self.lnworker.config) funding_tx = wallet.mktx([funding_output], password, self.lnworker.config, nonlocal_only=True)
funding_txid = funding_tx.txid() funding_txid = funding_tx.txid()
funding_index = funding_tx.outputs().index(funding_output) funding_index = funding_tx.outputs().index(funding_output)
# remote commitment transaction # remote commitment transaction

Loading…
Cancel
Save