From 02287e194d4ca2f10cfd13ffe7f8ba66b47180f9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Dec 2020 14:20:18 +1030 Subject: [PATCH] currencyrate: support multiple options for recent lightningd. Signed-off-by: Rusty Russell --- currencyrate/README.md | 3 +++ currencyrate/currencyrate.py | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/currencyrate/README.md b/currencyrate/README.md index b027189..042dae7 100644 --- a/currencyrate/README.md +++ b/currencyrate/README.md @@ -17,6 +17,9 @@ For general plugin installation instructions see the repos main would be "USD,last_trade". * --disable-source: Disable the source with this name. +For c-lightning versions 0.9.3 and above, you can specify these +options multiple times to add or disable multiple sources. + ## Commands `currencyrate` returns the number of msats per unit from every backend, eg: diff --git a/currencyrate/currencyrate.py b/currencyrate/currencyrate.py index aa48c52..0580436 100755 --- a/currencyrate/currencyrate.py +++ b/currencyrate/currencyrate.py @@ -104,16 +104,30 @@ def init(options, configuration, plugin): set_proxies(plugin) if options['add-source'] != '': - parts = options['add-source'].split(',') - sources.append(Source(parts[0], parts[1], parts[2:])) + sourceopts = options['add-source'] + # Prior to 0.9.3, 'multi' was unsupported. + if type(sourceopts) is not list: + sourceopts = [sourceopts] + for s in sourceopts: + parts = s.split(',') + sources.append(Source(parts[0], parts[1], parts[2:])) if options['disable-source'] != '': + disableopts = options['disable-source'] + # Prior to 0.9.3, 'multi' was unsupported. + if type(disableopts) is not list: + disableopts = [disableopts] for s in sources[:]: - if s.name == options['disable-source']: + if s.name in disableopts: sources.remove(s) # As a bad example: binance,https://api.binance.com/api/v3/ticker/price?symbol=BTC{currency}T,price plugin.add_option(name='add-source', default='', description='Add source name,urlformat,resultmembers...') plugin.add_option(name='disable-source', default='', description='Disable source by name') + +# This has an effect only for recent pyln versions (0.9.3+). +plugin.options['add-source']['multi'] = True +plugin.options['disable-source']['multi'] = True + plugin.run()