Browse Source

add command line for rebalancing channels

patch-4
ThomasV 3 years ago
parent
commit
f5abd4f1d1
  1. 18
      electrum/commands.py
  2. 11
      electrum/lnworker.py

18
electrum/commands.py

@ -1232,6 +1232,24 @@ class Commands:
""" return the local watchtower's ctn of channel. used in regtests """
return await self.network.local_watchtower.sweepstore.get_ctn(channel_point, None)
@command('wnl')
async def rebalance_channels(self, from_scid, dest_scid, amount, wallet: Abstract_Wallet = None):
"""
Rebalance channels.
If trampoline is used, channels must be with diferent trampolines.
"""
from .lnutil import ShortChannelID
from_scid = ShortChannelID.from_str(from_scid)
dest_scid = ShortChannelID.from_str(dest_scid)
from_channel = wallet.lnworker.get_channel_by_scid(from_scid)
dest_channel = wallet.lnworker.get_channel_by_scid(dest_scid)
amount_sat = satoshis(amount)
success, log = await wallet.lnworker.rebalance_channels(from_channel, dest_channel, amount_sat * 1000)
return {
'success': success,
'log': [x.formatted_tuple() for x in log]
}
@command('wnpl')
async def normal_swap(self, onchain_amount, lightning_amount, password=None, wallet: Abstract_Wallet = None):
"""

11
electrum/lnworker.py

@ -693,6 +693,11 @@ class LNWallet(LNWorker):
def get_channel_by_id(self, channel_id: bytes) -> Optional[Channel]:
return self._channels.get(channel_id, None)
def get_channel_by_scid(self, scid: bytes) -> Optional[Channel]:
for chan in self._channels.values():
if chan.short_channel_id == scid:
return chan
def diagnostic_name(self):
return self.wallet.diagnostic_name()
@ -2299,6 +2304,10 @@ class LNWallet(LNWorker):
return (chan, swap_recv_amount)
async def rebalance_channels(self, chan1, chan2, amount_msat):
if chan1 == chan2:
raise Exception('Rebalance requires two different channels')
if not self.channel_db and chan1.node_id == chan2.node_id:
raise Exception('Rebalance requires channels from different trampolines')
lnaddr, invoice = self.create_invoice(
amount_msat=amount_msat,
message='rebalance',
@ -2306,7 +2315,7 @@ class LNWallet(LNWorker):
fallback_address=None,
channels = [chan2]
)
await self.pay_invoice(
return await self.pay_invoice(
invoice, channels=[chan1])
def num_sats_can_receive_no_mpp(self) -> Decimal:

Loading…
Cancel
Save