Skip to content

Commit 13cec86

Browse files
daywalker90chrisguida
authored andcommitted
currencyrate: general update and fixes for upstream options compat
1 parent 90ec46e commit 13cec86

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

currencyrate/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Currencyrate plugin
22

33
This plugin provides Bitcoin currency conversion functions using various
4-
different backends and taking the median. It caches results for an hour.
4+
different backends and taking the median. It caches results for an hour.
55

66
## Installation
77

@@ -17,8 +17,7 @@ For general plugin installation instructions see the repos main
1717
would be "USD,last_trade".
1818
* --disable-source: Disable the source with this name.
1919

20-
For c-lightning versions 0.9.3 and above, you can specify these
21-
options multiple times to add or disable multiple sources.
20+
You can specify these options multiple times to add or disable multiple sources.
2221

2322
## Commands
2423

@@ -27,7 +26,7 @@ options multiple times to add or disable multiple sources.
2726
```
2827
$ lightning-cli currencyrates USD
2928
{
30-
"localbitcoins": "5347227msat",
29+
"coindesk": "5347227msat",
3130
"bitstamp": "5577515msat",
3231
"coingecko": "5579273msat",
3332
}
@@ -48,7 +47,6 @@ $ lightning-cli currencyconvert 100 USD
4847
Thanks to those services who provide this information. Coindesk require
4948
a blurb, so I did that for everyone (quoting from their front page):
5049

51-
* localbitcoins.com: "Buy and Sell Bitcoin Everywhere"
5250
* www.bitstamp.net: "The original global crypto exchange."
5351
* api.coingecko.com: "The world's most comprehensive cryptocurrency API"
5452
* api.coindesk.com: "Powered by CoinDesk: https://www.coindesk.com/price/bitcoin"

currencyrate/currencyrate.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
#!/usr/bin/env python3
2-
from pyln.client import Plugin
3-
from collections import namedtuple
4-
from pyln.client import Millisatoshi
5-
from cachetools import cached, TTLCache
6-
from requests.adapters import HTTPAdapter
7-
from requests.packages.urllib3.util.retry import Retry
8-
import requests
9-
import statistics
2+
try:
3+
import statistics
4+
from collections import namedtuple
5+
6+
import requests
7+
from cachetools import TTLCache, cached
8+
from pyln.client import Millisatoshi, Plugin
9+
from requests.adapters import HTTPAdapter
10+
from urllib3.util import Retry
11+
except ModuleNotFoundError as err:
12+
# OK, something is not installed?
13+
import json
14+
import sys
15+
16+
getmanifest = json.loads(sys.stdin.readline())
17+
print(
18+
json.dumps({
19+
"jsonrpc": "2.0",
20+
"id": getmanifest["id"],
21+
"result": {"disable": str(err)},
22+
})
23+
)
24+
sys.exit(1)
1025

1126
plugin = Plugin()
1227

@@ -141,18 +156,12 @@ def init(options, configuration, plugin):
141156
set_proxies(plugin)
142157

143158
sourceopts = options["add-source"]
144-
# Prior to 0.9.3, 'multi' was unsupported.
145-
if type(sourceopts) is not list:
146-
sourceopts = [sourceopts]
147159
if sourceopts != [""]:
148160
for s in sourceopts:
149161
parts = s.split(",")
150162
sources.append(Source(parts[0], parts[1], parts[2:]))
151163

152164
disableopts = options["disable-source"]
153-
# Prior to 0.9.3, 'multi' was unsupported.
154-
if type(disableopts) is not list:
155-
disableopts = [disableopts]
156165
if disableopts != [""]:
157166
for s in sources[:]:
158167
if s.name in disableopts:
@@ -164,13 +173,13 @@ def init(options, configuration, plugin):
164173
name="add-source",
165174
default="",
166175
description="Add source name,urlformat,resultmembers...",
176+
multi=True,
167177
)
168178
plugin.add_option(
169-
name="disable-source", default="", description="Disable source by name"
179+
name="disable-source",
180+
default="",
181+
description="Disable source by name",
182+
multi=True,
170183
)
171184

172-
# This has an effect only for recent pyln versions (0.9.3+).
173-
plugin.options["add-source"]["multi"] = True
174-
plugin.options["disable-source"]["multi"] = True
175-
176185
plugin.run()

currencyrate/requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pyln-client>=0.7.3
2-
requests>=2.10.0
3-
requests[socks]>=2.10.0
4-
cachetools
1+
pyln-client>=23
2+
requests>=2.32.2
3+
requests[socks]>=2.32.2
4+
urllib3>=2.2.2
5+
cachetools>=5.3.3

currencyrate/test_currencyrate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_currencyrate(node_factory):
3131
opts = {
3232
"plugin": plugin_path,
3333
"allow-deprecated-apis": deprecated_apis,
34-
"disable-source": "bitstamp",
34+
"disable-source": ["bitstamp", "coinbase"],
3535
}
3636
l1 = node_factory.get_node(options=opts)
3737
plugins = [os.path.basename(p["name"]) for p in l1.rpc.plugin("list")["plugins"]]
@@ -40,6 +40,7 @@ def test_currencyrate(node_factory):
4040
rates = l1.rpc.call("currencyrates", ["USD"])
4141
LOGGER.info(rates)
4242
assert "bitstamp" not in rates
43+
assert "coinbase" not in rates
4344
assert "coingecko" in rates
4445
assert extract_digits(rates["coingecko"]) > 0
4546

0 commit comments

Comments
 (0)