diff --git a/currencyrate/README.md b/currencyrate/README.md index 1de222b0d..5ad2480d2 100644 --- a/currencyrate/README.md +++ b/currencyrate/README.md @@ -1,7 +1,7 @@ # Currencyrate plugin This plugin provides Bitcoin currency conversion functions using various -different backends and taking the median. It caches results for an hour. +different backends and taking the median. It caches results for an hour. ## Installation @@ -17,8 +17,7 @@ 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. +You can specify these options multiple times to add or disable multiple sources. ## Commands @@ -27,7 +26,7 @@ options multiple times to add or disable multiple sources. ``` $ lightning-cli currencyrates USD { - "localbitcoins": "5347227msat", + "coindesk": "5347227msat", "bitstamp": "5577515msat", "coingecko": "5579273msat", } @@ -48,7 +47,6 @@ $ lightning-cli currencyconvert 100 USD Thanks to those services who provide this information. Coindesk require a blurb, so I did that for everyone (quoting from their front page): -* localbitcoins.com: "Buy and Sell Bitcoin Everywhere" * www.bitstamp.net: "The original global crypto exchange." * api.coingecko.com: "The world's most comprehensive cryptocurrency API" * api.coindesk.com: "Powered by CoinDesk: https://www.coindesk.com/price/bitcoin" diff --git a/currencyrate/currencyrate.py b/currencyrate/currencyrate.py index 31fe22320..63847e92c 100755 --- a/currencyrate/currencyrate.py +++ b/currencyrate/currencyrate.py @@ -1,12 +1,27 @@ #!/usr/bin/env python3 -from pyln.client import Plugin -from collections import namedtuple -from pyln.client import Millisatoshi -from cachetools import cached, TTLCache -from requests.adapters import HTTPAdapter -from requests.packages.urllib3.util.retry import Retry -import requests -import statistics +try: + import statistics + from collections import namedtuple + + import requests + from cachetools import TTLCache, cached + from pyln.client import Millisatoshi, Plugin + from requests.adapters import HTTPAdapter + from urllib3.util import Retry +except ModuleNotFoundError as err: + # OK, something is not installed? + import json + import sys + + getmanifest = json.loads(sys.stdin.readline()) + print( + json.dumps({ + "jsonrpc": "2.0", + "id": getmanifest["id"], + "result": {"disable": str(err)}, + }) + ) + sys.exit(1) plugin = Plugin() @@ -141,18 +156,12 @@ def init(options, configuration, plugin): set_proxies(plugin) sourceopts = options["add-source"] - # Prior to 0.9.3, 'multi' was unsupported. - if type(sourceopts) is not list: - sourceopts = [sourceopts] if sourceopts != [""]: for s in sourceopts: parts = s.split(",") sources.append(Source(parts[0], parts[1], parts[2:])) disableopts = options["disable-source"] - # Prior to 0.9.3, 'multi' was unsupported. - if type(disableopts) is not list: - disableopts = [disableopts] if disableopts != [""]: for s in sources[:]: if s.name in disableopts: @@ -164,13 +173,13 @@ def init(options, configuration, plugin): name="add-source", default="", description="Add source name,urlformat,resultmembers...", + multi=True, ) plugin.add_option( - name="disable-source", default="", description="Disable source by name" + name="disable-source", + default="", + description="Disable source by name", + multi=True, ) -# 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() diff --git a/currencyrate/requirements.txt b/currencyrate/requirements.txt index bfca3421b..156c62f6b 100644 --- a/currencyrate/requirements.txt +++ b/currencyrate/requirements.txt @@ -1,4 +1,5 @@ -pyln-client>=0.7.3 -requests>=2.10.0 -requests[socks]>=2.10.0 -cachetools +pyln-client>=23 +requests>=2.32.2 +requests[socks]>=2.32.2 +urllib3>=2.2.2 +cachetools>=5.3.3 diff --git a/currencyrate/test_currencyrate.py b/currencyrate/test_currencyrate.py index 86a72c8c2..44fc1ce2b 100644 --- a/currencyrate/test_currencyrate.py +++ b/currencyrate/test_currencyrate.py @@ -31,7 +31,7 @@ def test_currencyrate(node_factory): opts = { "plugin": plugin_path, "allow-deprecated-apis": deprecated_apis, - "disable-source": "bitstamp", + "disable-source": ["bitstamp", "coinbase"], } l1 = node_factory.get_node(options=opts) plugins = [os.path.basename(p["name"]) for p in l1.rpc.plugin("list")["plugins"]] @@ -40,6 +40,7 @@ def test_currencyrate(node_factory): rates = l1.rpc.call("currencyrates", ["USD"]) LOGGER.info(rates) assert "bitstamp" not in rates + assert "coinbase" not in rates assert "coingecko" in rates assert extract_digits(rates["coingecko"]) > 0