-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminus-plugin
executable file
·57 lines (40 loc) · 1.56 KB
/
terminus-plugin
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
52
53
54
55
56
57
#!/usr/bin/env python3
# Copyright (c) 2021 Moneysocket Developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php
import os
import time
import json
import logging
import datetime
from configparser import ConfigParser
from OpenSSL import SSL
from twisted.internet import reactor, ssl
from autobahn.twisted.websocket import listenWS
from pyln.client import Plugin
from moneysocket.lightning.clightning import CLightning
from terminus.log_setup import setup_logging
from terminus.app import TerminusApp
plugin = Plugin()
CLIGHTNING = CLightning(plugin)
def run_app(wallet_config_file):
config = ConfigParser()
config.read(wallet_config_file)
now = datetime.datetime.now().strftime("%y%m%d-%H.%M.%S")
logfile = os.path.join(config['App']['LogDir'], "terminus-%s.log" % now)
setup_logging(logfile, "terminus", min_level=logging.INFO)
app = TerminusApp(config, CLIGHTNING)
app.run_app()
@plugin.init()
def init(options, configuration, plugin, **kwargs):
terminus_config_file = plugin.get_option("moneysocket_terminus_config")
plugin.log("using config file %s" % os.path.abspath(terminus_config_file))
reactor.callFromThread(run_app, terminus_config_file)
DEFAULT_WALLET_CONFIG = "./moneysocket-terminus.conf"
plugin.add_option("moneysocket_terminus_config", DEFAULT_WALLET_CONFIG,
"config file to obtain settings")
def plugin_thread():
plugin.run()
reactor.callFromThread(reactor.stop)
reactor.callInThread(plugin_thread)
reactor.run()