add command line for rebalancing channels
This commit is contained in:
@@ -1232,6 +1232,24 @@ class Commands:
|
|||||||
""" return the local watchtower's ctn of channel. used in regtests """
|
""" return the local watchtower's ctn of channel. used in regtests """
|
||||||
return await self.network.local_watchtower.sweepstore.get_ctn(channel_point, None)
|
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')
|
@command('wnpl')
|
||||||
async def normal_swap(self, onchain_amount, lightning_amount, password=None, wallet: Abstract_Wallet = None):
|
async def normal_swap(self, onchain_amount, lightning_amount, password=None, wallet: Abstract_Wallet = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -693,6 +693,11 @@ class LNWallet(LNWorker):
|
|||||||
def get_channel_by_id(self, channel_id: bytes) -> Optional[Channel]:
|
def get_channel_by_id(self, channel_id: bytes) -> Optional[Channel]:
|
||||||
return self._channels.get(channel_id, None)
|
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):
|
def diagnostic_name(self):
|
||||||
return self.wallet.diagnostic_name()
|
return self.wallet.diagnostic_name()
|
||||||
|
|
||||||
@@ -2299,6 +2304,10 @@ class LNWallet(LNWorker):
|
|||||||
return (chan, swap_recv_amount)
|
return (chan, swap_recv_amount)
|
||||||
|
|
||||||
async def rebalance_channels(self, chan1, chan2, amount_msat):
|
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(
|
lnaddr, invoice = self.create_invoice(
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
message='rebalance',
|
message='rebalance',
|
||||||
@@ -2306,7 +2315,7 @@ class LNWallet(LNWorker):
|
|||||||
fallback_address=None,
|
fallback_address=None,
|
||||||
channels = [chan2]
|
channels = [chan2]
|
||||||
)
|
)
|
||||||
await self.pay_invoice(
|
return await self.pay_invoice(
|
||||||
invoice, channels=[chan1])
|
invoice, channels=[chan1])
|
||||||
|
|
||||||
def num_sats_can_receive_no_mpp(self) -> Decimal:
|
def num_sats_can_receive_no_mpp(self) -> Decimal:
|
||||||
|
|||||||
Reference in New Issue
Block a user