-
Notifications
You must be signed in to change notification settings - Fork 1
/
zero-conf-cln.py
executable file
·51 lines (36 loc) · 1.28 KB
/
zero-conf-cln.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
"""Use the openchannel hook to selectively opt-into zeroconf
"""
import sys
from pyln.client import Plugin
plugin = Plugin()
@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin, **kwargs):
plugin.log(repr(openchannel))
mindepth = plugin.zeroconf_mindepth
if openchannel['id'] == plugin.zeroconf_allow_peer:
plugin.log(f"This peer is in the zeroconf allowlist, setting mindepth={mindepth}")
return {'result': 'continue', 'mindepth': mindepth}
else:
return {'result': 'continue'}
plugin.add_option(
'zeroconf-allow',
None,
'A node_id to allow zeroconf channels from',
)
plugin.add_option(
'zeroconf-mindepth',
0,
'Number of confirmations to require from allowlisted peers',
)
@plugin.init()
def init(options, configuration, plugin):
plugin.log(f"initializing with configuration: {configuration}")
plugin.log(f"initializing with options: {options}")
plugin.zeroconf_mindepth = int(plugin.get_option('zeroconf-mindepth'))
plugin.zeroconf_allow_peer = plugin.get_option('zeroconf-allow')
if plugin.zeroconf_allow_peer is None:
error_msg = "init: option zeroconf-allow is not set"
plugin.log(error_msg, level="error")
sys.exit(error_msg)
plugin.run()