retry_for: int=60, exemptfee: Millisatoshi=Millisatoshi(5000)): """Filling channel liquidity with circular payments. Percentage defaults to 100, resulting in a full channel. Chunks defaults to 0 (auto-detect). Use 'fill 10' to incease a channels total balance by 10%. """ payload = read_params('fill', scid, percentage, chunks, maxfeepercent, retry_for, exemptfee) return execute(payload) @plugin.method("setbalance") def setbalance(plugin, scid: str, percentage: float=50, chunks: int=0, maxfeepercent: float=0.5, retry_for: int=60, exemptfee: Millisatoshi=Millisatoshi(5000)): """Brings a channels own liquidity to X percent using circular payments. Percentage defaults to 50, resulting in a balanced channel. Chunks defaults to 0 (auto-detect). Use 'setbalance 100' to fill a channel. Use 'setbalance 0' to drain a channel. """ payload = read_params('setbalance', scid, percentage, chunks, maxfeepercent, retry_for, exemptfee) return execute(payload) @plugin.init() def init(options, configuration, plugin): plugin.options['cltv-final']['value'] = plugin.rpc.listconfigs().get('cltv-final') plugin.log("Plugin drain.py initialized") plugin.add_option('cltv-final', 10, 'Number of blocks for final CheckLockTimeVerify expiry') plugin.run()
labels = [p['id'], c['short_channel_id']] balance_gauge.add_metric(labels, c['to_us_msat'].to_satoshi()) spendable_gauge.add_metric(labels, c['spendable_msat'].to_satoshi()) total_gauge.add_metric(labels, c['total_msat'].to_satoshi()) htlc_gauge.add_metric(labels, len(c['htlcs'])) return [htlc_gauge, total_gauge, spendable_gauge, balance_gauge] @plugin.init() def init(options, configuration, plugin): s = options['prometheus-listen'].rpartition(':') if len(s) != 3 or s[1] != ':': print("Could not parse prometheus-listen address") exit(1) ip, port = s[0], int(s[2]) registry = CollectorRegistry() start_http_server(addr=ip, port=port, registry=registry) registry.register(NodeCollector(plugin.rpc, registry)) registry.register(FundsCollector(plugin.rpc, registry)) registry.register(PeerCollector(plugin.rpc, registry)) registry.register(ChannelsCollector(plugin.rpc, registry)) plugin.add_option('prometheus-listen', '0.0.0.0:9900', 'Address and port to bind to') plugin.run()
def hello(plugin, name="world"): """This is the documentation string for the hello-function. It gets reported as the description when registering the function as a method with `lightningd`. """ greeting = plugin.get_option('greeting') s = '{} {}'.format(greeting, name) plugin.log(s) return s @plugin.method("init") def init(options, configuration, plugin): plugin.log("Plugin helloworld.py initialized") @plugin.subscribe("connect") def on_connect(plugin, id, address): plugin.log("Received connect event for peer {}".format(id)) @plugin.subscribe("disconnect") def on_disconnect(plugin, id): plugin.log("Received disconnect event for peer {}".format(id)) plugin.add_option('greeting', 'Hello', 'The greeting I should use.') plugin.run()
# Schedule the next run heapq.heappush(next_runs, (time() + n[2], n[1], n[2])) @plugin.init() def init(configuration, options, plugin): plugin.probe_interval = int(options['probe-interval']) plugin.probe_exclusion_duration = int(options['probe-exclusion-duration']) db_filename = 'sqlite:///' + os.path.join(configuration['lightning-dir'], 'probes.db') engine = create_engine(db_filename, echo=True) Base.metadata.create_all(engine) plugin.Session = sessionmaker() plugin.Session.configure(bind=engine) t = threading.Thread(target=schedule, args=[plugin]) t.daemon = True t.start() # Probes that are still pending and need to be checked against. plugin.pending_probes = [] plugin.add_option('probe-interval', '3600', 'How many seconds should we wait between probes?') plugin.add_option( 'probe-exclusion-duration', '1800', 'How many seconds should temporarily failed channels be excluded?') plugin.run()
# Prefer IPv4, otherwise take any to give out address. best_address = None for a in info['address']: if best_address is None: best_address = a elif a['type'] == 'ipv4' and best_address['type'] != 'ipv4': best_address = a if best_address: plugin.my_address = info['id'] + '@' + best_address['address'] if best_address['port'] != 9735: plugin.my_address += ':' + str(best_address['port']) else: plugin.my_address = None plugin.log("Plugin summary.py initialized") plugin.add_option( 'summary-currency', 'USD', 'What currency should I look up on btcaverage?' ) plugin.add_option( 'summary-currency-prefix', 'USD $', 'What prefix to use for currency' ) plugin.run()
'%Y-%m-%d %H:%M:%S (UTC)') entry['resolved_time'] = forward['resolved_time'] entry['timestamp'] = time_str result.append(entry) return result @plugin.init() def init(options, configuration, plugin): plugin.options['cltv-final']['value'] = plugin.rpc.listconfigs().get( 'cltv-final') plugin.options['fee-base']['value'] = plugin.rpc.listconfigs().get( 'fee-base') plugin.options['fee-per-satoshi']['value'] = plugin.rpc.listconfigs().get( 'fee-per-satoshi') plugin.log("Plugin sendinvoiceless.py initialized") plugin.add_option('cltv-final', 10, 'Number of blocks for final CheckLockTimeVerify expiry') plugin.add_option( 'fee-base', None, 'The routing base fee in msat. Will be derived automatically via rpc.listconfigs()' ) plugin.add_option( 'fee-per-satoshi', None, 'The routing fee ppm. Will be derived automatically via rpc.listconfigs()') plugin.run()
if stop_server(port): return "stopped server on port{}".format(port) else: return "could not stop the server" if command == "restart": stop_server(port) suc = start_server(port) if suc: return "started server successfully on port {}".format(port) else: return "Could not start server on port {}".format(port) plugin.add_option( 'donation-autostart', 'true', 'Should the donation server start automatically' ) plugin.add_option( 'donation-web-port', '33506', 'Which port should the donation server listen to?' ) @plugin.init() def init(options, configuration, plugin): port = int(options['donation-web-port']) if options['donation-autostart'].lower() in ['true', '1']:
#!/usr/bin/env python3 """Simple plugin to allow testing while closing of HTLC is delayed. """ from lightning import Plugin import time plugin = Plugin() @plugin.hook('invoice_payment') def on_payment(payment, plugin): time.sleep(float(plugin.get_option('holdtime'))) return {} plugin.add_option('holdtime', '10', 'The time to hold invoice for.') plugin.run()
for c in plugin.sqlite_pre_init_cmds: plugin.conn.execute(c) plugin.log("{}".format(c)) plugin.conn.execute("COMMIT;") plugin.initted = True plugin.log("initialized {}".format(configuration)) @plugin.hook('db_write') def db_write(plugin, writes, **kwargs): if not plugin.initted: plugin.log("deferring {} commands".format(len(writes))) plugin.sqlite_pre_init_cmds += writes else: print(writes) plugin.conn.execute("BEGIN TRANSACTION;") for c in writes: plugin.conn.execute(c) plugin.log("{}".format(c)) plugin.conn.execute("COMMIT;") return True plugin.add_option('dblog-file', None, 'The db file to create.') plugin.run()
def hello(plugin, name="world"): """This is the documentation string for the hello-function. It gets reported as the description when registering the function as a method with `lightningd`. """ greeting = plugin.get_option('greeting') s = '{} {}'.format(greeting, name) plugin.log(s) return s @plugin.init() def init(options, configuration, plugin): plugin.log("Plugin helloworld.py initialized") @plugin.subscribe("connect") def on_connect(plugin, id, address): plugin.log("Received connect event for peer {}".format(id)) @plugin.subscribe("disconnect") def on_disconnect(plugin, id): plugin.log("Received disconnect event for peer {}".format(id)) plugin.add_option('greeting', 'Hello', 'The greeting I should use.') plugin.run()
#!/usr/bin/env python3 """This plugin is used to check that plugin options are parsed properly. The plugin offers 3 options, one of each supported type. """ from lightning import Plugin plugin = Plugin() @plugin.init() def init(configuration, options, plugin): for name, val in options.items(): plugin.log("option {} {} {}".format(name, val, type(val))) plugin.add_option('str_opt', 'i am a string', 'an example string option') plugin.add_option('int_opt', 7, 'an example int type option', opt_type='int') plugin.add_option('bool_opt', True, 'an example bool type option', opt_type='bool') plugin.run()
# Each channel will have this capacity channel_capacity = math.floor(available_funds / num_channels) print("I'd like to open {} new channels with {} satoshis each".format(num_channels, channel_capacity)) candidates = plugin.autopilot.find_candidates( num_channels, strategy=Strategy.DIVERSE, percentile=0.5 ) plugin.autopilot.connect(candidates, available_funds, dryrun=dryrun) plugin.add_option( 'autopilot-percent', '75', 'What percentage of funds should be under the autopilots control?' ) plugin.add_option( 'autopilot-num-channels', '10', 'How many channels should the autopilot aim for?' ) plugin.add_option( 'autopilot-min-channel-size-msat', '100000000', 'Minimum channel size to open.',
# reload since we need to start it to pass through its manifest before we get # any cli options. So we're doomed to get our parent cmdline and parse out the # argument by hand. parent = psutil.Process().parent() cmdline = parent.cmdline() plugin.path = None prefix = '--autoreload-plugin=' for c in cmdline: if c.startswith(prefix): plugin.path = c[len(prefix):] break if plugin.path: plugin.child = ChildPlugin(plugin.path, plugin) # If we can't start on the first attempt we can't inject into the # manifest, no point in continuing. if not plugin.child.start(): raise Exception( "Could not start the plugin under development, can't continue") inject_manifest(plugin, plugin.child.manifest) # Now we can run the actual plugin plugin.add_option( "autoreload-plugin", None, "Path to the plugin that we should be watching and reloading.") plugin.run()
@plugin.init() def init(configuration, options, plugin): if not plugin.get_option('dblog-file'): raise RpcError("No dblog-file specified") plugin.conn = sqlite3.connect(plugin.get_option('dblog-file'), isolation_level=None) plugin.log("replaying pre-init data:") for c in plugin.sqlite_pre_init_cmds: plugin.conn.execute(c) plugin.log("{}".format(c)) plugin.initted = True plugin.log("initialized") @plugin.hook('db_write') def db_write(plugin, writes): if not plugin.initted: plugin.log("deferring {} commands".format(len(writes))) plugin.sqlite_pre_init_cmds += writes else: for c in writes: plugin.conn.execute(c) plugin.log("{}".format(c)) return True plugin.add_option('dblog-file', None, 'The db file to create.') plugin.run()