-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaythrough.py
executable file
·51 lines (41 loc) · 1.83 KB
/
paythrough.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
'''Pay through a specific channel
'''
from pyln.client import Plugin
from pyln.client.lightning import RpcError
plugin = Plugin()
@plugin.init()
def init(options: dict, configuration: dict, plugin: Plugin, **kwargs):
plugin.log('Plugin paythrough initialized')
return {}
@plugin.method('paythrough')
def paythrough(plugin, bolt11, scid, msatoshi=None, label=None, riskfactor=None,
maxfeepercent=None, retry_for=None, maxdelay=None,
exemptfee=None):
"""Pay a bolt11 invoice through a specific channel,
even if better/cheaper routes exist through other channels.
All parameters after scid are identical to pay except exclude. These will
all be forwarded to pay via this plugin.
"""
# Fetch the list of channels from the RPC response
channels = plugin.rpc.listpeerchannels()['channels']
# Filter out only the channels that are in 'CHANNELD_NORMAL' state
channels = list(filter(lambda channel: channel['state'] == 'CHANNELD_NORMAL', channels))
# Get the length of the filtered channels
channels_length = len(channels)
channels = list(filter(lambda channel: channel['short_channel_id'] != scid,
channels))
if len(channels) != channels_length-1: # We should have one less channel
return { 'code': -1,
'message': f'Short channel id {scid} is not valid' }
scids = list(map(lambda channel:
f"{channel['short_channel_id']}/{channel['direction']}", channels))
try:
resp = plugin.rpc.pay(bolt11=bolt11, msatoshi=msatoshi, label=label,
riskfactor=riskfactor, maxfeepercent=maxfeepercent,
retry_for=retry_for, maxdelay=maxdelay, exemptfee=exemptfee,
exclude=scids)
return resp
except RpcError as e:
return e.error
plugin.run()